diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-02-15 11:07:32 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-15 17:47:57 +0000 |
commit | e4602321f3175fa5addb6761d0e94f5c2fc93d0c (patch) | |
tree | 6671774659645fad6d9ce55a5910b4665a25094f /core/fxge | |
parent | eb55885e9a9eec670ed98cbd12dc96d63e6a6623 (diff) | |
download | pdfium-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/fxge')
-rw-r--r-- | core/fxge/agg/fx_agg_driver.cpp | 17 | ||||
-rw-r--r-- | core/fxge/cfx_pathdata.h | 38 | ||||
-rw-r--r-- | core/fxge/ge/cfx_font.cpp | 192 | ||||
-rw-r--r-- | core/fxge/ge/cfx_pathdata.cpp | 410 | ||||
-rw-r--r-- | core/fxge/ge/cfx_renderdevice.cpp | 14 | ||||
-rw-r--r-- | core/fxge/skia/fx_skia_device.cpp | 10 | ||||
-rw-r--r-- | core/fxge/win32/cfx_psrenderer.cpp | 17 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_device.cpp | 17 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_gdipext.cpp | 27 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_print.cpp | 7 |
10 files changed, 326 insertions, 423 deletions
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, ¶ms); - 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, ¶ms); + if (pPath->GetPoints().empty()) + return nullptr; + Outline_CheckEmptyContour(¶ms); - 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); } |