Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: core/fxge/ge/fx_ge_linux.cpp

Issue 2529013002: Nits in fx_ge_linux (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef _SKIA_SUPPORT_
8 #include "core/fxge/agg/fx_agg_driver.h"
9 #endif
10
11 #include <memory> 7 #include <memory>
12 8
13 #include "core/fxge/cfx_gemodule.h" 9 #include "core/fxge/cfx_gemodule.h"
14 #include "core/fxge/ge/cfx_folderfontinfo.h" 10 #include "core/fxge/ge/cfx_folderfontinfo.h"
15 #include "core/fxge/ge/fx_text_int.h"
16 #include "core/fxge/ifx_systemfontinfo.h" 11 #include "core/fxge/ifx_systemfontinfo.h"
17 12
18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ 13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
19 namespace { 14 namespace {
20 15
21 class CFX_LinuxFontInfo : public CFX_FolderFontInfo {
22 public:
23 void* MapFont(int weight,
24 bool bItalic,
25 int charset,
26 int pitch_family,
27 const FX_CHAR* family,
28 int& iExact) override;
29 bool ParseFontCfg(const char** pUserPaths);
30 };
31
32 const size_t kLinuxGpNameSize = 6; 16 const size_t kLinuxGpNameSize = 6;
33 17
34 const FX_CHAR* const g_LinuxGpFontList[][kLinuxGpNameSize] = { 18 const FX_CHAR* const g_LinuxGpFontList[][kLinuxGpNameSize] = {
35 {"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", 19 {"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic",
36 "VL Gothic regular"}, 20 "VL Gothic regular"},
37 {"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr, 21 {"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", nullptr,
38 "VL Gothic regular"}, 22 "VL Gothic regular"},
39 {"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", nullptr, 23 {"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", nullptr,
40 "VL Gothic regular"}, 24 "VL Gothic regular"},
41 {"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", nullptr, 25 {"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", nullptr,
(...skipping 24 matching lines...) Expand all
66 } 50 }
67 return 1; 51 return 1;
68 } 52 }
69 if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) { 53 if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
70 if (face.Find("PMincho") >= 0 || 54 if (face.Find("PMincho") >= 0 ||
71 face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) { 55 face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) {
72 return 2; 56 return 2;
73 } 57 }
74 return 3; 58 return 3;
75 } 59 }
76 if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) { 60 if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400)
77 return 0; 61 return 0;
78 } 62
79 return 2; 63 return 2;
80 } 64 }
81 65
82 } // namespace 66 class CFX_LinuxFontInfo : public CFX_FolderFontInfo {
67 public:
68 CFX_LinuxFontInfo() {}
69 ~CFX_LinuxFontInfo() override {}
70
71 void* MapFont(int weight,
72 bool bItalic,
73 int charset,
74 int pitch_family,
75 const FX_CHAR* family,
76 int& iExact) override;
77 bool ParseFontCfg(const char** pUserPaths);
78 };
83 79
84 void* CFX_LinuxFontInfo::MapFont(int weight, 80 void* CFX_LinuxFontInfo::MapFont(int weight,
85 bool bItalic, 81 bool bItalic,
86 int charset, 82 int charset,
87 int pitch_family, 83 int pitch_family,
88 const FX_CHAR* cstr_face, 84 const FX_CHAR* cstr_face,
89 int& iExact) { 85 int& iExact) {
90 void* font = GetSubstFont(cstr_face); 86 void* font = GetSubstFont(cstr_face);
91 if (font) { 87 if (font) {
92 iExact = 1; 88 iExact = 1;
93 return font; 89 return font;
94 } 90 }
95 bool bCJK = true; 91 bool bCJK = true;
96 switch (charset) { 92 switch (charset) {
97 case FXFONT_SHIFTJIS_CHARSET: { 93 case FXFONT_SHIFTJIS_CHARSET: {
98 size_t index = GetJapanesePreference(cstr_face, weight, pitch_family); 94 size_t index = GetJapanesePreference(cstr_face, weight, pitch_family);
99 ASSERT(index < FX_ArraySize(g_LinuxGpFontList)); 95 ASSERT(index < FX_ArraySize(g_LinuxGpFontList));
100 for (size_t i = 0; i < kLinuxGpNameSize; i++) { 96 for (size_t i = 0; i < kLinuxGpNameSize; i++) {
101 auto it = m_FontList.find(g_LinuxGpFontList[index][i]); 97 auto it = m_FontList.find(g_LinuxGpFontList[index][i]);
102 if (it != m_FontList.end()) { 98 if (it != m_FontList.end())
103 return it->second; 99 return it->second;
104 }
105 } 100 }
106 break; 101 break;
107 } 102 }
108 case FXFONT_GB2312_CHARSET: { 103 case FXFONT_GB2312_CHARSET: {
109 for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { 104 for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) {
110 auto it = m_FontList.find(g_LinuxGbFontList[i]); 105 auto it = m_FontList.find(g_LinuxGbFontList[i]);
111 if (it != m_FontList.end()) { 106 if (it != m_FontList.end())
112 return it->second; 107 return it->second;
113 }
114 } 108 }
115 break; 109 break;
116 } 110 }
117 case FXFONT_CHINESEBIG5_CHARSET: { 111 case FXFONT_CHINESEBIG5_CHARSET: {
118 for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { 112 for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) {
119 auto it = m_FontList.find(g_LinuxB5FontList[i]); 113 auto it = m_FontList.find(g_LinuxB5FontList[i]);
120 if (it != m_FontList.end()) { 114 if (it != m_FontList.end())
121 return it->second; 115 return it->second;
122 }
123 } 116 }
124 break; 117 break;
125 } 118 }
126 case FXFONT_HANGUL_CHARSET: { 119 case FXFONT_HANGUL_CHARSET: {
127 for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { 120 for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) {
128 auto it = m_FontList.find(g_LinuxHGFontList[i]); 121 auto it = m_FontList.find(g_LinuxHGFontList[i]);
129 if (it != m_FontList.end()) { 122 if (it != m_FontList.end())
130 return it->second; 123 return it->second;
131 }
132 } 124 }
133 break; 125 break;
134 } 126 }
135 default: 127 default:
136 bCJK = false; 128 bCJK = false;
137 break; 129 break;
138 } 130 }
139 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK); 131 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
140 } 132 }
141 133
134 bool CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) {
135 if (!pUserPaths)
136 return false;
137
138 for (const char** pPath = pUserPaths; *pPath; ++pPath)
139 AddPath(*pPath);
140 return true;
141 }
142
143 } // namespace
144
142 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( 145 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
143 const char** pUserPaths) { 146 const char** pUserPaths) {
144 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo; 147 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo;
145 if (!pInfo->ParseFontCfg(pUserPaths)) { 148 if (!pInfo->ParseFontCfg(pUserPaths)) {
146 pInfo->AddPath("/usr/share/fonts"); 149 pInfo->AddPath("/usr/share/fonts");
147 pInfo->AddPath("/usr/share/X11/fonts/Type1"); 150 pInfo->AddPath("/usr/share/X11/fonts/Type1");
148 pInfo->AddPath("/usr/share/X11/fonts/TTF"); 151 pInfo->AddPath("/usr/share/X11/fonts/TTF");
149 pInfo->AddPath("/usr/local/share/fonts"); 152 pInfo->AddPath("/usr/local/share/fonts");
150 } 153 }
151 return std::unique_ptr<IFX_SystemFontInfo>(pInfo); 154 return std::unique_ptr<IFX_SystemFontInfo>(pInfo);
152 } 155 }
153 156
154 bool CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) {
155 if (!pUserPaths)
156 return false;
157
158 for (const char** pPath = pUserPaths; *pPath; ++pPath)
159 AddPath(*pPath);
160 return true;
161 }
162
163 void CFX_GEModule::InitPlatform() { 157 void CFX_GEModule::InitPlatform() {
164 m_pFontMgr->SetSystemFontInfo( 158 m_pFontMgr->SetSystemFontInfo(
165 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths)); 159 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths));
166 } 160 }
167 161
168 void CFX_GEModule::DestroyPlatform() {} 162 void CFX_GEModule::DestroyPlatform() {}
169 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ 163 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698