summaryrefslogtreecommitdiff
path: root/core/fxge
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 /core/fxge
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 'core/fxge')
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp4
-rw-r--r--core/fxge/cfx_font.cpp82
-rw-r--r--core/fxge/cfx_font.h18
-rw-r--r--core/fxge/cfx_fontmapper.cpp33
4 files changed, 103 insertions, 34 deletions
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index d44d7d56d2..0b49f6283c 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -187,9 +187,7 @@ uint32_t FPF_SKIAGetFamilyHash(const ByteStringView& bsFamily,
}
bool FPF_SkiaIsCJK(uint8_t uCharset) {
- return (uCharset == FX_CHARSET_ChineseSimplified) ||
- (uCharset == FX_CHARSET_ChineseTraditional) ||
- (uCharset == FX_CHARSET_Hangul) || (uCharset == FX_CHARSET_ShiftJIS);
+ return FX_CharSetIsCJK(uCharset);
}
bool FPF_SkiaMaybeSymbol(const ByteStringView& bsFacename) {
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index d04fc0dac0..bee1d789ef 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -209,6 +209,88 @@ const uint8_t CFX_Font::s_WeightPow_SHIFTJIS[] = {
59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60,
};
+const CFX_Font::CharsetFontMap CFX_Font::defaultTTFMap[] = {
+ {FX_CHARSET_ANSI, kDefaultAnsiFontName},
+ {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}};
+
+// static
+const char CFX_Font::kDefaultAnsiFontName[] = "Helvetica";
+// static
+const char CFX_Font::kUniversalDefaultFontName[] = "Arial Unicode MS";
+
+// static
+ByteString CFX_Font::GetDefaultFontNameByCharset(uint8_t nCharset) {
+ int i = 0;
+ while (defaultTTFMap[i].charset != -1) {
+ if (nCharset == static_cast<uint8_t>(defaultTTFMap[i].charset))
+ return defaultTTFMap[i].fontname;
+ ++i;
+ }
+ return kUniversalDefaultFontName;
+}
+
+// static
+uint8_t CFX_Font::GetCharSetFromUnicode(uint16_t word) {
+ // to avoid CJK Font to show ASCII
+ if (word < 0x7F)
+ return FX_CHARSET_ANSI;
+
+ // 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;
+}
+
CFX_Font::CFX_Font()
:
m_Face(nullptr),
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index fbf35eaca1..a5a0057c16 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -30,6 +30,11 @@ class CFX_Font {
CFX_Font();
~CFX_Font();
+ static const char kDefaultAnsiFontName[];
+ static const char kUniversalDefaultFontName[];
+ static ByteString GetDefaultFontNameByCharset(uint8_t nCharset);
+ static uint8_t GetCharSetFromUnicode(uint16_t word);
+
void LoadSubst(const ByteString& face_name,
bool bTrueType,
uint32_t flags,
@@ -96,6 +101,19 @@ class CFX_Font {
static const uint8_t s_WeightPow_11[kWeightPowArraySize];
static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize];
+ // This struct shoub same as FPDF_CharsetFontMap
+ typedef struct {
+ int charset; // Character Set Enum value, see FX_CHARSET_XXX.
+ const char* fontname; // Name of default font to use with that charset.
+ } CharsetFontMap;
+
+ /**
+ * Pointer to the default character set to TT Font name map. The
+ * map is an array of CharsetFontMap structs, with its end indicated
+ * by a { -1, NULL } entry.
+ **/
+ static const CharsetFontMap defaultTTFMap[];
+
#ifdef PDF_ENABLE_XFA
protected:
std::unique_ptr<FXFT_StreamRec> m_pOwnedStream;
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index b9a8eac1a1..e6fc984edc 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -145,19 +145,6 @@ const struct AltFontFamily {
{"ForteMT", "Forte"},
};
-const struct CODEPAGE_MAP {
- uint16_t codepage;
- uint8_t charset;
-} g_Codepage2CharsetTable[] = {
- {0, 1}, {42, 2}, {437, 254}, {850, 255}, {874, 222},
- {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238},
- {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177},
- {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77},
- {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83},
- {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88},
- {10081, 86},
-};
-
ByteString TT_NormalizeName(const char* family) {
ByteString norm(family);
norm.Remove(' ');
@@ -170,19 +157,6 @@ ByteString TT_NormalizeName(const char* family) {
return norm;
}
-uint8_t GetCharsetFromCodePage(uint16_t codepage) {
- const CODEPAGE_MAP* pEnd =
- g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable);
- const CODEPAGE_MAP* pCharmap =
- std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage,
- [](const CODEPAGE_MAP& charset, uint16_t page) {
- return charset.codepage < page;
- });
- if (pCharmap < pEnd && codepage == pCharmap->codepage)
- return pCharmap->charset;
- return FX_CHARSET_Default;
-}
-
void GetFontFamily(uint32_t nStyle, ByteString* fontName) {
if (fontName->Contains("Script")) {
if (FontStyleIsBold(nStyle))
@@ -544,13 +518,10 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
int Charset = FX_CHARSET_ANSI;
if (WindowCP)
- Charset = GetCharsetFromCodePage(WindowCP);
+ Charset = FX_GetCharsetFromCodePage(WindowCP);
else if (iBaseFont == kNumStandardFonts && FontStyleIsSymbolic(flags))
Charset = FX_CHARSET_Symbol;
- const bool bCJK = (Charset == FX_CHARSET_ShiftJIS ||
- Charset == FX_CHARSET_ChineseSimplified ||
- Charset == FX_CHARSET_Hangul ||
- Charset == FX_CHARSET_ChineseTraditional);
+ const bool bCJK = FX_CharSetIsCJK(Charset);
bool bItalic = FontStyleIsItalic(nStyle);
GetFontFamily(nStyle, &family);