OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
8 #include "../agg/include/fx_agg_driver.h" | 8 #include "../agg/include/fx_agg_driver.h" |
9 #include "text_int.h" | 9 #include "text_int.h" |
10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ | 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
11 static const struct { | 11 static const struct { |
12 FX_LPCSTR» m_pName; | 12 const FX_CHAR*» m_pName; |
13 FX_LPCSTR» m_pSubstName; | 13 const FX_CHAR*» m_pSubstName; |
14 } | 14 } |
15 Base14Substs[] = { | 15 Base14Substs[] = { |
16 {"Courier", "Courier New"}, | 16 {"Courier", "Courier New"}, |
17 {"Courier-Bold", "Courier New Bold"}, | 17 {"Courier-Bold", "Courier New Bold"}, |
18 {"Courier-BoldOblique", "Courier New Bold Italic"}, | 18 {"Courier-BoldOblique", "Courier New Bold Italic"}, |
19 {"Courier-Oblique", "Courier New Italic"}, | 19 {"Courier-Oblique", "Courier New Italic"}, |
20 {"Helvetica", "Arial"}, | 20 {"Helvetica", "Arial"}, |
21 {"Helvetica-Bold", "Arial Bold"}, | 21 {"Helvetica-Bold", "Arial Bold"}, |
22 {"Helvetica-BoldOblique", "Arial Bold Italic"}, | 22 {"Helvetica-BoldOblique", "Arial Bold Italic"}, |
23 {"Helvetica-Oblique", "Arial Italic"}, | 23 {"Helvetica-Oblique", "Arial Italic"}, |
24 {"Times-Roman", "Times New Roman"}, | 24 {"Times-Roman", "Times New Roman"}, |
25 {"Times-Bold", "Times New Roman Bold"}, | 25 {"Times-Bold", "Times New Roman Bold"}, |
26 {"Times-BoldItalic", "Times New Roman Bold Italic"}, | 26 {"Times-BoldItalic", "Times New Roman Bold Italic"}, |
27 {"Times-Italic", "Times New Roman Italic"}, | 27 {"Times-Italic", "Times New Roman Italic"}, |
28 }; | 28 }; |
29 class CFX_LinuxFontInfo : public CFX_FolderFontInfo | 29 class CFX_LinuxFontInfo : public CFX_FolderFontInfo |
30 { | 30 { |
31 public: | 31 public: |
32 virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset
, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact); | 32 virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset
, int pitch_family, const FX_CHAR* family, FX_BOOL& bExact); |
33 FX_BOOL ParseFontCfg(); | 33 FX_BOOL ParseFontCfg(); |
34 void*» » » » FindFont(int weight, FX_BOOL bItalic, in
t charset, int pitch_family, FX_LPCSTR family, FX_BOOL bMatchName); | 34 void*» » » » FindFont(int weight, FX_BOOL bItalic, in
t charset, int pitch_family, const FX_CHAR* family, FX_BOOL bMatchName); |
35 }; | 35 }; |
36 #define LINUX_GPNAMESIZE 6 | 36 #define LINUX_GPNAMESIZE 6 |
37 static const struct { | 37 static const struct { |
38 FX_LPCSTR NameArr[LINUX_GPNAMESIZE]; | 38 const FX_CHAR* NameArr[LINUX_GPNAMESIZE]; |
39 } | 39 } |
40 LinuxGpFontList[] = { | 40 LinuxGpFontList[] = { |
41 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", "
VL Gothic regular"}}, | 41 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", "
VL Gothic regular"}}, |
42 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", NULL, "VL Gothic
regular"}}, | 42 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", NULL, "VL Gothic
regular"}}, |
43 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothi
c regular"}}, | 43 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothi
c regular"}}, |
44 {{"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothic
regular"}}, | 44 {{"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothic
regular"}}, |
45 }; | 45 }; |
46 static const FX_LPCSTR g_LinuxGbFontList[] = { | 46 static const FX_CHAR* const g_LinuxGbFontList[] = { |
47 "AR PL UMing CN Light", | 47 "AR PL UMing CN Light", |
48 "WenQuanYi Micro Hei", | 48 "WenQuanYi Micro Hei", |
49 "AR PL UKai CN", | 49 "AR PL UKai CN", |
50 }; | 50 }; |
51 static const FX_LPCSTR g_LinuxB5FontList[] = { | 51 static const FX_CHAR* const g_LinuxB5FontList[] = { |
52 "AR PL UMing TW Light", | 52 "AR PL UMing TW Light", |
53 "WenQuanYi Micro Hei", | 53 "WenQuanYi Micro Hei", |
54 "AR PL UKai TW", | 54 "AR PL UKai TW", |
55 }; | 55 }; |
56 static const FX_LPCSTR g_LinuxHGFontList[] = { | 56 static const FX_CHAR* const g_LinuxHGFontList[] = { |
57 "UnDotum", | 57 "UnDotum", |
58 }; | 58 }; |
59 static int32_t GetJapanesePreference(FX_LPCSTR facearr, int weight, int picth_fa
mily) | 59 static int32_t GetJapanesePreference(const FX_CHAR* facearr, int weight, int pic
th_family) |
60 { | 60 { |
61 CFX_ByteString face = facearr; | 61 CFX_ByteString face = facearr; |
62 if (face.Find("Gothic") >= 0 || face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e"
) >= 0) { | 62 if (face.Find("Gothic") >= 0 || face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e"
) >= 0) { |
63 if (face.Find("PGothic") >= 0 || face.Find("\x82\x6f\x83\x53\x83\x56\x83
\x62\x83\x4e") >= 0) { | 63 if (face.Find("PGothic") >= 0 || face.Find("\x82\x6f\x83\x53\x83\x56\x83
\x62\x83\x4e") >= 0) { |
64 return 0; | 64 return 0; |
65 } else { | 65 } else { |
66 return 1; | 66 return 1; |
67 } | 67 } |
68 } else if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) { | 68 } else if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) { |
69 if (face.Find("PMincho") >= 0 || face.Find("\x82\x6f\x96\xbe\x92\xa9") >
= 0) { | 69 if (face.Find("PMincho") >= 0 || face.Find("\x82\x6f\x96\xbe\x92\xa9") >
= 0) { |
70 return 2; | 70 return 2; |
71 } else { | 71 } else { |
72 return 3; | 72 return 3; |
73 } | 73 } |
74 } | 74 } |
75 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { | 75 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 return 2; | 78 return 2; |
79 } | 79 } |
80 void* CFX_LinuxFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int p
itch_family, FX_LPCSTR cstr_face, FX_BOOL& bExact) | 80 void* CFX_LinuxFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int p
itch_family, const FX_CHAR* cstr_face, FX_BOOL& bExact) |
81 { | 81 { |
82 CFX_ByteString face = cstr_face; | 82 CFX_ByteString face = cstr_face; |
83 int iBaseFont; | 83 int iBaseFont; |
84 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++) | 84 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++) |
85 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { | 85 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { |
86 face = Base14Substs[iBaseFont].m_pSubstName; | 86 face = Base14Substs[iBaseFont].m_pSubstName; |
87 bExact = TRUE; | 87 bExact = TRUE; |
88 break; | 88 break; |
89 } | 89 } |
90 if (iBaseFont < 12) { | 90 if (iBaseFont < 12) { |
91 return GetFont(face); | 91 return GetFont(face); |
92 } | 92 } |
93 FX_LPVOID p = NULL; | 93 void* p = NULL; |
94 FX_BOOL bCJK = TRUE; | 94 FX_BOOL bCJK = TRUE; |
95 switch (charset) { | 95 switch (charset) { |
96 case FXFONT_SHIFTJIS_CHARSET: { | 96 case FXFONT_SHIFTJIS_CHARSET: { |
97 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_f
amily); | 97 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_f
amily); |
98 if (index < 0) { | 98 if (index < 0) { |
99 break; | 99 break; |
100 } | 100 } |
101 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) | 101 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) |
102 if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p))
{ | 102 if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p))
{ |
103 return p; | 103 return p; |
104 } | 104 } |
105 } | 105 } |
106 break; | 106 break; |
107 case FXFONT_GB2312_CHARSET: { | 107 case FXFONT_GB2312_CHARSET: { |
108 static int32_t s_gbCount = sizeof(g_LinuxGbFontList) / sizeof(FX
_LPCSTR); | 108 static int32_t s_gbCount = sizeof(g_LinuxGbFontList) / sizeof(co
nst FX_CHAR*); |
109 for (int32_t i = 0; i < s_gbCount; i++) | 109 for (int32_t i = 0; i < s_gbCount; i++) |
110 if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) { | 110 if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) { |
111 return p; | 111 return p; |
112 } | 112 } |
113 } | 113 } |
114 break; | 114 break; |
115 case FXFONT_CHINESEBIG5_CHARSET: { | 115 case FXFONT_CHINESEBIG5_CHARSET: { |
116 static int32_t s_b5Count = sizeof(g_LinuxB5FontList) / sizeof(FX
_LPCSTR); | 116 static int32_t s_b5Count = sizeof(g_LinuxB5FontList) / sizeof(co
nst FX_CHAR*); |
117 for (int32_t i = 0; i < s_b5Count; i++) | 117 for (int32_t i = 0; i < s_b5Count; i++) |
118 if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) { | 118 if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) { |
119 return p; | 119 return p; |
120 } | 120 } |
121 } | 121 } |
122 break; | 122 break; |
123 case FXFONT_HANGEUL_CHARSET: { | 123 case FXFONT_HANGEUL_CHARSET: { |
124 static int32_t s_hgCount = sizeof(g_LinuxHGFontList) / sizeof(FX
_LPCSTR); | 124 static int32_t s_hgCount = sizeof(g_LinuxHGFontList) / sizeof(co
nst FX_CHAR*); |
125 for (int32_t i = 0; i < s_hgCount; i++) | 125 for (int32_t i = 0; i < s_hgCount; i++) |
126 if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) { | 126 if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) { |
127 return p; | 127 return p; |
128 } | 128 } |
129 } | 129 } |
130 break; | 130 break; |
131 default: | 131 default: |
132 bCJK = FALSE; | 132 bCJK = FALSE; |
133 break; | 133 break; |
134 } | 134 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 iSimilarValue += 16; | 170 iSimilarValue += 16; |
171 } | 171 } |
172 if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) { | 172 if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) { |
173 iSimilarValue += 8; | 173 iSimilarValue += 8; |
174 } | 174 } |
175 if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) { | 175 if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) { |
176 iSimilarValue += 8; | 176 iSimilarValue += 8; |
177 } | 177 } |
178 return iSimilarValue; | 178 return iSimilarValue; |
179 } | 179 } |
180 void* CFX_LinuxFontInfo::FindFont(int weight, FX_BOOL bItalic, int charset, int
pitch_family, FX_LPCSTR family, FX_BOOL bMatchName) | 180 void* CFX_LinuxFontInfo::FindFont(int weight, FX_BOOL bItalic, int charset, int
pitch_family, const FX_CHAR* family, FX_BOOL bMatchName) |
181 { | 181 { |
182 CFontFaceInfo* pFind = NULL; | 182 CFontFaceInfo* pFind = NULL; |
183 FX_DWORD charset_flag = _LinuxGetCharset(charset); | 183 FX_DWORD charset_flag = _LinuxGetCharset(charset); |
184 int32_t iBestSimilar = 0; | 184 int32_t iBestSimilar = 0; |
185 FX_POSITION pos = m_FontList.GetStartPosition(); | 185 FX_POSITION pos = m_FontList.GetStartPosition(); |
186 while (pos) { | 186 while (pos) { |
187 CFX_ByteString bsName; | 187 CFX_ByteString bsName; |
188 CFontFaceInfo* pFont = NULL; | 188 CFontFaceInfo* pFont = NULL; |
189 m_FontList.GetNextAssoc(pos, bsName, (FX_LPVOID&)pFont); | 189 m_FontList.GetNextAssoc(pos, bsName, (void*&)pFont); |
190 if (!(pFont->m_Charsets & charset_flag) && charset != FXFONT_DEFAULT_CHA
RSET) { | 190 if (!(pFont->m_Charsets & charset_flag) && charset != FXFONT_DEFAULT_CHA
RSET) { |
191 continue; | 191 continue; |
192 } | 192 } |
193 int32_t iSimilarValue = 0; | 193 int32_t iSimilarValue = 0; |
194 int32_t index = bsName.Find(family); | 194 int32_t index = bsName.Find(family); |
195 if (bMatchName && index < 0) { | 195 if (bMatchName && index < 0) { |
196 continue; | 196 continue; |
197 } | 197 } |
198 if (!bMatchName && index > 0) { | 198 if (!bMatchName && index > 0) { |
199 iSimilarValue += 64; | 199 iSimilarValue += 64; |
(...skipping 22 matching lines...) Expand all Loading... |
222 return FALSE; | 222 return FALSE; |
223 } | 223 } |
224 void CFX_GEModule::InitPlatform() | 224 void CFX_GEModule::InitPlatform() |
225 { | 225 { |
226 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); | 226 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); |
227 } | 227 } |
228 void CFX_GEModule::DestroyPlatform() | 228 void CFX_GEModule::DestroyPlatform() |
229 { | 229 { |
230 } | 230 } |
231 #endif | 231 #endif |
OLD | NEW |