Floatify printing code and APIs.
We were passing offsets and sizes as integers. Use floats instead. In some parts of the code, sizes and offsets are in CSS pixels, in other parts they are in device pixels, and in some other parts they are in points. There are reasons for this, although it's currently a bit more convoluted than it has to be. Converting between them was done carefully with integer arithmetic and some special rounding code. This has worked mostly fine, but is fragile. I'm working on a CL that straightens out the conversions, to use CSS pixels instead of points in the Blink APIs (since that's what Blink uses internally). This would however mean that, if we were to keep on using integers, rounding errors that used to occur when printing HTML with Blink would be fixed, but, at the same time, we'd introduce new rounding errors when printing with a plug-in (when opening a PDF and printing it), since that part of the code wants things in points. So use floats to avoid this. This also allows for removal of PrintParamsWithFloatingSize. Although floats have precision issues for large integer values, this shouldn't be a problem here, since all the values changed are about page sizes, or offsets into a page (margins, unprintable area, etc.). Floats have 23 bits for the integer part, so as long as we stay (way) below a million pixels / points / whatever, we're good. It would easily become a problem if we start using floats for offsets into documents, though, as documents can become very tall. This CL isn't expected to make much of a behavior difference on its own. We'll still round down sizes to the nearest integer when entering Blink HTML layout, since we cannot reliably print fractional page sizes anyway. Furthermore, the way LocalFrame::ResizePageRectsKeepingRatio() is used to magically convert from points to pixels is inaccurate, and still causes the symptoms described in crbug.com/1444579 But it should now be more straight-forward to fix such issues without introducing new ones. Change-Id: I5fc5afeb14e5470faf970c9f7c94d0fad243ce3d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4604506 Reviewed-by: danakj <danakj@chromium.org> Commit-Queue: Morten Stenshorne <mstensho@chromium.org> Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1160870}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9c087d9626
commit
c61b68aecf
chrome/browser
printing
ui
webui
print_preview
components/printing
browser
common
renderer
test
content
renderer
web_test
pdf/pdfium
third_party/blink
public
renderer
core
exported
frame
scheduler_integration_tests
@ -23,7 +23,9 @@
|
||||
#include "ui/gfx/codec/jpeg_codec.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_conversions.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/geometry/size_conversions.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
|
||||
using printing::ConvertUnit;
|
||||
@ -322,10 +324,13 @@ ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gfx::Size int_paper_size = ToFlooredSize(print_params.paper_size);
|
||||
gfx::Rect int_printable_area = ToEnclosedRect(print_params.printable_area);
|
||||
|
||||
float scale_factor = print_params.scale_factor / 100.0f;
|
||||
FitContentsToPrintableAreaIfRequired(
|
||||
output_doc.get(), scale_factor, print_params.print_scaling_option,
|
||||
print_params.paper_size, print_params.printable_area);
|
||||
FitContentsToPrintableAreaIfRequired(output_doc.get(), scale_factor,
|
||||
print_params.print_scaling_option,
|
||||
int_paper_size, int_printable_area);
|
||||
if (!FlattenPrintData(output_doc.get()))
|
||||
return nullptr;
|
||||
|
||||
@ -334,13 +339,12 @@ ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
|
||||
return output_doc;
|
||||
|
||||
gfx::Rect symmetrical_printable_area =
|
||||
printing::PageSetup::GetSymmetricalPrintableArea(
|
||||
print_params.paper_size, print_params.printable_area);
|
||||
printing::PageSetup::GetSymmetricalPrintableArea(int_paper_size,
|
||||
int_printable_area);
|
||||
if (symmetrical_printable_area.IsEmpty())
|
||||
return nullptr;
|
||||
return CreateNupPdfDocument(std::move(output_doc), pages_per_sheet,
|
||||
print_params.paper_size,
|
||||
symmetrical_printable_area);
|
||||
int_paper_size, symmetrical_printable_area);
|
||||
}
|
||||
|
||||
ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(ScopedFPDFDocument doc,
|
||||
|
@ -34,9 +34,9 @@ using ::testing::ElementsAre;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr gfx::Size kUSLetterSize = {612, 792};
|
||||
constexpr gfx::Rect kUSLetterRect = {{0, 0}, kUSLetterSize};
|
||||
constexpr gfx::Rect kPrintableAreaRect = {{18, 18}, {576, 733}};
|
||||
constexpr gfx::SizeF kUSLetterSize = {612, 792};
|
||||
constexpr gfx::RectF kUSLetterRect = {{0, 0}, kUSLetterSize};
|
||||
constexpr gfx::RectF kPrintableAreaRect = {{18, 18}, {576, 733}};
|
||||
|
||||
using ExpectedDimensions = std::vector<gfx::SizeF>;
|
||||
|
||||
|
Reference in New Issue
Block a user