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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1142313002: PDF: On Linux, convert font names to UTF-8 if needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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 | « chrome/renderer/pepper/pepper_flash_font_file_host.cc ('k') | 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 (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/i18n/icu_encoding_detection.h"
10 #include "base/i18n/icu_string_conversions.h"
9 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "base/numerics/safe_conversions.h" 14 #include "base/numerics/safe_conversions.h"
13 #include "base/stl_util.h" 15 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
16 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "base/values.h" 20 #include "base/values.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // MS P?(Mincho|Gothic) are the most notable fonts in Japanese PDF files 169 // MS P?(Mincho|Gothic) are the most notable fonts in Japanese PDF files
168 // without embedding the glyphs. Sometimes the font names are encoded 170 // without embedding the glyphs. Sometimes the font names are encoded
169 // in Japanese Windows's locale (CP932/Shift_JIS) without space. 171 // in Japanese Windows's locale (CP932/Shift_JIS) without space.
170 // Most Linux systems don't have the exact font, but for outsourcing 172 // Most Linux systems don't have the exact font, but for outsourcing
171 // fontconfig to find substitutable font in the system, we pass ASCII 173 // fontconfig to find substitutable font in the system, we pass ASCII
172 // font names to it. 174 // font names to it.
173 {"MS-PGothic", "MS PGothic", false, false}, 175 {"MS-PGothic", "MS PGothic", false, false},
174 {"MS-Gothic", "MS Gothic", false, false}, 176 {"MS-Gothic", "MS Gothic", false, false},
175 {"MS-PMincho", "MS PMincho", false, false}, 177 {"MS-PMincho", "MS PMincho", false, false},
176 {"MS-Mincho", "MS Mincho", false, false}, 178 {"MS-Mincho", "MS Mincho", false, false},
177 // MS PGothic in Shift_JIS encoding. 179 // MS PGothic in Shift_JIS encoding.
kochi 2015/05/20 06:24:27 With the code added in this CL, the following shou
178 {"\x82\x6C\x82\x72\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E", 180 {"\x82\x6C\x82\x72\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E",
179 "MS PGothic", false, false}, 181 "MS PGothic", false, false},
180 // MS Gothic in Shift_JIS encoding. 182 // MS Gothic in Shift_JIS encoding.
181 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E", 183 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E",
182 "MS Gothic", false, false}, 184 "MS Gothic", false, false},
183 // MS PMincho in Shift_JIS encoding. 185 // MS PMincho in Shift_JIS encoding.
184 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9", 186 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9",
185 "MS PMincho", false, false}, 187 "MS PMincho", false, false},
186 // MS Mincho in Shift_JIS encoding. 188 // MS Mincho in Shift_JIS encoding.
187 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9", 189 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9",
(...skipping 28 matching lines...) Expand all
216 description.set_face(PDFFontSubstitutions[i].face); 218 description.set_face(PDFFontSubstitutions[i].face);
217 if (PDFFontSubstitutions[i].bold) 219 if (PDFFontSubstitutions[i].bold)
218 description.set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD); 220 description.set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD);
219 if (PDFFontSubstitutions[i].italic) 221 if (PDFFontSubstitutions[i].italic)
220 description.set_italic(true); 222 description.set_italic(true);
221 break; 223 break;
222 } 224 }
223 } 225 }
224 226
225 if (i == arraysize(PDFFontSubstitutions)) { 227 if (i == arraysize(PDFFontSubstitutions)) {
226 // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8, 228 // Convert to UTF-8 before calling set_face().
227 // convert to UTF-8 before passing. 229 std::string face_utf8;
228 description.set_face(face); 230 if (base::IsStringUTF8(face)) {
231 face_utf8 = face;
232 } else {
233 std::string encoding;
234 if (base::DetectEncoding(face, &encoding)) {
235 // ConvertToUtf8AndNormalize() clears |face_utf8| on failure.
236 base::ConvertToUtf8AndNormalize(face, encoding, &face_utf8);
237 }
238 }
229 239
240 if (face_utf8.empty())
241 return nullptr;
242
243 description.set_face(face_utf8);
230 description.set_weight(WeightToBrowserFontTrustedWeight(weight)); 244 description.set_weight(WeightToBrowserFontTrustedWeight(weight));
231 description.set_italic(italic > 0); 245 description.set_italic(italic > 0);
232 } 246 }
233 247
234 if (!pp::PDF::IsAvailable()) { 248 if (!pp::PDF::IsAvailable()) {
235 NOTREACHED(); 249 NOTREACHED();
236 return NULL; 250 return NULL;
237 } 251 }
238 252
239 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( 253 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
(...skipping 3765 matching lines...) Expand 10 before | Expand all | Expand 10 after
4005 double* height) { 4019 double* height) {
4006 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4020 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4007 if (!doc) 4021 if (!doc)
4008 return false; 4022 return false;
4009 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4023 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4010 FPDF_CloseDocument(doc); 4024 FPDF_CloseDocument(doc);
4011 return success; 4025 return success;
4012 } 4026 }
4013 4027
4014 } // namespace chrome_pdf 4028 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/renderer/pepper/pepper_flash_font_file_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698