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) {
gfx::Size PDFiumEngine::GetPageSizeForLayout(
int index,
const DocumentLayout::Options& layout_options) {
gfx::Size size;
double width_in_points = 0;
double height_in_points = 0;
int rv = FPDF_GetPageSizeByIndex(doc(), index, &width_in_points,
&height_in_points);
if (rv) {
int width_in_pixels = static_cast<int>(
ConvertUnitDouble(width_in_points, kPointsPerInch, kPixelsPerInch));
int height_in_pixels = static_cast<int>(
ConvertUnitDouble(height_in_points, kPointsPerInch, kPixelsPerInch));
switch (layout_options.default_page_orientation()) {
case PageOrientation::kOriginal:
case PageOrientation::kClockwise180:
// No axis swap needed.
break;
case PageOrientation::kClockwise90:
case PageOrientation::kClockwise270:
// Rotated 90 degrees: swap axes.
std::swap(width_in_pixels, height_in_pixels);
break;
}
size = gfx::Size(width_in_pixels, height_in_pixels);
FS_SIZEF size_in_points;
if (!FPDF_GetPageSizeByIndexF(doc(), index, &size_in_points))
return gfx::Size();
int width_in_pixels = static_cast<int>(
ConvertUnitDouble(size_in_points.width, kPointsPerInch, kPixelsPerInch));
int height_in_pixels = static_cast<int>(
ConvertUnitDouble(size_in_points.height, kPointsPerInch, kPixelsPerInch));
switch (layout_options.default_page_orientation()) {
case PageOrientation::kOriginal:
case PageOrientation::kClockwise180:
// No axis swap needed.
break;
case PageOrientation::kClockwise90:
case PageOrientation::kClockwise270:
// Rotated 90 degrees: swap axes.
std::swap(width_in_pixels, height_in_pixels);
break;
}
return size;
return gfx::Size(width_in_pixels, height_in_pixels);
}
draw_utils::PageInsetSizes PDFiumEngine::GetInsetSizes(
......
......@@ -391,12 +391,10 @@ bool PDFiumEngineExports::GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
if (max_page_width) {
*max_page_width = 0;
for (int page_number = 0; page_number < page_count_local; page_number++) {
double page_width = 0;
double page_height = 0;
FPDF_GetPageSizeByIndex(doc.get(), page_number, &page_width,
&page_height);
if (page_width > *max_page_width) {
*max_page_width = page_width;
FS_SIZEF page_size;
if (FPDF_GetPageSizeByIndexF(doc.get(), page_number, &page_size) &&
page_size.width > *max_page_width) {
*max_page_width = page_size.width;
}
}
}
......@@ -446,9 +444,16 @@ bool PDFiumEngineExports::GetPDFPageSizeByIndex(
double* width,
double* height) {
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 FPDF_GetPageSizeByIndex(doc.get(), page_number, width, height) != 0;
*width = size.width;
*height = size.height;
return true;
}
} // 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