Chromium Code Reviews| 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/i18n/icu_encoding_detection.h" | 9 #include "base/i18n/icu_encoding_detection.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 page_numbers.push_back(page_number); | 108 page_numbers.push_back(page_number); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 return page_numbers; | 111 return page_numbers; |
| 112 } | 112 } |
| 113 | 113 |
| 114 #if defined(OS_LINUX) | 114 #if defined(OS_LINUX) |
| 115 | 115 |
| 116 PP_Instance g_last_instance_id; | 116 PP_Instance g_last_instance_id; |
| 117 | 117 |
| 118 struct PDFFontSubstitution { | |
| 119 const char* pdf_name; | |
| 120 const char* face; | |
| 121 bool bold; | |
| 122 bool italic; | |
| 123 }; | |
| 124 | |
| 125 PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { | 118 PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { |
| 126 static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_100 == 0, | 119 static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_100 == 0, |
| 127 "PP_BrowserFont_Trusted_Weight min"); | 120 "PP_BrowserFont_Trusted_Weight min"); |
| 128 static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8, | 121 static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8, |
| 129 "PP_BrowserFont_Trusted_Weight max"); | 122 "PP_BrowserFont_Trusted_Weight max"); |
| 130 const int kMinimumWeight = 100; | 123 const int kMinimumWeight = 100; |
| 131 const int kMaximumWeight = 900; | 124 const int kMaximumWeight = 900; |
| 132 int normalized_weight = | 125 int normalized_weight = |
| 133 std::min(std::max(weight, kMinimumWeight), kMaximumWeight); | 126 std::min(std::max(weight, kMinimumWeight), kMaximumWeight); |
| 134 normalized_weight = (normalized_weight / 100) - 1; | 127 normalized_weight = (normalized_weight / 100) - 1; |
| 135 return static_cast<PP_BrowserFont_Trusted_Weight>(normalized_weight); | 128 return static_cast<PP_BrowserFont_Trusted_Weight>(normalized_weight); |
| 136 } | 129 } |
| 137 | 130 |
| 138 // This list is for CPWL_FontMap::GetDefaultFontByCharset(). | 131 // This list is for CPWL_FontMap::GetDefaultFontByCharset(). |
| 139 // We pretend to have these font natively and let the browser (or underlying | 132 // We pretend to have these font natively and let the browser (or underlying |
| 140 // fontconfig) to pick the proper font on the system. | 133 // fontconfig) to pick the proper font on the system. |
| 141 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { | 134 void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) { |
| 142 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); | 135 FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET); |
| 143 | 136 |
| 144 const FPDF_CharsetFontMap* font_map = FPDF_GetDefaultTTFMap(); | 137 const FPDF_CharsetFontMap* font_map = FPDF_GetDefaultTTFMap(); |
| 145 for (; font_map->charset != -1; ++font_map) { | 138 for (; font_map->charset != -1; ++font_map) { |
| 146 FPDF_AddInstalledFont(mapper, font_map->fontname, font_map->charset); | 139 FPDF_AddInstalledFont(mapper, font_map->fontname, font_map->charset); |
| 147 } | 140 } |
| 148 } | 141 } |
| 149 | 142 |
| 150 const PDFFontSubstitution PDFFontSubstitutions[] = { | 143 void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic, |
| 144 int charset, int pitch_family, const char* face, int* exact) { | |
| 145 // Do not attempt to map fonts if pepper is not initialized (for privet local | |
| 146 // printing). | |
| 147 // TODO(noamsml): Real font substitution (http://crbug.com/391978) | |
| 148 if (!pp::Module::Get()) | |
| 149 return NULL; | |
| 150 | |
| 151 pp::BrowserFontDescription description; | |
| 152 | |
| 153 // Pretend the system does not have the Symbol font to force a fallback to | |
| 154 // the built in Symbol font in CFX_FontMapper::FindSubstFont(). | |
| 155 if (strcmp(face, "Symbol") == 0) | |
| 156 return NULL; | |
| 157 | |
| 158 if (pitch_family & FXFONT_FF_FIXEDPITCH) { | |
| 159 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE); | |
| 160 } else if (pitch_family & FXFONT_FF_ROMAN) { | |
| 161 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); | |
| 162 } | |
| 163 | |
| 164 static const struct { | |
| 165 const char* pdf_name; | |
| 166 const char* face; | |
| 167 bool bold; | |
| 168 bool italic; | |
| 169 } kPdfFontSubstitutions[] = { | |
| 151 {"Courier", "Courier New", false, false}, | 170 {"Courier", "Courier New", false, false}, |
| 152 {"Courier-Bold", "Courier New", true, false}, | 171 {"Courier-Bold", "Courier New", true, false}, |
| 153 {"Courier-BoldOblique", "Courier New", true, true}, | 172 {"Courier-BoldOblique", "Courier New", true, true}, |
| 154 {"Courier-Oblique", "Courier New", false, true}, | 173 {"Courier-Oblique", "Courier New", false, true}, |
| 155 {"Helvetica", "Arial", false, false}, | 174 {"Helvetica", "Arial", false, false}, |
| 156 {"Helvetica-Bold", "Arial", true, false}, | 175 {"Helvetica-Bold", "Arial", true, false}, |
| 157 {"Helvetica-BoldOblique", "Arial", true, true}, | 176 {"Helvetica-BoldOblique", "Arial", true, true}, |
| 158 {"Helvetica-Oblique", "Arial", false, true}, | 177 {"Helvetica-Oblique", "Arial", false, true}, |
| 159 {"Times-Roman", "Times New Roman", false, false}, | 178 {"Times-Roman", "Times New Roman", false, false}, |
| 160 {"Times-Bold", "Times New Roman", true, false}, | 179 {"Times-Bold", "Times New Roman", true, false}, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 178 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E", | 197 {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E", |
| 179 "MS Gothic", false, false}, | 198 "MS Gothic", false, false}, |
| 180 // MS PMincho in Shift_JIS encoding. | 199 // MS PMincho in Shift_JIS encoding. |
| 181 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9", | 200 {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9", |
| 182 "MS PMincho", false, false}, | 201 "MS PMincho", false, false}, |
| 183 // MS Mincho in Shift_JIS encoding. | 202 // MS Mincho in Shift_JIS encoding. |
| 184 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9", | 203 {"\x82\x6C\x82\x72\x96\xBE\x92\xA9", |
| 185 "MS Mincho", false, false}, | 204 "MS Mincho", false, false}, |
| 186 }; | 205 }; |
| 187 | 206 |
| 188 void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic, | |
| 189 int charset, int pitch_family, const char* face, int* exact) { | |
| 190 // Do not attempt to map fonts if pepper is not initialized (for privet local | |
| 191 // printing). | |
| 192 // TODO(noamsml): Real font substitution (http://crbug.com/391978) | |
| 193 if (!pp::Module::Get()) | |
| 194 return NULL; | |
| 195 | |
| 196 pp::BrowserFontDescription description; | |
| 197 | |
| 198 // Pretend the system does not have the Symbol font to force a fallback to | |
| 199 // the built in Symbol font in CFX_FontMapper::FindSubstFont(). | |
| 200 if (strcmp(face, "Symbol") == 0) | |
| 201 return NULL; | |
| 202 | |
| 203 if (pitch_family & FXFONT_FF_FIXEDPITCH) { | |
| 204 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE); | |
| 205 } else if (pitch_family & FXFONT_FF_ROMAN) { | |
| 206 description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); | |
| 207 } | |
| 208 | |
| 209 // Map from the standard PDF fonts to TrueType font names. | 207 // Map from the standard PDF fonts to TrueType font names. |
| 210 size_t i; | 208 size_t i; |
| 211 for (i = 0; i < arraysize(PDFFontSubstitutions); ++i) { | 209 for (i = 0; i < arraysize(kPdfFontSubstitutions); ++i) { |
| 212 if (strcmp(face, PDFFontSubstitutions[i].pdf_name) == 0) { | 210 if (strcmp(face, kPdfFontSubstitutions[i].pdf_name) == 0) { |
| 213 description.set_face(PDFFontSubstitutions[i].face); | 211 description.set_face(kPdfFontSubstitutions[i].face); |
| 214 if (PDFFontSubstitutions[i].bold) | 212 if (kPdfFontSubstitutions[i].bold) |
| 215 description.set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD); | 213 description.set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD); |
| 216 if (PDFFontSubstitutions[i].italic) | 214 if (kPdfFontSubstitutions[i].italic) |
| 217 description.set_italic(true); | 215 description.set_italic(true); |
| 218 break; | 216 break; |
| 219 } | 217 } |
| 220 } | 218 } |
| 221 | 219 |
| 222 if (i == arraysize(PDFFontSubstitutions)) { | 220 if (i == arraysize(kPdfFontSubstitutions)) { |
| 223 // Convert to UTF-8 before calling set_face(). | 221 // Convert to UTF-8 before calling set_face(). |
| 224 std::string face_utf8; | 222 std::string face_utf8; |
| 225 if (base::IsStringUTF8(face)) { | 223 if (base::IsStringUTF8(face)) { |
| 226 face_utf8 = face; | 224 face_utf8 = face; |
| 227 } else { | 225 } else { |
| 228 std::string encoding; | 226 std::string encoding; |
| 229 if (base::DetectEncoding(face, &encoding)) { | 227 if (base::DetectEncoding(face, &encoding)) { |
| 230 // ConvertToUtf8AndNormalize() clears |face_utf8| on failure. | 228 // ConvertToUtf8AndNormalize() clears |face_utf8| on failure. |
| 231 base::ConvertToUtf8AndNormalize(face, encoding, &face_utf8); | 229 base::ConvertToUtf8AndNormalize(face, encoding, &face_utf8); |
| 232 } | 230 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 288 |
| 291 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 289 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { |
| 292 if (!g_engine_for_unsupported) { | 290 if (!g_engine_for_unsupported) { |
| 293 NOTREACHED(); | 291 NOTREACHED(); |
| 294 return; | 292 return; |
| 295 } | 293 } |
| 296 | 294 |
| 297 g_engine_for_unsupported->UnsupportedFeature(type); | 295 g_engine_for_unsupported->UnsupportedFeature(type); |
| 298 } | 296 } |
| 299 | 297 |
| 300 UNSUPPORT_INFO g_unsuppored_info = { | 298 UNSUPPORT_INFO g_unsupported_info = { |
| 301 1, | 299 1, |
| 302 Unsupported_Handler | 300 Unsupported_Handler |
| 303 }; | 301 }; |
| 304 | 302 |
| 305 // Set the destination page size and content area in points based on source | 303 // Set the destination page size and content area in points based on source |
| 306 // page rotation and orientation. | 304 // page rotation and orientation. |
| 307 // | 305 // |
| 308 // |rotated| True if source page is rotated 90 degree or 270 degree. | 306 // |rotated| True if source page is rotated 90 degree or 270 degree. |
| 309 // |is_src_page_landscape| is true if the source page orientation is landscape. | 307 // |is_src_page_landscape| is true if the source page orientation is landscape. |
| 310 // |page_size| has the actual destination page size in points. | 308 // |page_size| has the actual destination page size in points. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 321 if (rotate_dst_page) { | 319 if (rotate_dst_page) { |
| 322 page_size->SetSize(page_size->height(), page_size->width()); | 320 page_size->SetSize(page_size->height(), page_size->width()); |
| 323 content_rect->SetRect(content_rect->y(), content_rect->x(), | 321 content_rect->SetRect(content_rect->y(), content_rect->x(), |
| 324 content_rect->height(), content_rect->width()); | 322 content_rect->height(), content_rect->width()); |
| 325 } | 323 } |
| 326 } | 324 } |
| 327 | 325 |
| 328 // Calculate the scale factor between |content_rect| and a page of size | 326 // Calculate the scale factor between |content_rect| and a page of size |
| 329 // |src_width| x |src_height|. | 327 // |src_width| x |src_height|. |
| 330 // | 328 // |
| 331 // |scale_to_fit| is true, if we need to calculate the scale factor. | |
| 332 // |content_rect| specifies the printable area of the destination page, with | 329 // |content_rect| specifies the printable area of the destination page, with |
| 333 // origin at left-bottom. Values are in points. | 330 // origin at left-bottom. Values are in points. |
| 334 // |src_width| specifies the source page width in points. | 331 // |src_width| specifies the source page width in points. |
| 335 // |src_height| specifies the source page height in points. | 332 // |src_height| specifies the source page height in points. |
| 336 // |rotated| True if source page is rotated 90 degree or 270 degree. | 333 // |rotated| True if source page is rotated 90 degree or 270 degree. |
| 337 double CalculateScaleFactor(bool scale_to_fit, | 334 double CalculateScaleFactor(const pp::Rect& content_rect, |
| 338 const pp::Rect& content_rect, | 335 double src_width, |
| 339 double src_width, double src_height, bool rotated) { | 336 double src_height, |
| 340 if (!scale_to_fit || src_width == 0 || src_height == 0) | 337 bool rotated) { |
| 338 if (src_width == 0 || src_height == 0) | |
| 341 return 1.0; | 339 return 1.0; |
| 342 | 340 |
| 343 double actual_source_page_width = rotated ? src_height : src_width; | 341 double actual_source_page_width = rotated ? src_height : src_width; |
| 344 double actual_source_page_height = rotated ? src_width : src_height; | 342 double actual_source_page_height = rotated ? src_width : src_height; |
| 345 double ratio_x = static_cast<double>(content_rect.width()) / | 343 double ratio_x = static_cast<double>(content_rect.width()) / |
| 346 actual_source_page_width; | 344 actual_source_page_width; |
| 347 double ratio_y = static_cast<double>(content_rect.height()) / | 345 double ratio_y = static_cast<double>(content_rect.height()) / |
| 348 actual_source_page_height; | 346 actual_source_page_height; |
| 349 return std::min(ratio_x, ratio_y); | 347 return std::min(ratio_x, ratio_y); |
| 350 } | 348 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 364 void SetDefaultClipBox(bool rotated, ClipBox* clip_box) { | 362 void SetDefaultClipBox(bool rotated, ClipBox* clip_box) { |
| 365 const int kDpi = 72; | 363 const int kDpi = 72; |
| 366 const float kPaperWidth = 8.5 * kDpi; | 364 const float kPaperWidth = 8.5 * kDpi; |
| 367 const float kPaperHeight = 11 * kDpi; | 365 const float kPaperHeight = 11 * kDpi; |
| 368 clip_box->left = 0; | 366 clip_box->left = 0; |
| 369 clip_box->bottom = 0; | 367 clip_box->bottom = 0; |
| 370 clip_box->right = rotated ? kPaperHeight : kPaperWidth; | 368 clip_box->right = rotated ? kPaperHeight : kPaperWidth; |
| 371 clip_box->top = rotated ? kPaperWidth : kPaperHeight; | 369 clip_box->top = rotated ? kPaperWidth : kPaperHeight; |
| 372 } | 370 } |
| 373 | 371 |
| 374 // Compute source clip box boundaries based on the crop box / media box of | 372 // Set the media box and/or crop box as needed. |
|
raymes
2015/10/27 05:59:07
nit: fill 80chars
Lei Zhang
2015/10/27 06:52:13
Done.
| |
| 375 // source page and scale factor. | 373 // If both boxes are there, then nothing needs to be done. If one box is |
| 376 // | 374 // missing, then fill it with the value from the other box. If both boxes are |
| 377 // |page| Handle to the source page. Returned by FPDF_LoadPage function. | 375 // missing, then they both get the default value from SetDefaultClipBox(), based |
| 378 // |scale_factor| specifies the scale factor that should be applied to source | 376 // on |rotated|. |
| 379 // clip box boundaries. | 377 void CalculateMediaBoxAndCropBox(bool rotated, |
| 380 // |rotated| True if source page is rotated 90 degree or 270 degree. | 378 bool has_media_box, |
| 381 // |clip_box| out param to hold the computed source clip box values. | 379 bool has_crop_box, |
| 382 void CalculateClipBoxBoundary(FPDF_PAGE page, double scale_factor, bool rotated, | 380 ClipBox* media_box, |
| 383 ClipBox* clip_box) { | 381 ClipBox* crop_box) { |
| 384 ClipBox media_box; | 382 if (has_media_box) { |
| 385 if (!FPDFPage_GetMediaBox(page, &media_box.left, &media_box.bottom, | 383 if (!has_crop_box) |
| 386 &media_box.right, &media_box.top)) { | 384 *crop_box = *media_box; |
| 387 SetDefaultClipBox(rotated, &media_box); | 385 return; |
| 388 } | 386 } |
| 389 | 387 |
| 390 ClipBox crop_box; | 388 if (!has_crop_box) |
| 391 if (!FPDFPage_GetCropBox(page, &crop_box.left, &crop_box.bottom, | 389 SetDefaultClipBox(rotated, crop_box); |
| 392 &crop_box.right, &crop_box.top)) { | 390 *media_box = *crop_box; |
|
raymes
2015/10/27 05:59:07
This is a little confusing to me. Perhaps we just
Lei Zhang
2015/10/27 06:52:13
Done.
| |
| 393 SetDefaultClipBox(rotated, &crop_box); | 391 } |
| 394 } | 392 |
| 393 // Compute source clip box boundaries based on the crop box / media box of | |
| 394 // source page. | |
| 395 // | |
| 396 // |media_box| The PDF's media box. | |
| 397 // |crop_box| The PDF's crop box. | |
| 398 ClipBox CalculateClipBoxBoundary(const ClipBox& media_box, | |
| 399 const ClipBox& crop_box) { | |
| 400 ClipBox clip_box; | |
| 395 | 401 |
| 396 // Clip |media_box| to the size of |crop_box|, but ignore |crop_box| if it is | 402 // Clip |media_box| to the size of |crop_box|, but ignore |crop_box| if it is |
| 397 // bigger than |media_box|. | 403 // bigger than |media_box|. |
| 398 clip_box->left = | 404 clip_box.left = |
| 399 (crop_box.left < media_box.left) ? media_box.left : crop_box.left; | 405 (crop_box.left < media_box.left) ? media_box.left : crop_box.left; |
| 400 clip_box->right = | 406 clip_box.right = |
| 401 (crop_box.right > media_box.right) ? media_box.right : crop_box.right; | 407 (crop_box.right > media_box.right) ? media_box.right : crop_box.right; |
| 402 clip_box->top = (crop_box.top > media_box.top) ? media_box.top : crop_box.top; | 408 clip_box.top = (crop_box.top > media_box.top) ? media_box.top : crop_box.top; |
| 403 clip_box->bottom = | 409 clip_box.bottom = |
| 404 (crop_box.bottom < media_box.bottom) ? media_box.bottom : crop_box.bottom; | 410 (crop_box.bottom < media_box.bottom) ? media_box.bottom : crop_box.bottom; |
| 411 return clip_box; | |
| 412 } | |
| 405 | 413 |
| 406 // Finally, scale |clip_box|. | 414 // Scale |box| by |scale_factor|. |
| 407 clip_box->left *= scale_factor; | 415 void ScaleClipBox(double scale_factor, ClipBox* box) { |
| 408 clip_box->right *= scale_factor; | 416 box->left *= scale_factor; |
| 409 clip_box->bottom *= scale_factor; | 417 box->right *= scale_factor; |
| 410 clip_box->top *= scale_factor; | 418 box->bottom *= scale_factor; |
| 419 box->top *= scale_factor; | |
| 411 } | 420 } |
| 412 | 421 |
| 413 // Calculate the clip box translation offset for a page that does need to be | 422 // Calculate the clip box translation offset for a page that does need to be |
| 414 // scaled. All parameters are in points. | 423 // scaled. All parameters are in points. |
| 415 // | 424 // |
| 416 // |content_rect| specifies the printable area of the destination page, with | 425 // |content_rect| specifies the printable area of the destination page, with |
| 417 // origin at left-bottom. | 426 // origin at left-bottom. |
| 418 // |source_clip_box| specifies the source clip box positions, relative to | 427 // |source_clip_box| specifies the source clip box positions, relative to |
| 419 // origin at left-bottom. | 428 // origin at left-bottom. |
| 420 // |offset_x| and |offset_y| will contain the final translation offsets for the | 429 // |offset_x| and |offset_y| will contain the final translation offsets for the |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 config.m_pUserFontPaths = nullptr; | 614 config.m_pUserFontPaths = nullptr; |
| 606 config.m_pIsolate = v8::Isolate::GetCurrent(); | 615 config.m_pIsolate = v8::Isolate::GetCurrent(); |
| 607 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; | 616 config.m_v8EmbedderSlot = gin::kEmbedderPDFium; |
| 608 FPDF_InitLibraryWithConfig(&config); | 617 FPDF_InitLibraryWithConfig(&config); |
| 609 | 618 |
| 610 #if defined(OS_LINUX) | 619 #if defined(OS_LINUX) |
| 611 // Font loading doesn't work in the renderer sandbox in Linux. | 620 // Font loading doesn't work in the renderer sandbox in Linux. |
| 612 FPDF_SetSystemFontInfo(&g_font_info); | 621 FPDF_SetSystemFontInfo(&g_font_info); |
| 613 #endif | 622 #endif |
| 614 | 623 |
| 615 FSDK_SetUnSpObjProcessHandler(&g_unsuppored_info); | 624 FSDK_SetUnSpObjProcessHandler(&g_unsupported_info); |
| 616 | 625 |
| 617 return true; | 626 return true; |
| 618 } | 627 } |
| 619 | 628 |
| 620 void ShutdownSDK() { | 629 void ShutdownSDK() { |
| 621 FPDF_DestroyLibrary(); | 630 FPDF_DestroyLibrary(); |
| 622 } | 631 } |
| 623 | 632 |
| 624 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { | 633 PDFEngine* PDFEngine::Create(PDFEngine::Client* client) { |
| 625 return new PDFiumEngine(client); | 634 return new PDFiumEngine(client); |
| (...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3405 src_page_width > src_page_height, | 3414 src_page_width > src_page_height, |
| 3406 &page_size, | 3415 &page_size, |
| 3407 &content_rect); | 3416 &content_rect); |
| 3408 | 3417 |
| 3409 // Compute the screen page width and height in points. | 3418 // Compute the screen page width and height in points. |
| 3410 const int actual_page_width = | 3419 const int actual_page_width = |
| 3411 rotated ? page_size.height() : page_size.width(); | 3420 rotated ? page_size.height() : page_size.width(); |
| 3412 const int actual_page_height = | 3421 const int actual_page_height = |
| 3413 rotated ? page_size.width() : page_size.height(); | 3422 rotated ? page_size.width() : page_size.height(); |
| 3414 | 3423 |
| 3415 const double scale_factor = CalculateScaleFactor(fit_to_page, content_rect, | 3424 const double scale_factor = fit_to_page ? |
| 3416 src_page_width, | 3425 CalculateScaleFactor( |
| 3417 src_page_height, rotated); | 3426 content_rect, src_page_width, src_page_height, rotated) : 1.0; |
| 3418 | 3427 |
| 3419 // Calculate positions for the clip box. | 3428 // Calculate positions for the clip box. |
| 3420 ClipBox source_clip_box; | 3429 ClipBox media_box; |
| 3421 CalculateClipBoxBoundary(page, scale_factor, rotated, &source_clip_box); | 3430 ClipBox crop_box; |
| 3431 bool has_media_box = !!FPDFPage_GetMediaBox(page, | |
| 3432 &media_box.left, | |
| 3433 &media_box.bottom, | |
| 3434 &media_box.right, | |
| 3435 &media_box.top); | |
| 3436 bool has_crop_box = !!FPDFPage_GetCropBox(page, | |
| 3437 &crop_box.left, | |
| 3438 &crop_box.bottom, | |
| 3439 &crop_box.right, | |
| 3440 &crop_box.top); | |
| 3441 CalculateMediaBoxAndCropBox( | |
| 3442 rotated, has_media_box, has_crop_box, &media_box, &crop_box); | |
| 3443 ClipBox source_clip_box = CalculateClipBoxBoundary(media_box, crop_box); | |
| 3444 ScaleClipBox(scale_factor, &source_clip_box); | |
| 3422 | 3445 |
| 3423 // Calculate the translation offset values. | 3446 // Calculate the translation offset values. |
| 3424 double offset_x = 0; | 3447 double offset_x = 0; |
| 3425 double offset_y = 0; | 3448 double offset_y = 0; |
| 3426 if (fit_to_page) { | 3449 if (fit_to_page) { |
| 3427 CalculateScaledClipBoxOffset(content_rect, source_clip_box, &offset_x, | 3450 CalculateScaledClipBoxOffset(content_rect, source_clip_box, &offset_x, |
| 3428 &offset_y); | 3451 &offset_y); |
| 3429 } else { | 3452 } else { |
| 3430 CalculateNonScaledClipBoxOffset(content_rect, src_page_rotation, | 3453 CalculateNonScaledClipBoxOffset(content_rect, src_page_rotation, |
| 3431 actual_page_width, actual_page_height, | 3454 actual_page_width, actual_page_height, |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4097 double* height) { | 4120 double* height) { |
| 4098 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4121 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 4099 if (!doc) | 4122 if (!doc) |
| 4100 return false; | 4123 return false; |
| 4101 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4124 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4102 FPDF_CloseDocument(doc); | 4125 FPDF_CloseDocument(doc); |
| 4103 return success; | 4126 return success; |
| 4104 } | 4127 } |
| 4105 | 4128 |
| 4106 } // namespace chrome_pdf | 4129 } // namespace chrome_pdf |
| OLD | NEW |