diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-24 18:46:26 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-24 18:46:26 +0000 |
commit | e835574db56d3a59f444fa98318458d83ffe15a4 (patch) | |
tree | 35bf8f662045c75a645fbebaeef7e2cca3b440bb | |
parent | 877e1e212794c6a43f6661198ac1b369fab975be (diff) | |
download | pdfium-e835574db56d3a59f444fa98318458d83ffe15a4.tar.xz |
Make CPDF_PathObject::m_Path private.
Change-Id: I5c42af8e9e2d6a60648d291153326aef04e4c49e
Reviewed-on: https://pdfium-review.googlesource.com/c/44513
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 42 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pathobject.h | 12 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_renderstatus.cpp | 12 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpath.cpp | 26 |
6 files changed, 52 insertions, 48 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index cfc8c5159a..4ae5631534 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -354,8 +354,8 @@ void CPDF_PageContentGenerator::ProcessPath(std::ostringstream* buf, *buf << pPathObj->matrix() << " cm "; - auto& pPoints = pPathObj->m_Path.GetPoints(); - if (pPathObj->m_Path.IsRect()) { + const auto& pPoints = pPathObj->path().GetPoints(); + if (pPathObj->path().IsRect()) { CFX_PointF diff = pPoints[2].m_Point - pPoints[0].m_Point; *buf << pPoints[0].m_Point.x << " " << pPoints[0].m_Point.y << " " << diff.x << " " << diff.y << " re"; diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index f4555287d7..b5fbec80ec 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -51,9 +51,9 @@ class CPDF_PageContentGeneratorTest : public testing::Test { TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendRect(10, 5, 13, 30); - pPathObj->set_filltype(FXFILL_ALTERNATE); pPathObj->set_stroke(true); + pPathObj->set_filltype(FXFILL_ALTERNATE); + pPathObj->path().AppendRect(10, 5, 13, 30); auto pTestPage = pdfium::MakeRetain<CPDF_Page>(nullptr, nullptr, false); CPDF_PageContentGenerator generator(pTestPage.Get()); @@ -62,11 +62,11 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { EXPECT_EQ("q 1 0 0 1 0 0 cm 10 5 3 25 re B* Q\n", ByteString(buf)); pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendPoint(CFX_PointF(0, 0), FXPT_TYPE::MoveTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(5.2f, 0), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(5.2f, 3.78f), FXPT_TYPE::LineTo, + pPathObj->path().AppendPoint(CFX_PointF(0, 0), FXPT_TYPE::MoveTo, false); + pPathObj->path().AppendPoint(CFX_PointF(5.2f, 0), FXPT_TYPE::LineTo, false); + pPathObj->path().AppendPoint(CFX_PointF(5.2f, 3.78f), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(0, 3.78f), FXPT_TYPE::LineTo, true); + pPathObj->path().AppendPoint(CFX_PointF(0, 3.78f), FXPT_TYPE::LineTo, true); buf.str(""); TestProcessPath(&generator, &buf, pPathObj.get()); @@ -75,26 +75,26 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendPoint(CFX_PointF(3.102f, 4.67f), FXPT_TYPE::MoveTo, + pPathObj->set_filltype(FXFILL_WINDING); + pPathObj->path().AppendPoint(CFX_PointF(3.102f, 4.67f), FXPT_TYPE::MoveTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(5.45f, 0.29f), FXPT_TYPE::LineTo, + pPathObj->path().AppendPoint(CFX_PointF(5.45f, 0.29f), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(4.24f, 3.15f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(4.24f, 3.15f), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(4.65f, 2.98f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(4.65f, 2.98f), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(3.456f, 0.24f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(3.456f, 0.24f), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(10.6f, 11.15f), FXPT_TYPE::LineTo, + pPathObj->path().AppendPoint(CFX_PointF(10.6f, 11.15f), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(11, 12.5f), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(11.46f, 12.67f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(11, 12.5f), FXPT_TYPE::LineTo, false); + pPathObj->path().AppendPoint(CFX_PointF(11.46f, 12.67f), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(11.84f, 12.96f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(11.84f, 12.96f), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(12, 13.64f), FXPT_TYPE::BezierTo, + pPathObj->path().AppendPoint(CFX_PointF(12, 13.64f), FXPT_TYPE::BezierTo, true); - pPathObj->set_filltype(FXFILL_WINDING); auto pTestPage = pdfium::MakeRetain<CPDF_Page>(nullptr, nullptr, false); CPDF_PageContentGenerator generator(pTestPage.Get()); @@ -109,11 +109,11 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendPoint(CFX_PointF(1, 2), FXPT_TYPE::MoveTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(3, 4), FXPT_TYPE::LineTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(5, 6), FXPT_TYPE::LineTo, true); - pPathObj->set_filltype(FXFILL_WINDING); pPathObj->set_stroke(true); + pPathObj->set_filltype(FXFILL_WINDING); + pPathObj->path().AppendPoint(CFX_PointF(1, 2), FXPT_TYPE::MoveTo, false); + pPathObj->path().AppendPoint(CFX_PointF(3, 4), FXPT_TYPE::LineTo, false); + pPathObj->path().AppendPoint(CFX_PointF(5, 6), FXPT_TYPE::LineTo, true); static const std::vector<float> rgb = {0.5f, 0.7f, 0.35f}; CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); diff --git a/core/fpdfapi/page/cpdf_pathobject.h b/core/fpdfapi/page/cpdf_pathobject.h index e6e0d19de8..c2166b3277 100644 --- a/core/fpdfapi/page/cpdf_pathobject.h +++ b/core/fpdfapi/page/cpdf_pathobject.h @@ -27,20 +27,22 @@ class CPDF_PathObject final : public CPDF_PageObject { void CalcBoundingBox(); + bool stroke() const { return m_bStroke; } + void set_stroke(bool stroke) { m_bStroke = stroke; } + int filltype() const { return m_FillType; } void set_filltype(int filltype) { m_FillType = filltype; } - bool stroke() const { return m_bStroke; } - void set_stroke(bool stroke) { m_bStroke = stroke; } + CPDF_Path& path() { return m_Path; } + const CPDF_Path& path() const { return m_Path; } const CFX_Matrix& matrix() const { return m_Matrix; } void set_matrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } - CPDF_Path m_Path; - private: - int m_FillType = 0; bool m_bStroke = false; + int m_FillType = 0; + CPDF_Path m_Path; CFX_Matrix m_Matrix; }; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 245a2852bc..5a9d6b6ea2 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -1475,9 +1475,9 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { if (bStroke || FillType) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(GetCurrentStreamIndex()); - pPathObj->m_Path = Path; - pPathObj->set_filltype(FillType); pPathObj->set_stroke(bStroke); + pPathObj->set_filltype(FillType); + pPathObj->path() = Path; pPathObj->set_matrix(matrix); SetGraphicStates(pPathObj.get(), true, false, true); pPathObj->CalcBoundingBox(); diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 7bd2d7cd22..26ce0a6d3c 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1276,7 +1276,7 @@ bool CPDF_RenderStatus::ProcessPath(CPDF_PathObject* pPathObj, if (m_Options.HasFlag(RENDER_THINLINE)) graphState.SetLineWidth(0); return m_pDevice->DrawPathWithBlend( - pPathObj->m_Path.GetObject(), &path_matrix, graphState.GetObject(), + pPathObj->path().GetObject(), &path_matrix, graphState.GetObject(), fill_argb, stroke_argb, FillType, m_curBlend); } @@ -1421,14 +1421,14 @@ bool CPDF_RenderStatus::SelectClipPath(const CPDF_PathObject* pPathObj, CFX_GraphState graphState = pPathObj->m_GraphState; if (m_Options.HasFlag(RENDER_THINLINE)) graphState.SetLineWidth(0); - return m_pDevice->SetClip_PathStroke(pPathObj->m_Path.GetObject(), + return m_pDevice->SetClip_PathStroke(pPathObj->path().GetObject(), &path_matrix, graphState.GetObject()); } int fill_mode = pPathObj->filltype(); if (m_Options.HasFlag(RENDER_NOPATHSMOOTH)) { fill_mode |= FXFILL_NOPATHSMOOTH; } - return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix, + return m_pDevice->SetClip_PathFill(pPathObj->path().GetObject(), &path_matrix, fill_mode); } @@ -1973,7 +1973,7 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, path.m_ClipPath.AppendTexts(&pCopy); path.m_ColorState = textobj->m_ColorState; path.m_GeneralState = textobj->m_GeneralState; - path.m_Path.AppendRect(textobj->GetRect().left, textobj->GetRect().bottom, + path.path().AppendRect(textobj->GetRect().left, textobj->GetRect().bottom, textobj->GetRect().right, textobj->GetRect().top); path.SetRect(textobj->GetRect()); @@ -2006,9 +2006,9 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, } matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x, charpos.m_Origin.y)); - path.m_Path.Append(pPath, &matrix); - path.set_filltype(bFill ? FXFILL_WINDING : 0); path.set_stroke(bStroke); + path.set_filltype(bFill ? FXFILL_WINDING : 0); + path.path().Append(pPath, &matrix); path.set_matrix(*pTextMatrix); path.CalcBoundingBox(); ProcessPath(&path, mtObj2Device); diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp index b6926a2492..d9213c8b49 100644 --- a/fpdfsdk/fpdf_editpath.cpp +++ b/fpdfsdk/fpdf_editpath.cpp @@ -49,7 +49,7 @@ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x, float y) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); + pPathObj->path().AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); pPathObj->DefaultStates(); // Caller takes ownership. @@ -61,7 +61,7 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x, float w, float h) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); - pPathObj->m_Path.AppendRect(x, y, x + w, y + h); + pPathObj->path().AppendRect(x, y, x + w, y + h); pPathObj->DefaultStates(); // Caller takes ownership. @@ -131,7 +131,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountSegments(FPDF_PAGEOBJECT path) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); if (!pPathObj) return -1; - return pdfium::CollectionSize<int>(pPathObj->m_Path.GetPoints()); + return pdfium::CollectionSize<int>(pPathObj->path().GetPoints()); } FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV @@ -140,7 +140,7 @@ FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index) { if (!pPathObj) return nullptr; - const std::vector<FX_PATHPOINT>& points = pPathObj->m_Path.GetPoints(); + const std::vector<FX_PATHPOINT>& points = pPathObj->path().GetPoints(); if (!pdfium::IndexInBounds(points, index)) return nullptr; @@ -154,7 +154,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path, if (!pPathObj) return false; - pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); + pPathObj->path().AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); pPathObj->SetDirty(true); return true; } @@ -166,7 +166,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_LineTo(FPDF_PAGEOBJECT path, if (!pPathObj) return false; - pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::LineTo, false); + pPathObj->path().AppendPoint(CFX_PointF(x, y), FXPT_TYPE::LineTo, false); pPathObj->SetDirty(true); return true; } @@ -182,9 +182,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path, if (!pPathObj) return false; - pPathObj->m_Path.AppendPoint(CFX_PointF(x1, y1), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(x2, y2), FXPT_TYPE::BezierTo, false); - pPathObj->m_Path.AppendPoint(CFX_PointF(x3, y3), FXPT_TYPE::BezierTo, false); + CPDF_Path& cpath = pPathObj->path(); + cpath.AppendPoint(CFX_PointF(x1, y1), FXPT_TYPE::BezierTo, false); + cpath.AppendPoint(CFX_PointF(x2, y2), FXPT_TYPE::BezierTo, false); + cpath.AppendPoint(CFX_PointF(x3, y3), FXPT_TYPE::BezierTo, false); pPathObj->SetDirty(true); return true; } @@ -194,10 +195,11 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) { if (!pPathObj) return false; - if (pPathObj->m_Path.GetPoints().empty()) + CPDF_Path& cpath = pPathObj->path(); + if (cpath.GetPoints().empty()) return false; - pPathObj->m_Path.ClosePath(); + cpath.ClosePath(); pPathObj->SetDirty(true); return true; } @@ -209,13 +211,13 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, if (!pPathObj) return false; + pPathObj->set_stroke(!!stroke); if (fillmode == FPDF_FILLMODE_ALTERNATE) pPathObj->set_filltype(FXFILL_ALTERNATE); else if (fillmode == FPDF_FILLMODE_WINDING) pPathObj->set_filltype(FXFILL_WINDING); else pPathObj->set_filltype(0); - pPathObj->set_stroke(!!stroke); pPathObj->SetDirty(true); return true; } |