PDF: DCHECK page from/to device calls.
FPDF_PageToDevice() and FPDF_DeviceToPage() now return results. Change-Id: I2f49fa37d295ea7ee4bc3dcd8cdcebaa085f5b23 Reviewed-on: https://chromium-review.googlesource.com/1013283 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Cr-Commit-Position: refs/heads/master@{#551154}
This commit is contained in:
@ -3845,15 +3845,16 @@ void PDFiumEngine::DeviceToPage(int page_index,
|
||||
pages_[page_index]->rect().x());
|
||||
int temp_y = static_cast<int>((device_y + position_.y()) / current_zoom_ -
|
||||
pages_[page_index]->rect().y());
|
||||
FPDF_DeviceToPage(pages_[page_index]->GetPage(), 0, 0,
|
||||
pages_[page_index]->rect().width(),
|
||||
pages_[page_index]->rect().height(), current_rotation_,
|
||||
temp_x, temp_y, page_x, page_y);
|
||||
FPDF_BOOL ret = FPDF_DeviceToPage(
|
||||
pages_[page_index]->GetPage(), 0, 0, pages_[page_index]->rect().width(),
|
||||
pages_[page_index]->rect().height(), current_rotation_, temp_x, temp_y,
|
||||
page_x, page_y);
|
||||
DCHECK(ret);
|
||||
}
|
||||
|
||||
int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
|
||||
// Copy visible_pages_ since it can change as a result of loading the page in
|
||||
// GetPage(). See https://crbug.com/822091.
|
||||
// Copy |visible_pages_| since it can change as a result of loading the page
|
||||
// in GetPage(). See https://crbug.com/822091.
|
||||
std::vector<int> visible_pages_copy(visible_pages_);
|
||||
for (int page_index : visible_pages_copy) {
|
||||
if (pages_[page_index]->GetPage() == page)
|
||||
|
@ -414,7 +414,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
std::vector<pp::Rect>* highlighted_rects);
|
||||
|
||||
// Helper function to convert a device to page coordinates. If the page is
|
||||
// not yet loaded, page_x and page_y will be set to 0.
|
||||
// not yet loaded, |page_x| and |page_y| will be set to 0.
|
||||
void DeviceToPage(int page_index,
|
||||
const pp::Point& device_point,
|
||||
double* page_x,
|
||||
|
@ -36,10 +36,12 @@ pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
|
||||
int min_y;
|
||||
int max_x;
|
||||
int max_y;
|
||||
FPDF_PageToDevice(page, 0, 0, output_width, output_height, 0, input.x(),
|
||||
input.y(), &min_x, &min_y);
|
||||
FPDF_PageToDevice(page, 0, 0, output_width, output_height, 0, input.right(),
|
||||
input.bottom(), &max_x, &max_y);
|
||||
FPDF_BOOL ret = FPDF_PageToDevice(page, 0, 0, output_width, output_height, 0,
|
||||
input.x(), input.y(), &min_x, &min_y);
|
||||
DCHECK(ret);
|
||||
ret = FPDF_PageToDevice(page, 0, 0, output_width, output_height, 0,
|
||||
input.right(), input.bottom(), &max_x, &max_y);
|
||||
DCHECK(ret);
|
||||
|
||||
if (max_x < min_x)
|
||||
std::swap(min_x, max_x);
|
||||
@ -248,8 +250,10 @@ PDFiumPage::Area PDFiumPage::GetCharIndex(const pp::Point& point,
|
||||
pp::Point point2 = point - rect_.point();
|
||||
double new_x;
|
||||
double new_y;
|
||||
FPDF_DeviceToPage(GetPage(), 0, 0, rect_.width(), rect_.height(), rotation,
|
||||
point2.x(), point2.y(), &new_x, &new_y);
|
||||
FPDF_BOOL ret =
|
||||
FPDF_DeviceToPage(GetPage(), 0, 0, rect_.width(), rect_.height(),
|
||||
rotation, point2.x(), point2.y(), &new_x, &new_y);
|
||||
DCHECK(ret);
|
||||
|
||||
// hit detection tolerance, in points.
|
||||
constexpr double kTolerance = 20.0;
|
||||
@ -553,14 +557,16 @@ pp::Rect PDFiumPage::PageToScreen(const pp::Point& offset,
|
||||
int new_top;
|
||||
int new_right;
|
||||
int new_bottom;
|
||||
FPDF_PageToDevice(page_, static_cast<int>(start_x), static_cast<int>(start_y),
|
||||
static_cast<int>(ceil(size_x)),
|
||||
static_cast<int>(ceil(size_y)), rotation, left, top,
|
||||
&new_left, &new_top);
|
||||
FPDF_PageToDevice(page_, static_cast<int>(start_x), static_cast<int>(start_y),
|
||||
static_cast<int>(ceil(size_x)),
|
||||
static_cast<int>(ceil(size_y)), rotation, right, bottom,
|
||||
&new_right, &new_bottom);
|
||||
FPDF_BOOL ret = FPDF_PageToDevice(
|
||||
page_, static_cast<int>(start_x), static_cast<int>(start_y),
|
||||
static_cast<int>(ceil(size_x)), static_cast<int>(ceil(size_y)), rotation,
|
||||
left, top, &new_left, &new_top);
|
||||
DCHECK(ret);
|
||||
ret = FPDF_PageToDevice(
|
||||
page_, static_cast<int>(start_x), static_cast<int>(start_y),
|
||||
static_cast<int>(ceil(size_x)), static_cast<int>(ceil(size_y)), rotation,
|
||||
right, bottom, &new_right, &new_bottom);
|
||||
DCHECK(ret);
|
||||
|
||||
// If the PDF is rotated, the horizontal/vertical coordinates could be
|
||||
// flipped. See
|
||||
|
Reference in New Issue
Block a user