Commit fb23608e authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Use float variant of PDFium page size API

FPDF_GetPageSizeByIndexF() is encouraged over the older
FPDF_GetPageSizeByIndex(), which is will be deprecated in the future.

Meanwhile, clean some surrounding code.

Change-Id: Id315c67bec5361f23225e49a0fd1438fbcb92428
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392947
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804507}
parent 1f06da32
...@@ -2941,33 +2941,28 @@ gfx::Size PDFiumEngine::GetPageSize(int index) { ...@@ -2941,33 +2941,28 @@ gfx::Size PDFiumEngine::GetPageSize(int index) {
gfx::Size PDFiumEngine::GetPageSizeForLayout( gfx::Size PDFiumEngine::GetPageSizeForLayout(
int index, int index,
const DocumentLayout::Options& layout_options) { const DocumentLayout::Options& layout_options) {
gfx::Size size; FS_SIZEF size_in_points;
double width_in_points = 0; if (!FPDF_GetPageSizeByIndexF(doc(), index, &size_in_points))
double height_in_points = 0; return gfx::Size();
int rv = FPDF_GetPageSizeByIndex(doc(), index, &width_in_points,
&height_in_points); int width_in_pixels = static_cast<int>(
ConvertUnitDouble(size_in_points.width, kPointsPerInch, kPixelsPerInch));
if (rv) { int height_in_pixels = static_cast<int>(
int width_in_pixels = static_cast<int>( ConvertUnitDouble(size_in_points.height, kPointsPerInch, kPixelsPerInch));
ConvertUnitDouble(width_in_points, kPointsPerInch, kPixelsPerInch));
int height_in_pixels = static_cast<int>( switch (layout_options.default_page_orientation()) {
ConvertUnitDouble(height_in_points, kPointsPerInch, kPixelsPerInch)); case PageOrientation::kOriginal:
case PageOrientation::kClockwise180:
switch (layout_options.default_page_orientation()) { // No axis swap needed.
case PageOrientation::kOriginal: break;
case PageOrientation::kClockwise180: case PageOrientation::kClockwise90:
// No axis swap needed. case PageOrientation::kClockwise270:
break; // Rotated 90 degrees: swap axes.
case PageOrientation::kClockwise90: std::swap(width_in_pixels, height_in_pixels);
case PageOrientation::kClockwise270: break;
// Rotated 90 degrees: swap axes.
std::swap(width_in_pixels, height_in_pixels);
break;
}
size = gfx::Size(width_in_pixels, height_in_pixels);
} }
return size;
return gfx::Size(width_in_pixels, height_in_pixels);
} }
draw_utils::PageInsetSizes PDFiumEngine::GetInsetSizes( draw_utils::PageInsetSizes PDFiumEngine::GetInsetSizes(
......
...@@ -391,12 +391,10 @@ bool PDFiumEngineExports::GetPDFDocInfo(base::span<const uint8_t> pdf_buffer, ...@@ -391,12 +391,10 @@ bool PDFiumEngineExports::GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
if (max_page_width) { if (max_page_width) {
*max_page_width = 0; *max_page_width = 0;
for (int page_number = 0; page_number < page_count_local; page_number++) { for (int page_number = 0; page_number < page_count_local; page_number++) {
double page_width = 0; FS_SIZEF page_size;
double page_height = 0; if (FPDF_GetPageSizeByIndexF(doc.get(), page_number, &page_size) &&
FPDF_GetPageSizeByIndex(doc.get(), page_number, &page_width, page_size.width > *max_page_width) {
&page_height); *max_page_width = page_size.width;
if (page_width > *max_page_width) {
*max_page_width = page_width;
} }
} }
} }
...@@ -446,9 +444,16 @@ bool PDFiumEngineExports::GetPDFPageSizeByIndex( ...@@ -446,9 +444,16 @@ bool PDFiumEngineExports::GetPDFPageSizeByIndex(
double* width, double* width,
double* height) { double* height) {
ScopedFPDFDocument doc = LoadPdfData(pdf_buffer); ScopedFPDFDocument doc = LoadPdfData(pdf_buffer);
if (!doc) if (!doc || !width || !height)
return false;
FS_SIZEF size;
if (!FPDF_GetPageSizeByIndexF(doc.get(), page_number, &size))
return false; return false;
return FPDF_GetPageSizeByIndex(doc.get(), page_number, width, height) != 0;
*width = size.width;
*height = size.height;
return true;
} }
} // namespace chrome_pdf } // namespace chrome_pdf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment