OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 PP_Instance g_last_instance_id; | 130 PP_Instance g_last_instance_id; |
131 | 131 |
132 struct PDFFontSubstitution { | 132 struct PDFFontSubstitution { |
133 const char* pdf_name; | 133 const char* pdf_name; |
134 const char* face; | 134 const char* face; |
135 bool bold; | 135 bool bold; |
136 bool italic; | 136 bool italic; |
137 }; | 137 }; |
138 | 138 |
| 139 PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { |
| 140 COMPILE_ASSERT(PP_BROWSERFONT_TRUSTED_WEIGHT_100 == 0, |
| 141 PP_BrowserFont_Trusted_Weight_Min); |
| 142 COMPILE_ASSERT(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8, |
| 143 PP_BrowserFont_Trusted_Weight_Max); |
| 144 const int kMinimumWeight = 100; |
| 145 const int kMaximumWeight = 900; |
| 146 int normalized_weight = |
| 147 std::min(std::max(weight, kMinimumWeight), kMaximumWeight); |
| 148 normalized_weight = (normalized_weight / 100) - 1; |
| 149 return static_cast<PP_BrowserFont_Trusted_Weight>(normalized_weight); |
| 150 } |
| 151 |
139 // This list is for CPWL_FontMap::GetDefaultFontByCharset(). | 152 // This list is for CPWL_FontMap::GetDefaultFontByCharset(). |
140 // We pretend to have these font natively and let the browser (or underlying | 153 // We pretend to have these font natively and let the browser (or underlying |
141 // fontconfig) to pick the proper font on the system. | 154 // fontconfig) to pick the proper font on the system. |
142 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { | 155 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { |
143 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); | 156 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); |
144 | 157 |
145 int i = 0; | 158 int i = 0; |
146 while (CPWL_FontMap::defaultTTFMap[i].charset != -1) { | 159 while (CPWL_FontMap::defaultTTFMap[i].charset != -1) { |
147 FPDF_AddInstalledFont(mapper, | 160 FPDF_AddInstalledFont(mapper, |
148 CPWL_FontMap::defaultTTFMap[i].fontname, | 161 CPWL_FontMap::defaultTTFMap[i].fontname, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (PDFFontSubstitutions[i].italic) | 227 if (PDFFontSubstitutions[i].italic) |
215 description.set_italic(true); | 228 description.set_italic(true); |
216 break; | 229 break; |
217 } | 230 } |
218 } | 231 } |
219 | 232 |
220 if (i == arraysize(PDFFontSubstitutions)) { | 233 if (i == arraysize(PDFFontSubstitutions)) { |
221 // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8, | 234 // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8, |
222 // convert to UTF-8 before passing. | 235 // convert to UTF-8 before passing. |
223 description.set_face(face); | 236 description.set_face(face); |
| 237 |
| 238 description.set_weight(WeightToBrowserFontTrustedWeight(weight)); |
| 239 description.set_italic(italic > 0); |
224 } | 240 } |
225 | 241 |
226 if (!pp::PDF::IsAvailable()) { | 242 if (!pp::PDF::IsAvailable()) { |
227 NOTREACHED(); | 243 NOTREACHED(); |
228 return NULL; | 244 return NULL; |
229 } | 245 } |
230 | 246 |
231 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( | 247 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( |
232 pp::InstanceHandle(g_last_instance_id), | 248 pp::InstanceHandle(g_last_instance_id), |
233 &description.pp_font_description(), | 249 &description.pp_font_description(), |
(...skipping 3144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 if (page_width > *max_page_width) { | 3394 if (page_width > *max_page_width) { |
3379 *max_page_width = page_width; | 3395 *max_page_width = page_width; |
3380 } | 3396 } |
3381 } | 3397 } |
3382 } | 3398 } |
3383 FPDF_CloseDocument(doc); | 3399 FPDF_CloseDocument(doc); |
3384 return true; | 3400 return true; |
3385 } | 3401 } |
3386 | 3402 |
3387 } // namespace chrome_pdf | 3403 } // namespace chrome_pdf |
OLD | NEW |