diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-18 15:07:51 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-18 19:45:58 +0000 |
commit | 1d0dc5ea42642b253bf87b69b9d8cff01f4e6dbb (patch) | |
tree | e1cdc4c27da0e013282ca6ea9b8fc47cfc539d68 | |
parent | 4fcdf058734b5df696420aa653ea787842678224 (diff) | |
download | pdfium-1d0dc5ea42642b253bf87b69b9d8cff01f4e6dbb.tar.xz |
Codepage code into anonymouse namespace
This CL moves the FX_GetCodePageFromCharset method into cfgas_fontmgr
anonymouse namespace.
Change-Id: I1232341b8639328035f12aebfb7a65a4fc0ba08f
Reviewed-on: https://pdfium-review.googlesource.com/4291
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | xfa/fgas/crt/fgas_codepage.cpp | 70 | ||||
-rw-r--r-- | xfa/fgas/crt/fgas_codepage.h | 3 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 63 |
4 files changed, 61 insertions, 76 deletions
@@ -1427,7 +1427,6 @@ if (pdf_enable_xfa) { "xfa/fde/xml/cfde_xmltext.h", "xfa/fgas/crt/cfgas_formatstring.cpp", "xfa/fgas/crt/cfgas_formatstring.h", - "xfa/fgas/crt/fgas_codepage.cpp", "xfa/fgas/crt/fgas_codepage.h", "xfa/fgas/crt/fgas_language.h", "xfa/fgas/crt/ifgas_stream.cpp", diff --git a/xfa/fgas/crt/fgas_codepage.cpp b/xfa/fgas/crt/fgas_codepage.cpp deleted file mode 100644 index c1a4322883..0000000000 --- a/xfa/fgas/crt/fgas_codepage.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/fx_ext.h" -#include "xfa/fgas/crt/fgas_codepage.h" -#include "xfa/fgas/crt/fgas_language.h" - -namespace { - -struct FX_CHARSET_MAP { - uint16_t charset; - uint16_t codepage; -}; - -const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { - {FX_CHARSET_ANSI, FX_CODEPAGE_MSWin_WesternEuropean}, - {FX_CHARSET_Default, FX_CODEPAGE_DefANSI}, - {FX_CHARSET_Symbol, FX_CODEPAGE_Symbol}, - {FX_CHARSET_MAC_Roman, FX_CODEPAGE_MAC_Roman}, - {FX_CHARSET_MAC_ShiftJIS, FX_CODEPAGE_MAC_ShiftJIS}, - {FX_CHARSET_MAC_Korean, FX_CODEPAGE_MAC_Korean}, - {FX_CHARSET_MAC_ChineseSimplified, FX_CODEPAGE_MAC_ChineseSimplified}, - {FX_CHARSET_MAC_ChineseTriditional, FX_CODEPAGE_MAC_ChineseTraditional}, - {FX_CHARSET_MAC_Hebrew, FX_CODEPAGE_MAC_Hebrew}, - {FX_CHARSET_MAC_Arabic, FX_CODEPAGE_MAC_Arabic}, - {FX_CHARSET_MAC_Greek, FX_CODEPAGE_MAC_Greek}, - {FX_CHARSET_MAC_Turkish, FX_CODEPAGE_MAC_Turkish}, - {FX_CHARSET_MAC_Thai, FX_CODEPAGE_MAC_Thai}, - {FX_CHARSET_MAC_EasternEuropean, FX_CODEPAGE_MAC_EasternEuropean}, - {FX_CHARSET_MAC_Cyrillic, FX_CODEPAGE_MAC_Cyrillic}, - {FX_CHARSET_ShiftJIS, FX_CODEPAGE_ShiftJIS}, - {FX_CHARSET_Korean, FX_CODEPAGE_Korean}, - {FX_CHARSET_Johab, FX_CODEPAGE_Johab}, - {FX_CHARSET_ChineseSimplified, FX_CODEPAGE_ChineseSimplified}, - {FX_CHARSET_ChineseTriditional, FX_CODEPAGE_ChineseTraditional}, - {FX_CHARSET_MSWin_Greek, FX_CODEPAGE_MSWin_Greek}, - {FX_CHARSET_MSWin_Turkish, FX_CODEPAGE_MSWin_Turkish}, - {FX_CHARSET_MSWin_Vietnamese, FX_CODEPAGE_MSWin_Vietnamese}, - {FX_CHARSET_MSWin_Hebrew, FX_CODEPAGE_MSWin_Hebrew}, - {FX_CHARSET_MSWin_Arabic, FX_CODEPAGE_MSWin_Arabic}, - {FX_CHARSET_MSWin_Baltic, FX_CODEPAGE_MSWin_Baltic}, - {FX_CHARSET_MSWin_Cyrillic, FX_CODEPAGE_MSWin_Cyrillic}, - {FX_CHARSET_Thai, FX_CODEPAGE_MSDOS_Thai}, - {FX_CHARSET_MSWin_EasterEuropean, FX_CODEPAGE_MSWin_EasternEuropean}, - {FX_CHARSET_US, FX_CODEPAGE_MSDOS_US}, - {FX_CHARSET_OEM, FX_CODEPAGE_MSDOS_WesternEuropean}, -}; - -} // namespace - -uint16_t FX_GetCodePageFromCharset(uint8_t charset) { - int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1; - ASSERT(iEnd >= 0); - - int32_t iStart = 0, iMid; - do { - iMid = (iStart + iEnd) / 2; - const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid]; - if (charset == cp.charset) - return cp.codepage; - if (charset < cp.charset) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); - return 0xFFFF; -} diff --git a/xfa/fgas/crt/fgas_codepage.h b/xfa/fgas/crt/fgas_codepage.h index 8e29736149..17813595e6 100644 --- a/xfa/fgas/crt/fgas_codepage.h +++ b/xfa/fgas/crt/fgas_codepage.h @@ -97,6 +97,7 @@ #define FX_CODEPAGE_ISCII_Punjabi 57011 #define FX_CODEPAGE_UTF7 65000 #define FX_CODEPAGE_UTF8 65001 + #define FX_CHARSET_ANSI 0 #define FX_CHARSET_Default 1 #define FX_CHARSET_Symbol 2 @@ -133,6 +134,4 @@ #define FX_CHARSET_US 254 #define FX_CHARSET_OEM 255 -uint16_t FX_GetCodePageFromCharset(uint8_t charset); - #endif // XFA_FGAS_CRT_FGAS_CODEPAGE_H_ diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 766422e381..8cd799e37a 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -25,6 +25,63 @@ namespace { +struct FX_CHARSET_MAP { + uint16_t charset; + uint16_t codepage; +}; + +const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { + {FX_CHARSET_ANSI, FX_CODEPAGE_MSWin_WesternEuropean}, + {FX_CHARSET_Default, FX_CODEPAGE_DefANSI}, + {FX_CHARSET_Symbol, FX_CODEPAGE_Symbol}, + {FX_CHARSET_MAC_Roman, FX_CODEPAGE_MAC_Roman}, + {FX_CHARSET_MAC_ShiftJIS, FX_CODEPAGE_MAC_ShiftJIS}, + {FX_CHARSET_MAC_Korean, FX_CODEPAGE_MAC_Korean}, + {FX_CHARSET_MAC_ChineseSimplified, FX_CODEPAGE_MAC_ChineseSimplified}, + {FX_CHARSET_MAC_ChineseTriditional, FX_CODEPAGE_MAC_ChineseTraditional}, + {FX_CHARSET_MAC_Hebrew, FX_CODEPAGE_MAC_Hebrew}, + {FX_CHARSET_MAC_Arabic, FX_CODEPAGE_MAC_Arabic}, + {FX_CHARSET_MAC_Greek, FX_CODEPAGE_MAC_Greek}, + {FX_CHARSET_MAC_Turkish, FX_CODEPAGE_MAC_Turkish}, + {FX_CHARSET_MAC_Thai, FX_CODEPAGE_MAC_Thai}, + {FX_CHARSET_MAC_EasternEuropean, FX_CODEPAGE_MAC_EasternEuropean}, + {FX_CHARSET_MAC_Cyrillic, FX_CODEPAGE_MAC_Cyrillic}, + {FX_CHARSET_ShiftJIS, FX_CODEPAGE_ShiftJIS}, + {FX_CHARSET_Korean, FX_CODEPAGE_Korean}, + {FX_CHARSET_Johab, FX_CODEPAGE_Johab}, + {FX_CHARSET_ChineseSimplified, FX_CODEPAGE_ChineseSimplified}, + {FX_CHARSET_ChineseTriditional, FX_CODEPAGE_ChineseTraditional}, + {FX_CHARSET_MSWin_Greek, FX_CODEPAGE_MSWin_Greek}, + {FX_CHARSET_MSWin_Turkish, FX_CODEPAGE_MSWin_Turkish}, + {FX_CHARSET_MSWin_Vietnamese, FX_CODEPAGE_MSWin_Vietnamese}, + {FX_CHARSET_MSWin_Hebrew, FX_CODEPAGE_MSWin_Hebrew}, + {FX_CHARSET_MSWin_Arabic, FX_CODEPAGE_MSWin_Arabic}, + {FX_CHARSET_MSWin_Baltic, FX_CODEPAGE_MSWin_Baltic}, + {FX_CHARSET_MSWin_Cyrillic, FX_CODEPAGE_MSWin_Cyrillic}, + {FX_CHARSET_Thai, FX_CODEPAGE_MSDOS_Thai}, + {FX_CHARSET_MSWin_EasterEuropean, FX_CODEPAGE_MSWin_EasternEuropean}, + {FX_CHARSET_US, FX_CODEPAGE_MSDOS_US}, + {FX_CHARSET_OEM, FX_CODEPAGE_MSDOS_WesternEuropean}, +}; + +uint16_t GetCodePageFromCharset(uint8_t charset) { + int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1; + ASSERT(iEnd >= 0); + + int32_t iStart = 0, iMid; + do { + iMid = (iStart + iEnd) / 2; + const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid]; + if (charset == cp.charset) + return cp.codepage; + if (charset < cp.charset) + iEnd = iMid - 1; + else + iStart = iMid + 1; + } while (iStart <= iEnd); + return 0xFFFF; +} + int32_t GetSimilarityScore(FX_FONTDESCRIPTOR const* pFont, uint32_t dwFontStyles) { int32_t iValue = 0; @@ -67,7 +124,7 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont( if (font.uCharSet == FX_CHARSET_Symbol) continue; if (pParams->wCodePage != 0xFFFF) { - if (FX_GetCodePageFromCharset(font.uCharSet) != pParams->wCodePage) + if (GetCodePageFromCharset(font.uCharSet) != pParams->wCodePage) continue; } else { if (pParams->dwUSB < 128) { @@ -195,7 +252,7 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( if (!pFD) return nullptr; - uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); + uint16_t wCodePage = GetCodePageFromCharset(pFD->uCharSet); const wchar_t* pFontFace = pFD->wsFontFace; CFX_RetainPtr<CFGAS_GEFont> pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this); @@ -227,7 +284,7 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFont( return nullptr; if (wCodePage == 0xFFFF) - wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); + wCodePage = GetCodePageFromCharset(pFD->uCharSet); pFont = CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |