Stop exposing fx_unicode.h uint32_t internal representation.

This, in turn, requires removing it from CFX_Char, which is
safe because it is never updated to be different from that
of the corresponding charcode at time of construction.

Initialize in header, and reduce size of CFX_BreakType enum
to pack better.

Change-Id: I7b6e3c675d3e97cca1dc9203fd9fa84d51e69324
Reviewed-on: https://pdfium-review.googlesource.com/c/48131
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/cfx_char.cpp b/core/fxcrt/cfx_char.cpp
index 33c4145..15fe47d 100644
--- a/core/fxcrt/cfx_char.cpp
+++ b/core/fxcrt/cfx_char.cpp
@@ -6,25 +6,12 @@
 
 #include "core/fxcrt/cfx_char.h"
 
-CFX_Char::CFX_Char(uint16_t wCharCode, uint32_t dwCharProps)
-    : CFX_Char(wCharCode, dwCharProps, 100, 100) {}
+CFX_Char::CFX_Char(uint16_t wCharCode) : CFX_Char(wCharCode, 100, 100) {}
 
 CFX_Char::CFX_Char(uint16_t wCharCode,
-                   uint32_t dwCharProps,
                    int32_t iHorizontalScale,
                    int32_t iVerticalScale)
-    : m_dwStatus(CFX_BreakType::None),
-      m_nBreakType(0),
-      m_dwCharStyles(0),
-      m_iCharWidth(0),
-      m_iBidiClass(0),
-      m_iBidiLevel(0),
-      m_iBidiPos(0),
-      m_iBidiOrder(0),
-      m_iFontSize(0),
-      m_dwIdentity(0),
-      m_wCharCode(wCharCode),
-      m_dwCharProps(dwCharProps),
+    : m_wCharCode(wCharCode),
       m_iHorizontalScale(iHorizontalScale),
       m_iVerticalScale(iVerticalScale) {}
 
@@ -33,5 +20,5 @@
 CFX_Char::~CFX_Char() = default;
 
 FX_CHARTYPE CFX_Char::GetCharType() const {
-  return FX_GetCharTypeFromProp(m_dwCharProps);
+  return FX_GetCharType(m_wCharCode);
 }
diff --git a/core/fxcrt/cfx_char.h b/core/fxcrt/cfx_char.h
index f680b59..f275887 100644
--- a/core/fxcrt/cfx_char.h
+++ b/core/fxcrt/cfx_char.h
@@ -12,13 +12,12 @@
 #include "core/fxcrt/fx_unicode.h"
 #include "core/fxcrt/retain_ptr.h"
 
-enum class CFX_BreakType { None = 0, Piece, Line, Paragraph, Page };
+enum class CFX_BreakType : uint8_t { None = 0, Piece, Line, Paragraph, Page };
 
 class CFX_Char {
  public:
-  CFX_Char(uint16_t wCharCode, uint32_t dwCharProps);
+  explicit CFX_Char(uint16_t wCharCode);
   CFX_Char(uint16_t wCharCode,
-           uint32_t dwCharProps,
            int32_t iHorizontalScale,
            int32_t iVerticalScale);
   CFX_Char(const CFX_Char& other);
@@ -27,25 +26,23 @@
   FX_CHARTYPE GetCharType() const;
 
   uint16_t char_code() const { return m_wCharCode; }
-  uint32_t char_props() const { return m_dwCharProps; }
   int16_t horizonal_scale() const { return m_iHorizontalScale; }
   int16_t vertical_scale() const { return m_iVerticalScale; }
 
-  CFX_BreakType m_dwStatus;
-  uint8_t m_nBreakType;
-  uint32_t m_dwCharStyles;
-  int32_t m_iCharWidth;
-  int16_t m_iBidiClass;
-  uint16_t m_iBidiLevel;
-  uint16_t m_iBidiPos;
-  uint16_t m_iBidiOrder;
-  int32_t m_iFontSize;
-  uint32_t m_dwIdentity;
+  CFX_BreakType m_dwStatus = CFX_BreakType::None;
+  uint8_t m_nBreakType = 0;
+  uint32_t m_dwCharStyles = 0;
+  int32_t m_iCharWidth = 0;
+  int16_t m_iBidiClass = 0;
+  uint16_t m_iBidiLevel = 0;
+  uint16_t m_iBidiPos = 0;
+  uint16_t m_iBidiOrder = 0;
+  int32_t m_iFontSize = 0;
+  uint32_t m_dwIdentity = 0;
   RetainPtr<Retainable> m_pUserData;
 
  private:
   uint16_t m_wCharCode;
-  uint32_t m_dwCharProps;
   int32_t m_iHorizontalScale;
   int32_t m_iVerticalScale;
 };
diff --git a/core/fxcrt/fx_arabic.cpp b/core/fxcrt/fx_arabic.cpp
index 00e4f67..a3d049a 100644
--- a/core/fxcrt/fx_arabic.cpp
+++ b/core/fxcrt/fx_arabic.cpp
@@ -176,9 +176,9 @@
 namespace arabic {
 
 wchar_t GetFormChar(wchar_t wch, wchar_t prev, wchar_t next) {
-  CFX_Char c(wch, FX_GetUnicodeProperties(wch));
-  CFX_Char p(prev, FX_GetUnicodeProperties(prev));
-  CFX_Char n(next, FX_GetUnicodeProperties(next));
+  CFX_Char c(wch);
+  CFX_Char p(prev);
+  CFX_Char n(next);
   return GetFormChar(&c, &p, &n);
 }
 
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp
index 9496336..a8c0701 100644
--- a/core/fxcrt/fx_bidi.cpp
+++ b/core/fxcrt/fx_bidi.cpp
@@ -267,8 +267,7 @@
   if (bWS) {
     for (size_t i = 0; i < iCount; ++i) {
       CFX_Char& cur = (*chars)[i];
-      cur.m_iBidiClass =
-          static_cast<int16_t>(FX_GetBidiClassFromProp(cur.char_props()));
+      cur.m_iBidiClass = static_cast<int16_t>(FX_GetBidiClass(cur.char_code()));
     }
     return;
   }
@@ -277,7 +276,7 @@
     CFX_Char& cur = (*chars)[i];
     cur.m_iBidiClass =
         static_cast<int16_t>(gc_FX_BidiNTypes[static_cast<size_t>(
-            FX_GetBidiClassFromProp(cur.char_props()))]);
+            FX_GetBidiClass(cur.char_code()))]);
   }
 }
 
@@ -529,8 +528,7 @@
 
 bool CFX_BidiChar::AppendChar(wchar_t wch) {
   Direction direction;
-  uint32_t dwProps = FX_GetUnicodeProperties(wch);
-  switch (FX_GetBidiClassFromProp(dwProps)) {
+  switch (FX_GetBidiClass(wch)) {
     case FX_BIDICLASS::kL:
     case FX_BIDICLASS::kAN:
     case FX_BIDICLASS::kEN:
diff --git a/core/fxcrt/fx_unicode.cpp b/core/fxcrt/fx_unicode.cpp
index 97d93c2..4bb4c80 100644
--- a/core/fxcrt/fx_unicode.cpp
+++ b/core/fxcrt/fx_unicode.cpp
@@ -132,7 +132,17 @@
 const size_t kFXTextLayoutBidiMirrorSize =
     FX_ArraySize(kFXTextLayoutBidiMirror);
 
-wchar_t GetMirrorChar(wchar_t wch, uint32_t dwProps) {
+uint32_t GetUnicodeProperties(wchar_t wch) {
+  size_t idx = static_cast<size_t>(wch);
+  if (idx < kTextLayoutCodePropertiesSize)
+    return kTextLayoutCodeProperties[idx];
+  return 0;
+}
+
+}  // namespace
+
+wchar_t FX_GetMirrorChar(wchar_t wch) {
+  uint32_t dwProps = GetUnicodeProperties(wch);
   uint32_t dwTemp = (dwProps & kMirrorBitMask);
   if (dwTemp == kMirrorBitMask)
     return wch;
@@ -140,39 +150,25 @@
   return idx < kFXTextLayoutBidiMirrorSize ? kFXTextLayoutBidiMirror[idx] : wch;
 }
 
-}  // namespace
-
-uint32_t FX_GetUnicodeProperties(wchar_t wch) {
-  size_t idx = static_cast<size_t>(wch);
-  if (idx < kTextLayoutCodePropertiesSize)
-    return kTextLayoutCodeProperties[idx];
-  return 0;
-}
-
-wchar_t FX_GetMirrorChar(wchar_t wch) {
-  return GetMirrorChar(wch, FX_GetUnicodeProperties(wch));
-}
-
-FX_BIDICLASS FX_GetBidiClassFromProp(uint32_t prop) {
+FX_BIDICLASS FX_GetBidiClass(wchar_t wch) {
+  uint32_t prop = GetUnicodeProperties(wch);
   uint32_t result = (prop & kBidiClassBitMask) >> kBidiClassBitPos;
   ASSERT(result <= static_cast<uint32_t>(FX_BIDICLASS::kPDF));
   return static_cast<FX_BIDICLASS>(result);
 }
 
 #ifdef PDF_ENABLE_XFA
-FX_CHARTYPE FX_GetCharTypeFromProp(uint32_t prop) {
+FX_CHARTYPE FX_GetCharType(wchar_t wch) {
+  uint32_t prop = GetUnicodeProperties(wch);
   uint32_t result = (prop & kCharTypeBitMask) >> kCharTypeBitPos;
   ASSERT(result <= static_cast<uint32_t>(FX_CHARTYPE::kArabic));
   return static_cast<FX_CHARTYPE>(result);
 }
 
-FX_BREAKPROPERTY FX_GetBreakPropertyFromProp(uint32_t prop) {
+FX_BREAKPROPERTY FX_GetBreakProperty(wchar_t wch) {
+  uint32_t prop = GetUnicodeProperties(wch);
   uint32_t result = (prop & kBreakTypeBitMask) >> kBreakTypeBitPos;
   ASSERT(result <= static_cast<uint32_t>(FX_BREAKPROPERTY::kTB));
   return static_cast<FX_BREAKPROPERTY>(result);
 }
-
-wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps) {
-  return GetMirrorChar(wch, dwProps);
-}
 #endif  // PDF_ENABLE_XFA
diff --git a/core/fxcrt/fx_unicode.h b/core/fxcrt/fx_unicode.h
index 9155aed..e482406 100644
--- a/core/fxcrt/fx_unicode.h
+++ b/core/fxcrt/fx_unicode.h
@@ -90,18 +90,15 @@
   kArabic,
 };
 
-uint32_t FX_GetUnicodeProperties(wchar_t wch);
 wchar_t FX_GetMirrorChar(wchar_t wch);
-FX_BIDICLASS FX_GetBidiClassFromProp(uint32_t prop);
+FX_BIDICLASS FX_GetBidiClass(wchar_t wch);
 
 #ifdef PDF_ENABLE_XFA
-FX_CHARTYPE FX_GetCharTypeFromProp(uint32_t prop);
+FX_CHARTYPE FX_GetCharType(wchar_t wch);
 
 // Analagous to ULineBreak in icu's uchar.h, but permuted order, and a
 // subset lacking some more recent additions.
-FX_BREAKPROPERTY FX_GetBreakPropertyFromProp(uint32_t prop);
-
-wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps);
+FX_BREAKPROPERTY FX_GetBreakProperty(wchar_t wch);
 #endif  // PDF_ENABLE_XFA
 
 #endif  // CORE_FXCRT_FX_UNICODE_H_
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 0026247..e446626 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -69,9 +69,8 @@
   ASSERT(m_pFont);
   ASSERT(m_pCurLine);
 
-  uint32_t dwProps = FX_GetUnicodeProperties(wch);
-  FX_CHARTYPE chartype = FX_GetCharTypeFromProp(dwProps);
-  m_pCurLine->m_LineChars.emplace_back(wch, dwProps, m_iHorizontalScale,
+  FX_CHARTYPE chartype = FX_GetCharType(wch);
+  m_pCurLine->m_LineChars.emplace_back(wch, m_iHorizontalScale,
                                        m_iVerticalScale);
   CFX_Char* pCurChar = &m_pCurLine->m_LineChars.back();
   pCurChar->m_iFontSize = m_iFontSize;
@@ -609,16 +608,14 @@
   if (bAllChars)
     pCur->m_nBreakType = FX_LBT_UNKNOWN;
 
-  uint32_t nCodeProp = pCur->char_props();
-  FX_BREAKPROPERTY nNext = FX_GetBreakPropertyFromProp(nCodeProp);
+  FX_BREAKPROPERTY nNext = FX_GetBreakProperty(pCur->char_code());
   int32_t iCharWidth = pCur->m_iCharWidth;
   if (iCharWidth > 0)
     *pEndPos -= iCharWidth;
 
   while (iLength >= 0) {
     pCur = pCharArray + iLength;
-    nCodeProp = pCur->char_props();
-    FX_BREAKPROPERTY nCur = FX_GetBreakPropertyFromProp(nCodeProp);
+    FX_BREAKPROPERTY nCur = FX_GetBreakProperty(pCur->char_code());
     bool bNeedBreak = false;
     FX_LINEBREAKTYPE eType;
     if (nCur == FX_BREAKPROPERTY::kTB) {
@@ -657,7 +654,7 @@
       if (iCharWidth > 0)
         *pEndPos -= iCharWidth;
     }
-    nNext = FX_GetBreakPropertyFromProp(nCodeProp);
+    nNext = nCur;
     --iLength;
   }
   if (bOnlyBrk)
@@ -753,8 +750,7 @@
   for (int32_t i = 0; i < pText->iLength; ++i) {
     wchar_t wch = pText->pStr[i];
     int32_t iWidth = pText->pWidths[i];
-    uint32_t dwProps = FX_GetUnicodeProperties(wch);
-    FX_CHARTYPE dwCharType = FX_GetCharTypeFromProp(dwProps);
+    FX_CHARTYPE dwCharType = FX_GetCharType(wch);
     if (iWidth == 0) {
       if (dwCharType == FX_CHARTYPE::kArabicAlef)
         wPrev = 0xFEFF;
@@ -780,7 +776,7 @@
         }
         wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext);
       } else if (bRTLPiece) {
-        wForm = FX_GetMirrorChar(wch, dwProps);
+        wForm = FX_GetMirrorChar(wch);
       }
 
       if (!bEmptyChar) {
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index e120fcb..2ed51bd 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -17,8 +17,8 @@
 
 namespace {
 
-bool IsCtrlCode(wchar_t ch) {
-  FX_CHARTYPE dwRet = FX_GetCharTypeFromProp(FX_GetUnicodeProperties(ch));
+bool IsCtrlCode(wchar_t wch) {
+  FX_CHARTYPE dwRet = FX_GetCharType(wch);
   return dwRet == FX_CHARTYPE::kTab || dwRet == FX_CHARTYPE::kControl;
 }
 
@@ -224,9 +224,8 @@
 }
 
 CFX_BreakType CFX_TxtBreak::AppendChar(wchar_t wch) {
-  uint32_t dwProps = FX_GetUnicodeProperties(wch);
-  FX_CHARTYPE chartype = FX_GetCharTypeFromProp(dwProps);
-  m_pCurLine->m_LineChars.emplace_back(wch, dwProps, m_iHorizontalScale,
+  FX_CHARTYPE chartype = FX_GetCharType(wch);
+  m_pCurLine->m_LineChars.emplace_back(wch, m_iHorizontalScale,
                                        m_iVerticalScale);
   CFX_Char* pCurChar = &m_pCurLine->m_LineChars.back();
   pCurChar->m_dwCharStyles = m_iAlignment | (1 << 8);
@@ -548,23 +547,20 @@
   }
 
   FX_LINEBREAKTYPE eType;
-  uint32_t nCodeProp;
   FX_BREAKPROPERTY nCur;
   FX_BREAKPROPERTY nNext;
   CFX_Char* pCur = &chars[iLength--];
   if (bAllChars)
     pCur->m_nBreakType = FX_LBT_UNKNOWN;
 
-  nCodeProp = pCur->char_props();
-  nNext = FX_GetBreakPropertyFromProp(nCodeProp);
+  nNext = FX_GetBreakProperty(pCur->char_code());
   int32_t iCharWidth = pCur->m_iCharWidth;
   if (iCharWidth > 0)
     *pEndPos -= iCharWidth;
 
   while (iLength >= 0) {
     pCur = &chars[iLength];
-    nCodeProp = pCur->char_props();
-    nCur = FX_GetBreakPropertyFromProp(nCodeProp);
+    nCur = FX_GetBreakProperty(pCur->char_code());
     if (nNext == FX_BREAKPROPERTY::kSP)
       eType = FX_LBT_PROHIBITED_BRK;
     else
@@ -592,7 +588,7 @@
       if (iCharWidth > 0)
         *pEndPos -= iCharWidth;
     }
-    nNext = FX_GetBreakPropertyFromProp(nCodeProp);
+    nNext = nCur;
     iLength--;
   }
   if (bOnlyBrk)
@@ -714,8 +710,7 @@
       iWidth = *pWidths++;
     }
 
-    uint32_t dwProps = FX_GetUnicodeProperties(wch);
-    FX_CHARTYPE chartype = FX_GetCharTypeFromProp(dwProps);
+    FX_CHARTYPE chartype = FX_GetCharType(wch);
     if (chartype == FX_CHARTYPE::kArabicAlef && iWidth == 0) {
       wPrev = 0xFEFF;
       wLast = wch;
@@ -729,8 +724,7 @@
           while (iNext <= iLength) {
             int32_t iNextAbsolute = iNext + pTxtRun->iStart;
             wNext = pEngine->GetChar(iNextAbsolute);
-            dwProps = FX_GetUnicodeProperties(wNext);
-            if (FX_GetCharTypeFromProp(dwProps) != FX_CHARTYPE::kCombination)
+            if (FX_GetCharType(wNext) != FX_CHARTYPE::kCombination)
               break;
 
             iNext++;
@@ -745,9 +739,7 @@
               break;
 
             wNext = pStr[j];
-            dwProps = FX_GetUnicodeProperties(wNext);
-          } while (FX_GetCharTypeFromProp(dwProps) ==
-                   FX_CHARTYPE::kCombination);
+          } while (FX_GetCharType(wNext) == FX_CHARTYPE::kCombination);
           if (i + j >= iLength)
             wNext = 0xFEFF;
         }
@@ -797,7 +789,7 @@
     } else if (wch == L',') {
       wForm = wch;
     } else if (bRTLPiece) {
-      wForm = FX_GetMirrorChar(wch, dwProps);
+      wForm = FX_GetMirrorChar(wch);
     } else {
       wForm = wch;
     }
@@ -878,9 +870,7 @@
                 fYBase + fFontSize - fFontSize * rtBBox.Height() / iMaxHeight;
           }
           if (wForm == wch && wLast != 0xFEFF) {
-            uint32_t dwLastProps = FX_GetUnicodeProperties(wLast);
-            if (FX_GetCharTypeFromProp(dwLastProps) ==
-                FX_CHARTYPE::kCombination) {
+            if (FX_GetCharType(wLast) == FX_CHARTYPE::kCombination) {
               FX_RECT rtBox;
               if (pFont->GetCharBBox(wLast, &rtBox))
                 pCharPos->m_Origin.y -= fFontSize * rtBox.Height() / iMaxHeight;