Skip to content

Commit

Permalink
Use ToPDFiumRotation() helper function in more parts of the PDF code.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#972603}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed Feb 17, 2022
1 parent 74f8ebe commit 38b99bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
21 changes: 3 additions & 18 deletions pdf/pdfium/pdfium_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
16 changes: 15 additions & 1 deletion pdf/pdfium/pdfium_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion pdf/pdfium/pdfium_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38b99bc

Please sign in to comment.