diff options
author | Lei Zhang <thestig@chromium.org> | 2017-07-27 13:47:27 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-27 23:20:44 +0000 |
commit | 672a1721620c3f4e62fe6adfaceb929d423ae31f (patch) | |
tree | cd9e07848dc9a99e48a9276324c2dbcb655e4ffc /core/fxcrt | |
parent | 3f7ff0540e7913ddc2c2d4f60e144cc0c7700e9e (diff) | |
download | pdfium-672a1721620c3f4e62fe6adfaceb929d423ae31f.tar.xz |
Simplify FX_GetMirrorChar() code.
Change-Id: I43ec0d4a3b60d51c59ba5a540dfe24803e725089
Reviewed-on: https://pdfium-review.googlesource.com/9170
Reviewed-by: Nicolás Peña <npm@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_ucd.h | 20 | ||||
-rw-r--r-- | core/fxcrt/fx_ucddata.cpp | 13 | ||||
-rw-r--r-- | core/fxcrt/fx_unicode.cpp | 59 |
3 files changed, 27 insertions, 65 deletions
diff --git a/core/fxcrt/fx_ucd.h b/core/fxcrt/fx_ucd.h index b96d09a406..3b72516324 100644 --- a/core/fxcrt/fx_ucd.h +++ b/core/fxcrt/fx_ucd.h @@ -10,8 +10,8 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_basic.h" -#define FX_BIDICLASSBITS 6 -#define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) +constexpr uint32_t FX_BIDICLASSBITS = 6; +constexpr uint32_t FX_BIDICLASSBITSMASK = 0x1F << FX_BIDICLASSBITS; enum FX_BIDICLASS { FX_BIDICLASS_ON = 0, // Other Neutral @@ -39,14 +39,12 @@ enum FX_BIDICLASS { extern const uint32_t kTextLayoutCodeProperties[]; extern const size_t kTextLayoutCodePropertiesSize; -extern const uint16_t kFXTextLayoutVerticalMirror[]; -extern const size_t kFXTextLayoutVerticalMirrorSize; - extern const uint16_t kFXTextLayoutBidiMirror[]; extern const size_t kFXTextLayoutBidiMirrorSize; uint32_t FX_GetUnicodeProperties(wchar_t wch); -wchar_t FX_GetMirrorChar(wchar_t wch, bool bRTL, bool bVertical); + +wchar_t FX_GetMirrorChar(wchar_t wch); #ifdef PDF_ENABLE_XFA @@ -93,8 +91,9 @@ enum FXCHAR_BREAKPROP { FX_CBP_TB = 37, // ? }; -#define FX_CHARTYPEBITS 11 -#define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) +constexpr uint32_t FX_CHARTYPEBITS = 11; +constexpr uint32_t FX_CHARTYPEBITSMASK = 0xF << FX_CHARTYPEBITS; + enum FX_CHARTYPE { FX_CHARTYPE_Unknown = 0, FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS), @@ -114,10 +113,7 @@ inline FX_CHARTYPE GetCharTypeFromProp(uint32_t prop) { return static_cast<FX_CHARTYPE>(prop & FX_CHARTYPEBITSMASK); } -wchar_t FX_GetMirrorChar(wchar_t wch, - uint32_t dwProps, - bool bRTL, - bool bVertical); +wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps); #endif // PDF_ENABLE_XFA diff --git a/core/fxcrt/fx_ucddata.cpp b/core/fxcrt/fx_ucddata.cpp index b8661b87cb..5e3d3afbd4 100644 --- a/core/fxcrt/fx_ucddata.cpp +++ b/core/fxcrt/fx_ucddata.cpp @@ -10936,19 +10936,6 @@ const uint32_t kTextLayoutCodeProperties[] = { const size_t kTextLayoutCodePropertiesSize = FX_ArraySize(kTextLayoutCodeProperties); -const uint16_t kFXTextLayoutVerticalMirror[] = { - 0xFE33, 0xFE32, 0xFE31, 0xFE41, 0xFE42, 0xFE43, 0xFE44, 0xFE3F, - 0xFE40, 0xFE3D, 0xFE3E, 0xFE41, 0xFE42, 0xFE43, 0xFE44, 0xFE3B, - 0xFE3C, 0xFE39, 0xFE3A, 0xFE34, 0xFE35, 0xFE36, 0xFE37, 0xFE38, - 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, - 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, - 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, - 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, - 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, -}; -const size_t kFXTextLayoutVerticalMirrorSize = - FX_ArraySize(kFXTextLayoutVerticalMirror); - const uint16_t kFXTextLayoutBidiMirror[] = { 0x0029, 0x0028, 0x003E, 0x003C, 0x005D, 0x005B, 0x007D, 0x007B, 0x00BB, 0x00AB, 0x0F3B, 0x0F3A, 0x0F3D, 0x0F3C, 0x169C, 0x169B, 0x2019, 0x2018, diff --git a/core/fxcrt/fx_unicode.cpp b/core/fxcrt/fx_unicode.cpp index fce826dac8..595bb65a63 100644 --- a/core/fxcrt/fx_unicode.cpp +++ b/core/fxcrt/fx_unicode.cpp @@ -6,6 +6,21 @@ #include "core/fxcrt/fx_ucd.h" +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) + return wch; + size_t idx = dwTemp >> kMirrorBits; + 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) @@ -13,48 +28,12 @@ uint32_t FX_GetUnicodeProperties(wchar_t wch) { return 0; } -wchar_t FX_GetMirrorChar(wchar_t wch, bool bRTL, bool bVertical) { - uint32_t dwProps = FX_GetUnicodeProperties(wch); - uint32_t dwTemp = (dwProps & 0xFF800000); - if (bRTL && dwTemp < 0xFF800000) { - size_t idx = dwTemp >> 23; - if (idx < kFXTextLayoutBidiMirrorSize) { - wch = kFXTextLayoutBidiMirror[idx]; - dwProps = FX_GetUnicodeProperties(wch); - } - } - if (bVertical) { - dwTemp = (dwProps & 0x007E0000); - if (dwTemp < 0x007E0000) { - size_t idx = dwTemp >> 17; - if (idx < kFXTextLayoutVerticalMirrorSize) - wch = kFXTextLayoutVerticalMirror[idx]; - } - } - return wch; +wchar_t FX_GetMirrorChar(wchar_t wch) { + return GetMirrorChar(wch, FX_GetUnicodeProperties(wch)); } #ifdef PDF_ENABLE_XFA -wchar_t FX_GetMirrorChar(wchar_t wch, - uint32_t dwProps, - bool bRTL, - bool bVertical) { - uint32_t dwTemp = (dwProps & 0xFF800000); - if (bRTL && dwTemp < 0xFF800000) { - size_t idx = dwTemp >> 23; - if (idx < kFXTextLayoutBidiMirrorSize) { - wch = kFXTextLayoutBidiMirror[idx]; - dwProps = FX_GetUnicodeProperties(wch); - } - } - if (bVertical) { - dwTemp = (dwProps & 0x007E0000); - if (dwTemp < 0x007E0000) { - size_t idx = dwTemp >> 17; - if (idx < kFXTextLayoutVerticalMirrorSize) - wch = kFXTextLayoutVerticalMirror[idx]; - } - } - return wch; +wchar_t FX_GetMirrorChar(wchar_t wch, uint32_t dwProps) { + return GetMirrorChar(wch, dwProps); } #endif // PDF_ENABLE_XFA |