From 672a1721620c3f4e62fe6adfaceb929d423ae31f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 27 Jul 2017 13:47:27 -0700 Subject: Simplify FX_GetMirrorChar() code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I43ec0d4a3b60d51c59ba5a540dfe24803e725089 Reviewed-on: https://pdfium-review.googlesource.com/9170 Reviewed-by: Nicolás Peña Commit-Queue: Lei Zhang --- core/fpdftext/cpdf_textpage.cpp | 2 +- core/fxcrt/fx_ucd.h | 20 ++++++-------- core/fxcrt/fx_ucddata.cpp | 13 --------- core/fxcrt/fx_unicode.cpp | 59 +++++++++++++---------------------------- 4 files changed, 28 insertions(+), 66 deletions(-) (limited to 'core') diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index b6b3a0dbce..1dc03db4ff 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -673,7 +673,7 @@ void CPDF_TextPage::AddCharInfoByRLDirection(wchar_t wChar, } info.m_Index = m_TextBuf.GetLength(); - wChar = FX_GetMirrorChar(wChar, true, false); + wChar = FX_GetMirrorChar(wChar); wchar_t* pDst = nullptr; FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); if (nCount >= 1) { 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(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(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 -- cgit v1.2.3