summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_extension.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-05-05 16:49:30 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-05-05 21:42:22 +0000
commit54b9166366085b30b7ee3094c2b71cd36e377153 (patch)
treecb7eded9f2304cefbb2ea0ce2542b4864780199f /core/fxcrt/fx_extension.cpp
parent0ec418f043b946134bee1a37c1dde1cc987579df (diff)
downloadpdfium-54b9166366085b30b7ee3094c2b71cd36e377153.tar.xz
Encode unicodes in UTF-16BE in ToUnicode map
Bug: pdfium:667 Change-Id: I811571c334ff28162905a65781ca14f03caf2966 Reviewed-on: https://pdfium-review.googlesource.com/4910 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_extension.cpp')
-rw-r--r--core/fxcrt/fx_extension.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 209584b68d..2b290ed79d 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -137,6 +137,31 @@ uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase) {
return dwHashCode;
}
+void FXSYS_IntToTwoHexChars(uint8_t n, char* buf) {
+ static const char kHex[] = "0123456789ABCDEF";
+ buf[0] = kHex[n / 16];
+ buf[1] = kHex[n % 16];
+}
+
+void FXSYS_IntToFourHexChars(uint16_t n, char* buf) {
+ FXSYS_IntToTwoHexChars(n / 256, buf);
+ FXSYS_IntToTwoHexChars(n % 256, buf + 2);
+}
+
+size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf) {
+ ASSERT(unicode <= 0xD7FF || (unicode > 0xDFFF && unicode <= 0x10FFFF));
+ if (unicode <= 0xFFFF) {
+ FXSYS_IntToFourHexChars(unicode, buf);
+ return 4;
+ }
+ unicode -= 0x010000;
+ // High ten bits plus 0xD800
+ FXSYS_IntToFourHexChars(0xD800 + unicode / 0x400, buf);
+ // Low ten bits plus 0xDC00
+ FXSYS_IntToFourHexChars(0xDC00 + unicode % 0x400, buf + 4);
+ return 8;
+}
+
void* FX_Random_MT_Start(uint32_t dwSeed) {
FX_MTRANDOMCONTEXT* pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
pContext->mt[0] = dwSeed;