Cleanup fx_ucddata.h, part 1.
First step at hiding internal representation of this packed
uint32_t table from its callers.
Change-Id: I014fd72af26483fe77d785eb5ec5a93abbd45687
Reviewed-on: https://pdfium-review.googlesource.com/c/47911
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_ucddata.cpp b/core/fxcrt/fx_ucddata.cpp
index 527eacf..7985f94 100644
--- a/core/fxcrt/fx_ucddata.cpp
+++ b/core/fxcrt/fx_ucddata.cpp
@@ -8,6 +8,8 @@
#include "core/fxcrt/fx_memory.h"
+namespace fxcrt {
+
const uint32_t kTextLayoutCodeProperties[] = {
0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93,
0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe8ae5, 0xfffe9b5c, 0xfffe9ada,
@@ -10937,6 +10939,23 @@
const size_t kTextLayoutCodePropertiesSize =
FX_ArraySize(kTextLayoutCodeProperties);
+static_assert(kTextLayoutCodePropertiesSize == 65536, "missing characters");
+
+static_assert((kBreakTypeBitMask | kBidiClassBitMask | kCharTypeBitMask |
+ kField2BitMask | kMirrorBitMask) == 0xffffffff,
+ "missing bits in mask");
+
+static_assert((kBreakTypeBitMask & kBidiClassBitMask) == 0, "overlapping bits");
+static_assert((kBreakTypeBitMask & kCharTypeBitMask) == 0, "overlapping bits");
+static_assert((kBreakTypeBitMask & kField2BitMask) == 0, "overlapping bits");
+static_assert((kBreakTypeBitMask & kMirrorBitMask) == 0, "overlapping bits");
+static_assert((kBidiClassBitMask & kCharTypeBitMask) == 0, "overlapping bits");
+static_assert((kBidiClassBitMask & kField2BitMask) == 0, "overlapping bits");
+static_assert((kBidiClassBitMask & kMirrorBitMask) == 0, "overlapping bits");
+static_assert((kCharTypeBitMask & kField2BitMask) == 0, "overlapping bits");
+static_assert((kCharTypeBitMask & kMirrorBitMask) == 0, "overlapping bits");
+static_assert((kField2BitMask & kMirrorBitMask) == 0, "overlapping bits");
+
const uint16_t kFXTextLayoutBidiMirror[] = {
0x0029, 0x0028, 0x003E, 0x003C, 0x005D, 0x005B, 0x007D, 0x007B, 0x00BB,
0x00AB, 0x0F3B, 0x0F3A, 0x0F3D, 0x0F3C, 0x169C, 0x169B, 0x2019, 0x2018,
@@ -10999,3 +11018,5 @@
const size_t kFXTextLayoutBidiMirrorSize =
FX_ArraySize(kFXTextLayoutBidiMirror);
+
+} // namespace fxcrt
diff --git a/core/fxcrt/fx_ucddata.h b/core/fxcrt/fx_ucddata.h
index 78a6b97..3296333 100644
--- a/core/fxcrt/fx_ucddata.h
+++ b/core/fxcrt/fx_ucddata.h
@@ -9,10 +9,61 @@
#include "core/fxcrt/fx_system.h"
+namespace fxcrt {
+
+// Format of uint32_t values in kTextLayoutCodeProperties[].
+constexpr uint32_t kBreakTypeBitPos = 0;
+constexpr uint32_t kBreakTypeBitCount = 6;
+constexpr uint32_t kBreakTypeBitMask =
+ (((1u << kBreakTypeBitCount) - 1) << kBreakTypeBitPos);
+
+constexpr uint32_t kBidiClassBitPos = 6;
+constexpr uint32_t kBidiClassBitCount = 5;
+constexpr uint32_t kBidiClassBitMask =
+ (((1u << kBidiClassBitCount) - 1) << kBidiClassBitPos);
+
+constexpr uint32_t kCharTypeBitPos = 11;
+constexpr uint32_t kCharTypeBitCount = 4;
+constexpr uint32_t kCharTypeBitMask =
+ (((1u << kCharTypeBitCount) - 1) << kCharTypeBitPos);
+
+// TODO(tsepez): Unknown, possibly unused field.
+constexpr uint32_t kField2BitPos = 15;
+constexpr uint32_t kField2BitCount = 8;
+constexpr uint32_t kField2BitMask =
+ (((1 << kField2BitCount) - 1) << kField2BitPos);
+
+constexpr uint32_t kMirrorBitPos = 23;
+constexpr uint32_t kMirrorBitCount = 9;
+constexpr uint32_t kMirrorBitMask =
+ (((1 << kMirrorBitCount) - 1) << kMirrorBitPos);
+
extern const uint32_t kTextLayoutCodeProperties[];
extern const size_t kTextLayoutCodePropertiesSize;
extern const uint16_t kFXTextLayoutBidiMirror[];
extern const size_t kFXTextLayoutBidiMirrorSize;
+} // namespace fxcrt
+
+using fxcrt::kBidiClassBitCount;
+using fxcrt::kBidiClassBitMask;
+using fxcrt::kBidiClassBitPos;
+using fxcrt::kBreakTypeBitCount;
+using fxcrt::kBreakTypeBitMask;
+using fxcrt::kBreakTypeBitPos;
+using fxcrt::kCharTypeBitCount;
+using fxcrt::kCharTypeBitMask;
+using fxcrt::kCharTypeBitPos;
+using fxcrt::kField2BitCount;
+using fxcrt::kField2BitMask;
+using fxcrt::kField2BitPos;
+using fxcrt::kFXTextLayoutBidiMirror;
+using fxcrt::kFXTextLayoutBidiMirrorSize;
+using fxcrt::kMirrorBitCount;
+using fxcrt::kMirrorBitMask;
+using fxcrt::kMirrorBitPos;
+using fxcrt::kTextLayoutCodeProperties;
+using fxcrt::kTextLayoutCodePropertiesSize;
+
#endif // CORE_FXCRT_FX_UCDDATA_H_
diff --git a/core/fxcrt/fx_unicode.cpp b/core/fxcrt/fx_unicode.cpp
index aafdba1..303ef34 100644
--- a/core/fxcrt/fx_unicode.cpp
+++ b/core/fxcrt/fx_unicode.cpp
@@ -10,14 +10,11 @@
namespace {
-constexpr uint32_t kMirrorBits = 23;
-constexpr uint32_t kMirrorMask = 0x1FFU << kMirrorBits;
-
wchar_t GetMirrorChar(wchar_t wch, uint32_t dwProps) {
- uint32_t dwTemp = (dwProps & kMirrorMask);
- if (dwTemp == kMirrorMask)
+ uint32_t dwTemp = (dwProps & kMirrorBitMask);
+ if (dwTemp == kMirrorBitMask)
return wch;
- size_t idx = dwTemp >> kMirrorBits;
+ size_t idx = dwTemp >> kMirrorBitPos;
return idx < kFXTextLayoutBidiMirrorSize ? kFXTextLayoutBidiMirror[idx] : wch;
}
@@ -35,6 +32,20 @@
}
#ifdef PDF_ENABLE_XFA
+static_assert(FX_CHARTYPEBITS == kCharTypeBitPos, "positions must match");
+
+FX_CHARTYPE GetCharTypeFromProp(uint32_t prop) {
+ uint32_t result = (prop & kCharTypeBitMask);
+ ASSERT(result <= FX_CHARTYPE_Arabic);
+ return static_cast<FX_CHARTYPE>(result);
+}
+
+uint32_t GetBreakPropertyFromProp(uint32_t prop) {
+ uint32_t result = (prop & kBreakTypeBitMask) >> kBreakTypeBitPos;
+ ASSERT(result <= kBreakPropertyTB);
+ return result;
+}
+
wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps) {
return GetMirrorChar(wch, dwProps);
}
diff --git a/core/fxcrt/fx_unicode.h b/core/fxcrt/fx_unicode.h
index 9611011..e701a76 100644
--- a/core/fxcrt/fx_unicode.h
+++ b/core/fxcrt/fx_unicode.h
@@ -19,7 +19,6 @@
constexpr uint8_t kBreakPropertyTB = 37; // Highest, don't know what this is.
constexpr uint32_t FX_CHARTYPEBITS = 11;
-constexpr uint32_t FX_CHARTYPEBITSMASK = 0xF << FX_CHARTYPEBITS;
enum FX_CHARTYPE {
FX_CHARTYPE_Unknown = 0,
@@ -37,16 +36,11 @@
FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS),
};
-inline FX_CHARTYPE GetCharTypeFromProp(uint32_t prop) {
- return static_cast<FX_CHARTYPE>(prop & FX_CHARTYPEBITSMASK);
-}
+FX_CHARTYPE GetCharTypeFromProp(uint32_t prop);
-inline uint32_t GetBreakPropertyFromProp(uint32_t prop) {
- // Analagous to ULineBreak in icu's uchar.h, but permuted order, and a
- // subset lacking some more recent additions.
- ASSERT((prop & 0x3f) <= kBreakPropertyTB);
- return prop & 0x3f;
-}
+// Analagous to ULineBreak in icu's uchar.h, but permuted order, and a
+// subset lacking some more recent additions.
+uint32_t GetBreakPropertyFromProp(uint32_t prop);
wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps);
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 70a5756..70488da 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -752,7 +752,7 @@
wchar_t wch = pText->pStr[i];
int32_t iWidth = pText->pWidths[i];
uint32_t dwProps = FX_GetUnicodeProperties(wch);
- uint32_t dwCharType = (dwProps & FX_CHARTYPEBITSMASK);
+ uint32_t dwCharType = GetCharTypeFromProp(dwProps);
if (iWidth == 0) {
if (dwCharType == FX_CHARTYPE_ArabicAlef)
wPrev = 0xFEFF;
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index 9d14305..96bf9bd 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -18,7 +18,7 @@
namespace {
bool IsCtrlCode(wchar_t ch) {
- uint32_t dwRet = (FX_GetUnicodeProperties(ch) & FX_CHARTYPEBITSMASK);
+ uint32_t dwRet = GetCharTypeFromProp(FX_GetUnicodeProperties(ch));
return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control;
}
@@ -728,7 +728,7 @@
int32_t iNextAbsolute = iNext + pTxtRun->iStart;
wNext = pEngine->GetChar(iNextAbsolute);
dwProps = FX_GetUnicodeProperties(wNext);
- if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination)
+ if (GetCharTypeFromProp(dwProps) != FX_CHARTYPE_Combination)
break;
iNext++;
@@ -744,7 +744,7 @@
wNext = pStr[j];
dwProps = FX_GetUnicodeProperties(wNext);
- } while ((dwProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination);
+ } while (GetCharTypeFromProp(dwProps) == FX_CHARTYPE_Combination);
if (i + j >= iLength)
wNext = 0xFEFF;
}
@@ -876,8 +876,7 @@
}
if (wForm == wch && wLast != 0xFEFF) {
uint32_t dwLastProps = FX_GetUnicodeProperties(wLast);
- if ((dwLastProps & FX_CHARTYPEBITSMASK) ==
- FX_CHARTYPE_Combination) {
+ if (GetCharTypeFromProp(dwLastProps) == FX_CHARTYPE_Combination) {
FX_RECT rtBox;
if (pFont->GetCharBBox(wLast, &rtBox))
pCharPos->m_Origin.y -= fFontSize * rtBox.Height() / iMaxHeight;