summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-02-15 11:07:32 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-15 17:47:57 +0000
commite4602321f3175fa5addb6761d0e94f5c2fc93d0c (patch)
tree6671774659645fad6d9ce55a5910b4665a25094f /core
parenteb55885e9a9eec670ed98cbd12dc96d63e6a6623 (diff)
downloadpdfium-e4602321f3175fa5addb6761d0e94f5c2fc93d0c.tar.xz
Cleanup CFX_PathData.
This CL replaces the array of path points with a vector. Cleaning up the usage as required. Change-Id: Ifa386a2c847005fef68af748ebe99c4e08961238 Reviewed-on: https://pdfium-review.googlesource.com/2710 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp7
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp99
-rw-r--r--core/fpdfapi/page/cpdf_path.cpp17
-rw-r--r--core/fpdfapi/page/cpdf_path.h8
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp10
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp59
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp17
-rw-r--r--core/fxge/cfx_pathdata.h38
-rw-r--r--core/fxge/ge/cfx_font.cpp192
-rw-r--r--core/fxge/ge/cfx_pathdata.cpp410
-rw-r--r--core/fxge/ge/cfx_renderdevice.cpp14
-rw-r--r--core/fxge/skia/fx_skia_device.cpp10
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp17
-rw-r--r--core/fxge/win32/fx_win32_device.cpp17
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp27
-rw-r--r--core/fxge/win32/fx_win32_print.cpp7
16 files changed, 400 insertions, 549 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 4de89a47de..ff8b676de1 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -148,14 +148,13 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf,
void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf,
CPDF_PathObject* pPathObj) {
ProcessGraphics(buf, pPathObj);
- const FX_PATHPOINT* pPoints = pPathObj->m_Path.GetPoints();
+ auto& pPoints = pPathObj->m_Path.GetPoints();
if (pPathObj->m_Path.IsRect()) {
*buf << pPoints[0].m_PointX << " " << pPoints[0].m_PointY << " "
<< (pPoints[2].m_PointX - pPoints[0].m_PointX) << " "
<< (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re";
} else {
- int numPoints = pPathObj->m_Path.GetPointCount();
- for (int i = 0; i < numPoints; i++) {
+ for (size_t i = 0; i < pPoints.size(); i++) {
if (i > 0)
*buf << " ";
*buf << pPoints[i].m_PointX << " " << pPoints[i].m_PointY;
@@ -165,7 +164,7 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf,
} else if (pointType == FXPT_TYPE::LineTo) {
*buf << " l";
} else if (pointType == FXPT_TYPE::BezierTo) {
- if (i + 2 >= numPoints ||
+ if (i + 2 >= pPoints.size() ||
!pPoints[i].IsTypeAndOpen(FXPT_TYPE::BezierTo) ||
!pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::BezierTo) ||
pPoints[i + 2].m_Type != FXPT_TYPE::BezierTo) {
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 0a636a1888..42e6e2d843 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -44,6 +44,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) {
pPathObj->m_Path.AppendRect(10, 5, 13, 30);
pPathObj->m_FillType = FXFILL_ALTERNATE;
pPathObj->m_bStroke = true;
+
auto pTestPage = pdfium::MakeUnique<CPDF_Page>(nullptr, nullptr, false);
CPDF_PageContentGenerator generator(pTestPage.get());
CFX_ByteTextBuf buf;
@@ -51,77 +52,33 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) {
EXPECT_EQ("q 10 5 3 25 re B* Q\n", buf.MakeString());
pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.SetPointCount(4);
- FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints();
- pPoints[0].m_PointX = 0;
- pPoints[0].m_PointY = 0;
- pPoints[0].m_Type = FXPT_TYPE::MoveTo;
- pPoints[0].m_CloseFigure = false;
- pPoints[1].m_PointX = 5.2f;
- pPoints[1].m_PointY = 0;
- pPoints[1].m_Type = FXPT_TYPE::LineTo;
- pPoints[1].m_CloseFigure = false;
- pPoints[2].m_PointX = 5.2f;
- pPoints[2].m_PointY = 3.78f;
- pPoints[2].m_Type = FXPT_TYPE::LineTo;
- pPoints[2].m_CloseFigure = false;
- pPoints[3].m_PointX = 0;
- pPoints[3].m_PointY = 3.78f;
- pPoints[3].m_Type = FXPT_TYPE::LineTo;
- pPoints[3].m_CloseFigure = true;
+ pPathObj->m_Path.AppendPoint(0, 0, FXPT_TYPE::MoveTo, false);
+ pPathObj->m_Path.AppendPoint(5.2f, 0, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(5.2f, 3.78f, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(0, 3.78f, FXPT_TYPE::LineTo, true);
pPathObj->m_FillType = 0;
pPathObj->m_bStroke = false;
buf.Clear();
+
TestProcessPath(&generator, &buf, pPathObj.get());
EXPECT_EQ("q 0 0 5.2 3.78 re n Q\n", buf.MakeString());
}
TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) {
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.SetPointCount(10);
- FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints();
- pPoints[0].m_PointX = 3.102f;
- pPoints[0].m_PointY = 4.67f;
- pPoints[0].m_Type = FXPT_TYPE::MoveTo;
- pPoints[0].m_CloseFigure = false;
- pPoints[1].m_PointX = 5.45f;
- pPoints[1].m_PointY = 0.29f;
- pPoints[1].m_Type = FXPT_TYPE::LineTo;
- pPoints[1].m_CloseFigure = false;
- pPoints[2].m_PointX = 4.24f;
- pPoints[2].m_PointY = 3.15f;
- pPoints[2].m_Type = FXPT_TYPE::BezierTo;
- pPoints[2].m_CloseFigure = false;
- pPoints[3].m_PointX = 4.65f;
- pPoints[3].m_PointY = 2.98f;
- pPoints[3].m_Type = FXPT_TYPE::BezierTo;
- pPoints[3].m_CloseFigure = false;
- pPoints[4].m_PointX = 3.456f;
- pPoints[4].m_PointY = 0.24f;
- pPoints[4].m_Type = FXPT_TYPE::BezierTo;
- pPoints[4].m_CloseFigure = false;
- pPoints[5].m_PointX = 10.6f;
- pPoints[5].m_PointY = 11.15f;
- pPoints[5].m_Type = FXPT_TYPE::LineTo;
- pPoints[5].m_CloseFigure = false;
- pPoints[6].m_PointX = 11;
- pPoints[6].m_PointY = 12.5f;
- pPoints[6].m_Type = FXPT_TYPE::LineTo;
- pPoints[6].m_CloseFigure = false;
- pPoints[7].m_PointX = 11.46f;
- pPoints[7].m_PointY = 12.67f;
- pPoints[7].m_Type = FXPT_TYPE::BezierTo;
- pPoints[7].m_CloseFigure = false;
- pPoints[8].m_PointX = 11.84f;
- pPoints[8].m_PointY = 12.96f;
- pPoints[8].m_Type = FXPT_TYPE::BezierTo;
- pPoints[8].m_CloseFigure = false;
- pPoints[9].m_PointX = 12;
- pPoints[9].m_PointY = 13.64f;
- pPoints[9].m_Type = FXPT_TYPE::BezierTo;
- pPoints[9].m_CloseFigure = true;
+ pPathObj->m_Path.AppendPoint(3.102f, 4.67f, FXPT_TYPE::MoveTo, false);
+ pPathObj->m_Path.AppendPoint(5.45f, 0.29f, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(4.24f, 3.15f, FXPT_TYPE::BezierTo, false);
+ pPathObj->m_Path.AppendPoint(4.65f, 2.98f, FXPT_TYPE::BezierTo, false);
+ pPathObj->m_Path.AppendPoint(3.456f, 0.24f, FXPT_TYPE::BezierTo, false);
+ pPathObj->m_Path.AppendPoint(10.6f, 11.15f, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(11, 12.5f, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(11.46f, 12.67f, FXPT_TYPE::BezierTo, false);
+ pPathObj->m_Path.AppendPoint(11.84f, 12.96f, FXPT_TYPE::BezierTo, false);
+ pPathObj->m_Path.AppendPoint(12, 13.64f, FXPT_TYPE::BezierTo, true);
pPathObj->m_FillType = FXFILL_WINDING;
pPathObj->m_bStroke = false;
+
auto pTestPage = pdfium::MakeUnique<CPDF_Page>(nullptr, nullptr, false);
CPDF_PageContentGenerator generator(pTestPage.get());
CFX_ByteTextBuf buf;
@@ -134,29 +91,21 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) {
TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) {
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
- pPathObj->m_Path.SetPointCount(3);
- FX_PATHPOINT* pPoints = pPathObj->m_Path.GetMutablePoints();
- pPoints[0].m_PointX = 1;
- pPoints[0].m_PointY = 2;
- pPoints[0].m_Type = FXPT_TYPE::MoveTo;
- pPoints[0].m_CloseFigure = false;
- pPoints[1].m_PointX = 3;
- pPoints[1].m_PointY = 4;
- pPoints[1].m_Type = FXPT_TYPE::LineTo;
- pPoints[1].m_CloseFigure = false;
- pPoints[2].m_PointX = 5;
- pPoints[2].m_PointY = 6;
- pPoints[2].m_Type = FXPT_TYPE::LineTo;
- pPoints[2].m_CloseFigure = true;
+ pPathObj->m_Path.AppendPoint(1, 2, FXPT_TYPE::MoveTo, false);
+ pPathObj->m_Path.AppendPoint(3, 4, FXPT_TYPE::LineTo, false);
+ pPathObj->m_Path.AppendPoint(5, 6, FXPT_TYPE::LineTo, true);
pPathObj->m_FillType = FXFILL_WINDING;
pPathObj->m_bStroke = true;
+
FX_FLOAT rgb[3] = {0.5f, 0.7f, 0.35f};
CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
pPathObj->m_ColorState.SetFillColor(pCS, rgb, 3);
+
FX_FLOAT rgb2[3] = {1, 0.9f, 0};
pPathObj->m_ColorState.SetStrokeColor(pCS, rgb2, 3);
pPathObj->m_GeneralState.SetFillAlpha(0.5f);
pPathObj->m_GeneralState.SetStrokeAlpha(0.8f);
+
auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr);
pDoc->CreateNewDoc();
CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(0);
@@ -165,6 +114,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) {
CFX_ByteTextBuf buf;
TestProcessPath(&generator, &buf, pPathObj.get());
CFX_ByteString pathString = buf.MakeString();
+
// Color RGB values used are integers divided by 255.
EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /",
pathString.Left(48));
@@ -184,6 +134,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) {
EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG 10.5 w /",
pathString2.Left(55));
EXPECT_EQ(" gs 1 2 m 3 4 l 5 6 l h B Q\n", pathString2.Right(28));
+
// Compare with the previous (should use same dictionary for gs)
EXPECT_EQ(pathString.GetLength() + 7, pathString2.GetLength());
EXPECT_EQ(pathString.Mid(48, pathString.GetLength() - 76),
diff --git a/core/fpdfapi/page/cpdf_path.cpp b/core/fpdfapi/page/cpdf_path.cpp
index 96d6b72abb..a95ce1e5bc 100644
--- a/core/fpdfapi/page/cpdf_path.cpp
+++ b/core/fpdfapi/page/cpdf_path.cpp
@@ -12,20 +12,12 @@ CPDF_Path::CPDF_Path(const CPDF_Path& that) : m_Ref(that.m_Ref) {}
CPDF_Path::~CPDF_Path() {}
-int CPDF_Path::GetPointCount() const {
- return m_Ref.GetObject()->GetPointCount();
-}
-
-void CPDF_Path::SetPointCount(int count) {
- m_Ref.GetPrivateCopy()->SetPointCount(count);
-}
-
-const FX_PATHPOINT* CPDF_Path::GetPoints() const {
+const std::vector<FX_PATHPOINT>& CPDF_Path::GetPoints() const {
return m_Ref.GetObject()->GetPoints();
}
-FX_PATHPOINT* CPDF_Path::GetMutablePoints() {
- return m_Ref.GetPrivateCopy()->GetPoints();
+void CPDF_Path::ClosePath() {
+ m_Ref.GetPrivateCopy()->ClosePath();
}
FX_FLOAT CPDF_Path::GetPointX(int index) const {
@@ -73,7 +65,6 @@ void CPDF_Path::AppendPoint(FX_FLOAT x,
FXPT_TYPE type,
bool close) {
CFX_PathData data;
- data.SetPointCount(1);
- data.SetPoint(0, x, y, type, close);
+ data.AppendPoint(x, y, type, close);
Append(&data, nullptr);
}
diff --git a/core/fpdfapi/page/cpdf_path.h b/core/fpdfapi/page/cpdf_path.h
index 21a94becac..97dd8fd8a9 100644
--- a/core/fpdfapi/page/cpdf_path.h
+++ b/core/fpdfapi/page/cpdf_path.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_PATH_H_
#define CORE_FPDFAPI_PAGE_CPDF_PATH_H_
+#include <vector>
+
#include "core/fxcrt/cfx_shared_copy_on_write.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_fxgedevice.h"
@@ -22,10 +24,8 @@ class CPDF_Path {
void Emplace() { m_Ref.Emplace(); }
explicit operator bool() const { return !!m_Ref; }
- int GetPointCount() const;
- void SetPointCount(int count);
- const FX_PATHPOINT* GetPoints() const;
- FX_PATHPOINT* GetMutablePoints();
+ const std::vector<FX_PATHPOINT>& GetPoints() const;
+ void ClosePath();
FX_FLOAT GetPointX(int index) const;
FX_FLOAT GetPointY(int index) const;
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 0af43d08b2..e991e456b7 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1506,10 +1506,14 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) {
m_pPathPoints[PathPointCount - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
PathPointCount--;
}
+
CPDF_Path Path;
- Path.SetPointCount(PathPointCount);
- FXSYS_memcpy(Path.GetMutablePoints(), m_pPathPoints,
- sizeof(FX_PATHPOINT) * PathPointCount);
+ for (int i = 0; i < PathPointCount; i++) {
+ FX_PATHPOINT& point = m_pPathPoints[i];
+ Path.AppendPoint(point.m_PointX, point.m_PointY, point.m_Type,
+ point.m_CloseFigure);
+ }
+
CFX_Matrix matrix = m_pCurStates->m_CTM;
matrix.Concat(m_mtContentToUser);
if (bStroke || FillType) {
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 4f2638f276..60b57600c2 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -611,18 +611,21 @@ struct Coon_Bezier {
x.FromPoints(x0, x1, x2, x3);
y.FromPoints(y0, y1, y2, y3);
}
+
Coon_Bezier first_half() {
Coon_Bezier result;
result.x = x.first_half();
result.y = y.first_half();
return result;
}
+
Coon_Bezier second_half() {
Coon_Bezier result;
result.x = x.second_half();
result.y = y.second_half();
return result;
}
+
void BezierInterpol(Coon_Bezier& C1,
Coon_Bezier& C2,
Coon_Bezier& D1,
@@ -630,30 +633,31 @@ struct Coon_Bezier {
x.BezierInterpol(C1.x, C2.x, D1.x, D2.x);
y.BezierInterpol(C1.y, C2.y, D1.y, D2.y);
}
- void GetPoints(FX_PATHPOINT* pPoints) {
+
+ void GetPoints(std::vector<FX_PATHPOINT>& pPoints, size_t start_idx) {
float p[4];
int i;
x.GetPoints(p);
- for (i = 0; i < 4; i++) {
- pPoints[i].m_PointX = p[i];
- }
+ for (i = 0; i < 4; i++)
+ pPoints[start_idx + i].m_PointX = p[i];
+
y.GetPoints(p);
- for (i = 0; i < 4; i++) {
- pPoints[i].m_PointY = p[i];
- }
+ for (i = 0; i < 4; i++)
+ pPoints[start_idx + i].m_PointY = p[i];
}
- void GetPointsReverse(FX_PATHPOINT* pPoints) {
+
+ void GetPointsReverse(std::vector<FX_PATHPOINT>& pPoints, size_t start_idx) {
float p[4];
int i;
x.GetPointsReverse(p);
- for (i = 0; i < 4; i++) {
- pPoints[i].m_PointX = p[i];
- }
+ for (i = 0; i < 4; i++)
+ pPoints[i + start_idx].m_PointX = p[i];
+
y.GetPointsReverse(p);
- for (i = 0; i < 4; i++) {
- pPoints[i].m_PointY = p[i];
- }
+ for (i = 0; i < 4; i++)
+ pPoints[i + start_idx].m_PointY = p[i];
}
+
float Distance() { return x.Distance() + y.Distance(); }
};
@@ -693,6 +697,7 @@ struct Coon_Color {
}
};
+#define COONCOLOR_THRESHOLD 4
struct CPDF_PatchDrawer {
Coon_Color patch_colors[4];
int max_delta;
@@ -728,15 +733,15 @@ struct CPDF_PatchDrawer {
d_top = div_colors[1].Distance(div_colors[2]);
d_right = div_colors[2].Distance(div_colors[3]);
}
-#define COONCOLOR_THRESHOLD 4
+
if (bSmall ||
(d_bottom < COONCOLOR_THRESHOLD && d_left < COONCOLOR_THRESHOLD &&
d_top < COONCOLOR_THRESHOLD && d_right < COONCOLOR_THRESHOLD)) {
- FX_PATHPOINT* pPoints = path.GetPoints();
- C1.GetPoints(pPoints);
- D2.GetPoints(pPoints + 3);
- C2.GetPointsReverse(pPoints + 6);
- D1.GetPointsReverse(pPoints + 9);
+ std::vector<FX_PATHPOINT>& pPoints = path.GetPoints();
+ C1.GetPoints(pPoints, 0);
+ D2.GetPoints(pPoints, 3);
+ C2.GetPointsReverse(pPoints, 6);
+ D1.GetPointsReverse(pPoints, 9);
int fillFlags = FXFILL_WINDING | FXFILL_FULLCOVER;
if (fill_mode & RENDER_NOPATHSMOOTH) {
fillFlags |= FXFILL_NOPATHSMOOTH;
@@ -814,14 +819,12 @@ void DrawCoonPatchMeshes(
patch.alpha = alpha;
patch.pDevice = &device;
patch.fill_mode = fill_mode;
- patch.path.SetPointCount(13);
- FX_PATHPOINT* pPoints = patch.path.GetPoints();
- pPoints[0].m_Type = FXPT_TYPE::MoveTo;
- pPoints[0].m_CloseFigure = false;
- for (int i = 1; i < 13; i++) {
- pPoints[i].m_Type = FXPT_TYPE::BezierTo;
- pPoints[i].m_CloseFigure = false;
+
+ for (int i = 0; i < 13; i++) {
+ patch.path.AppendPoint(
+ 0, 0, i == 0 ? FXPT_TYPE::MoveTo : FXPT_TYPE::BezierTo, false);
}
+
CFX_PointF coords[16];
int point_count = type == kTensorProductPatchMeshShading ? 16 : 12;
while (!stream.BitStream()->IsEOF()) {
@@ -1368,7 +1371,7 @@ void CPDF_RenderStatus::ProcessClipPath(CPDF_ClipPath ClipPath,
if (!pPathData)
continue;
- if (pPathData->GetPointCount() == 0) {
+ if (pPathData->GetPoints().empty()) {
CFX_PathData EmptyPath;
EmptyPath.AppendRect(-1, -1, 0, 0);
int fill_mode = FXFILL_WINDING;
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 3ae2c37150..e17f2df13a 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -273,20 +273,20 @@ bool DibSetPixel(CFX_DIBitmap* pDevice,
void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
const CFX_Matrix* pObject2Device) {
- int nPoints = pPathData->GetPointCount();
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
- for (int i = 0; i < nPoints; i++) {
- FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY;
- if (pObject2Device) {
+ const std::vector<FX_PATHPOINT>& pPoints = pPathData->GetPoints();
+ for (size_t i = 0; i < pPoints.size(); i++) {
+ FX_FLOAT x = pPoints[i].m_PointX;
+ FX_FLOAT y = pPoints[i].m_PointY;
+ if (pObject2Device)
pObject2Device->TransformPoint(x, y);
- }
+
HardClip(x, y);
FXPT_TYPE point_type = pPoints[i].m_Type;
if (point_type == FXPT_TYPE::MoveTo) {
m_PathData.move_to(x, y);
} else if (point_type == FXPT_TYPE::LineTo) {
if (pPoints[i - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
- (i == nPoints - 1 ||
+ (i == pPoints.size() - 1 ||
pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) &&
pPoints[i].m_PointX == pPoints[i - 1].m_PointX &&
pPoints[i].m_PointY == pPoints[i - 1].m_PointY) {
@@ -553,7 +553,8 @@ bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(
GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
}
- if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
+ size_t size = pPathData->GetPoints().size();
+ if (size == 5 || size == 4) {
CFX_FloatRect rectf;
if (pPathData->IsRect(pObject2Device, &rectf)) {
rectf.Intersect(
diff --git a/core/fxge/cfx_pathdata.h b/core/fxge/cfx_pathdata.h
index 46fdfeb740..7d5e6e28c6 100644
--- a/core/fxge/cfx_pathdata.h
+++ b/core/fxge/cfx_pathdata.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXGE_CFX_PATHDATA_H_
#define CORE_FXGE_CFX_PATHDATA_H_
+#include <vector>
+
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_renderdevice.h"
@@ -28,41 +30,37 @@ class CFX_PathData {
CFX_PathData(const CFX_PathData& src);
~CFX_PathData();
- int GetPointCount() const { return m_PointCount; }
- FXPT_TYPE GetType(int index) const { return m_pPoints[index].m_Type; }
+ void Clear();
+
+ FXPT_TYPE GetType(int index) const { return m_Points[index].m_Type; }
bool IsClosingFigure(int index) const {
- return m_pPoints[index].m_CloseFigure;
+ return m_Points[index].m_CloseFigure;
}
- FX_FLOAT GetPointX(int index) const { return m_pPoints[index].m_PointX; }
- FX_FLOAT GetPointY(int index) const { return m_pPoints[index].m_PointY; }
- FX_PATHPOINT* GetPoints() const { return m_pPoints; }
- void SetPointCount(int nPoints);
- void AllocPointCount(int nPoints);
- void AddPointCount(int addPoints);
+ FX_FLOAT GetPointX(int index) const { return m_Points[index].m_PointX; }
+ FX_FLOAT GetPointY(int index) const { return m_Points[index].m_PointY; }
+ const std::vector<FX_PATHPOINT>& GetPoints() const { return m_Points; }
+ std::vector<FX_PATHPOINT>& GetPoints() { return m_Points; }
+
CFX_FloatRect GetBoundingBox() const;
CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const;
+
void Transform(const CFX_Matrix* pMatrix);
bool IsRect() const;
- bool GetZeroAreaPath(CFX_PathData& NewPath,
+ bool GetZeroAreaPath(CFX_PathData* NewPath,
CFX_Matrix* pMatrix,
bool& bThin,
bool bAdjust) const;
bool IsRect(const CFX_Matrix* pMatrix, CFX_FloatRect* rect) const;
+
+ void Append(const CFX_PathData& data);
void Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix);
void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top);
- void SetPoint(int index,
- FX_FLOAT x,
- FX_FLOAT y,
- FXPT_TYPE type,
- bool closeFigure);
- void TrimPoints(int nPoints);
- void Copy(const CFX_PathData& src);
+ void AppendPoint(FX_FLOAT x, FX_FLOAT y, FXPT_TYPE type, bool closeFigure);
+ void ClosePath();
private:
- int m_PointCount;
- int m_AllocCount;
- FX_PATHPOINT* m_pPoints;
+ std::vector<FX_PATHPOINT> m_Points;
};
#endif // CORE_FXGE_CFX_PATHDATA_H_
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index 3ba2667f0f..ef6960a3d7 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -28,9 +28,7 @@
namespace {
typedef struct {
- bool m_bCount;
- int m_PointCount;
- FX_PATHPOINT* m_pPoints;
+ CFX_PathData* m_pPath;
int m_CurX;
int m_CurY;
FX_FLOAT m_CoordUnit;
@@ -86,64 +84,51 @@ FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
}
void Outline_CheckEmptyContour(OUTLINE_PARAMS* param) {
- if (param->m_PointCount >= 2 &&
- param->m_pPoints[param->m_PointCount - 2].IsTypeAndOpen(
- FXPT_TYPE::MoveTo) &&
- param->m_pPoints[param->m_PointCount - 2].m_PointX ==
- param->m_pPoints[param->m_PointCount - 1].m_PointX &&
- param->m_pPoints[param->m_PointCount - 2].m_PointY ==
- param->m_pPoints[param->m_PointCount - 1].m_PointY) {
- param->m_PointCount -= 2;
+ std::vector<FX_PATHPOINT>& points = param->m_pPath->GetPoints();
+ size_t size = points.size();
+
+ if (size >= 2 && points[size - 2].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
+ points[size - 2].m_PointX == points[size - 1].m_PointX &&
+ points[size - 2].m_PointY == points[size - 1].m_PointY) {
+ size -= 2;
}
- if (param->m_PointCount >= 4 &&
- param->m_pPoints[param->m_PointCount - 4].IsTypeAndOpen(
- FXPT_TYPE::MoveTo) &&
- param->m_pPoints[param->m_PointCount - 3].IsTypeAndOpen(
- FXPT_TYPE::BezierTo) &&
- param->m_pPoints[param->m_PointCount - 3].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 3].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY &&
- param->m_pPoints[param->m_PointCount - 2].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 2].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY &&
- param->m_pPoints[param->m_PointCount - 1].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 1].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY) {
- param->m_PointCount -= 4;
+ if (size >= 4 && points[size - 4].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
+ points[size - 3].IsTypeAndOpen(FXPT_TYPE::BezierTo) &&
+ points[size - 3].m_PointX == points[size - 4].m_PointX &&
+ points[size - 3].m_PointY == points[size - 4].m_PointY &&
+ points[size - 2].m_PointX == points[size - 4].m_PointX &&
+ points[size - 2].m_PointY == points[size - 4].m_PointY &&
+ points[size - 1].m_PointX == points[size - 4].m_PointX &&
+ points[size - 1].m_PointY == points[size - 4].m_PointY) {
+ size -= 4;
}
+ points.resize(size);
}
int Outline_MoveTo(const FXFT_Vector* to, void* user) {
OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- Outline_CheckEmptyContour(param);
- param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Type = FXPT_TYPE::MoveTo;
- param->m_pPoints[param->m_PointCount].m_CloseFigure = false;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- if (param->m_PointCount)
- param->m_pPoints[param->m_PointCount - 1].m_CloseFigure = true;
- }
- param->m_PointCount++;
+
+ Outline_CheckEmptyContour(param);
+
+ param->m_pPath->ClosePath();
+ param->m_pPath->AppendPoint(to->x / param->m_CoordUnit,
+ to->y / param->m_CoordUnit, FXPT_TYPE::MoveTo,
+ false);
+
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
return 0;
}
int Outline_LineTo(const FXFT_Vector* to, void* user) {
OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Type = FXPT_TYPE::LineTo;
- param->m_pPoints[param->m_PointCount].m_CloseFigure = false;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount++;
+
+ param->m_pPath->AppendPoint(to->x / param->m_CoordUnit,
+ to->y / param->m_CoordUnit, FXPT_TYPE::LineTo,
+ false);
+
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
return 0;
}
@@ -151,31 +136,25 @@ int Outline_ConicTo(const FXFT_Vector* control,
const FXFT_Vector* to,
void* user) {
OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX =
- (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
- param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY =
- (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) /
- param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount].m_CloseFigure = false;
- param->m_pPoints[param->m_PointCount + 1].m_PointX =
- (control->x + (to->x - control->x) / 3) / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_PointY =
- (control->y + (to->y - control->y) / 3) / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount + 1].m_CloseFigure = false;
- param->m_pPoints[param->m_PointCount + 2].m_PointX =
- to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_PointY =
- to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount + 2].m_CloseFigure = false;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount += 3;
+
+ param->m_pPath->AppendPoint(
+ (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
+ param->m_CoordUnit,
+ (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) /
+ param->m_CoordUnit,
+ FXPT_TYPE::BezierTo, false);
+
+ param->m_pPath->AppendPoint(
+ (control->x + (to->x - control->x) / 3) / param->m_CoordUnit,
+ (control->y + (to->y - control->y) / 3) / param->m_CoordUnit,
+ FXPT_TYPE::BezierTo, false);
+
+ param->m_pPath->AppendPoint(to->x / param->m_CoordUnit,
+ to->y / param->m_CoordUnit, FXPT_TYPE::BezierTo,
+ false);
+
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
return 0;
}
@@ -184,29 +163,21 @@ int Outline_CubicTo(const FXFT_Vector* control1,
const FXFT_Vector* to,
void* user) {
OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX =
- control1->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY =
- control1->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount].m_CloseFigure = false;
- param->m_pPoints[param->m_PointCount + 1].m_PointX =
- control2->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_PointY =
- control2->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount + 1].m_CloseFigure = false;
- param->m_pPoints[param->m_PointCount + 2].m_PointX =
- to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_PointY =
- to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_Type = FXPT_TYPE::BezierTo;
- param->m_pPoints[param->m_PointCount + 2].m_CloseFigure = false;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount += 3;
+
+ param->m_pPath->AppendPoint(control1->x / param->m_CoordUnit,
+ control1->y / param->m_CoordUnit,
+ FXPT_TYPE::BezierTo, false);
+
+ param->m_pPath->AppendPoint(control2->x / param->m_CoordUnit,
+ control2->y / param->m_CoordUnit,
+ FXPT_TYPE::BezierTo, false);
+
+ param->m_pPath->AppendPoint(to->x / param->m_CoordUnit,
+ to->y / param->m_CoordUnit, FXPT_TYPE::BezierTo,
+ false);
+
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
return 0;
}
@@ -683,6 +654,7 @@ CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index,
level = s_WeightPow[index] * 2;
FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
}
+
FXFT_Outline_Funcs funcs;
funcs.move_to = Outline_MoveTo;
funcs.line_to = Outline_LineTo;
@@ -690,25 +662,21 @@ CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index,
funcs.cubic_to = Outline_CubicTo;
funcs.shift = 0;
funcs.delta = 0;
+
OUTLINE_PARAMS params;
- params.m_bCount = true;
- params.m_PointCount = 0;
- FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
- if (params.m_PointCount == 0)
- return nullptr;
- CFX_PathData* pPath = new CFX_PathData;
- pPath->SetPointCount(params.m_PointCount);
- params.m_bCount = false;
- params.m_PointCount = 0;
- params.m_pPoints = pPath->GetPoints();
+ auto pPath = pdfium::MakeUnique<CFX_PathData>();
+ params.m_pPath = pPath.get();
params.m_CurX = params.m_CurY = 0;
params.m_CoordUnit = 64 * 64.0;
+
FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
+ if (pPath->GetPoints().empty())
+ return nullptr;
+
Outline_CheckEmptyContour(&params);
- pPath->TrimPoints(params.m_PointCount);
- if (params.m_PointCount)
- pPath->GetPoints()[params.m_PointCount - 1].m_CloseFigure = true;
- return pPath;
+ pPath->ClosePath();
+
+ return pPath.release();
}
const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index,
diff --git a/core/fxge/ge/cfx_pathdata.cpp b/core/fxge/ge/cfx_pathdata.cpp
index 14eabb990a..5ad3db4886 100644
--- a/core/fxge/ge/cfx_pathdata.cpp
+++ b/core/fxge/ge/cfx_pathdata.cpp
@@ -9,117 +9,62 @@
#include "core/fxcrt/fx_system.h"
#include "third_party/base/numerics/safe_math.h"
-CFX_PathData::CFX_PathData()
- : m_PointCount(0), m_AllocCount(0), m_pPoints(nullptr) {}
+CFX_PathData::CFX_PathData() {}
-CFX_PathData::~CFX_PathData() {
- FX_Free(m_pPoints);
-}
+CFX_PathData::~CFX_PathData() {}
-void CFX_PathData::SetPointCount(int nPoints) {
- m_PointCount = nPoints;
- if (m_AllocCount < nPoints) {
- FX_Free(m_pPoints);
- m_pPoints = FX_Alloc(FX_PATHPOINT, nPoints);
- m_AllocCount = nPoints;
- }
-}
+CFX_PathData::CFX_PathData(const CFX_PathData& src) : m_Points(src.m_Points) {}
-void CFX_PathData::AllocPointCount(int nPoints) {
- if (m_AllocCount < nPoints) {
- FX_PATHPOINT* pNewBuf = FX_Alloc(FX_PATHPOINT, nPoints);
- if (m_PointCount) {
- FXSYS_memcpy(pNewBuf, m_pPoints, m_PointCount * sizeof(FX_PATHPOINT));
- }
- FX_Free(m_pPoints);
- m_pPoints = pNewBuf;
- m_AllocCount = nPoints;
- }
+void CFX_PathData::Clear() {
+ m_Points.clear();
}
-CFX_PathData::CFX_PathData(const CFX_PathData& src) {
- m_PointCount = m_AllocCount = src.m_PointCount;
- m_pPoints = FX_Alloc(FX_PATHPOINT, src.m_PointCount);
- FXSYS_memcpy(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount);
+void CFX_PathData::ClosePath() {
+ if (m_Points.empty())
+ return;
+ m_Points.back().m_CloseFigure = true;
}
-void CFX_PathData::TrimPoints(int nPoints) {
- if (m_PointCount <= nPoints) {
+void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix) {
+ if (pSrc->m_Points.empty())
return;
- }
- SetPointCount(nPoints);
-}
-void CFX_PathData::AddPointCount(int addPoints) {
- pdfium::base::CheckedNumeric<int> safe_new_count = m_PointCount;
- safe_new_count += addPoints;
- int new_count = safe_new_count.ValueOrDie();
- AllocPointCount(new_count);
- m_PointCount = new_count;
-}
+ size_t cur_size = m_Points.size();
+ m_Points.insert(m_Points.end(), pSrc->m_Points.begin(), pSrc->m_Points.end());
-void CFX_PathData::Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix) {
- int old_count = m_PointCount;
- AddPointCount(pSrc->m_PointCount);
- FXSYS_memcpy(m_pPoints + old_count, pSrc->m_pPoints,
- pSrc->m_PointCount * sizeof(FX_PATHPOINT));
- if (pMatrix) {
- for (int i = 0; i < pSrc->m_PointCount; i++) {
- pMatrix->TransformPoint(m_pPoints[old_count + i].m_PointX,
- m_pPoints[old_count + i].m_PointY);
- }
- }
+ if (!pMatrix)
+ return;
+
+ for (size_t i = cur_size; i < m_Points.size(); i++)
+ pMatrix->TransformPoint(m_Points[i].m_PointX, m_Points[i].m_PointY);
}
-void CFX_PathData::SetPoint(int index,
- FX_FLOAT x,
- FX_FLOAT y,
- FXPT_TYPE type,
- bool closeFigure) {
- ASSERT(index < m_PointCount);
- m_pPoints[index].m_PointX = x;
- m_pPoints[index].m_PointY = y;
- m_pPoints[index].m_Type = type;
- m_pPoints[index].m_CloseFigure = closeFigure;
+void CFX_PathData::AppendPoint(FX_FLOAT x,
+ FX_FLOAT y,
+ FXPT_TYPE type,
+ bool closeFigure) {
+ m_Points.push_back({x, y, type, closeFigure});
}
void CFX_PathData::AppendRect(FX_FLOAT left,
FX_FLOAT bottom,
FX_FLOAT right,
FX_FLOAT top) {
- int old_count = m_PointCount;
- AddPointCount(5);
- FX_PATHPOINT* pPoints = m_pPoints + old_count;
- pPoints[0].m_PointX = left;
- pPoints[1].m_PointX = left;
- pPoints[4].m_PointX = left;
- pPoints[2].m_PointX = right;
- pPoints[3].m_PointX = right;
- pPoints[0].m_PointY = bottom;
- pPoints[3].m_PointY = bottom;
- pPoints[4].m_PointY = bottom;
- pPoints[1].m_PointY = top;
- pPoints[2].m_PointY = top;
- pPoints[0].m_Type = FXPT_TYPE::MoveTo;
- pPoints[1].m_Type = FXPT_TYPE::LineTo;
- pPoints[2].m_Type = FXPT_TYPE::LineTo;
- pPoints[3].m_Type = FXPT_TYPE::LineTo;
- pPoints[0].m_CloseFigure = false;
- pPoints[1].m_CloseFigure = false;
- pPoints[2].m_CloseFigure = false;
- pPoints[3].m_CloseFigure = false;
- pPoints[4].m_Type = FXPT_TYPE::LineTo;
- pPoints[4].m_CloseFigure = true;
+ m_Points.push_back({left, bottom, FXPT_TYPE::MoveTo, false});
+ m_Points.push_back({left, top, FXPT_TYPE::LineTo, false});
+ m_Points.push_back({right, top, FXPT_TYPE::LineTo, false});
+ m_Points.push_back({right, bottom, FXPT_TYPE::LineTo, false});
+ m_Points.push_back({left, bottom, FXPT_TYPE::LineTo, true});
}
CFX_FloatRect CFX_PathData::GetBoundingBox() const {
+ if (m_Points.empty())
+ return CFX_FloatRect();
+
CFX_FloatRect rect;
- if (m_PointCount) {
- rect.InitRect(m_pPoints[0].m_PointX, m_pPoints[0].m_PointY);
- for (int i = 1; i < m_PointCount; i++) {
- rect.UpdateRect(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY);
- }
- }
+ rect.InitRect(m_Points[0].m_PointX, m_Points[0].m_PointY);
+ for (size_t i = 1; i < m_Points.size(); i++)
+ rect.UpdateRect(m_Points[i].m_PointX, m_Points[i].m_PointY);
return rect;
}
@@ -264,26 +209,26 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width,
FX_FLOAT miter_limit) const {
CFX_FloatRect rect(100000 * 1.0f, 100000 * 1.0f, -100000 * 1.0f,
-100000 * 1.0f);
- int iPoint = 0;
+ size_t iPoint = 0;
FX_FLOAT half_width = line_width;
int iStartPoint = 0;
int iEndPoint = 0;
int iMiddlePoint = 0;
bool bJoin;
- while (iPoint < m_PointCount) {
- if (m_pPoints[iPoint].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
+ while (iPoint < m_Points.size()) {
+ if (m_Points[iPoint].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
iStartPoint = iPoint + 1;
iEndPoint = iPoint;
bJoin = false;
} else {
- if (m_pPoints[iPoint].IsTypeAndOpen(FXPT_TYPE::BezierTo)) {
- rect.UpdateRect(m_pPoints[iPoint].m_PointX, m_pPoints[iPoint].m_PointY);
- rect.UpdateRect(m_pPoints[iPoint + 1].m_PointX,
- m_pPoints[iPoint + 1].m_PointY);
+ if (m_Points[iPoint].IsTypeAndOpen(FXPT_TYPE::BezierTo)) {
+ rect.UpdateRect(m_Points[iPoint].m_PointX, m_Points[iPoint].m_PointY);
+ rect.UpdateRect(m_Points[iPoint + 1].m_PointX,
+ m_Points[iPoint + 1].m_PointY);
iPoint += 2;
}
- if (iPoint == m_PointCount - 1 ||
- m_pPoints[iPoint + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
+ if (iPoint == m_Points.size() - 1 ||
+ m_Points[iPoint + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) {
iStartPoint = iPoint - 1;
iEndPoint = iPoint;
bJoin = false;
@@ -294,13 +239,13 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width,
bJoin = true;
}
}
- FX_FLOAT start_x = m_pPoints[iStartPoint].m_PointX;
- FX_FLOAT start_y = m_pPoints[iStartPoint].m_PointY;
- FX_FLOAT end_x = m_pPoints[iEndPoint].m_PointX;
- FX_FLOAT end_y = m_pPoints[iEndPoint].m_PointY;
+ FX_FLOAT start_x = m_Points[iStartPoint].m_PointX;
+ FX_FLOAT start_y = m_Points[iStartPoint].m_PointY;
+ FX_FLOAT end_x = m_Points[iEndPoint].m_PointX;
+ FX_FLOAT end_y = m_Points[iEndPoint].m_PointY;
if (bJoin) {
- FX_FLOAT middle_x = m_pPoints[iMiddlePoint].m_PointX;
- FX_FLOAT middle_y = m_pPoints[iMiddlePoint].m_PointY;
+ FX_FLOAT middle_x = m_Points[iMiddlePoint].m_PointX;
+ FX_FLOAT middle_y = m_Points[iMiddlePoint].m_PointY;
_UpdateLineJoinPoints(rect, start_x, start_y, middle_x, middle_y, end_x,
end_y, half_width, miter_limit);
} else {
@@ -312,143 +257,140 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width,
}
void CFX_PathData::Transform(const CFX_Matrix* pMatrix) {
- if (!pMatrix) {
+ if (!pMatrix)
return;
- }
- for (int i = 0; i < m_PointCount; i++) {
- pMatrix->TransformPoint(m_pPoints[i].m_PointX, m_pPoints[i].m_PointY);
- }
+ for (auto& point : m_Points)
+ pMatrix->TransformPoint(point.m_PointX, point.m_PointY);
}
-bool CFX_PathData::GetZeroAreaPath(CFX_PathData& NewPath,
+bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath,
CFX_Matrix* pMatrix,
bool& bThin,
bool bAdjust) const {
- if (m_PointCount < 3) {
+ if (m_Points.size() < 3)
return false;
- }
- if (m_PointCount == 3 && m_pPoints[0].m_Type == FXPT_TYPE::MoveTo &&
- m_pPoints[1].m_Type == FXPT_TYPE::LineTo &&
- m_pPoints[2].m_Type == FXPT_TYPE::LineTo &&
- m_pPoints[0].m_PointX == m_pPoints[2].m_PointX &&
- m_pPoints[0].m_PointY == m_pPoints[2].m_PointY) {
- NewPath.AddPointCount(2);
+
+ if (m_Points.size() == 3 && m_Points[0].m_Type == FXPT_TYPE::MoveTo &&
+ m_Points[1].m_Type == FXPT_TYPE::LineTo &&
+ m_Points[2].m_Type == FXPT_TYPE::LineTo &&
+ m_Points[0].m_PointX == m_Points[2].m_PointX &&
+ m_Points[0].m_PointY == m_Points[2].m_PointY) {
if (bAdjust) {
if (pMatrix) {
- FX_FLOAT x = m_pPoints[0].m_PointX, y = m_pPoints[0].m_PointY;
+ FX_FLOAT x = m_Points[0].m_PointX;
+ FX_FLOAT y = m_Points[0].m_PointY;
pMatrix->TransformPoint(x, y);
+
x = (int)x + 0.5f;
y = (int)y + 0.5f;
- NewPath.SetPoint(0, x, y, FXPT_TYPE::MoveTo, false);
- x = m_pPoints[1].m_PointX, y = m_pPoints[1].m_PointY;
+ NewPath->AppendPoint(x, y, FXPT_TYPE::MoveTo, false);
+
+ x = m_Points[1].m_PointX;
+ y = m_Points[1].m_PointY;
pMatrix->TransformPoint(x, y);
x = (int)x + 0.5f;
y = (int)y + 0.5f;
- NewPath.SetPoint(1, x, y, FXPT_TYPE::LineTo, false);
+ NewPath->AppendPoint(x, y, FXPT_TYPE::LineTo, false);
+
pMatrix->SetIdentity();
} else {
- FX_FLOAT x = (int)m_pPoints[0].m_PointX + 0.5f,
- y = (int)m_pPoints[0].m_PointY + 0.5f;
- NewPath.SetPoint(0, x, y, FXPT_TYPE::MoveTo, false);
- x = (int)m_pPoints[1].m_PointX + 0.5f,
- y = (int)m_pPoints[1].m_PointY + 0.5f;
- NewPath.SetPoint(1, x, y, FXPT_TYPE::LineTo, false);
+ FX_FLOAT x = (int)m_Points[0].m_PointX + 0.5f;
+ FX_FLOAT y = (int)m_Points[0].m_PointY + 0.5f;
+ NewPath->AppendPoint(x, y, FXPT_TYPE::MoveTo, false);
+
+ x = (int)m_Points[1].m_PointX + 0.5f,
+ y = (int)m_Points[1].m_PointY + 0.5f;
+ NewPath->AppendPoint(x, y, FXPT_TYPE::LineTo, false);
}
} else {
- NewPath.SetPoint(0, m_pPoints[0].m_PointX, m_pPoints[0].m_PointY,
- FXPT_TYPE::MoveTo, false);
- NewPath.SetPoint(1, m_pPoints[1].m_PointX, m_pPoints[1].m_PointY,
- FXPT_TYPE::LineTo, false);
+ NewPath->AppendPoint(m_Points[0].m_PointX, m_Points[0].m_PointY,
+ FXPT_TYPE::MoveTo, false);
+ NewPath->AppendPoint(m_Points[1].m_PointX, m_Points[1].m_PointY,
+ FXPT_TYPE::LineTo, false);
}
- if (m_pPoints[0].m_PointX != m_pPoints[1].m_PointX &&
- m_pPoints[0].m_PointY != m_pPoints[1].m_PointY) {
+ if (m_Points[0].m_PointX != m_Points[1].m_PointX &&
+ m_Points[0].m_PointY != m_Points[1].m_PointY) {
bThin = true;
}
return true;
}
- if (((m_PointCount > 3) && (m_PointCount % 2))) {
- int mid = m_PointCount / 2;
+ if (((m_Points.size() > 3) && (m_Points.size() % 2))) {
+ int mid = m_Points.size() / 2;
bool bZeroArea = false;
CFX_PathData t_path;
for (int i = 0; i < mid; i++) {
- if (!(m_pPoints[mid - i - 1].m_PointX ==
- m_pPoints[mid + i + 1].m_PointX &&
- m_pPoints[mid - i - 1].m_PointY ==
- m_pPoints[mid + i + 1].m_PointY &&
- m_pPoints[mid - i - 1].m_Type != FXPT_TYPE::BezierTo &&
- m_pPoints[mid + i + 1].m_Type != FXPT_TYPE::BezierTo)) {
+ if (!(m_Points[mid - i - 1].m_PointX == m_Points[mid + i + 1].m_PointX &&
+ m_Points[mid - i - 1].m_PointY == m_Points[mid + i + 1].m_PointY &&
+ m_Points[mid - i - 1].m_Type != FXPT_TYPE::BezierTo &&
+ m_Points[mid + i + 1].m_Type != FXPT_TYPE::BezierTo)) {
bZeroArea = true;
break;
}
- int new_count = t_path.GetPointCount();
- t_path.AddPointCount(2);
- t_path.SetPoint(new_count, m_pPoints[mid - i].m_PointX,
- m_pPoints[mid - i].m_PointY, FXPT_TYPE::MoveTo, false);
- t_path.SetPoint(new_count + 1, m_pPoints[mid - i - 1].m_PointX,
- m_pPoints[mid - i - 1].m_PointY, FXPT_TYPE::LineTo,
- false);
+
+ t_path.AppendPoint(m_Points[mid - i].m_PointX, m_Points[mid - i].m_PointY,
+ FXPT_TYPE::MoveTo, false);
+ t_path.AppendPoint(m_Points[mid - i - 1].m_PointX,
+ m_Points[mid - i - 1].m_PointY, FXPT_TYPE::LineTo,
+ false);
}
if (!bZeroArea) {
- NewPath.Append(&t_path, nullptr);
+ NewPath->Append(&t_path, nullptr);
bThin = true;
return true;
}
}
int stratPoint = 0;
- int next = 0, i;
- for (i = 0; i < m_PointCount; i++) {
- FXPT_TYPE point_type = m_pPoints[i].m_Type;
+ int next = 0;
+ for (size_t i = 0; i < m_Points.size(); i++) {
+ FXPT_TYPE point_type = m_Points[i].m_Type;
if (point_type == FXPT_TYPE::MoveTo) {
stratPoint = i;
} else if (point_type == FXPT_TYPE::LineTo) {
- next = (i + 1 - stratPoint) % (m_PointCount - stratPoint) + stratPoint;
- if (m_pPoints[next].m_Type != FXPT_TYPE::BezierTo &&
- m_pPoints[next].m_Type != FXPT_TYPE::MoveTo) {
- if ((m_pPoints[i - 1].m_PointX == m_pPoints[i].m_PointX &&
- m_pPoints[i].m_PointX == m_pPoints[next].m_PointX) &&
- ((m_pPoints[i].m_PointY - m_pPoints[i - 1].m_PointY) *
- (m_pPoints[i].m_PointY - m_pPoints[next].m_PointY) >
+ next = (i + 1 - stratPoint) % (m_Points.size() - stratPoint) + stratPoint;
+ if (m_Points[next].m_Type != FXPT_TYPE::BezierTo &&
+ m_Points[next].m_Type != FXPT_TYPE::MoveTo) {
+ if ((m_Points[i - 1].m_PointX == m_Points[i].m_PointX &&
+ m_Points[i].m_PointX == m_Points[next].m_PointX) &&
+ ((m_Points[i].m_PointY - m_Points[i - 1].m_PointY) *
+ (m_Points[i].m_PointY - m_Points[next].m_PointY) >
0)) {
int pre = i;
- if (FXSYS_fabs(m_pPoints[i].m_PointY - m_pPoints[i - 1].m_PointY) <
- FXSYS_fabs(m_pPoints[i].m_PointY - m_pPoints[next].m_PointY)) {
+ if (FXSYS_fabs(m_Points[i].m_PointY - m_Points[i - 1].m_PointY) <
+ FXSYS_fabs(m_Points[i].m_PointY - m_Points[next].m_PointY)) {
pre--;
next--;
}
- int new_count = NewPath.GetPointCount();
- NewPath.AddPointCount(2);
- NewPath.SetPoint(new_count, m_pPoints[pre].m_PointX,
- m_pPoints[pre].m_PointY, FXPT_TYPE::MoveTo, false);
- NewPath.SetPoint(new_count + 1, m_pPoints[next].m_PointX,
- m_pPoints[next].m_PointY, FXPT_TYPE::LineTo, false);
- } else if ((m_pPoints[i - 1].m_PointY == m_pPoints[i].m_PointY &&
- m_pPoints[i].m_PointY == m_pPoints[next].m_PointY) &&
- ((m_pPoints[i].m_PointX - m_pPoints[i - 1].m_PointX) *
- (m_pPoints[i].m_PointX - m_pPoints[next].m_PointX) >
+
+ NewPath->AppendPoint(m_Points[pre].m_PointX, m_Points[pre].m_PointY,
+ FXPT_TYPE::MoveTo, false);
+ NewPath->AppendPoint(m_Points[next].m_PointX, m_Points[next].m_PointY,
+ FXPT_TYPE::LineTo, false);
+ } else if ((m_Points[i - 1].m_PointY == m_Points[i].m_PointY &&
+ m_Points[i].m_PointY == m_Points[next].m_PointY) &&
+ ((m_Points[i].m_PointX - m_Points[i - 1].m_PointX) *
+ (m_Points[i].m_PointX - m_Points[next].m_PointX) >
0)) {
int pre = i;
- if (FXSYS_fabs(m_pPoints[i].m_PointX - m_pPoints[i - 1].m_PointX) <
- FXSYS_fabs(m_pPoints[i].m_PointX - m_pPoints[next].m_PointX)) {
+ if (FXSYS_fabs(m_Points[i].m_PointX - m_Points[i - 1].m_PointX) <
+ FXSYS_fabs(m_Points[i].m_PointX - m_Points[next].m_PointX)) {
pre--;
next--;
}
- int new_count = NewPath.GetPointCount();
- NewPath.AddPointCount(2);
- NewPath.SetPoint(new_count, m_pPoints[pre].m_PointX,
- m_pPoints[pre].m_PointY, FXPT_TYPE::MoveTo, false);
- NewPath.SetPoint(new_count + 1, m_pPoints[next].m_PointX,
- m_pPoints[next].m_PointY, FXPT_TYPE::LineTo, false);
- } else if (m_pPoints[i - 1].m_Type == FXPT_TYPE::MoveTo &&
- m_pPoints[next].m_Type == FXPT_TYPE::LineTo &&
- m_pPoints[i - 1].m_PointX == m_pPoints[next].m_PointX &&
- m_pPoints[i - 1].m_PointY == m_pPoints[next].m_PointY &&
- m_pPoints[next].m_CloseFigure) {
- int new_count = NewPath.GetPointCount();
- NewPath.AddPointCount(2);
- NewPath.SetPoint(new_count, m_pPoints[i - 1].m_PointX,
- m_pPoints[i - 1].m_PointY, FXPT_TYPE::MoveTo, false);
- NewPath.SetPoint(new_count + 1, m_pPoints[i].m_PointX,
- m_pPoints[i].m_PointY, FXPT_TYPE::LineTo, false);
+
+ NewPath->AppendPoint(m_Points[pre].m_PointX, m_Points[pre].m_PointY,
+ FXPT_TYPE::MoveTo, false);
+ NewPath->AppendPoint(m_Points[next].m_PointX, m_Points[next].m_PointY,
+ FXPT_TYPE::LineTo, false);
+ } else if (m_Points[i - 1].m_Type == FXPT_TYPE::MoveTo &&
+ m_Points[next].m_Type == FXPT_TYPE::LineTo &&
+ m_Points[i - 1].m_PointX == m_Points[next].m_PointX &&
+ m_Points[i - 1].m_PointY == m_Points[next].m_PointY &&
+ m_Points[next].m_CloseFigure) {
+ NewPath->AppendPoint(m_Points[i - 1].m_PointX,
+ m_Points[i - 1].m_PointY, FXPT_TYPE::MoveTo,
+ false);
+ NewPath->AppendPoint(m_Points[i].m_PointX, m_Points[i].m_PointY,
+ FXPT_TYPE::LineTo, false);
bThin = true;
}
}
@@ -457,41 +399,38 @@ bool CFX_PathData::GetZeroAreaPath(CFX_PathData& NewPath,
continue;
}
}
- if (m_PointCount > 3 && NewPath.GetPointCount()) {
+ size_t new_path_size = NewPath->GetPoints().size();
+ if (m_Points.size() > 3 && new_path_size > 0)
bThin = true;
- }
- if (NewPath.GetPointCount() == 0) {
- return false;
- }
- return true;
+ return new_path_size != 0;
}
bool CFX_PathData::IsRect() const {
- if (m_PointCount != 5 && m_PointCount != 4) {
+ if (m_Points.size() != 5 && m_Points.size() != 4)
return false;
- }
- if ((m_PointCount == 5 && (m_pPoints[0].m_PointX != m_pPoints[4].m_PointX ||
- m_pPoints[0].m_PointY != m_pPoints[4].m_PointY)) ||
- (m_pPoints[0].m_PointX == m_pPoints[2].m_PointX &&
- m_pPoints[0].m_PointY == m_pPoints[2].m_PointY) ||
- (m_pPoints[1].m_PointX == m_pPoints[3].m_PointX &&
- m_pPoints[1].m_PointY == m_pPoints[3].m_PointY)) {
+
+ if ((m_Points.size() == 5 &&
+ (m_Points[0].m_PointX != m_Points[4].m_PointX ||
+ m_Points[0].m_PointY != m_Points[4].m_PointY)) ||
+ (m_Points[0].m_PointX == m_Points[2].m_PointX &&
+ m_Points[0].m_PointY == m_Points[2].m_PointY) ||
+ (m_Points[1].m_PointX == m_Points[3].m_PointX &&
+ m_Points[1].m_PointY == m_Points[3].m_PointY)) {
return false;
}
- if (m_pPoints[0].m_PointX != m_pPoints[3].m_PointX &&
- m_pPoints[0].m_PointY != m_pPoints[3].m_PointY) {
+ if (m_Points[0].m_PointX != m_Points[3].m_PointX &&
+ m_Points[0].m_PointY != m_Points[3].m_PointY) {
return false;
}
for (int i = 1; i < 4; i++) {
- if (m_pPoints[i].m_Type != FXPT_TYPE::LineTo) {
+ if (m_Points[i].m_Type != FXPT_TYPE::LineTo)
return false;
- }
- if (m_pPoints[i].m_PointX != m_pPoints[i - 1].m_PointX &&
- m_pPoints[i].m_PointY != m_pPoints[i - 1].m_PointY) {
+ if (m_Points[i].m_PointX != m_Points[i - 1].m_PointX &&
+ m_Points[i].m_PointY != m_Points[i - 1].m_PointY) {
return false;
}
}
- return m_PointCount == 5 || m_pPoints[3].m_CloseFigure;
+ return m_Points.size() == 5 || m_Points[3].m_CloseFigure;
}
bool CFX_PathData::IsRect(const CFX_Matrix* pMatrix,
@@ -501,41 +440,43 @@ bool CFX_PathData::IsRect(const CFX_Matrix* pMatrix,
return false;
if (pRect) {
- pRect->left = m_pPoints[0].m_PointX;
- pRect->right = m_pPoints[2].m_PointX;
- pRect->bottom = m_pPoints[0].m_PointY;
- pRect->top = m_pPoints[2].m_PointY;
+ pRect->left = m_Points[0].m_PointX;
+ pRect->right = m_Points[2].m_PointX;
+ pRect->bottom = m_Points[0].m_PointY;
+ pRect->top = m_Points[2].m_PointY;
pRect->Normalize();
}
return true;
}
- if (m_PointCount != 5 && m_PointCount != 4)
+ if (m_Points.size() != 5 && m_Points.size() != 4)
return false;
- if ((m_PointCount == 5 && (m_pPoints[0].m_PointX != m_pPoints[4].m_PointX ||
- m_pPoints[0].m_PointY != m_pPoints[4].m_PointY)) ||
- (m_pPoints[1].m_PointX == m_pPoints[3].m_PointX &&
- m_pPoints[1].m_PointY == m_pPoints[3].m_PointY)) {
+ if ((m_Points.size() == 5 &&
+ (m_Points[0].m_PointX != m_Points[4].m_PointX ||
+ m_Points[0].m_PointY != m_Points[4].m_PointY)) ||
+ (m_Points[1].m_PointX == m_Points[3].m_PointX &&
+ m_Points[1].m_PointY == m_Points[3].m_PointY)) {
return false;
}
- if (m_PointCount == 4 && m_pPoints[0].m_PointX != m_pPoints[3].m_PointX &&
- m_pPoints[0].m_PointY != m_pPoints[3].m_PointY) {
+ if (m_Points.size() == 4 && m_Points[0].m_PointX != m_Points[3].m_PointX &&
+ m_Points[0].m_PointY != m_Points[3].m_PointY) {
return false;
}
FX_FLOAT x[5];
FX_FLOAT y[5];
- for (int i = 0; i < m_PointCount; i++) {
- x[i] = m_pPoints[i].m_PointX;
- y[i] = m_pPoints[i].m_PointY;
+ for (size_t i = 0; i < m_Points.size(); i++) {
+ x[i] = m_Points[i].m_PointX;
+ y[i] = m_Points[i].m_PointY;
pMatrix->TransformPoint(x[i], y[i]);
- if (i) {
- if (m_pPoints[i].m_Type != FXPT_TYPE::LineTo)
- return false;
- if (x[i] != x[i - 1] && y[i] != y[i - 1])
- return false;
- }
+
+ if (i == 0)
+ continue;
+ if (m_Points[i].m_Type != FXPT_TYPE::LineTo)
+ return false;
+ if (x[i] != x[i - 1] && y[i] != y[i - 1])
+ return false;
}
if (pRect) {
@@ -547,8 +488,3 @@ bool CFX_PathData::IsRect(const CFX_Matrix* pMatrix,
}
return true;
}
-
-void CFX_PathData::Copy(const CFX_PathData& src) {
- SetPointCount(src.m_PointCount);
- FXSYS_memcpy(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount);
-}
diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp
index 12a3dd480d..b0be4667e3 100644
--- a/core/fxge/ge/cfx_renderdevice.cpp
+++ b/core/fxge/ge/cfx_renderdevice.cpp
@@ -473,8 +473,8 @@ bool CFX_RenderDevice::DrawPathWithBlend(const CFX_PathData* pPathData,
int blend_type) {
uint8_t stroke_alpha = pGraphState ? FXARGB_A(stroke_color) : 0;
uint8_t fill_alpha = (fill_mode & 3) ? FXARGB_A(fill_color) : 0;
- if (stroke_alpha == 0 && pPathData->GetPointCount() == 2) {
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
+ const std::vector<FX_PATHPOINT>& pPoints = pPathData->GetPoints();
+ if (stroke_alpha == 0 && pPoints.size() == 2) {
FX_FLOAT x1 = pPoints[0].m_PointX;
FX_FLOAT y1 = pPoints[0].m_PointY;
FX_FLOAT x2 = pPoints[1].m_PointX;
@@ -487,8 +487,7 @@ bool CFX_RenderDevice::DrawPathWithBlend(const CFX_PathData* pPathData,
return true;
}
- if ((pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) &&
- stroke_alpha == 0) {
+ if ((pPoints.size() == 5 || pPoints.size() == 4) && stroke_alpha == 0) {
CFX_FloatRect rect_f;
if (!(fill_mode & FXFILL_RECT_AA) &&
pPathData->IsRect(pObject2Device, &rect_f)) {
@@ -536,7 +535,7 @@ bool CFX_RenderDevice::DrawPathWithBlend(const CFX_PathData* pPathData,
!(fill_mode & FX_FILL_TEXT_MODE)) {
CFX_PathData newPath;
bool bThin = false;
- if (pPathData->GetZeroAreaPath(newPath, (CFX_Matrix*)pObject2Device, bThin,
+ if (pPathData->GetZeroAreaPath(&newPath, (CFX_Matrix*)pObject2Device, bThin,
!!m_pDeviceDriver->GetDriverType())) {
CFX_GraphStateData graphState;
graphState.m_LineWidth = 0.0f;
@@ -673,9 +672,8 @@ bool CFX_RenderDevice::DrawCosmeticLine(FX_FLOAT x1,
}
CFX_GraphStateData graph_state;
CFX_PathData path;
- path.SetPointCount(2);
- path.SetPoint(0, x1, y1, FXPT_TYPE::MoveTo, false);
- path.SetPoint(1, x2, y2, FXPT_TYPE::LineTo, false);
+ path.AppendPoint(x1, y1, FXPT_TYPE::MoveTo, false);
+ path.AppendPoint(x2, y2, FXPT_TYPE::LineTo, false);
return m_pDeviceDriver->DrawPath(&path, nullptr, &graph_state, 0, color,
fill_mode, blend_type);
}
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index ba21bf4134..8263cf66f5 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -278,9 +278,8 @@ static void DebugValidate(const CFX_DIBitmap* bitmap,
SkPath BuildPath(const CFX_PathData* pPathData) {
SkPath skPath;
const CFX_PathData* pFPath = pPathData;
- int nPoints = pFPath->GetPointCount();
- FX_PATHPOINT* pPoints = pFPath->GetPoints();
- for (int i = 0; i < nPoints; i++) {
+ const std::vector<FX_PATHPOINT>& pPoints = pFPath->GetPoints();
+ for (size_t i = 0; i < pPoints.size(); i++) {
FX_FLOAT x = pPoints[i].m_PointX;
FX_FLOAT y = pPoints[i].m_PointY;
FXPT_TYPE point_type = pPoints[i].m_Type;
@@ -306,7 +305,7 @@ SkMatrix ToSkMatrix(const CFX_Matrix& m) {
return skMatrix;
}
-// use when pdf's y-axis points up insead of down
+// use when pdf's y-axis points up instead of down
SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) {
SkMatrix skMatrix;
skMatrix.setAll(m.a * flip, -m.c * flip, m.e, m.b * flip, -m.d * flip, m.f, 0,
@@ -1432,7 +1431,8 @@ bool CFX_SkiaDeviceDriver::SetClip_PathFill(
GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
}
#endif // _SKIA_SUPPORT_PATHS_
- if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
+ if (pPathData->GetPoints().size() == 5 ||
+ pPathData->GetPoints().size() == 4) {
CFX_FloatRect rectf;
if (pPathData->IsRect(deviceMatrix, &rectf)) {
rectf.Intersect(
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 7fc47b9a46..d5f1f4d91c 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -109,10 +109,11 @@ void CFX_PSRenderer::RestoreState(bool bKeepSaved) {
void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData,
const CFX_Matrix* pObject2Device) {
- int nPoints = pPathData->GetPointCount();
CFX_ByteTextBuf buf;
- buf.EstimateSize(nPoints * 10);
- for (int i = 0; i < nPoints; i++) {
+ size_t size = pPathData->GetPoints().size();
+ buf.EstimateSize(size * 10);
+
+ for (size_t i = 0; i < size; i++) {
FXPT_TYPE type = pPathData->GetType(i);
bool closing = pPathData->IsClosingFigure(i);
FX_FLOAT x = pPathData->GetPointX(i);
@@ -592,17 +593,17 @@ void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache,
matrix.Concat(CFX_Matrix(1.0f, 0, 0, 1.0f, 0, 0));
const CFX_PathData* pPathData = pFaceCache->LoadGlyphPath(
pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth);
- if (!pPathData) {
+ if (!pPathData)
return;
- }
+
CFX_PathData TransformedPath(*pPathData);
- if (charpos.m_bGlyphAdjust) {
+ if (charpos.m_bGlyphAdjust)
TransformedPath.Transform(&matrix);
- }
+
CFX_ByteTextBuf buf;
buf << "/X" << *ps_fontnum << " Ff/CharProcs get begin/" << glyphindex
<< "{n ";
- for (int p = 0; p < TransformedPath.GetPointCount(); p++) {
+ for (size_t p = 0; p < TransformedPath.GetPoints().size(); p++) {
FX_FLOAT x = TransformedPath.GetPointX(p), y = TransformedPath.GetPointY(p);
switch (TransformedPath.GetType(p)) {
case FXPT_TYPE::MoveTo: {
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index add0f0e3d3..b5ce7345c6 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -166,10 +166,11 @@ void SetPathToDC(HDC hDC,
const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix) {
BeginPath(hDC);
- int nPoints = pPathData->GetPointCount();
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
- for (int i = 0; i < nPoints; i++) {
- FX_FLOAT posx = pPoints[i].m_PointX, posy = pPoints[i].m_PointY;
+
+ const std::vector<FX_PATHPOINT>& pPoints = pPathData->GetPoints();
+ for (size_t i = 0; i < pPoints.size(); i++) {
+ FX_FLOAT posx = pPoints[i].m_PointX;
+ FX_FLOAT posy = pPoints[i].m_PointY;
if (pMatrix)
pMatrix->TransformPoint(posx, posy);
@@ -1019,8 +1020,8 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
(pGraphState && pGraphState->m_DashCount))) {
if (!((!pMatrix || !pMatrix->WillScale()) && pGraphState &&
pGraphState->m_LineWidth == 1.f &&
- (pPathData->GetPointCount() == 5 ||
- pPathData->GetPointCount() == 4) &&
+ (pPathData->GetPoints().size() == 5 ||
+ pPathData->GetPoints().size() == 4) &&
pPathData->IsRect())) {
if (pPlatform->m_GdiplusExt.DrawPath(m_hDC, pPathData, pMatrix,
pGraphState, fill_color,
@@ -1044,7 +1045,7 @@ bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
hBrush = CreateBrush(fill_color);
hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
}
- if (pPathData->GetPointCount() == 2 && pGraphState &&
+ if (pPathData->GetPoints().size() == 2 && pGraphState &&
pGraphState->m_DashCount) {
FX_FLOAT x1 = pPathData->GetPointX(0);
FX_FLOAT y1 = pPathData->GetPointY(0);
@@ -1108,7 +1109,7 @@ bool CGdiDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
bool CGdiDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix,
int fill_mode) {
- if (pPathData->GetPointCount() == 5) {
+ if (pPathData->GetPoints().size() == 5) {
CFX_FloatRect rectf;
if (pPathData->IsRect(pMatrix, &rectf)) {
FX_RECT rect = rectf.GetOuterRect();
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index c703e3e300..c766ac8f3b 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -1104,11 +1104,10 @@ bool CGdiplusExt::DrawPath(HDC hDC,
uint32_t fill_argb,
uint32_t stroke_argb,
int fill_mode) {
- int nPoints = pPathData->GetPointCount();
- if (nPoints == 0) {
+ auto& pPoints = pPathData->GetPoints();
+ if (pPoints.empty())
return true;
- }
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
+
GpGraphics* pGraphics = nullptr;
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
@@ -1122,14 +1121,14 @@ bool CGdiplusExt::DrawPath(HDC hDC,
pObject2Device->e, pObject2Device->f, &pMatrix);
CallFunc(GdipSetWorldTransform)(pGraphics, pMatrix);
}
- PointF* points = FX_Alloc(PointF, nPoints);
- BYTE* types = FX_Alloc(BYTE, nPoints);
+ PointF* points = FX_Alloc(PointF, pPoints.size());
+ BYTE* types = FX_Alloc(BYTE, pPoints.size());
int nSubPathes = 0;
bool bSubClose = false;
int pos_subclose = 0;
bool bSmooth = false;
int startpoint = 0;
- for (int i = 0; i < nPoints; i++) {
+ for (size_t i = 0; i < pPoints.size(); i++) {
points[i].X = pPoints[i].m_PointX;
points[i].Y = pPoints[i].m_PointY;
FX_FLOAT x = pPoints[i].m_PointX;
@@ -1155,7 +1154,7 @@ bool CGdiplusExt::DrawPath(HDC hDC,
} else if (point_type == FXPT_TYPE::LineTo) {
types[i] = PathPointTypeLine;
if (pPoints[i - 1].IsTypeAndOpen(FXPT_TYPE::MoveTo) &&
- (i == nPoints - 1 ||
+ (i == pPoints.size() - 1 ||
pPoints[i + 1].IsTypeAndOpen(FXPT_TYPE::MoveTo)) &&
points[i].Y == points[i - 1].Y && points[i].X == points[i - 1].X) {
points[i].X += 0.01f;
@@ -1195,7 +1194,7 @@ bool CGdiplusExt::DrawPath(HDC hDC,
}
}
int new_fill_mode = fill_mode & 3;
- if (nPoints == 4 && !pGraphState) {
+ if (pPoints.size() == 4 && !pGraphState) {
int v1, v2;
if (IsSmallTriangle(points, pObject2Device, v1, v2)) {
GpPen* pPen = nullptr;
@@ -1208,12 +1207,12 @@ bool CGdiplusExt::DrawPath(HDC hDC,
}
}
GpPath* pGpPath = nullptr;
- CallFunc(GdipCreatePath2)(points, types, nPoints,
+ CallFunc(GdipCreatePath2)(points, types, pPoints.size(),
GdiFillType2Gdip(new_fill_mode), &pGpPath);
if (!pGpPath) {
- if (pMatrix) {
+ if (pMatrix)
CallFunc(GdipDeleteMatrix)(pMatrix);
- }
+
FX_Free(points);
FX_Free(types);
CallFunc(GdipDeleteGraphics)(pGraphics);
@@ -1232,8 +1231,8 @@ bool CGdiplusExt::DrawPath(HDC hDC,
CallFunc(GdipDrawPath)(pGraphics, pPen, pGpPath);
} else {
int iStart = 0;
- for (int i = 0; i < nPoints; i++) {
- if (i == nPoints - 1 || types[i + 1] == PathPointTypeStart) {
+ for (size_t i = 0; i < pPoints.size(); i++) {
+ if (i == pPoints.size() - 1 || types[i + 1] == PathPointTypeStart) {
GpPath* pSubPath;
CallFunc(GdipCreatePath2)(points + iStart, types + iStart,
i - iStart + 1,
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index a2ea82a94e..3b0c6969f9 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -346,12 +346,13 @@ CPSPrinterDriver::CPSPrinterDriver(HDC hDC, int pslevel, bool bCmykOutput)
ret = ::GetRegionData(hRgn, ret, pData);
if (ret) {
CFX_PathData path;
- path.AllocPointCount(pData->rdh.nCount * 5);
for (uint32_t i = 0; i < pData->rdh.nCount; i++) {
RECT* pRect =
reinterpret_cast<RECT*>(pData->Buffer + pData->rdh.nRgnSize * i);
- path.AppendRect((FX_FLOAT)pRect->left, (FX_FLOAT)pRect->bottom,
- (FX_FLOAT)pRect->right, (FX_FLOAT)pRect->top);
+ path.AppendRect(static_cast<FX_FLOAT>(pRect->left),
+ static_cast<FX_FLOAT>(pRect->bottom),
+ static_cast<FX_FLOAT>(pRect->right),
+ static_cast<FX_FLOAT>(pRect->top));
}
m_PSRenderer.SetClip_PathFill(&path, nullptr, FXFILL_WINDING);
}