Move FX_BIDICLASS to fx_unicode.h.

Add FX_GetBidiClassFromProp() to compute it. Then remove duplicate
bitmask/bitposition definitions from fx_bidi.cpp.

Change-Id: I655468df13ac17df9cd56f0633b2b107452775b3
Reviewed-on: https://pdfium-review.googlesource.com/c/48091
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp
index bc31a32..9496336 100644
--- a/core/fxcrt/fx_bidi.cpp
+++ b/core/fxcrt/fx_bidi.cpp
@@ -17,31 +17,6 @@
 
 namespace {
 
-enum class FX_BIDICLASS : uint8_t {
-  kON = 0,    // Other Neutral
-  kL = 1,     // Left Letter
-  kR = 2,     // Right Letter
-  kAN = 3,    // Arabic Number
-  kEN = 4,    // European Number
-  kAL = 5,    // Arabic Letter
-  kNSM = 6,   // Non-spacing Mark
-  kCS = 7,    // Common Number Separator
-  kES = 8,    // European Separator
-  kET = 9,    // European Number Terminator
-  kBN = 10,   // Boundary Neutral
-  kS = 11,    // Segment Separator
-  kWS = 12,   // Whitespace
-  kB = 13,    // Paragraph Separator
-  kRLO = 14,  // Right-to-Left Override
-  kRLE = 15,  // Right-to-Left Embedding
-  kLRO = 16,  // Left-to-Right Override
-  kLRE = 17,  // Left-to-Right Embedding
-  kPDF = 18,  // Pop Directional Format
-  kN = kON,
-};
-constexpr uint32_t FX_BIDICLASSBITS = 6;
-constexpr uint32_t FX_BIDICLASSBITSMASK = 0x1F << FX_BIDICLASSBITS;
-
 #ifdef PDF_ENABLE_XFA
 
 #ifndef NDEBUG
@@ -293,17 +268,16 @@
     for (size_t i = 0; i < iCount; ++i) {
       CFX_Char& cur = (*chars)[i];
       cur.m_iBidiClass =
-          static_cast<int16_t>(cur.char_props() & FX_BIDICLASSBITSMASK) >>
-          FX_BIDICLASSBITS;
+          static_cast<int16_t>(FX_GetBidiClassFromProp(cur.char_props()));
     }
     return;
   }
 
   for (size_t i = 0; i < iCount; ++i) {
     CFX_Char& cur = (*chars)[i];
-    cur.m_iBidiClass = static_cast<int16_t>(
-        gc_FX_BidiNTypes[(cur.char_props() & FX_BIDICLASSBITSMASK) >>
-                         FX_BIDICLASSBITS]);
+    cur.m_iBidiClass =
+        static_cast<int16_t>(gc_FX_BidiNTypes[static_cast<size_t>(
+            FX_GetBidiClassFromProp(cur.char_props()))]);
   }
 }
 
@@ -554,11 +528,9 @@
     : m_CurrentSegment({0, 0, NEUTRAL}), m_LastSegment({0, 0, NEUTRAL}) {}
 
 bool CFX_BidiChar::AppendChar(wchar_t wch) {
-  uint32_t dwProps = FX_GetUnicodeProperties(wch);
-  FX_BIDICLASS iBidiCls = static_cast<FX_BIDICLASS>(
-      (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS);
   Direction direction;
-  switch (iBidiCls) {
+  uint32_t dwProps = FX_GetUnicodeProperties(wch);
+  switch (FX_GetBidiClassFromProp(dwProps)) {
     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 3341792..857b710 100644
--- a/core/fxcrt/fx_unicode.cpp
+++ b/core/fxcrt/fx_unicode.cpp
@@ -153,6 +153,12 @@
   return GetMirrorChar(wch, FX_GetUnicodeProperties(wch));
 }
 
+FX_BIDICLASS FX_GetBidiClassFromProp(uint32_t prop) {
+  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 GetCharTypeFromProp(uint32_t prop) {
   uint32_t result = (prop & kCharTypeBitMask) >> kCharTypeBitPos;
diff --git a/core/fxcrt/fx_unicode.h b/core/fxcrt/fx_unicode.h
index e888ddf..8decdc3 100644
--- a/core/fxcrt/fx_unicode.h
+++ b/core/fxcrt/fx_unicode.h
@@ -51,6 +51,29 @@
   kTB = 37,
 };
 
+enum class FX_BIDICLASS : uint8_t {
+  kON = 0,    // Other Neutral
+  kL = 1,     // Left Letter
+  kR = 2,     // Right Letter
+  kAN = 3,    // Arabic Number
+  kEN = 4,    // European Number
+  kAL = 5,    // Arabic Letter
+  kNSM = 6,   // Non-spacing Mark
+  kCS = 7,    // Common Number Separator
+  kES = 8,    // European Separator
+  kET = 9,    // European Number Terminator
+  kBN = 10,   // Boundary Neutral
+  kS = 11,    // Segment Separator
+  kWS = 12,   // Whitespace
+  kB = 13,    // Paragraph Separator
+  kRLO = 14,  // Right-to-Left Override
+  kRLE = 15,  // Right-to-Left Embedding
+  kLRO = 16,  // Left-to-Right Override
+  kLRE = 17,  // Left-to-Right Embedding
+  kPDF = 18,  // Pop Directional Format
+  kN = kON,
+};
+
 enum class FX_CHARTYPE : uint8_t {
   kUnknown = 0,
   kTab,
@@ -69,6 +92,7 @@
 
 uint32_t FX_GetUnicodeProperties(wchar_t wch);
 wchar_t FX_GetMirrorChar(wchar_t wch);
+FX_BIDICLASS FX_GetBidiClassFromProp(uint32_t prop);
 
 #ifdef PDF_ENABLE_XFA