summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_unicode.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-07-27 13:47:27 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-07-27 23:20:44 +0000
commit672a1721620c3f4e62fe6adfaceb929d423ae31f (patch)
treecd9e07848dc9a99e48a9276324c2dbcb655e4ffc /core/fxcrt/fx_unicode.cpp
parent3f7ff0540e7913ddc2c2d4f60e144cc0c7700e9e (diff)
downloadpdfium-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/fx_unicode.cpp')
-rw-r--r--core/fxcrt/fx_unicode.cpp59
1 files changed, 19 insertions, 40 deletions
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