0

Use ToPDFiumRotation() helper function in more parts of the PDF code.

Make it constexpr, so the value does not need to be calculated at
runtime when the rotation value is constant.

Change-Id: I56dfe6ab2743e872d2f17350c551ba5f9b7f71a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3472265
Reviewed-by: K. Moon <kmoon@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#972603}
This commit is contained in:
Lei Zhang
2022-02-17 20:27:55 +00:00
committed by Chromium LUCI CQ
parent 74f8ebe192
commit 38b99bcf3f
3 changed files with 21 additions and 20 deletions

@ -1571,12 +1571,13 @@ Thumbnail PDFiumPage::GenerateThumbnail(float device_pixel_ratio) {
constexpr int kRenderingFlags = FPDF_ANNOT | FPDF_REVERSE_BYTE_ORDER;
FPDF_RenderPageBitmap(fpdf_bitmap.get(), GetPage(), /*start_x=*/0,
/*start_y=*/0, image_size.width(), image_size.height(),
/*rotate=*/0, kRenderingFlags);
ToPDFiumRotation(PageOrientation::kOriginal),
kRenderingFlags);
// Draw the forms.
FPDF_FFLDraw(engine_->form(), fpdf_bitmap.get(), GetPage(), /*start_x=*/0,
/*start_y=*/0, image_size.width(), image_size.height(),
/*rotate=*/0, kRenderingFlags);
ToPDFiumRotation(PageOrientation::kOriginal), kRenderingFlags);
return thumbnail;
}
@ -1660,20 +1661,4 @@ uint32_t PDFiumPage::CountLinkHighlightOverlaps(
CountInternalTextOverlaps(highlights);
}
int ToPDFiumRotation(PageOrientation orientation) {
// Could use static_cast<int>(orientation), but using an exhaustive switch
// will trigger an error if we ever change the definition of
// `PageOrientation`.
switch (orientation) {
case PageOrientation::kOriginal:
return 0;
case PageOrientation::kClockwise90:
return 1;
case PageOrientation::kClockwise180:
return 2;
case PageOrientation::kClockwise270:
return 3;
}
}
} // namespace chrome_pdf

@ -430,7 +430,21 @@ class PDFiumPage {
// Converts page orientations to the PDFium equivalents, as defined by
// FPDF_RenderPage().
int ToPDFiumRotation(PageOrientation orientation);
constexpr int ToPDFiumRotation(PageOrientation orientation) {
// Could use static_cast<int>(orientation), but using an exhaustive switch
// will trigger an error if we ever change the definition of
// `PageOrientation`.
switch (orientation) {
case PageOrientation::kOriginal:
return 0;
case PageOrientation::kClockwise90:
return 1;
case PageOrientation::kClockwise180:
return 2;
case PageOrientation::kClockwise270:
return 3;
}
}
constexpr uint32_t MakeARGB(unsigned int a,
unsigned int r,

@ -393,7 +393,9 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
bitmap_size.height(), 0xFFFFFFFF);
FPDF_RenderPageBitmap(bitmap.get(), page_to_print, 0, 0, bitmap_size.width(),
bitmap_size.height(), /*rotate=*/0, FPDF_PRINTING);
bitmap_size.height(),
ToPDFiumRotation(PageOrientation::kOriginal),
FPDF_PRINTING);
float ratio_x = ConvertUnitFloat(bitmap_size.width(), dpi, kPointsPerInch);
float ratio_y = ConvertUnitFloat(bitmap_size.height(), dpi, kPointsPerInch);