summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-02-09 22:08:41 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-09 22:08:41 +0000
commitbc5dd9e7901ee56e0db66e76bf2e4903ab3d3fcd (patch)
tree0c62ff1e2e3695dbd98b8472d4846f792d1d87b4
parent2404eba504ac36ce2bfd2f7d6092f9e3898de9b0 (diff)
downloadpdfium-bc5dd9e7901ee56e0db66e76bf2e4903ab3d3fcd.tar.xz
Use CFX_Size in CPDF_Page and fpdf_ppo.cpp.
Instead of having separate floats for width and height. Also remove some out parameters and just return them instead. Change-Id: I798b1453910c89477d422dcb7c0805b90823bf98 Reviewed-on: https://pdfium-review.googlesource.com/26090 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Shirleen Lou <xlou@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp19
-rw-r--r--core/fpdfapi/page/cpdf_page.h15
-rw-r--r--fpdfsdk/fpdf_ppo.cpp125
3 files changed, 69 insertions, 90 deletions
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index ee7b5d408a..ba93f4a7d3 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -22,10 +22,7 @@
CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
CPDF_Dictionary* pPageDict,
bool bPageCache)
- : CPDF_PageObjectHolder(pDocument, pPageDict),
- m_PageWidth(100),
- m_PageHeight(100),
- m_pView(nullptr) {
+ : CPDF_PageObjectHolder(pDocument, pPageDict), m_PageSize(100, 100) {
if (bPageCache)
m_pPageRender = pdfium::MakeUnique<CPDF_PageRenderCache>(this);
if (!pPageDict)
@@ -45,12 +42,12 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
else
m_BBox.Intersect(mediabox);
- m_PageWidth = m_BBox.Width();
- m_PageHeight = m_BBox.Height();
+ m_PageSize.width = m_BBox.Width();
+ m_PageSize.height = m_BBox.Height();
int rotate = GetPageRotation();
if (rotate % 2)
- std::swap(m_PageWidth, m_PageHeight);
+ std::swap(m_PageSize.width, m_PageSize.height);
switch (rotate) {
case 0:
@@ -126,7 +123,7 @@ CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos,
int xSize,
int ySize,
int iRotate) const {
- if (m_PageWidth == 0 || m_PageHeight == 0)
+ if (m_PageSize.width == 0 || m_PageSize.height == 0)
return CFX_Matrix();
float x0 = 0;
@@ -171,9 +168,9 @@ CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos,
break;
}
CFX_Matrix matrix = m_PageMatrix;
- matrix.Concat(CFX_Matrix((x2 - x0) / m_PageWidth, (y2 - y0) / m_PageWidth,
- (x1 - x0) / m_PageHeight, (y1 - y0) / m_PageHeight,
- x0, y0));
+ matrix.Concat(CFX_Matrix(
+ (x2 - x0) / m_PageSize.width, (y2 - y0) / m_PageSize.width,
+ (x1 - x0) / m_PageSize.height, (y1 - y0) / m_PageSize.height, x0, y0));
return matrix;
}
diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h
index e1b5bcfa44..c7aa12e474 100644
--- a/core/fpdfapi/page/cpdf_page.h
+++ b/core/fpdfapi/page/cpdf_page.h
@@ -28,7 +28,7 @@ class CPDF_Page : public CPDF_PageObjectHolder {
bool bPageCache);
~CPDF_Page() override;
- // CPDF_PageObjectHolder
+ // CPDF_PageObjectHolder:
bool IsPage() const override;
void ParseContent();
@@ -39,9 +39,11 @@ class CPDF_Page : public CPDF_PageObjectHolder {
int ySize,
int iRotate) const;
- float GetPageWidth() const { return m_PageWidth; }
- float GetPageHeight() const { return m_PageHeight; }
- CFX_FloatRect GetPageBBox() const { return m_BBox; }
+ float GetPageWidth() const { return m_PageSize.width; }
+ float GetPageHeight() const { return m_PageSize.height; }
+ const CFX_SizeF& GetPageSize() const { return m_PageSize; }
+
+ const CFX_FloatRect& GetPageBBox() const { return m_BBox; }
int GetPageRotation() const;
CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender.get(); }
@@ -59,10 +61,9 @@ class CPDF_Page : public CPDF_PageObjectHolder {
CPDF_Object* GetPageAttr(const ByteString& name) const;
CFX_FloatRect GetBox(const ByteString& name) const;
- float m_PageWidth;
- float m_PageHeight;
+ CFX_SizeF m_PageSize;
CFX_Matrix m_PageMatrix;
- View* m_pView;
+ View* m_pView = nullptr;
std::unique_ptr<CPDF_PageRenderCache> m_pPageRender;
std::unique_ptr<CPDF_PageRenderContext> m_pRenderContext;
};
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 85da592d94..5499ecc222 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -45,17 +45,13 @@ struct NupPageSettings {
// on the input |numPagesOnXAxis| and |numPagesOnYAxis|.
class NupState {
public:
- NupState(float destPageWidth,
- float destPageHeight,
+ NupState(const CFX_SizeF& pagesize,
unsigned int numPagesOnXAxis,
unsigned int numPagesOnYAxis);
- // Calculate sub page origin and scale with the source page |inWidth| and
- // |inHeight| and new page |m_subPageWidth| and |m_subPageWidth|. With the
- // result stored in out parameter |ret|.
- void CalculateNewPagePosition(float inWidth,
- float inHeight,
- NupPageSettings* ret);
+ // Calculate sub page origin and scale with the source page of |pagesize| and
+ // new page of |m_subPageSize|.
+ NupPageSettings CalculateNewPagePosition(const CFX_SizeF& pagesize);
private:
// Helper function to get the subX, subY pair based on |m_subPageIndex|.
@@ -63,42 +59,38 @@ class NupState {
// subX and subY are 0-based indices that indicate which allocation slot to
// use.
std::pair<size_t, size_t> ConvertPageOrder() const;
+
// Given the |subx| and |suby| subpage position within a page, and a source
- // page with dimensions of |inPageWidth| x |inPageHeight|, calculate the sub
- // page's origin and scale, and store them in |ret|.
- void CalculatePageEdit(size_t subx,
- size_t suby,
- float inPageWidth,
- float inPageHeight,
- NupPageSettings* ret) const;
+ // page with dimensions of |pagesize|, calculate the sub page's origin and
+ // scale.
+ NupPageSettings CalculatePageEdit(size_t subx,
+ size_t suby,
+ const CFX_SizeF& pagesize) const;
+ const CFX_SizeF m_destPageSize;
const size_t m_numPagesOnXAxis;
const size_t m_numPagesOnYAxis;
- const float m_destPageWidth;
- const float m_destPageHeight;
const size_t m_numPagesPerSheet;
- float m_subPageWidth;
- float m_subPageHeight;
- // A 0-based index, in range of (0, m_numPagesPerSheet - 1) inclusive.
+ CFX_SizeF m_subPageSize;
+
+ // A 0-based index, in range of [0, m_numPagesPerSheet - 1).
size_t m_subPageIndex = 0;
};
-NupState::NupState(float destPageWidth,
- float destPageHeight,
+NupState::NupState(const CFX_SizeF& pagesize,
unsigned int numPagesOnXAxis,
unsigned int numPagesOnYAxis)
- : m_numPagesOnXAxis(numPagesOnXAxis),
+ : m_destPageSize(pagesize),
+ m_numPagesOnXAxis(numPagesOnXAxis),
m_numPagesOnYAxis(numPagesOnYAxis),
- m_destPageWidth(destPageWidth),
- m_destPageHeight(destPageHeight),
m_numPagesPerSheet(numPagesOnXAxis * numPagesOnYAxis) {
ASSERT(m_numPagesOnXAxis > 0);
ASSERT(m_numPagesOnYAxis > 0);
- ASSERT(m_destPageWidth > 0);
- ASSERT(m_destPageHeight > 0);
+ ASSERT(m_destPageSize.width > 0);
+ ASSERT(m_destPageSize.height > 0);
- m_subPageWidth = m_destPageWidth / m_numPagesOnXAxis;
- m_subPageHeight = m_destPageHeight / m_numPagesOnYAxis;
+ m_subPageSize.width = m_destPageSize.width / m_numPagesOnXAxis;
+ m_subPageSize.height = m_destPageSize.height / m_numPagesOnYAxis;
}
std::pair<size_t, size_t> NupState::ConvertPageOrder() const {
@@ -111,38 +103,35 @@ std::pair<size_t, size_t> NupState::ConvertPageOrder() const {
return {subX, subY};
}
-void NupState::CalculatePageEdit(size_t subXPos,
- size_t subYPos,
- float inPageWidth,
- float inPageHeight,
- NupPageSettings* pageEdit) const {
- pageEdit->subPageStartPoint.x = subXPos * m_subPageWidth;
- pageEdit->subPageStartPoint.y = subYPos * m_subPageHeight;
-
- const float xScale = m_subPageWidth / inPageWidth;
- const float yScale = m_subPageHeight / inPageHeight;
+NupPageSettings NupState::CalculatePageEdit(size_t subXPos,
+ size_t subYPos,
+ const CFX_SizeF& pagesize) const {
+ NupPageSettings settings;
+ settings.subPageStartPoint.x = subXPos * m_subPageSize.width;
+ settings.subPageStartPoint.y = subYPos * m_subPageSize.height;
- pageEdit->scale = std::min(xScale, yScale);
+ const float xScale = m_subPageSize.width / pagesize.width;
+ const float yScale = m_subPageSize.height / pagesize.height;
+ settings.scale = std::min(xScale, yScale);
- float subWidth = inPageWidth * pageEdit->scale;
- float subHeight = inPageHeight * pageEdit->scale;
+ float subWidth = pagesize.width * settings.scale;
+ float subHeight = pagesize.height * settings.scale;
if (xScale > yScale)
- pageEdit->subPageStartPoint.x += (m_subPageWidth - subWidth) / 2;
+ settings.subPageStartPoint.x += (m_subPageSize.width - subWidth) / 2;
else
- pageEdit->subPageStartPoint.y += (m_subPageHeight - subHeight) / 2;
+ settings.subPageStartPoint.y += (m_subPageSize.height - subHeight) / 2;
+ return settings;
}
-void NupState::CalculateNewPagePosition(float inWidth,
- float inHeight,
- NupPageSettings* pageEdit) {
+NupPageSettings NupState::CalculateNewPagePosition(const CFX_SizeF& pagesize) {
if (m_subPageIndex >= m_numPagesPerSheet)
m_subPageIndex = 0;
size_t subX;
size_t subY;
std::tie(subX, subY) = ConvertPageOrder();
- CalculatePageEdit(subX, subY, inWidth, inHeight, pageEdit);
++m_subPageIndex;
+ return CalculatePageEdit(subX, subY, pagesize);
}
CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict,
@@ -543,13 +532,12 @@ class CPDF_NPageToOneExporter : public CPDF_PageOrganizer {
// For the pages from the source document with |pageNums| as their page
// numbers, insert them into the destination document, starting at page 0.
// |pageNums| is 1-based.
- // |destPageWidth| and |destPageHeight| are the destination document page
- // dimensions, measured in pixels.
+ // |destPageSize| is the destination document page dimensions, measured in
+ // pixels.
// |numPagesOnXAxis| and |numPagesOnXAxis| together defines how many source
// pages fit on one destination page.
bool ExportNPagesToOne(const std::vector<uint32_t>& pageNums,
- float destPageWidth,
- float destPageHeight,
+ const CFX_SizeF& destPageSize,
unsigned int numPagesOnXAxis,
unsigned int numPagesOnYAxis);
@@ -566,8 +554,7 @@ class CPDF_NPageToOneExporter : public CPDF_PageOrganizer {
// bsContent string with the xobject reference surrounded by the
// transformation matrix.
void AddSubPage(CPDF_Dictionary* pPageDict,
- const CFX_PointF& position,
- float scale,
+ const NupPageSettings& settings,
ObjectNumberMap* pObjNumberMap,
PageXObjectMap* pPageXObjectMap,
XObjectNameNumberMap* pXObjNameNumberMap,
@@ -581,7 +568,6 @@ class CPDF_NPageToOneExporter : public CPDF_PageOrganizer {
XObjectNameNumberMap* pXObjNameNumberMap);
uint32_t m_xobjectNum = 0;
- CFX_SizeF m_pageSize;
XObjectNameNumberMap m_xobjs;
};
@@ -593,8 +579,7 @@ CPDF_NPageToOneExporter::~CPDF_NPageToOneExporter() = default;
bool CPDF_NPageToOneExporter::ExportNPagesToOne(
const std::vector<uint32_t>& pageNums,
- float destPageWidth,
- float destPageHeight,
+ const CFX_SizeF& destPageSize,
unsigned int numPagesOnXAxis,
unsigned int numPagesOnYAxis) {
if (!PDFDocInit())
@@ -614,9 +599,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne(
// If there are two pages that are identical and have the same object number,
// we can reuse one created XObject.
PageXObjectMap pageXObjectMap;
- const CFX_SizeF pagesize(destPageWidth, destPageHeight);
- NupState nupState(destPageWidth, destPageHeight, numPagesOnXAxis,
- numPagesOnYAxis);
+ NupState nupState(destPageSize, numPagesOnXAxis, numPagesOnYAxis);
size_t curpage = 0;
for (size_t outerPage = 0; outerPage < pageNums.size();
@@ -626,7 +609,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne(
if (!pCurPageDict)
return false;
- SetMediaBox(pCurPageDict, pagesize);
+ SetMediaBox(pCurPageDict, destPageSize);
ByteString bsContent;
size_t innerPageMax =
std::min(outerPage + numPagesPerSheet, pageNums.size());
@@ -638,12 +621,10 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne(
return false;
CPDF_Page srcPage(src(), pSrcPageDict, true);
- NupPageSettings pgEdit;
- nupState.CalculateNewPagePosition(srcPage.GetPageWidth(),
- srcPage.GetPageHeight(), &pgEdit);
- AddSubPage(pSrcPageDict, pgEdit.subPageStartPoint, pgEdit.scale,
- &objectNumberMap, &pageXObjectMap, &xObjectNameNumberMap,
- &bsContent);
+ NupPageSettings settings =
+ nupState.CalculateNewPagePosition(srcPage.GetPageSize());
+ AddSubPage(pSrcPageDict, settings, &objectNumberMap, &pageXObjectMap,
+ &xObjectNameNumberMap, &bsContent);
}
// Finish up the current page.
@@ -666,8 +647,7 @@ void CPDF_NPageToOneExporter::SetMediaBox(CPDF_Dictionary* pDestPageDict,
void CPDF_NPageToOneExporter::AddSubPage(
CPDF_Dictionary* pPageDict,
- const CFX_PointF& position,
- float scale,
+ const NupPageSettings& settings,
ObjectNumberMap* pObjNumberMap,
PageXObjectMap* pPageXObjectMap,
XObjectNameNumberMap* pXObjNameNumberMap,
@@ -687,8 +667,8 @@ void CPDF_NPageToOneExporter::AddSubPage(
(*pXObjNameNumberMap)[bsXObjectName] = m_xobjs[bsXObjectName];
CFX_Matrix matrix;
- matrix.Scale(scale, scale);
- matrix.Translate(position.x, position.y);
+ matrix.Scale(settings.scale, settings.scale);
+ matrix.Translate(settings.subPageStartPoint.x, settings.subPageStartPoint.y);
std::ostringstream contentStream;
contentStream << "q\n"
@@ -831,7 +811,8 @@ FPDF_ImportNPagesToOne(FPDF_DOCUMENT src_doc,
}
CPDF_NPageToOneExporter exporter(pDestDoc, pSrcDoc);
- if (!exporter.ExportNPagesToOne(page_numbers, output_width, output_height,
+ if (!exporter.ExportNPagesToOne(page_numbers,
+ CFX_SizeF(output_width, output_height),
num_pages_on_x_axis, num_pages_on_y_axis)) {
return nullptr;
}