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

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

Issue 376083002: Export a function from the PDF plugin to get the dimensions of a PDF page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('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/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
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) {
Lei Zhang 2014/07/09 02:10:48 Why is this code deleted?
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
152 // This list is for CPWL_FontMap::GetDefaultFontByCharset(). 139 // This list is for CPWL_FontMap::GetDefaultFontByCharset().
153 // We pretend to have these font natively and let the browser (or underlying 140 // We pretend to have these font natively and let the browser (or underlying
154 // fontconfig) to pick the proper font on the system. 141 // fontconfig) to pick the proper font on the system.
155 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { 142 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) {
156 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); 143 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET);
157 144
158 int i = 0; 145 int i = 0;
159 while (CPWL_FontMap::defaultTTFMap[i].charset != -1) { 146 while (CPWL_FontMap::defaultTTFMap[i].charset != -1) {
160 FPDF_AddInstalledFont(mapper, 147 FPDF_AddInstalledFont(mapper,
161 CPWL_FontMap::defaultTTFMap[i].fontname, 148 CPWL_FontMap::defaultTTFMap[i].fontname,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (PDFFontSubstitutions[i].italic) 214 if (PDFFontSubstitutions[i].italic)
228 description.set_italic(true); 215 description.set_italic(true);
229 break; 216 break;
230 } 217 }
231 } 218 }
232 219
233 if (i == arraysize(PDFFontSubstitutions)) { 220 if (i == arraysize(PDFFontSubstitutions)) {
234 // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8, 221 // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8,
235 // convert to UTF-8 before passing. 222 // convert to UTF-8 before passing.
236 description.set_face(face); 223 description.set_face(face);
237
238 description.set_weight(WeightToBrowserFontTrustedWeight(weight));
239 description.set_italic(italic > 0);
240 } 224 }
241 225
242 if (!pp::PDF::IsAvailable()) { 226 if (!pp::PDF::IsAvailable()) {
243 NOTREACHED(); 227 NOTREACHED();
244 return NULL; 228 return NULL;
245 } 229 }
246 230
247 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback( 231 PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
248 pp::InstanceHandle(g_last_instance_id), 232 pp::InstanceHandle(g_last_instance_id),
249 &description.pp_font_description(), 233 &description.pp_font_description(),
(...skipping 3143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 FPDF_GetPageSizeByIndex(doc, page_number, &page_width, &page_height); 3377 FPDF_GetPageSizeByIndex(doc, page_number, &page_width, &page_height);
3394 if (page_width > *max_page_width) { 3378 if (page_width > *max_page_width) {
3395 *max_page_width = page_width; 3379 *max_page_width = page_width;
3396 } 3380 }
3397 } 3381 }
3398 } 3382 }
3399 FPDF_CloseDocument(doc); 3383 FPDF_CloseDocument(doc);
3400 return true; 3384 return true;
3401 } 3385 }
3402 3386
3387 bool PDFiumEngineExports::GetPDFPageSizeByIndex(
3388 const void* pdf_buffer,
3389 int buffer_size,
3390 int index,
3391 double* width,
3392 double* height) {
3393 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL);
3394 bool success = false;
Lei Zhang 2014/07/09 02:10:48 Can you try following my suggested pattern? There'
3395 if (!doc)
3396 return success;
3397 success = FPDF_GetPageSizeByIndex(doc, index, width, height) != 0;
3398 FPDF_CloseDocument(doc);
3399 return success;
3400 }
3401
3403 } // namespace chrome_pdf 3402 } // namespace chrome_pdf
OLDNEW
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698