summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-05-31 14:08:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-31 14:08:11 +0000
commit656eb84f83fc1701737d9c65658371a99428d727 (patch)
tree6fb28e4283c1ef8696b42d8b7d200a13c32742fc /fpdfsdk
parent8f7ee98e2c622c21f452cd9fd5956fe85bcb2b7c (diff)
downloadpdfium-656eb84f83fc1701737d9c65658371a99428d727.tar.xz
Move codepage/charset methods into related places.
Change-Id: I71417cc5b1bd00f77d42740198cc17487ebd686e Reviewed-on: https://pdfium-review.googlesource.com/33330 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cfx_systemhandler.cpp19
-rw-r--r--fpdfsdk/fpdf_sysfontinfo.cpp5
-rw-r--r--fpdfsdk/pwl/cpwl_font_map.cpp133
-rw-r--r--fpdfsdk/pwl/cpwl_font_map.h3
4 files changed, 13 insertions, 147 deletions
diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp
index 28170d2878..62d7c735b0 100644
--- a/fpdfsdk/cfx_systemhandler.cpp
+++ b/fpdfsdk/cfx_systemhandler.cpp
@@ -20,22 +20,6 @@
#include "fpdfsdk/cpdfsdk_widget.h"
#include "fpdfsdk/formfiller/cffl_formfiller.h"
-namespace {
-
-int CharSet2CP(int charset) {
- if (charset == FX_CHARSET_ShiftJIS)
- return FX_CODEPAGE_ShiftJIS;
- if (charset == FX_CHARSET_ChineseSimplified)
- return FX_CODEPAGE_ChineseSimplified;
- if (charset == FX_CHARSET_Hangul)
- return FX_CODEPAGE_Hangul;
- if (charset == FX_CHARSET_ChineseTraditional)
- return FX_CODEPAGE_ChineseTraditional;
- return FX_CODEPAGE_DefANSI;
-}
-
-} // namespace
-
CFX_SystemHandler::CFX_SystemHandler(CPDFSDK_FormFillEnvironment* pFormFillEnv)
: m_pFormFillEnv(pFormFillEnv) {}
@@ -121,7 +105,8 @@ CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(
return nullptr;
auto pFXFont = pdfium::MakeUnique<CFX_Font>();
- pFXFont->LoadSubst(sFontFaceName, true, 0, 0, 0, CharSet2CP(nCharset), false);
+ pFXFont->LoadSubst(sFontFaceName, true, 0, 0, 0,
+ FX_GetCodePageFromCharset(nCharset), false);
return pDoc->AddFont(pFXFont.get(), nCharset, false);
}
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 3a3f9e1257..564912b85c 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -9,6 +9,7 @@
#include <memory>
#include "core/fxcrt/fx_codepage.h"
+#include "core/fxge/cfx_font.h"
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/cfx_fontmgr.h"
#include "core/fxge/cfx_gemodule.h"
@@ -30,6 +31,8 @@ static_assert(FXFONT_GB2312_CHARSET == FX_CHARSET_ChineseSimplified,
"Charset must match");
static_assert(FXFONT_CHINESEBIG5_CHARSET == FX_CHARSET_ChineseTraditional,
"Charset must match");
+static_assert(sizeof(CFX_Font::CharsetFontMap) == sizeof(FPDF_CharsetFontMap),
+ "CFX_Font::CharsetFontMap should be same as FPDF_CharsetFontMap");
class CFX_ExternalFontInfo final : public SystemFontInfoIface {
public:
@@ -122,7 +125,7 @@ FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) {
}
FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap() {
- return CPWL_FontMap::defaultTTFMap;
+ return reinterpret_cast<const FPDF_CharsetFontMap*>(CFX_Font::defaultTTFMap);
}
struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO {
diff --git a/fpdfsdk/pwl/cpwl_font_map.cpp b/fpdfsdk/pwl/cpwl_font_map.cpp
index 5e5556ebb0..f60e7d2fb1 100644
--- a/fpdfsdk/pwl/cpwl_font_map.cpp
+++ b/fpdfsdk/pwl/cpwl_font_map.cpp
@@ -21,8 +21,6 @@
namespace {
-const char kDefaultFontName[] = "Helvetica";
-
const char* const g_sDEStandardFontName[] = {"Courier",
"Courier-Bold",
"Courier-BoldOblique",
@@ -100,7 +98,8 @@ int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
if (KnowWord(nNewFontIndex, word))
return nNewFontIndex;
}
- nNewFontIndex = GetFontIndex("Arial Unicode MS", FX_CHARSET_Default, false);
+ nNewFontIndex = GetFontIndex(CFX_Font::kUniversalDefaultFontName,
+ FX_CHARSET_Default, false);
if (nNewFontIndex >= 0) {
if (KnowWord(nNewFontIndex, word))
return nNewFontIndex;
@@ -145,7 +144,7 @@ void CPWL_FontMap::Empty() {
}
void CPWL_FontMap::Initialize() {
- GetFontIndex(kDefaultFontName, FX_CHARSET_ANSI, false);
+ GetFontIndex(CFX_Font::kDefaultAnsiFontName, FX_CHARSET_ANSI, false);
}
bool CPWL_FontMap::IsStandardFont(const ByteString& sFontName) {
@@ -210,7 +209,7 @@ ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
if (nCharset == FX_CHARSET_Default)
nCharset = GetNativeCharset();
- ByteString sFontName = GetDefaultFontByCharset(nCharset);
+ ByteString sFontName = CFX_Font::GetDefaultFontNameByCharset(nCharset);
if (!m_pSystemHandler->FindNativeTrueTypeFont(sFontName))
return ByteString();
@@ -274,135 +273,17 @@ const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
}
int32_t CPWL_FontMap::GetNativeCharset() {
- uint8_t nCharset = FX_CHARSET_ANSI;
- int32_t iCodePage = FXSYS_GetACP();
- switch (iCodePage) {
- case FX_CODEPAGE_ShiftJIS:
- nCharset = FX_CHARSET_ShiftJIS;
- break;
- case FX_CODEPAGE_ChineseSimplified:
- nCharset = FX_CHARSET_ChineseSimplified;
- break;
- case FX_CODEPAGE_ChineseTraditional:
- nCharset = FX_CHARSET_ChineseTraditional;
- break;
- case FX_CODEPAGE_MSWin_WesternEuropean:
- nCharset = FX_CHARSET_ANSI;
- break;
- case FX_CODEPAGE_MSDOS_Thai:
- nCharset = FX_CHARSET_Thai;
- break;
- case FX_CODEPAGE_Hangul:
- nCharset = FX_CHARSET_Hangul;
- break;
- case FX_CODEPAGE_UTF16LE:
- nCharset = FX_CHARSET_ANSI;
- break;
- case FX_CODEPAGE_MSWin_EasternEuropean:
- nCharset = FX_CHARSET_MSWin_EasternEuropean;
- break;
- case FX_CODEPAGE_MSWin_Cyrillic:
- nCharset = FX_CHARSET_MSWin_Cyrillic;
- break;
- case FX_CODEPAGE_MSWin_Greek:
- nCharset = FX_CHARSET_MSWin_Greek;
- break;
- case FX_CODEPAGE_MSWin_Turkish:
- nCharset = FX_CHARSET_MSWin_Turkish;
- break;
- case FX_CODEPAGE_MSWin_Hebrew:
- nCharset = FX_CHARSET_MSWin_Hebrew;
- break;
- case FX_CODEPAGE_MSWin_Arabic:
- nCharset = FX_CHARSET_MSWin_Arabic;
- break;
- case FX_CODEPAGE_MSWin_Baltic:
- nCharset = FX_CHARSET_MSWin_Baltic;
- break;
- case FX_CODEPAGE_MSWin_Vietnamese:
- nCharset = FX_CHARSET_MSWin_Vietnamese;
- break;
- case FX_CODEPAGE_Johab:
- nCharset = FX_CHARSET_Johab;
- break;
- }
- return nCharset;
-}
-
-const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
- {FX_CHARSET_ANSI, "Helvetica"},
- {FX_CHARSET_ChineseSimplified, "SimSun"},
- {FX_CHARSET_ChineseTraditional, "MingLiU"},
- {FX_CHARSET_ShiftJIS, "MS Gothic"},
- {FX_CHARSET_Hangul, "Batang"},
- {FX_CHARSET_MSWin_Cyrillic, "Arial"},
-#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_ || _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
- {FX_CHARSET_MSWin_EasternEuropean, "Arial"},
-#else
- {FX_CHARSET_MSWin_EasternEuropean, "Tahoma"},
-#endif
- {FX_CHARSET_MSWin_Arabic, "Arial"},
- {-1, nullptr}};
-
-ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
- int i = 0;
- while (defaultTTFMap[i].charset != -1) {
- if (nCharset == defaultTTFMap[i].charset)
- return defaultTTFMap[i].fontname;
- ++i;
- }
- return "";
+ return FX_GetCharsetFromCodePage(FXSYS_GetACP());
}
int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
// to avoid CJK Font to show ASCII
if (word < 0x7F)
return FX_CHARSET_ANSI;
+
// follow the old charset
if (nOldCharset != FX_CHARSET_Default)
return nOldCharset;
- // find new charset
- if ((word >= 0x4E00 && word <= 0x9FA5) ||
- (word >= 0xE7C7 && word <= 0xE7F3) ||
- (word >= 0x3000 && word <= 0x303F) ||
- (word >= 0x2000 && word <= 0x206F)) {
- return FX_CHARSET_ChineseSimplified;
- }
-
- if (((word >= 0x3040) && (word <= 0x309F)) ||
- ((word >= 0x30A0) && (word <= 0x30FF)) ||
- ((word >= 0x31F0) && (word <= 0x31FF)) ||
- ((word >= 0xFF00) && (word <= 0xFFEF))) {
- return FX_CHARSET_ShiftJIS;
- }
-
- if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
- ((word >= 0x1100) && (word <= 0x11FF)) ||
- ((word >= 0x3130) && (word <= 0x318F))) {
- return FX_CHARSET_Hangul;
- }
-
- if (word >= 0x0E00 && word <= 0x0E7F)
- return FX_CHARSET_Thai;
-
- if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
- return FX_CHARSET_MSWin_Greek;
-
- if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
- return FX_CHARSET_MSWin_Arabic;
-
- if (word >= 0x0590 && word <= 0x05FF)
- return FX_CHARSET_MSWin_Hebrew;
-
- if (word >= 0x0400 && word <= 0x04FF)
- return FX_CHARSET_MSWin_Cyrillic;
-
- if (word >= 0x0100 && word <= 0x024F)
- return FX_CHARSET_MSWin_EasternEuropean;
-
- if (word >= 0x1E00 && word <= 0x1EFF)
- return FX_CHARSET_MSWin_Vietnamese;
-
- return FX_CHARSET_ANSI;
+ return CFX_Font::GetCharSetFromUnicode(word);
}
diff --git a/fpdfsdk/pwl/cpwl_font_map.h b/fpdfsdk/pwl/cpwl_font_map.h
index 592c3fafed..c465a0fc0c 100644
--- a/fpdfsdk/pwl/cpwl_font_map.h
+++ b/fpdfsdk/pwl/cpwl_font_map.h
@@ -46,9 +46,6 @@ class CPWL_FontMap : public IPVT_FontMap {
static int32_t GetNativeCharset();
ByteString GetNativeFontName(int32_t nCharset);
- static ByteString GetDefaultFontByCharset(int32_t nCharset);
- static const FPDF_CharsetFontMap defaultTTFMap[];
-
protected:
virtual void Initialize();
virtual CPDF_Document* GetDocument();