0

[PDF Ink Signatures] Plumb page size in points for PdfInkModule

Add plumbing for getting a PDF page's size in points through to
PdfInkModuleClient.  This makes that size available for PdfInkModule,
to use for an upcoming update to the Ink strokes rendering transform.

Also define a constant for the conversion factor from pixels to points,
which while used once here can be used repeatedly in future CLs.

Bug: 380038343
Change-Id: Idfb2c350a00e87644ee1099ccd6b33731803d0c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6311049
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1426612}
This commit is contained in:
Alan Screen
2025-02-28 16:01:40 -08:00
committed by Chromium LUCI CQ
parent c70ab27efa
commit 473530ce6f
7 changed files with 39 additions and 1 deletions

@ -53,6 +53,10 @@ class PdfInkModuleClient {
// non-negative page index returned from `VisiblePageIndexFromPoint()`.
virtual gfx::Rect GetPageContentsRect(int page_index) = 0;
// Gets the page size in points for `page_index`. Must be non-empty for any
// non-negative page index returned from `VisiblePageIndexFromPoint()`.
virtual gfx::SizeF GetPageSizeInPoints(int page_index) = 0;
// Gets the thumbnail size for `page_index`. The size must be non-empty for
// any valid page index.
virtual gfx::Size GetThumbnailSize(int page_index) = 0;

@ -30,6 +30,7 @@
#include "pdf/test/mouse_event_builder.h"
#include "pdf/test/pdf_ink_test_helpers.h"
#include "pdf/ui/thumbnail.h"
#include "printing/units.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
@ -267,6 +268,14 @@ class FakeClient : public PdfInkModuleClient {
return gfx::ToEnclosedRect(page_layouts_[page_index]);
}
gfx::SizeF GetPageSizeInPoints(int page_index) override {
CHECK_GE(page_index, 0);
CHECK_LT(static_cast<size_t>(page_index), page_layouts_.size());
gfx::SizeF page_size = page_layouts_[page_index].size();
page_size.Scale(printing::kUnitConversionFactorPixelsToPoints);
return page_size;
}
float GetZoom() const override { return zoom_; }
void Invalidate(const gfx::Rect& rect) override {

@ -291,6 +291,13 @@ class PdfViewWebPlugin::PdfInkModuleClientImpl : public PdfInkModuleClient {
return plugin_->engine_->GetPageContentsRect(page_index);
}
gfx::SizeF GetPageSizeInPoints(int page_index) override {
if (page_index < 0 || page_index >= plugin_->engine_->GetNumberOfPages()) {
return gfx::SizeF();
}
return plugin_->engine_->GetPageSizeInPoints(page_index).value();
}
gfx::Size GetThumbnailSize(int page_index) override {
return plugin_->engine_->GetThumbnailSize(page_index,
plugin_->device_scale_);

@ -2622,6 +2622,8 @@ class PdfViewWebPluginInkTest : public PdfViewWebPluginTest {
.WillByDefault([](int page_index) -> gfx::Rect {
return gfx::Rect(/*x=*/0, /*y=*/0, /*width=*/100, /*height=*/50);
});
ON_CALL(*engine_ptr_, GetPageSizeInPoints)
.WillByDefault(Return(gfx::SizeF(/*width=*/75.0f, /*height=*/37.5f)));
ON_CALL(*engine_ptr_, GetThumbnailSize)
.WillByDefault(Return(gfx::Size(50, 25)));
ON_CALL(*engine_ptr_, IsPageVisible)
@ -2782,6 +2784,13 @@ TEST_F(PdfViewWebPluginInkTest, UpdateCursor) {
EXPECT_EQ(ui::mojom::CursorType::kPointer, cursor.type());
}
TEST_F(PdfViewWebPluginInkTest, GetPageSizeInPoints) {
SetUpWithTrivialInkStrokes();
EXPECT_EQ(gfx::SizeF(75.0f, 37.5f),
plugin_->ink_module_client_for_testing()->GetPageSizeInPoints(
/*page_index=*/0));
}
TEST_F(PdfViewWebPluginInkTest, GetThumbnailSize) {
SetUpWithTrivialInkStrokes();
EXPECT_EQ(gfx::Size(50, 25),

@ -336,7 +336,7 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
// Gets the size of the page in points for the page at `page_index`. Any
// fractional portion of the size is retained in the result. Returns
// `std::nullopt` if the indicated page index is not available.
std::optional<gfx::SizeF> GetPageSizeInPoints(int page_index) const;
virtual std::optional<gfx::SizeF> GetPageSizeInPoints(int page_index) const;
// Returns the uniform page size of the document in points. Returns
// `std::nullopt` if the document has more than one page size.

@ -88,6 +88,11 @@ class TestPDFiumEngine : public PDFiumEngine {
MOCK_METHOD(gfx::Rect, GetPageScreenRect, (int), (const override));
MOCK_METHOD(std::optional<gfx::SizeF>,
GetPageSizeInPoints,
(int),
(const override));
// Returns an empty bookmark list.
base::Value::List GetBookmarks() override;

@ -31,6 +31,10 @@ constexpr int kPointsPerInch = 72;
// http://dev.w3.org/csswg/css3-values/#the-px-unit
constexpr int kPixelsPerInch = 96;
// Factor to convert from pixels per inch to points per inch.
inline constexpr float kUnitConversionFactorPixelsToPoints =
static_cast<float>(kPointsPerInch) / kPixelsPerInch;
#if BUILDFLAG(IS_MAC)
constexpr int kDefaultMacDpi = 72;
#endif // BUILDFLAG(IS_MAC)