Remove #defines in cpdf_textpage.h.

Inline most of them, as they, e.g. L'\n', are well known. Along the way,
add a new constant in cpdf_textpagefind.cpp for the value 160, which is
not so well known.

Change-Id: Id95459ac3a62f76457bd8199f419d3429509d405
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65570
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index b3be585..81519a1 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -121,11 +121,11 @@
   while (pos < nTotalChar) {
     const CPDF_TextPage::CharInfo& char_info = m_pTextPage->GetCharInfo(pos);
     if (char_info.m_CharType != CPDF_TextPage::CharType::kGenerated &&
-        char_info.m_Unicode != TEXT_SPACE_CHAR && pos != nTotalChar - 1) {
+        char_info.m_Unicode != L' ' && pos != nTotalChar - 1) {
       bAfterHyphen =
           (char_info.m_CharType == CPDF_TextPage::CharType::kHyphen ||
            (char_info.m_CharType == CPDF_TextPage::CharType::kNormal &&
-            char_info.m_Unicode == TEXT_HYPHEN_CHAR));
+            char_info.m_Unicode == L'-'));
       ++pos;
       continue;
     }
@@ -133,8 +133,8 @@
     int nCount = pos - start;
     if (pos == nTotalChar - 1) {
       ++nCount;
-    } else if (bAfterHyphen && (char_info.m_Unicode == TEXT_LINEFEED_CHAR ||
-                                char_info.m_Unicode == TEXT_RETURN_CHAR)) {
+    } else if (bAfterHyphen &&
+               (char_info.m_Unicode == L'\n' || char_info.m_Unicode == L'\r')) {
       // Handle text breaks with a hyphen to the next line.
       bLineBreak = true;
       ++pos;
@@ -143,12 +143,12 @@
 
     WideString strBeCheck = page_text.Mid(start, nCount);
     if (bLineBreak) {
-      strBeCheck.Remove(TEXT_LINEFEED_CHAR);
-      strBeCheck.Remove(TEXT_RETURN_CHAR);
+      strBeCheck.Remove(L'\n');
+      strBeCheck.Remove(L'\r');
       bLineBreak = false;
     }
     // Replace the generated code with the hyphen char.
-    strBeCheck.Replace(L"\xfffe", TEXT_HYPHEN);
+    strBeCheck.Replace(L"\xfffe", L"-");
 
     if (strBeCheck.GetLength() > 5) {
       while (strBeCheck.GetLength() > 0) {
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 0a1fb05..f128475 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -933,11 +933,11 @@
       case GenerateCharacter::kNone:
         break;
       case GenerateCharacter::kSpace: {
-        Optional<CharInfo> pGenerateChar = GenerateCharInfo(TEXT_SPACE_CHAR);
+        Optional<CharInfo> pGenerateChar = GenerateCharInfo(L' ');
         if (pGenerateChar) {
           if (!formMatrix.IsIdentity())
             pGenerateChar->m_Matrix = formMatrix;
-          m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR);
+          m_TempTextBuf.AppendChar(L' ');
           m_TempCharList.push_back(*pGenerateChar);
         }
         break;
@@ -945,8 +945,8 @@
       case GenerateCharacter::kLineBreak:
         CloseTempLine();
         if (m_TextBuf.GetSize()) {
-          AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix);
-          AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix);
+          AppendGeneratedCharacter(L'\r', formMatrix);
+          AppendGeneratedCharacter(L'\n', formMatrix);
         }
         break;
       case GenerateCharacter::kHyphen:
@@ -1005,7 +1005,7 @@
       WideString str = m_TempTextBuf.MakeString();
       if (str.IsEmpty())
         str = m_TextBuf.AsStringView();
-      if (str.IsEmpty() || str[str.GetLength() - 1] == TEXT_SPACE_CHAR)
+      if (str.IsEmpty() || str[str.GetLength() - 1] == L' ')
         continue;
 
       float fontsize_h = pTextObj->m_TextState.GetFontSizeH();
@@ -1034,11 +1034,11 @@
         threshold = fontsize_h * threshold / 1000;
       }
       if (threshold && (spacing && spacing >= threshold)) {
-        charinfo.m_Unicode = TEXT_SPACE_CHAR;
+        charinfo.m_Unicode = L' ';
         charinfo.m_CharType = CPDF_TextPage::CharType::kGenerated;
         charinfo.m_pTextObj = pTextObj;
         charinfo.m_Index = m_TextBuf.GetLength();
-        m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR);
+        m_TempTextBuf.AppendChar(L' ');
         charinfo.m_CharCode = CPDF_Font::kInvalidCharCode;
         charinfo.m_Matrix = formMatrix;
         charinfo.m_Origin = matrix.Transform(item.m_Origin);
@@ -1092,8 +1092,9 @@
     int nTotal = wstrItem.GetLength();
     bool bDel = false;
     const int count = std::min(pdfium::CollectionSize<int>(m_TempCharList), 7);
+    constexpr float kTextCharRatioGapDelta = 0.07f;
     float threshold = charinfo.m_Matrix.TransformXDistance(
-        static_cast<float>(TEXT_CHARRATIO_GAPDELTA) * pTextObj->GetFontSize());
+        kTextCharRatioGapDelta * pTextObj->GetFontSize());
     for (int n = pdfium::CollectionSize<int>(m_TempCharList);
          n > pdfium::CollectionSize<int>(m_TempCharList) - count; --n) {
       const CharInfo& charinfo1 = m_TempCharList[n - 1];
@@ -1118,7 +1119,7 @@
       }
     } else if (i == 0) {
       WideString str = m_TempTextBuf.MakeString();
-      if (!str.IsEmpty() && str[str.GetLength() - 1] == TEXT_SPACE_CHAR) {
+      if (!str.IsEmpty() && str[str.GetLength() - 1] == L' ') {
         m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
         m_TempCharList.pop_back();
       }
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index e0f7d5c..bac7181 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -23,13 +23,6 @@
 class CPDF_Page;
 class CPDF_TextObject;
 
-#define TEXT_SPACE_CHAR L' '
-#define TEXT_LINEFEED_CHAR L'\n'
-#define TEXT_RETURN_CHAR L'\r'
-#define TEXT_HYPHEN_CHAR L'-'
-#define TEXT_HYPHEN L"-"
-#define TEXT_CHARRATIO_GAPDELTA 0.070
-
 struct PDFTEXT_Obj {
   PDFTEXT_Obj();
   PDFTEXT_Obj(const PDFTEXT_Obj& that);
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index e5518a6..04f4130 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -19,6 +19,8 @@
 
 namespace {
 
+constexpr wchar_t kNonBreakingSpace = 160;
+
 bool IsIgnoreSpaceCharacter(wchar_t curChar) {
   if (curChar < 255 || (curChar >= 0x0600 && curChar <= 0x06FF) ||
       (curChar >= 0xFE70 && curChar <= 0xFEFF) ||
@@ -92,16 +94,16 @@
   ASSERT(lpszFullString);
 
   while (iSubString--) {
-    lpszFullString = std::wcschr(lpszFullString, TEXT_SPACE_CHAR);
+    lpszFullString = std::wcschr(lpszFullString, L' ');
     if (!lpszFullString)
       return {};
 
     lpszFullString++;
-    while (*lpszFullString == TEXT_SPACE_CHAR)
+    while (*lpszFullString == L' ')
       lpszFullString++;
   }
 
-  const wchar_t* lpchEnd = std::wcschr(lpszFullString, TEXT_SPACE_CHAR);
+  const wchar_t* lpchEnd = std::wcschr(lpszFullString, L' ');
   int nLen = lpchEnd ? static_cast<int>(lpchEnd - lpszFullString)
                      : static_cast<int>(wcslen(lpszFullString));
   if (nLen < 0)
@@ -223,8 +225,8 @@
     if (csWord.IsEmpty()) {
       if (iWord == nCount - 1) {
         wchar_t strInsert = m_strText[nStartPos];
-        if (strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_SPACE_CHAR ||
-            strInsert == TEXT_RETURN_CHAR || strInsert == 160) {
+        if (strInsert == L'\n' || strInsert == L' ' || strInsert == L'\r' ||
+            strInsert == kNonBreakingSpace) {
           nResultPos = nStartPos + 1;
           break;
         }
@@ -254,8 +256,8 @@
       }
       for (size_t d = PreResEndPos; d < nResultPos.value(); d++) {
         wchar_t strInsert = m_strText[d];
-        if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR &&
-            strInsert != TEXT_RETURN_CHAR && strInsert != 160) {
+        if (strInsert != L'\n' && strInsert != L' ' && strInsert != L'\r' &&
+            strInsert != kNonBreakingSpace) {
           bMatch = false;
           break;
         }
@@ -263,8 +265,8 @@
     } else if (bSpaceStart) {
       if (nResultPos.value() > 0) {
         wchar_t strInsert = m_strText[nResultPos.value() - 1];
-        if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR &&
-            strInsert != TEXT_RETURN_CHAR && strInsert != 160) {
+        if (strInsert != L'\n' && strInsert != L' ' && strInsert != L'\r' &&
+            strInsert != kNonBreakingSpace) {
           bMatch = false;
           m_resStart = nResultPos.value();
         } else {