From 4093039d19f832173ec58cfd9f2e8ac393a76091 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 15 Feb 2017 11:10:16 -0500 Subject: Cleanup GetZeroAreaPath method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL simplifies some of the logic in GetZeroAreaPath. It also removes the side effect of resetting the object device matrix. Change-Id: Id1e355bde811341c5ceab0331fbe64b1aed895d5 Reviewed-on: https://pdfium-review.googlesource.com/2712 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- core/fxge/cfx_pathdata.h | 9 +++--- core/fxge/ge/cfx_pathdata.cpp | 66 ++++++++++++++++----------------------- core/fxge/ge/cfx_renderdevice.cpp | 16 +++++++--- 3 files changed, 43 insertions(+), 48 deletions(-) (limited to 'core/fxge') diff --git a/core/fxge/cfx_pathdata.h b/core/fxge/cfx_pathdata.h index 7d5e6e28c6..14a8d992b9 100644 --- a/core/fxge/cfx_pathdata.h +++ b/core/fxge/cfx_pathdata.h @@ -47,10 +47,11 @@ class CFX_PathData { void Transform(const CFX_Matrix* pMatrix); bool IsRect() const; - bool GetZeroAreaPath(CFX_PathData* NewPath, - CFX_Matrix* pMatrix, - bool& bThin, - bool bAdjust) const; + bool GetZeroAreaPath(const CFX_Matrix* pMatrix, + bool bAdjust, + CFX_PathData* NewPath, + bool* bThin, + bool* setIdentity) const; bool IsRect(const CFX_Matrix* pMatrix, CFX_FloatRect* rect) const; void Append(const CFX_PathData& data); diff --git a/core/fxge/ge/cfx_pathdata.cpp b/core/fxge/ge/cfx_pathdata.cpp index 5ad3db4886..11c421e468 100644 --- a/core/fxge/ge/cfx_pathdata.cpp +++ b/core/fxge/ge/cfx_pathdata.cpp @@ -263,10 +263,12 @@ void CFX_PathData::Transform(const CFX_Matrix* pMatrix) { pMatrix->TransformPoint(point.m_PointX, point.m_PointY); } -bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath, - CFX_Matrix* pMatrix, - bool& bThin, - bool bAdjust) const { +bool CFX_PathData::GetZeroAreaPath(const CFX_Matrix* pMatrix, + bool bAdjust, + CFX_PathData* NewPath, + bool* bThin, + bool* setIdentity) const { + *setIdentity = false; if (m_Points.size() < 3) return false; @@ -275,45 +277,29 @@ bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath, 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_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->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->AppendPoint(x, y, FXPT_TYPE::LineTo, false); - - pMatrix->SetIdentity(); - } else { - 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); + for (size_t i = 0; i < 2; i++) { + FX_FLOAT x = m_Points[i].m_PointX; + FX_FLOAT y = m_Points[i].m_PointY; + if (bAdjust) { + if (pMatrix) + pMatrix->TransformPoint(x, y); + + x = static_cast(x) + 0.5f; + y = static_cast(y) + 0.5f; } - } else { - 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); + NewPath->AppendPoint(x, y, i == 0 ? FXPT_TYPE::MoveTo : FXPT_TYPE::LineTo, + false); } + if (bAdjust && pMatrix) + *setIdentity = true; + if (m_Points[0].m_PointX != m_Points[1].m_PointX && m_Points[0].m_PointY != m_Points[1].m_PointY) { - bThin = true; + *bThin = true; } return true; } + if (((m_Points.size() > 3) && (m_Points.size() % 2))) { int mid = m_Points.size() / 2; bool bZeroArea = false; @@ -335,10 +321,11 @@ bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath, } if (!bZeroArea) { NewPath->Append(&t_path, nullptr); - bThin = true; + *bThin = true; return true; } } + int stratPoint = 0; int next = 0; for (size_t i = 0; i < m_Points.size(); i++) { @@ -391,7 +378,7 @@ bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath, false); NewPath->AppendPoint(m_Points[i].m_PointX, m_Points[i].m_PointY, FXPT_TYPE::LineTo, false); - bThin = true; + *bThin = true; } } } else if (point_type == FXPT_TYPE::BezierTo) { @@ -399,9 +386,10 @@ bool CFX_PathData::GetZeroAreaPath(CFX_PathData* NewPath, continue; } } + size_t new_path_size = NewPath->GetPoints().size(); if (m_Points.size() > 3 && new_path_size > 0) - bThin = true; + *bThin = true; return new_path_size != 0; } diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index b0be4667e3..d2c677ecc2 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -535,19 +535,25 @@ 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, - !!m_pDeviceDriver->GetDriverType())) { + bool setIdentity = false; + if (pPathData->GetZeroAreaPath(pObject2Device, + !!m_pDeviceDriver->GetDriverType(), &newPath, + &bThin, &setIdentity)) { CFX_GraphStateData graphState; graphState.m_LineWidth = 0.0f; + uint32_t strokecolor = fill_color; if (bThin) strokecolor = (((fill_alpha >> 2) << 24) | (strokecolor & 0x00ffffff)); - CFX_Matrix* pMatrix = nullptr; - if (pObject2Device && !pObject2Device->IsIdentity()) - pMatrix = (CFX_Matrix*)pObject2Device; + + const CFX_Matrix* pMatrix = nullptr; + if (pObject2Device && !pObject2Device->IsIdentity() && !setIdentity) + pMatrix = pObject2Device; + int smooth_path = FX_ZEROAREA_FILL; if (fill_mode & FXFILL_NOPATHSMOOTH) smooth_path |= FXFILL_NOPATHSMOOTH; + m_pDeviceDriver->DrawPath(&newPath, pMatrix, &graphState, 0, strokecolor, smooth_path, blend_type); } -- cgit v1.2.3