diff options
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/cfde_path.cpp | 221 | ||||
-rw-r--r-- | xfa/fde/cfde_path.h | 52 | ||||
-rw-r--r-- | xfa/fde/cfde_renderdevice.cpp | 11 | ||||
-rw-r--r-- | xfa/fde/cfde_renderdevice.h | 4 | ||||
-rw-r--r-- | xfa/fde/cfde_textout.cpp | 12 | ||||
-rw-r--r-- | xfa/fde/ifde_visualset.h | 1 |
6 files changed, 11 insertions, 290 deletions
diff --git a/xfa/fde/cfde_path.cpp b/xfa/fde/cfde_path.cpp deleted file mode 100644 index a7d2e47ac1..0000000000 --- a/xfa/fde/cfde_path.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fde/cfde_path.h" - -#include "third_party/base/stl_util.h" - -void CFDE_Path::CloseFigure() { - m_Path.ClosePath(); -} - -bool CFDE_Path::FigureClosed() const { - const std::vector<FX_PATHPOINT>& points = m_Path.GetPoints(); - return points.empty() ? true : points.back().m_CloseFigure; -} - -void CFDE_Path::MoveTo(const CFX_PointF& point) { - m_Path.AppendPoint(point, FXPT_TYPE::MoveTo, false); -} - -void CFDE_Path::LineTo(const CFX_PointF& point) { - m_Path.AppendPoint(point, FXPT_TYPE::LineTo, false); -} - -void CFDE_Path::BezierTo(const CFX_PointF& p1, - const CFX_PointF& p2, - const CFX_PointF& p3) { - m_Path.AppendPoint(p1, FXPT_TYPE::BezierTo, false); - m_Path.AppendPoint(p2, FXPT_TYPE::BezierTo, false); - m_Path.AppendPoint(p3, FXPT_TYPE::BezierTo, false); -} - -void CFDE_Path::ArcTo(bool bStart, - const CFX_RectF& rect, - float startAngle, - float endAngle) { - float rx = rect.width / 2; - float ry = rect.height / 2; - float cx = rect.left + rx; - float cy = rect.top + ry; - float alpha = atan2(rx * sin(startAngle), ry * cos(startAngle)); - float beta = atan2(rx * sin(endAngle), ry * cos(endAngle)); - if (fabs(beta - alpha) > FX_PI) { - if (beta > alpha) - beta -= 2 * FX_PI; - else - alpha -= 2 * FX_PI; - } - - float half_delta = (beta - alpha) / 2; - float bcp = 4.0f / 3 * (1 - cos(half_delta)) / sin(half_delta); - float sin_alpha = sin(alpha); - float sin_beta = sin(beta); - float cos_alpha = cos(alpha); - float cos_beta = cos(beta); - if (bStart) - MoveTo(CFX_PointF(cx + rx * cos_alpha, cy + ry * sin_alpha)); - - BezierTo(CFX_PointF(cx + rx * (cos_alpha - bcp * sin_alpha), - cy + ry * (sin_alpha + bcp * cos_alpha)), - CFX_PointF(cx + rx * (cos_beta + bcp * sin_beta), - cy + ry * (sin_beta - bcp * cos_beta)), - CFX_PointF(cx + rx * cos_beta, cy + ry * sin_beta)); -} - -void CFDE_Path::AddBezier(const std::vector<CFX_PointF>& points) { - if (points.size() != 4) - return; - - MoveTo(points[0]); - BezierTo(points[1], points[2], points[3]); -} - -void CFDE_Path::AddBeziers(const std::vector<CFX_PointF>& points) { - int32_t iCount = points.size(); - if (iCount < 4) - return; - - const CFX_PointF* p = points.data(); - const CFX_PointF* pEnd = p + iCount; - MoveTo(p[0]); - for (++p; p <= pEnd - 3; p += 3) - BezierTo(p[0], p[1], p[2]); -} - -void CFDE_Path::GetCurveTangents(const std::vector<CFX_PointF>& points, - std::vector<CFX_PointF>* tangents, - bool bClosed, - float fTension) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(points); - tangents->resize(iCount); - if (iCount < 3) - return; - - float fCoefficient = fTension / 3.0f; - const CFX_PointF* pPoints = points.data(); - CFX_PointF* pTangents = tangents->data(); - for (int32_t i = 0; i < iCount; ++i) { - int32_t r = i + 1; - int32_t s = i - 1; - if (r >= iCount) - r = bClosed ? (r - iCount) : (iCount - 1); - if (s < 0) - s = bClosed ? (s + iCount) : 0; - - pTangents[i].x += (fCoefficient * (pPoints[r].x - pPoints[s].x)); - pTangents[i].y += (fCoefficient * (pPoints[r].y - pPoints[s].y)); - } -} - -void CFDE_Path::AddCurve(const std::vector<CFX_PointF>& points, - bool bClosed, - float fTension) { - int32_t iLast = pdfium::CollectionSize<int32_t>(points) - 1; - if (iLast < 1) - return; - - std::vector<CFX_PointF> tangents; - GetCurveTangents(points, &tangents, bClosed, fTension); - const CFX_PointF* pPoints = points.data(); - CFX_PointF* pTangents = tangents.data(); - MoveTo(pPoints[0]); - for (int32_t i = 0; i < iLast; ++i) { - BezierTo(CFX_PointF(pPoints[i].x + pTangents[i].x, - pPoints[i].y + pTangents[i].y), - CFX_PointF(pPoints[i + 1].x - pTangents[i + 1].x, - pPoints[i + 1].y - pTangents[i + 1].y), - CFX_PointF(pPoints[i + 1].x, pPoints[i + 1].y)); - } - if (bClosed) { - BezierTo(CFX_PointF(pPoints[iLast].x + pTangents[iLast].x, - pPoints[iLast].y + pTangents[iLast].y), - CFX_PointF(pPoints[0].x - pTangents[0].x, - pPoints[0].y - pTangents[0].y), - CFX_PointF(pPoints[0].x, pPoints[0].y)); - CloseFigure(); - } -} - -void CFDE_Path::AddEllipse(const CFX_RectF& rect) { - float fStartAngle = 0; - float fEndAngle = FX_PI / 2; - for (int32_t i = 0; i < 4; ++i) { - ArcTo(i == 0, rect, fStartAngle, fEndAngle); - fStartAngle += FX_PI / 2; - fEndAngle += FX_PI / 2; - } - CloseFigure(); -} - -void CFDE_Path::AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) { - std::vector<FX_PATHPOINT>& points = m_Path.GetPoints(); - if (points.empty() || fabs(points.back().m_Point.x - pt1.x) > 0.001 || - fabs(points.back().m_Point.y - pt1.y) > 0.001) { - MoveTo(pt1); - } - LineTo(pt2); -} - -void CFDE_Path::AddPath(const CFDE_Path* pSrc, bool bConnect) { - if (!pSrc) - return; - - if (pSrc->m_Path.GetPoints().empty()) - return; - if (bConnect) - LineTo(pSrc->m_Path.GetPoint(0)); - - m_Path.Append(&pSrc->m_Path, nullptr); -} - -void CFDE_Path::AddPolygon(const std::vector<CFX_PointF>& points) { - size_t iCount = points.size(); - if (iCount < 2) - return; - - AddLines(points); - const CFX_PointF* p = points.data(); - if (fabs(p[0].x - p[iCount - 1].x) < 0.01f || - fabs(p[0].y - p[iCount - 1].y) < 0.01f) { - LineTo(p[0]); - } - CloseFigure(); -} - -void CFDE_Path::AddLines(const std::vector<CFX_PointF>& points) { - size_t iCount = points.size(); - if (iCount < 2) - return; - - const CFX_PointF* p = points.data(); - const CFX_PointF* pEnd = p + iCount; - MoveTo(p[0]); - for (++p; p < pEnd; ++p) - LineTo(*p); -} - -void CFDE_Path::AddRectangle(const CFX_RectF& rect) { - MoveTo(rect.TopLeft()); - LineTo(rect.TopRight()); - LineTo(rect.BottomRight()); - LineTo(rect.BottomLeft()); - CloseFigure(); -} - -CFX_RectF CFDE_Path::GetBBox() const { - CFX_FloatRect rect = m_Path.GetBoundingBox(); - CFX_RectF bbox = CFX_RectF(rect.left, rect.top, rect.Width(), rect.Height()); - bbox.Normalize(); - return bbox; -} - -CFX_RectF CFDE_Path::GetBBox(float fLineWidth, float fMiterLimit) const { - CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); - CFX_RectF bbox = CFX_RectF(rect.left, rect.top, rect.Width(), rect.Height()); - bbox.Normalize(); - return bbox; -} diff --git a/xfa/fde/cfde_path.h b/xfa/fde/cfde_path.h deleted file mode 100644 index b0a229f172..0000000000 --- a/xfa/fde/cfde_path.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FDE_CFDE_PATH_H_ -#define XFA_FDE_CFDE_PATH_H_ - -#include <vector> - -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" - -class CFDE_Path { - public: - void CloseFigure(); - - void AddBezier(const std::vector<CFX_PointF>& points); - void AddBeziers(const std::vector<CFX_PointF>& points); - void AddCurve(const std::vector<CFX_PointF>& points, - bool bClosed, - float fTension = 0.5f); - void AddEllipse(const CFX_RectF& rect); - void AddLines(const std::vector<CFX_PointF>& points); - void AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2); - void AddPath(const CFDE_Path* pSrc, bool bConnect); - void AddPolygon(const std::vector<CFX_PointF>& points); - void AddRectangle(const CFX_RectF& rect); - - CFX_RectF GetBBox() const; - CFX_RectF GetBBox(float fLineWidth, float fMiterLimit) const; - - bool FigureClosed() const; - void BezierTo(const CFX_PointF& p1, - const CFX_PointF& p2, - const CFX_PointF& p3); - void ArcTo(bool bStart, - const CFX_RectF& rect, - float startAngle, - float endAngle); - void MoveTo(const CFX_PointF& p); - void LineTo(const CFX_PointF& p); - - void GetCurveTangents(const std::vector<CFX_PointF>& points, - std::vector<CFX_PointF>* tangents, - bool bClosed, - float fTension) const; - CFX_PathData m_Path; -}; - -#endif // XFA_FDE_CFDE_PATH_H_ diff --git a/xfa/fde/cfde_renderdevice.cpp b/xfa/fde/cfde_renderdevice.cpp index 65a81b5ea7..e9457f4c5e 100644 --- a/xfa/fde/cfde_renderdevice.cpp +++ b/xfa/fde/cfde_renderdevice.cpp @@ -11,11 +11,11 @@ #include <utility> #include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/dib/cfx_imagerenderer.h" #include "third_party/base/ptr_util.h" -#include "xfa/fde/cfde_path.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_gefont.h" @@ -147,18 +147,13 @@ bool CFDE_RenderDevice::DrawString(FX_ARGB color, bool CFDE_RenderDevice::DrawPath(FX_ARGB color, float fPenWidth, - const CFDE_Path* pPath, + const CFX_PathData& pPath, const CFX_Matrix* pMatrix) { - CFDE_Path* pGePath = (CFDE_Path*)pPath; - if (!pGePath) - return false; - CFX_GraphStateData graphState; graphState.m_LineCap = CFX_GraphStateData::LineCapButt; graphState.m_LineJoin = CFX_GraphStateData::LineJoinMiter; graphState.m_LineWidth = fPenWidth; graphState.m_MiterLimit = 10; graphState.m_DashPhase = 0; - return m_pDevice->DrawPath(&pGePath->m_Path, (const CFX_Matrix*)pMatrix, - &graphState, 0, color, 0); + return m_pDevice->DrawPath(&pPath, pMatrix, &graphState, 0, color, 0); } diff --git a/xfa/fde/cfde_renderdevice.h b/xfa/fde/cfde_renderdevice.h index f1082fb39a..ccc2ef281e 100644 --- a/xfa/fde/cfde_renderdevice.h +++ b/xfa/fde/cfde_renderdevice.h @@ -12,7 +12,7 @@ #include "core/fxge/cfx_renderdevice.h" #include "xfa/fgas/font/cfgas_gefont.h" -class CFDE_Path; +class CFX_PathData; class CFX_GraphStateData; class CFDE_RenderDevice { @@ -37,7 +37,7 @@ class CFDE_RenderDevice { const CFX_Matrix* pMatrix); bool DrawPath(FX_ARGB color, float fPenWidth, - const CFDE_Path* pPath, + const CFX_PathData& pPath, const CFX_Matrix* pMatrix); private: diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index 202074bdc4..e796bdcdb3 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp @@ -11,9 +11,9 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" +#include "core/fxge/cfx_pathdata.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_path.h" #include "xfa/fde/cfde_renderdevice.h" #include "xfa/fgas/layout/cfx_txtbreak.h" @@ -704,7 +704,7 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, FX_ARGB color) { if (!bUnderLine && !bStrikeOut && !bHotKey) return; - auto pPath = pdfium::MakeUnique<CFDE_Path>(); + CFX_PathData path; int32_t iLineCount = 0; CFX_RectF rtText = pPiece->rtPiece; CFX_PointF pt1, pt2; @@ -713,7 +713,7 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, FX_ARGB color) { pt1.y = rtText.bottom(); pt2.x = rtText.right(); pt2.y = rtText.bottom(); - pPath->AddLine(pt1, pt2); + path.AppendLine(pt1, pt2); iLineCount++; } if (bStrikeOut) { @@ -721,7 +721,7 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, FX_ARGB color) { pt1.y = rtText.bottom() - rtText.height * 2.0f / 5.0f; pt2.x = rtText.right(); pt2.y = pt1.y; - pPath->AddLine(pt1, pt2); + path.AppendLine(pt1, pt2); iLineCount++; } if (bHotKey) { @@ -734,14 +734,14 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, FX_ARGB color) { pt1.y = rect.bottom(); pt2.x = rect.right(); pt2.y = rect.bottom(); - pPath->AddLine(pt1, pt2); + path.AppendLine(pt1, pt2); iLineCount++; } } } } if (iLineCount > 0) - m_pRenderDevice->DrawPath(color, 1, pPath.get(), &m_Matrix); + m_pRenderDevice->DrawPath(color, 1, path, &m_Matrix); } CFDE_TTOLine::CFDE_TTOLine() : m_bNewReload(false) {} diff --git a/xfa/fde/ifde_visualset.h b/xfa/fde/ifde_visualset.h index 144475f047..b5babd2c46 100644 --- a/xfa/fde/ifde_visualset.h +++ b/xfa/fde/ifde_visualset.h @@ -13,7 +13,6 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_dib.h" -#include "xfa/fde/cfde_path.h" #include "xfa/fgas/font/cfgas_fontmgr.h" class FXTEXT_CHARPOS; |