Replace more integer fill types with CFX_FillRenderOptions::FillType.
To migrate from using integers (0, FXFILL_WINDING and FXFILL_ALTERNATE)
as fill types to using CFX_FillRenderOptions::FillType, this CL makes
the following changes:
1. Replaces usages of integer fill types with
CFX_FillRenderOptions::FillType in class CPDF_PathObject.
2. Changes parameter types for CPDF_RenderStatus::ProcessPathPattern()
and CPDF_StreamContentParser::AddPathObject().
Bug: pdfium:1531
Change-Id: I535d1853e2620fc858d2d04f39c8b8cb39c6c54d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71531
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 60f5057..c3fe7f0 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -24,7 +24,7 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/render/cpdf_docrenderdata.h"
#include "core/fxcrt/fx_memory_wrappers.h"
-#include "core/fxge/render_defines.h"
+#include "core/fxge/cfx_fillrenderoptions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/base/stl_util.h"
@@ -55,7 +55,7 @@
TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) {
auto pPathObj = std::make_unique<CPDF_PathObject>();
pPathObj->set_stroke(true);
- pPathObj->set_filltype(FXFILL_ALTERNATE);
+ pPathObj->set_filltype(CFX_FillRenderOptions::FillType::kEvenOdd);
pPathObj->path().AppendRect(10, 5, 13, 30);
auto dummy_page_dict = pdfium::MakeRetain<CPDF_Dictionary>();
@@ -81,7 +81,7 @@
RetainPtr<CPDF_ColorSpace> pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
{
auto pPathObj = std::make_unique<CPDF_PathObject>();
- pPathObj->set_filltype(FXFILL_WINDING);
+ pPathObj->set_filltype(CFX_FillRenderOptions::FillType::kWinding);
// Test code in ProcessPath that generates re operator
pPathObj->path().AppendRect(0.000000000000000000001,
@@ -114,7 +114,7 @@
pPathObj->m_GraphState.SetLineWidth(2.000000000000000000001);
pPathObj->Transform(CFX_Matrix(1, 0, 0, 1, 432, 500000000000000.000002));
- pPathObj->set_filltype(FXFILL_WINDING);
+ pPathObj->set_filltype(CFX_FillRenderOptions::FillType::kWinding);
pPathObj->path().AppendPoint(CFX_PointF(0.000000000000000000001f, 4.67f),
FXPT_TYPE::MoveTo);
pPathObj->path().AppendPoint(
@@ -144,7 +144,7 @@
TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) {
auto pPathObj = std::make_unique<CPDF_PathObject>();
- pPathObj->set_filltype(FXFILL_WINDING);
+ pPathObj->set_filltype(CFX_FillRenderOptions::FillType::kWinding);
pPathObj->path().AppendPoint(CFX_PointF(3.102f, 4.67f), FXPT_TYPE::MoveTo);
pPathObj->path().AppendPoint(CFX_PointF(5.45f, 0.29f), FXPT_TYPE::LineTo);
pPathObj->path().AppendPoint(CFX_PointF(4.24f, 3.15f), FXPT_TYPE::BezierTo);
@@ -174,7 +174,7 @@
TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) {
auto pPathObj = std::make_unique<CPDF_PathObject>();
pPathObj->set_stroke(true);
- pPathObj->set_filltype(FXFILL_WINDING);
+ pPathObj->set_filltype(CFX_FillRenderOptions::FillType::kWinding);
pPathObj->path().AppendPoint(CFX_PointF(1, 2), FXPT_TYPE::MoveTo);
pPathObj->path().AppendPoint(CFX_PointF(3, 4), FXPT_TYPE::LineTo);
pPathObj->path().AppendPointAndClose(CFX_PointF(5, 6), FXPT_TYPE::LineTo);
diff --git a/core/fpdfapi/page/cpdf_pathobject.h b/core/fpdfapi/page/cpdf_pathobject.h
index 889d8a6..d337cdb 100644
--- a/core/fpdfapi/page/cpdf_pathobject.h
+++ b/core/fpdfapi/page/cpdf_pathobject.h
@@ -11,7 +11,7 @@
#include "core/fpdfapi/page/cpdf_path.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
-#include "core/fxge/render_defines.h"
+#include "core/fxge/cfx_fillrenderoptions.h"
class CPDF_PathObject final : public CPDF_PageObject {
public:
@@ -31,16 +31,30 @@
bool stroke() const { return m_bStroke; }
void set_stroke(bool stroke) { m_bStroke = stroke; }
- // Layering, avoid caller knowledge of FXFILL_ values.
- bool has_no_filltype() const { return m_FillType == 0; }
- bool has_winding_filltype() const { return m_FillType == FXFILL_WINDING; }
- bool has_alternate_filltype() const { return m_FillType == FXFILL_ALTERNATE; }
- void set_no_filltype() { m_FillType = 0; }
- void set_winding_filltype() { m_FillType = FXFILL_WINDING; }
- void set_alternate_filltype() { m_FillType = FXFILL_ALTERNATE; }
+ // Layering, avoid caller knowledge of CFX_FillRenderOptions::FillType values.
+ bool has_no_filltype() const {
+ return m_FillType == CFX_FillRenderOptions::FillType::kNoFill;
+ }
+ bool has_winding_filltype() const {
+ return m_FillType == CFX_FillRenderOptions::FillType::kWinding;
+ }
+ bool has_alternate_filltype() const {
+ return m_FillType == CFX_FillRenderOptions::FillType::kEvenOdd;
+ }
+ void set_no_filltype() {
+ m_FillType = CFX_FillRenderOptions::FillType::kNoFill;
+ }
+ void set_winding_filltype() {
+ m_FillType = CFX_FillRenderOptions::FillType::kWinding;
+ }
+ void set_alternate_filltype() {
+ m_FillType = CFX_FillRenderOptions::FillType::kEvenOdd;
+ }
- int filltype() const { return m_FillType; }
- void set_filltype(int filltype) { m_FillType = filltype; }
+ CFX_FillRenderOptions::FillType filltype() const { return m_FillType; }
+ void set_filltype(CFX_FillRenderOptions::FillType fill_type) {
+ m_FillType = fill_type;
+ }
CPDF_Path& path() { return m_Path; }
const CPDF_Path& path() const { return m_Path; }
@@ -50,7 +64,8 @@
private:
bool m_bStroke = false;
- int m_FillType = 0;
+ CFX_FillRenderOptions::FillType m_FillType =
+ CFX_FillRenderOptions::FillType::kNoFill;
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 51f590c..e42f6ce 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -556,20 +556,20 @@
void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
Handle_ClosePath();
- AddPathObject(FXFILL_WINDING, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kWinding, true);
}
void CPDF_StreamContentParser::Handle_FillStrokePath() {
- AddPathObject(FXFILL_WINDING, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kWinding, true);
}
void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() {
AddPathPoint(m_PathStartX, m_PathStartY, FXPT_TYPE::LineTo, true);
- AddPathObject(FXFILL_ALTERNATE, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, true);
}
void CPDF_StreamContentParser::Handle_EOFillStrokePath() {
- AddPathObject(FXFILL_ALTERNATE, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, true);
}
void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
@@ -866,15 +866,15 @@
}
void CPDF_StreamContentParser::Handle_FillPath() {
- AddPathObject(FXFILL_WINDING, false);
+ AddPathObject(CFX_FillRenderOptions::FillType::kWinding, false);
}
void CPDF_StreamContentParser::Handle_FillPathOld() {
- AddPathObject(FXFILL_WINDING, false);
+ AddPathObject(CFX_FillRenderOptions::FillType::kWinding, false);
}
void CPDF_StreamContentParser::Handle_EOFillPath() {
- AddPathObject(FXFILL_ALTERNATE, false);
+ AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, false);
}
void CPDF_StreamContentParser::Handle_SetGray_Fill() {
@@ -965,7 +965,7 @@
void CPDF_StreamContentParser::Handle_MarkPlace() {}
void CPDF_StreamContentParser::Handle_EndPath() {
- AddPathObject(0, false);
+ AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, false);
}
void CPDF_StreamContentParser::Handle_SaveGraphState() {
@@ -1016,11 +1016,11 @@
void CPDF_StreamContentParser::Handle_CloseStrokePath() {
Handle_ClosePath();
- AddPathObject(0, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, true);
}
void CPDF_StreamContentParser::Handle_StrokePath() {
- AddPathObject(0, true);
+ AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, true);
}
void CPDF_StreamContentParser::Handle_SetColor_Fill() {
@@ -1439,7 +1439,9 @@
m_PathPoints.push_back(FX_PATHPOINT(CFX_PointF(x, y), type, close));
}
-void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) {
+void CPDF_StreamContentParser::AddPathObject(
+ CFX_FillRenderOptions::FillType fill_type,
+ bool bStroke) {
std::vector<FX_PATHPOINT> path_points;
path_points.swap(m_PathPoints);
CFX_FillRenderOptions::FillType path_clip_type = m_PathClipType;
@@ -1470,10 +1472,10 @@
}
CFX_Matrix matrix = m_pCurStates->m_CTM * m_mtContentToUser;
- if (bStroke || FillType) {
+ if (bStroke || fill_type != CFX_FillRenderOptions::FillType::kNoFill) {
auto pPathObj = std::make_unique<CPDF_PathObject>(GetCurrentStreamIndex());
pPathObj->set_stroke(bStroke);
- pPathObj->set_filltype(FillType);
+ pPathObj->set_filltype(fill_type);
pPathObj->path() = path;
pPathObj->set_matrix(matrix);
SetGraphicStates(pPathObj.get(), true, false, true);
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h
index 89fd2f8..4f43e12 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.h
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.h
@@ -108,7 +108,7 @@
void ParsePathObject();
void AddPathPoint(float x, float y, FXPT_TYPE type, bool close);
void AddPathRect(float x, float y, float w, float h);
- void AddPathObject(int FillType, bool bStroke);
+ void AddPathObject(CFX_FillRenderOptions::FillType fill_type, bool bStroke);
CPDF_ImageObject* AddImage(RetainPtr<CPDF_Stream> pStream);
CPDF_ImageObject* AddImage(uint32_t streamObjNum);
CPDF_ImageObject* AddImage(const RetainPtr<CPDF_Image>& pImage);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index f8c6130..5926db8 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -398,23 +398,25 @@
bool CPDF_RenderStatus::ProcessPath(CPDF_PathObject* path_obj,
const CFX_Matrix& mtObj2Device) {
- // Path fill type, can be 0, FXFILL_ALTERNATE or FXFILL_WINDING.
- int fill_type = path_obj->filltype();
+ CFX_FillRenderOptions::FillType fill_type = path_obj->filltype();
bool stroke = path_obj->stroke();
ProcessPathPattern(path_obj, mtObj2Device, &fill_type, &stroke);
- if (fill_type == 0 && !stroke)
+ if (fill_type == CFX_FillRenderOptions::FillType::kNoFill && !stroke)
return true;
// If the option to convert fill paths to stroke is enabled for forced color,
- // set |fill_type| to 0 and |stroke| to true.
+ // set |fill_type| to FillType::kNoFill and |stroke| to true.
CPDF_RenderOptions::Options& options = m_Options.GetOptions();
if (m_Options.ColorModeIs(CPDF_RenderOptions::Type::kForcedColor) &&
- options.bConvertFillToStroke && (fill_type != 0)) {
+ options.bConvertFillToStroke &&
+ fill_type != CFX_FillRenderOptions::FillType::kNoFill) {
stroke = true;
- fill_type = 0;
+ fill_type = CFX_FillRenderOptions::FillType::kNoFill;
}
- uint32_t fill_argb = fill_type ? GetFillArgb(path_obj) : 0;
+ uint32_t fill_argb = fill_type != CFX_FillRenderOptions::FillType::kNoFill
+ ? GetFillArgb(path_obj)
+ : 0;
uint32_t stroke_argb = stroke ? GetStrokeArgb(path_obj) : 0;
CFX_Matrix path_matrix = path_obj->matrix() * mtObj2Device;
if (!IsAvailableMatrix(path_matrix))
@@ -423,8 +425,8 @@
return m_pDevice->DrawPathWithBlend(
path_obj->path().GetObject(), &path_matrix,
path_obj->m_GraphState.GetObject(), fill_argb, stroke_argb,
- GetFillOptionsForDrawPathWithBlend(
- options, path_obj, GetFillType(fill_type), stroke, m_pType3Char),
+ GetFillOptionsForDrawPathWithBlend(options, path_obj, fill_type, stroke,
+ m_pType3Char),
m_curBlend);
}
@@ -575,7 +577,7 @@
&path_matrix,
path_obj->m_GraphState.GetObject());
}
- CFX_FillRenderOptions fill_options(GetFillType(path_obj->filltype()));
+ CFX_FillRenderOptions fill_options(path_obj->filltype());
if (m_Options.GetOptions().bNoPathSmooth) {
fill_options.aliased_path = true;
}
@@ -1080,7 +1082,7 @@
pCopy.push_back(std::unique_ptr<CPDF_TextObject>(textobj->Clone()));
CPDF_PathObject path;
- path.set_filltype(FXFILL_WINDING);
+ path.set_filltype(CFX_FillRenderOptions::FillType::kWinding);
path.m_ClipPath.CopyClipPath(m_LastClipPath);
path.m_ClipPath.AppendTexts(&pCopy);
path.m_ColorState = textobj->m_ColorState;
@@ -1117,7 +1119,8 @@
matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x,
charpos.m_Origin.y));
path.set_stroke(stroke);
- path.set_filltype(fill ? FXFILL_WINDING : 0);
+ path.set_filltype(fill ? CFX_FillRenderOptions::FillType::kWinding
+ : CFX_FillRenderOptions::FillType::kNoFill);
path.path().Append(pPath, &matrix);
path.set_matrix(*pTextMatrix);
path.CalcBoundingBox();
@@ -1207,18 +1210,19 @@
DrawShadingPattern(pShadingPattern, path_obj, mtObj2Device, stroke);
}
-void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* path_obj,
- const CFX_Matrix& mtObj2Device,
- int* filltype,
- bool* stroke) {
- ASSERT(filltype);
+void CPDF_RenderStatus::ProcessPathPattern(
+ CPDF_PathObject* path_obj,
+ const CFX_Matrix& mtObj2Device,
+ CFX_FillRenderOptions::FillType* fill_type,
+ bool* stroke) {
+ ASSERT(fill_type);
ASSERT(stroke);
- if (*filltype) {
+ if (*fill_type != CFX_FillRenderOptions::FillType::kNoFill) {
const CPDF_Color& FillColor = *path_obj->m_ColorState.GetFillColor();
if (FillColor.IsPattern()) {
DrawPathWithPattern(path_obj, mtObj2Device, &FillColor, false);
- *filltype = 0;
+ *fill_type = CFX_FillRenderOptions::FillType::kNoFill;
}
}
if (*stroke) {
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 2f370f8..3de7206 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -138,7 +138,7 @@
bool ProcessPath(CPDF_PathObject* path_obj, const CFX_Matrix& mtObj2Device);
void ProcessPathPattern(CPDF_PathObject* path_obj,
const CFX_Matrix& mtObj2Device,
- int* filltype,
+ CFX_FillRenderOptions::FillType* filltype,
bool* stroke);
void DrawPathWithPattern(CPDF_PathObject* path_obj,
const CFX_Matrix& mtObj2Device,