Commit b23deb3d authored by Ankit Kumar 🌪️'s avatar Ankit Kumar 🌪️ Committed by Commit Bot

Migrate pp::Rect to gfx::Rect in PDFEngineExports

Update PDFEngineExports to use gfx::Rect instead of pp::Rect. Update
callers to expect gfx::Rect as return value instead of pp::Rect.

Bug: 1101101
Change-Id: Id549e93bfa361d61eceb058c98b1e20daa4ab8b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367132
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800694}
parent 6ccb15af
......@@ -32,6 +32,7 @@ if (enable_pdf) {
deps = [
":internal",
"//base",
"//ui/gfx/geometry",
]
}
......
......@@ -10,6 +10,7 @@
#include "pdf/pdf_engine.h"
#include "pdf/pdf_init.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf {
......@@ -61,7 +62,7 @@ bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
PDFEngineExports* engine_exports = PDFEngineExports::Get();
PDFEngineExports::RenderingSettings settings(
dpi_x, dpi_y,
pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
gfx::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
autorotate, use_color);
return engine_exports->RenderPDFPageToDC(pdf_buffer, page_number, settings,
......@@ -128,7 +129,7 @@ bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
PDFEngineExports* engine_exports = PDFEngineExports::Get();
PDFEngineExports::RenderingSettings settings(
dpi_x, dpi_y, pp::Rect(bitmap_width, bitmap_height),
dpi_x, dpi_y, gfx::Rect(bitmap_width, bitmap_height),
/*fit_to_bounds=*/true, stretch_to_bounds, keep_aspect_ratio,
/*center_in_bounds=*/true, autorotate, use_color);
return engine_exports->RenderPDFPageToBitmap(pdf_buffer, page_number,
......
......@@ -23,12 +23,12 @@
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var_array.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#if defined(OS_WIN)
#include <windows.h>
......@@ -53,6 +53,7 @@ class Vector2d;
namespace pp {
class InputEvent;
class Rect;
class VarDictionary;
} // namespace pp
......@@ -497,7 +498,7 @@ class PDFEngineExports {
struct RenderingSettings {
RenderingSettings(int dpi_x,
int dpi_y,
const pp::Rect& bounds,
const gfx::Rect& bounds,
bool fit_to_bounds,
bool stretch_to_bounds,
bool keep_aspect_ratio,
......@@ -508,7 +509,7 @@ class PDFEngineExports {
int dpi_x;
int dpi_y;
pp::Rect bounds;
gfx::Rect bounds;
bool fit_to_bounds;
bool stretch_to_bounds;
bool keep_aspect_ratio;
......
......@@ -13,7 +13,6 @@
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
#include "pdf/pdfium/pdfium_print.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "printing/nup_parameters.h"
#include "printing/units.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
......@@ -34,7 +33,7 @@ namespace {
int CalculatePosition(FPDF_PAGE page,
const PDFiumEngineExports::RenderingSettings& settings,
pp::Rect* dest) {
gfx::Rect* dest) {
// settings.bounds is in terms of the max DPI. Convert page sizes to match.
int dpi = std::max(settings.dpi_x, settings.dpi_y);
int page_width = static_cast<int>(
......@@ -97,7 +96,7 @@ int CalculatePosition(FPDF_PAGE page,
gfx::Vector2d offset(
(settings.bounds.width() * settings.dpi_x / dpi - dest->width()) / 2,
(settings.bounds.height() * settings.dpi_y / dpi - dest->height()) / 2);
dest->Offset(PPPointFromVector(offset));
dest->Offset(offset);
}
return rotate;
}
......@@ -184,7 +183,7 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
PDFEngineExports::RenderingSettings::RenderingSettings(int dpi_x,
int dpi_y,
const pp::Rect& bounds,
const gfx::Rect& bounds,
bool fit_to_bounds,
bool stretch_to_bounds,
bool keep_aspect_ratio,
......@@ -243,7 +242,7 @@ bool PDFiumEngineExports::RenderPDFPageToDC(
if (new_settings.dpi_y == -1)
new_settings.dpi_y = GetDeviceCaps(dc, LOGPIXELSY);
pp::Rect dest;
gfx::Rect dest;
int rotate = CalculatePosition(page.get(), new_settings, &dest);
int save_state = SaveDC(dc);
......@@ -322,7 +321,7 @@ bool PDFiumEngineExports::RenderPDFPageToBitmap(
if (!page)
return false;
pp::Rect dest;
gfx::Rect dest;
int rotate = CalculatePosition(page.get(), settings, &dest);
ScopedFPDFBitmap bitmap(FPDFBitmap_CreateEx(
......@@ -332,7 +331,7 @@ bool PDFiumEngineExports::RenderPDFPageToBitmap(
FPDFBitmap_FillRect(bitmap.get(), 0, 0, settings.bounds.width(),
settings.bounds.height(), 0xFFFFFFFF);
// Shift top-left corner of bounds to (0, 0) if it's not there.
dest.set_point(dest.point() - settings.bounds.point());
dest.set_origin(dest.origin() - settings.bounds.OffsetFromOrigin());
int flags = FPDF_ANNOT | FPDF_PRINTING;
if (!settings.use_color)
......
......@@ -17,6 +17,7 @@
#include "printing/pdf_render_settings.h"
#include "printing/units.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf {
......@@ -66,7 +67,7 @@ void CheckPdfRendering(const std::vector<uint8_t>& pdf_data,
printing::ConvertUnit(size_in_points.height, printing::kPointsPerInch,
printing::kDefaultPdfDpi);
const pp::Rect page_rect(width_in_pixels, height_in_pixels);
const gfx::Rect page_rect(width_in_pixels, height_in_pixels);
std::vector<uint8_t> page_bitmap_data(kColorChannels * page_rect.width() *
page_rect.height());
......
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