From acd0d59e3c09f04bffd178aecd3638d3e189faba Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 21 Apr 2016 11:06:27 -0700 Subject: Cleanup FDE interfaces. This CL removes IFDE_TextOut, IFDE_Path, IFDE_RenderContext, IFDE_RenderDevice, and IFDE_VisualSetIterator in favour of the concrete classes. BUG=pdfium:468 Review URL: https://codereview.chromium.org/1896893003 --- BUILD.gn | 6 +- xfa.gyp | 6 +- xfa/fde/cfde_path.cpp | 264 +++++++++++++++++++++++++++++++++++++ xfa/fde/cfde_path.h | 56 ++++++++ xfa/fde/fde_gedevice.cpp | 183 ++++++++++++------------- xfa/fde/fde_gedevice.h | 169 +++++++++++++----------- xfa/fde/fde_geobject.cpp | 255 ----------------------------------- xfa/fde/fde_geobject.h | 57 -------- xfa/fde/fde_iterator.cpp | 61 +++++---- xfa/fde/fde_iterator.h | 18 +-- xfa/fde/fde_path.h | 37 ------ xfa/fde/fde_render.cpp | 95 +------------ xfa/fde/fde_render.h | 44 ++++--- xfa/fde/fde_renderdevice.h | 110 ---------------- xfa/fde/fde_visualset.h | 15 +-- xfa/fde/tto/fde_textout.cpp | 215 ++++-------------------------- xfa/fde/tto/fde_textout.h | 205 +++++++++++++++++++--------- xfa/fee/fde_txtedtengine.cpp | 2 +- xfa/fwl/basewidget/fwl_editimp.cpp | 10 +- xfa/fwl/theme/cfwl_widgettp.cpp | 2 +- xfa/fwl/theme/cfwl_widgettp.h | 6 +- xfa/fxfa/app/xfa_ffpageview.cpp | 54 +++++++- xfa/fxfa/app/xfa_ffwidgetacc.cpp | 15 ++- xfa/fxfa/app/xfa_fwltheme.cpp | 2 +- xfa/fxfa/app/xfa_fwltheme.h | 2 +- xfa/fxfa/app/xfa_textlayout.cpp | 14 +- xfa/fxfa/app/xfa_textlayout.h | 6 +- 27 files changed, 830 insertions(+), 1079 deletions(-) create mode 100644 xfa/fde/cfde_path.cpp create mode 100644 xfa/fde/cfde_path.h delete mode 100644 xfa/fde/fde_geobject.cpp delete mode 100644 xfa/fde/fde_geobject.h delete mode 100644 xfa/fde/fde_path.h delete mode 100644 xfa/fde/fde_renderdevice.h diff --git a/BUILD.gn b/BUILD.gn index 3ecc9a97e5..bdc7570794 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -897,6 +897,8 @@ if (pdf_enable_xfa) { static_library("xfa") { sources = [ + "xfa/fde/cfde_path.cpp", + "xfa/fde/cfde_path.h", "xfa/fde/css/fde_css.h", "xfa/fde/css/fde_csscache.cpp", "xfa/fde/css/fde_csscache.h", @@ -911,16 +913,12 @@ if (pdf_enable_xfa) { "xfa/fde/css/fde_csssyntax.cpp", "xfa/fde/css/fde_csssyntax.h", "xfa/fde/fde_gedevice.cpp", - "xfa/fde/fde_gedevice.h", - "xfa/fde/fde_geobject.cpp", "xfa/fde/fde_geobject.h", "xfa/fde/fde_iterator.cpp", "xfa/fde/fde_iterator.h", "xfa/fde/fde_object.h", - "xfa/fde/fde_path.h", "xfa/fde/fde_render.cpp", "xfa/fde/fde_render.h", - "xfa/fde/fde_renderdevice.h", "xfa/fde/tto/fde_textout.cpp", "xfa/fde/tto/fde_textout.h", "xfa/fde/xml/fde_xml.h", diff --git a/xfa.gyp b/xfa.gyp index 57152d8dd4..ce7d720087 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -61,15 +61,13 @@ "xfa/fde/css/fde_cssstylesheet.h", "xfa/fde/css/fde_csssyntax.cpp", "xfa/fde/css/fde_csssyntax.h", - "xfa/fde/fde_renderdevice.h", + "xfa/fde/cfde_path.cpp", + "xfa/fde/cfde_path.h", "xfa/fde/fde_gedevice.cpp", "xfa/fde/fde_gedevice.h", - "xfa/fde/fde_geobject.cpp", - "xfa/fde/fde_geobject.h", "xfa/fde/fde_iterator.cpp", "xfa/fde/fde_iterator.h", "xfa/fde/fde_object.h", - "xfa/fde/fde_path.h", "xfa/fde/fde_render.cpp", "xfa/fde/fde_render.h", "xfa/fde/tto/fde_textout.cpp", diff --git a/xfa/fde/cfde_path.cpp b/xfa/fde/cfde_path.cpp new file mode 100644 index 0000000000..7ea458d485 --- /dev/null +++ b/xfa/fde/cfde_path.cpp @@ -0,0 +1,264 @@ +// 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 "xfa/fde/fde_object.h" + +FX_BOOL CFDE_Path::StartFigure() { + return CloseFigure(); +} + +FX_BOOL CFDE_Path::CloseFigure() { + FX_PATHPOINT* pPoint = GetLastPoint(); + if (pPoint) + pPoint->m_Flag |= FXPT_CLOSEFIGURE; + return TRUE; +} + +FX_PATHPOINT* CFDE_Path::GetLastPoint(int32_t iCount) const { + if (iCount < 1) + return nullptr; + + int32_t iPoints = m_Path.GetPointCount(); + if (iCount > iPoints) + return nullptr; + return m_Path.GetPoints() + iPoints - iCount; +} + +FX_BOOL CFDE_Path::FigureClosed() const { + FX_PATHPOINT* pPoint = GetLastPoint(); + return pPoint ? (pPoint->m_Flag & FXPT_CLOSEFIGURE) : TRUE; +} + +FX_PATHPOINT* CFDE_Path::AddPoints(int32_t iCount) { + if (iCount < 1) + return nullptr; + + int32_t iPoints = m_Path.GetPointCount(); + m_Path.AddPointCount(iCount); + return m_Path.GetPoints() + iPoints; +} + +void CFDE_Path::MoveTo(FX_FLOAT fx, FX_FLOAT fy) { + FX_PATHPOINT* pPoint = AddPoints(1); + pPoint->m_PointX = fx; + pPoint->m_PointY = fy; + pPoint->m_Flag = FXPT_MOVETO; +} + +void CFDE_Path::LineTo(FX_FLOAT fx, FX_FLOAT fy) { + FX_PATHPOINT* pPoint = AddPoints(1); + pPoint->m_PointX = fx; + pPoint->m_PointY = fy; + pPoint->m_Flag = FXPT_LINETO; +} + +void CFDE_Path::BezierTo(const CFX_PointF& p1, + const CFX_PointF& p2, + const CFX_PointF& p3) { + FX_PATHPOINT* p = AddPoints(3); + p[0].m_PointX = p1.x; + p[0].m_PointY = p1.y; + p[0].m_Flag = FXPT_BEZIERTO; + p[1].m_PointX = p2.x; + p[1].m_PointY = p2.y; + p[1].m_Flag = FXPT_BEZIERTO; + p[2].m_PointX = p3.x; + p[2].m_PointY = p3.y; + p[2].m_Flag = FXPT_BEZIERTO; +} + +void CFDE_Path::ArcTo(FX_BOOL bStart, + const CFX_RectF& rect, + FX_FLOAT startAngle, + FX_FLOAT endAngle) { + FX_FLOAT rx = rect.width / 2; + FX_FLOAT ry = rect.height / 2; + FX_FLOAT cx = rect.left + rx; + FX_FLOAT cy = rect.top + ry; + FX_FLOAT alpha = + FXSYS_atan2(rx * FXSYS_sin(startAngle), ry * FXSYS_cos(startAngle)); + FX_FLOAT beta = + FXSYS_atan2(rx * FXSYS_sin(endAngle), ry * FXSYS_cos(endAngle)); + if (FXSYS_fabs(beta - alpha) > FX_PI) { + if (beta > alpha) + beta -= 2 * FX_PI; + else + alpha -= 2 * FX_PI; + } + FX_FLOAT half_delta = (beta - alpha) / 2; + FX_FLOAT bcp = 4.0f / 3 * (1 - FXSYS_cos(half_delta)) / FXSYS_sin(half_delta); + FX_FLOAT sin_alpha = FXSYS_sin(alpha); + FX_FLOAT sin_beta = FXSYS_sin(beta); + FX_FLOAT cos_alpha = FXSYS_cos(alpha); + FX_FLOAT cos_beta = FXSYS_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 CFX_PointsF& points) { + if (points.GetSize() != 4) + return; + + const CFX_PointF* p = points.GetData(); + MoveTo(p[0]); + BezierTo(p[1], p[2], p[3]); +} + +void CFDE_Path::AddBeziers(const CFX_PointsF& points) { + int32_t iCount = points.GetSize(); + if (iCount < 4) + return; + + const CFX_PointF* p = points.GetData(); + 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 CFX_PointsF& points, + CFX_PointsF& tangents, + FX_BOOL bClosed, + FX_FLOAT fTension) const { + int32_t iCount = points.GetSize(); + tangents.SetSize(iCount); + if (iCount < 3) + return; + + FX_FLOAT fCoefficient = fTension / 3.0f; + const CFX_PointF* pPoints = points.GetData(); + CFX_PointF* pTangents = tangents.GetData(); + 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 CFX_PointsF& points, + FX_BOOL bClosed, + FX_FLOAT fTension) { + int32_t iLast = points.GetUpperBound(); + if (iLast < 1) + return; + + CFX_PointsF tangents; + GetCurveTangents(points, tangents, bClosed, fTension); + const CFX_PointF* pPoints = points.GetData(); + CFX_PointF* pTangents = tangents.GetData(); + 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) { + FX_FLOAT fStartAngle = 0; + FX_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) { + FX_PATHPOINT* pLast = GetLastPoint(); + if (!pLast || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 || + FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) { + MoveTo(pt1); + } + LineTo(pt2); +} + +void CFDE_Path::AddPath(const CFDE_Path* pSrc, FX_BOOL bConnect) { + CFDE_Path* pPath = (CFDE_Path*)pSrc; + if (!pPath) + return; + + int32_t iCount = pPath->m_Path.GetPointCount(); + if (iCount < 1) + return; + if (bConnect) + LineTo(pPath->m_Path.GetPointX(0), pPath->m_Path.GetPointY(0)); + + m_Path.Append(&pPath->m_Path, nullptr); +} + +void CFDE_Path::AddPolygon(const CFX_PointsF& points) { + int32_t iCount = points.GetSize(); + if (iCount < 2) + return; + + AddLines(points); + const CFX_PointF* p = points.GetData(); + if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || + FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { + LineTo(p[0]); + } + CloseFigure(); +} + +void CFDE_Path::AddLines(const CFX_PointsF& points) { + int32_t iCount = points.GetSize(); + if (iCount < 2) + return; + + const CFX_PointF* p = points.GetData(); + 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(); +} + +void CFDE_Path::GetBBox(CFX_RectF& bbox) const { + CFX_FloatRect rect = m_Path.GetBoundingBox(); + bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); + bbox.Normalize(); +} + +void CFDE_Path::GetBBox(CFX_RectF& bbox, + FX_FLOAT fLineWidth, + FX_FLOAT fMiterLimit) const { + CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); + bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); + bbox.Normalize(); +} diff --git a/xfa/fde/cfde_path.h b/xfa/fde/cfde_path.h new file mode 100644 index 0000000000..c4b66f063e --- /dev/null +++ b/xfa/fde/cfde_path.h @@ -0,0 +1,56 @@ +// 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 "core/fxge/include/fx_ge.h" +#include "xfa/fgas/crt/fgas_memory.h" + +class CFDE_Path : public CFX_Target { + public: + void Release() { delete this; } + + FX_BOOL StartFigure(); + FX_BOOL CloseFigure(); + + void AddBezier(const CFX_PointsF& points); + void AddBeziers(const CFX_PointsF& points); + void AddCurve(const CFX_PointsF& points, + FX_BOOL bClosed, + FX_FLOAT fTension = 0.5f); + void AddEllipse(const CFX_RectF& rect); + void AddLines(const CFX_PointsF& points); + void AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2); + void AddPath(const CFDE_Path* pSrc, FX_BOOL bConnect); + void AddPolygon(const CFX_PointsF& points); + void AddRectangle(const CFX_RectF& rect); + void GetBBox(CFX_RectF& bbox) const; + void GetBBox(CFX_RectF& bbox, + FX_FLOAT fLineWidth, + FX_FLOAT fMiterLimit) const; + FX_PATHPOINT* AddPoints(int32_t iCount); + FX_PATHPOINT* GetLastPoint(int32_t iCount = 1) const; + FX_BOOL FigureClosed() const; + void MoveTo(FX_FLOAT fx, FX_FLOAT fy); + void LineTo(FX_FLOAT fx, FX_FLOAT fy); + void BezierTo(const CFX_PointF& p1, + const CFX_PointF& p2, + const CFX_PointF& p3); + void ArcTo(FX_BOOL bStart, + const CFX_RectF& rect, + FX_FLOAT startAngle, + FX_FLOAT endAngle); + void MoveTo(const CFX_PointF& p0) { MoveTo(p0.x, p0.y); } + void LineTo(const CFX_PointF& p1) { LineTo(p1.x, p1.y); } + void GetCurveTangents(const CFX_PointsF& points, + CFX_PointsF& tangents, + FX_BOOL bClosed, + FX_FLOAT fTension) const; + CFX_PathData m_Path; +}; + +#endif // XFA_FDE_CFDE_PATH_H_ diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp index 605c4f97c0..49345ffeaa 100644 --- a/xfa/fde/fde_gedevice.cpp +++ b/xfa/fde/fde_gedevice.cpp @@ -8,80 +8,71 @@ #include -#include "xfa/fde/fde_geobject.h" +#include "xfa/fde/cfde_path.h" #include "xfa/fde/fde_object.h" +#include "xfa/fgas/font/fgas_font.h" -IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_DIBitmap* pBitmap, - FX_BOOL bRgbByteOrder) { - if (pBitmap == NULL) { - return NULL; - } - CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; - pDevice->Attach(pBitmap, 0, bRgbByteOrder); - return new CFDE_FxgeDevice(pDevice, TRUE); -} -IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_RenderDevice* pDevice) { - return pDevice ? new CFDE_FxgeDevice(pDevice, FALSE) : nullptr; -} -CFDE_FxgeDevice::CFDE_FxgeDevice(CFX_RenderDevice* pDevice, - FX_BOOL bOwnerDevice) +CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice, + FX_BOOL bOwnerDevice) : m_pDevice(pDevice), m_bOwnerDevice(bOwnerDevice), - m_pCharPos(NULL), + m_pCharPos(nullptr), m_iCharCount(0) { - FXSYS_assert(pDevice != NULL); + FXSYS_assert(pDevice); + FX_RECT rt = m_pDevice->GetClipBox(); m_rtClip.Set((FX_FLOAT)rt.left, (FX_FLOAT)rt.top, (FX_FLOAT)rt.Width(), (FX_FLOAT)rt.Height()); } -CFDE_FxgeDevice::~CFDE_FxgeDevice() { + +CFDE_RenderDevice::~CFDE_RenderDevice() { FX_Free(m_pCharPos); if (m_bOwnerDevice) delete m_pDevice; } -int32_t CFDE_FxgeDevice::GetWidth() const { +int32_t CFDE_RenderDevice::GetWidth() const { return m_pDevice->GetWidth(); } -int32_t CFDE_FxgeDevice::GetHeight() const { +int32_t CFDE_RenderDevice::GetHeight() const { return m_pDevice->GetHeight(); } -FDE_HDEVICESTATE CFDE_FxgeDevice::SaveState() { +FDE_HDEVICESTATE CFDE_RenderDevice::SaveState() { m_pDevice->SaveState(); return NULL; } -void CFDE_FxgeDevice::RestoreState(FDE_HDEVICESTATE hState) { +void CFDE_RenderDevice::RestoreState(FDE_HDEVICESTATE hState) { m_pDevice->RestoreState(); const FX_RECT& rt = m_pDevice->GetClipBox(); m_rtClip.Set((FX_FLOAT)rt.left, (FX_FLOAT)rt.top, (FX_FLOAT)rt.Width(), (FX_FLOAT)rt.Height()); } -FX_BOOL CFDE_FxgeDevice::SetClipRect(const CFX_RectF& rtClip) { +FX_BOOL CFDE_RenderDevice::SetClipRect(const CFX_RectF& rtClip) { m_rtClip = rtClip; return m_pDevice->SetClip_Rect(FX_RECT((int32_t)FXSYS_floor(rtClip.left), (int32_t)FXSYS_floor(rtClip.top), (int32_t)FXSYS_ceil(rtClip.right()), (int32_t)FXSYS_ceil(rtClip.bottom()))); } -const CFX_RectF& CFDE_FxgeDevice::GetClipRect() { +const CFX_RectF& CFDE_RenderDevice::GetClipRect() { return m_rtClip; } -FX_BOOL CFDE_FxgeDevice::SetClipPath(const IFDE_Path* pClip) { +FX_BOOL CFDE_RenderDevice::SetClipPath(const CFDE_Path* pClip) { return FALSE; } -IFDE_Path* CFDE_FxgeDevice::GetClipPath() const { +CFDE_Path* CFDE_RenderDevice::GetClipPath() const { return NULL; } -FX_FLOAT CFDE_FxgeDevice::GetDpiX() const { +FX_FLOAT CFDE_RenderDevice::GetDpiX() const { return 96; } -FX_FLOAT CFDE_FxgeDevice::GetDpiY() const { +FX_FLOAT CFDE_RenderDevice::GetDpiY() const { return 96; } -FX_BOOL CFDE_FxgeDevice::DrawImage(CFX_DIBSource* pDib, - const CFX_RectF* pSrcRect, - const CFX_RectF& dstRect, - const CFX_Matrix* pImgMatrix, - const CFX_Matrix* pDevMatrix) { +FX_BOOL CFDE_RenderDevice::DrawImage(CFX_DIBSource* pDib, + const CFX_RectF* pSrcRect, + const CFX_RectF& dstRect, + const CFX_Matrix* pImgMatrix, + const CFX_Matrix* pDevMatrix) { FXSYS_assert(pDib != NULL); CFX_RectF srcRect; if (pSrcRect) { @@ -113,12 +104,12 @@ FX_BOOL CFDE_FxgeDevice::DrawImage(CFX_DIBSource* pDib, m_pDevice->CancelDIBits(handle); return handle != NULL; } -FX_BOOL CFDE_FxgeDevice::DrawString(CFDE_Brush* pBrush, - IFX_Font* pFont, - const FXTEXT_CHARPOS* pCharPos, - int32_t iCount, - FX_FLOAT fFontSize, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, + IFX_Font* pFont, + const FXTEXT_CHARPOS* pCharPos, + int32_t iCount, + FX_FLOAT fFontSize, + const CFX_Matrix* pMatrix) { FXSYS_assert(pBrush != NULL && pFont != NULL && pCharPos != NULL && iCount > 0); CFX_FontCache* pCache = CFX_GEModule::Get()->GetFontCache(); @@ -207,13 +198,13 @@ FX_BOOL CFDE_FxgeDevice::DrawString(CFDE_Brush* pBrush, return TRUE; } -FX_BOOL CFDE_FxgeDevice::DrawBezier(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_PointF& pt3, - const CFX_PointF& pt4, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawBezier(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointF& pt1, + const CFX_PointF& pt2, + const CFX_PointF& pt3, + const CFX_PointF& pt4, + const CFX_Matrix* pMatrix) { CFX_PointsF points; points.Add(pt1); points.Add(pt2); @@ -223,45 +214,45 @@ FX_BOOL CFDE_FxgeDevice::DrawBezier(CFDE_Pen* pPen, path.AddBezier(points); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawCurve(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawCurve(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + FX_BOOL bClosed, + FX_FLOAT fTension, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddCurve(points, bClosed, fTension); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawEllipse(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawEllipse(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddEllipse(rect); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawLines(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawLines(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddLines(points); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawLine(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawLine(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointF& pt1, + const CFX_PointF& pt2, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddLine(pt1, pt2); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawPath(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawPath(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFDE_Path* pPath, + const CFX_Matrix* pMatrix) { CFDE_Path* pGePath = (CFDE_Path*)pPath; if (pGePath == NULL) { return FALSE; @@ -273,54 +264,54 @@ FX_BOOL CFDE_FxgeDevice::DrawPath(CFDE_Pen* pPen, return m_pDevice->DrawPath(&pGePath->m_Path, (const CFX_Matrix*)pMatrix, &graphState, 0, pPen->GetColor(), 0); } -FX_BOOL CFDE_FxgeDevice::DrawPolygon(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawPolygon(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddPolygon(points); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::DrawRectangle(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::DrawRectangle(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddRectangle(rect); return DrawPath(pPen, fPenWidth, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::FillClosedCurve(CFDE_Brush* pBrush, - const CFX_PointsF& points, - FX_FLOAT fTension, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::FillClosedCurve(CFDE_Brush* pBrush, + const CFX_PointsF& points, + FX_FLOAT fTension, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddCurve(points, TRUE, fTension); return FillPath(pBrush, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::FillEllipse(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::FillEllipse(CFDE_Brush* pBrush, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddEllipse(rect); return FillPath(pBrush, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::FillPolygon(CFDE_Brush* pBrush, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::FillPolygon(CFDE_Brush* pBrush, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddPolygon(points); return FillPath(pBrush, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::FillRectangle(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::FillRectangle(CFDE_Brush* pBrush, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix) { CFDE_Path path; path.AddRectangle(rect); return FillPath(pBrush, &path, pMatrix); } -FX_BOOL CFDE_FxgeDevice::CreatePen(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - CFX_GraphStateData& graphState) { +FX_BOOL CFDE_RenderDevice::CreatePen(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + CFX_GraphStateData& graphState) { if (!pPen) return FALSE; @@ -332,9 +323,9 @@ FX_BOOL CFDE_FxgeDevice::CreatePen(CFDE_Pen* pPen, return TRUE; } -FX_BOOL CFDE_FxgeDevice::FillPath(CFDE_Brush* pBrush, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix) { +FX_BOOL CFDE_RenderDevice::FillPath(CFDE_Brush* pBrush, + const CFDE_Path* pPath, + const CFX_Matrix* pMatrix) { CFDE_Path* pGePath = (CFDE_Path*)pPath; if (!pGePath) return FALSE; diff --git a/xfa/fde/fde_gedevice.h b/xfa/fde/fde_gedevice.h index 4d43ea0ef5..3d14a0f8af 100644 --- a/xfa/fde/fde_gedevice.h +++ b/xfa/fde/fde_gedevice.h @@ -7,92 +7,101 @@ #ifndef XFA_FDE_FDE_GEDEVICE_H_ #define XFA_FDE_FDE_GEDEVICE_H_ -#include "xfa/fde/fde_renderdevice.h" +#include "core/fxge/include/fx_ge.h" #include "xfa/fgas/crt/fgas_memory.h" -class CFDE_FxgeDevice : public IFDE_RenderDevice, public CFX_Target { +typedef struct FDE_HDEVICESTATE_ { void* pData; } * FDE_HDEVICESTATE; + +class CFDE_Brush; +class CFDE_Path; +class CFDE_Pen; +class CFX_RenderDevice; +class IFX_Font; + +class CFDE_RenderDevice : public CFX_Target { public: - CFDE_FxgeDevice(CFX_RenderDevice* pDevice, FX_BOOL bOwnerDevice); - ~CFDE_FxgeDevice(); - virtual void Release() { delete this; } + CFDE_RenderDevice(CFX_RenderDevice* pDevice, FX_BOOL bOwnerDevice); + ~CFDE_RenderDevice(); + + void Release() { delete this; } - virtual int32_t GetWidth() const; - virtual int32_t GetHeight() const; - virtual FDE_HDEVICESTATE SaveState(); - virtual void RestoreState(FDE_HDEVICESTATE hState); - virtual FX_BOOL SetClipPath(const IFDE_Path* pClip); - virtual IFDE_Path* GetClipPath() const; - virtual FX_BOOL SetClipRect(const CFX_RectF& rtClip); - virtual const CFX_RectF& GetClipRect(); + int32_t GetWidth() const; + int32_t GetHeight() const; + FDE_HDEVICESTATE SaveState(); + void RestoreState(FDE_HDEVICESTATE hState); + FX_BOOL SetClipPath(const CFDE_Path* pClip); + CFDE_Path* GetClipPath() const; + FX_BOOL SetClipRect(const CFX_RectF& rtClip); + const CFX_RectF& GetClipRect(); - virtual FX_FLOAT GetDpiX() const; - virtual FX_FLOAT GetDpiY() const; + FX_FLOAT GetDpiX() const; + FX_FLOAT GetDpiY() const; - virtual FX_BOOL DrawImage(CFX_DIBSource* pDib, - const CFX_RectF* pSrcRect, - const CFX_RectF& dstRect, - const CFX_Matrix* pImgMatrix = NULL, - const CFX_Matrix* pDevMatrix = NULL); - virtual FX_BOOL DrawString(CFDE_Brush* pBrush, - IFX_Font* pFont, - const FXTEXT_CHARPOS* pCharPos, - int32_t iCount, - FX_FLOAT fFontSize, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawBezier(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_PointF& pt3, - const CFX_PointF& pt4, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawCurve(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension = 0.5f, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawEllipse(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawLines(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawLine(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawPath(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawPolygon(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL DrawRectangle(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL FillClosedCurve(CFDE_Brush* pBrush, - const CFX_PointsF& points, - FX_FLOAT fTension = 0.5f, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL FillEllipse(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL FillPath(CFDE_Brush* pBrush, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL FillPolygon(CFDE_Brush* pBrush, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL); - virtual FX_BOOL FillRectangle(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawImage(CFX_DIBSource* pDib, + const CFX_RectF* pSrcRect, + const CFX_RectF& dstRect, + const CFX_Matrix* pImgMatrix = NULL, + const CFX_Matrix* pDevMatrix = NULL); + FX_BOOL DrawString(CFDE_Brush* pBrush, + IFX_Font* pFont, + const FXTEXT_CHARPOS* pCharPos, + int32_t iCount, + FX_FLOAT fFontSize, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawBezier(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointF& pt1, + const CFX_PointF& pt2, + const CFX_PointF& pt3, + const CFX_PointF& pt4, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawCurve(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + FX_BOOL bClosed, + FX_FLOAT fTension = 0.5f, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawEllipse(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawLines(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawLine(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointF& pt1, + const CFX_PointF& pt2, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawPath(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFDE_Path* pPath, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawPolygon(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL DrawRectangle(CFDE_Pen* pPen, + FX_FLOAT fPenWidth, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL FillClosedCurve(CFDE_Brush* pBrush, + const CFX_PointsF& points, + FX_FLOAT fTension = 0.5f, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL FillEllipse(CFDE_Brush* pBrush, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL FillPath(CFDE_Brush* pBrush, + const CFDE_Path* pPath, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL FillPolygon(CFDE_Brush* pBrush, + const CFX_PointsF& points, + const CFX_Matrix* pMatrix = NULL); + FX_BOOL FillRectangle(CFDE_Brush* pBrush, + const CFX_RectF& rect, + const CFX_Matrix* pMatrix = NULL); FX_BOOL DrawSolidString(CFDE_Brush* pBrush, IFX_Font* pFont, diff --git a/xfa/fde/fde_geobject.cpp b/xfa/fde/fde_geobject.cpp deleted file mode 100644 index f4aede0ee4..0000000000 --- a/xfa/fde/fde_geobject.cpp +++ /dev/null @@ -1,255 +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/fde_geobject.h" - -#include "xfa/fde/fde_object.h" - -IFDE_Path* IFDE_Path::Create() { - return new CFDE_Path; -} -FX_BOOL CFDE_Path::StartFigure() { - return CloseFigure(); -} -FX_BOOL CFDE_Path::CloseFigure() { - FX_PATHPOINT* pPoint = GetLastPoint(); - if (pPoint) { - pPoint->m_Flag |= FXPT_CLOSEFIGURE; - } - return TRUE; -} -FX_PATHPOINT* CFDE_Path::GetLastPoint(int32_t iCount) const { - if (iCount < 1) { - return NULL; - } - int32_t iPoints = m_Path.GetPointCount(); - if (iCount > iPoints) { - return NULL; - } - return m_Path.GetPoints() + iPoints - iCount; -} -FX_BOOL CFDE_Path::FigureClosed() const { - FX_PATHPOINT* pPoint = GetLastPoint(); - return pPoint ? (pPoint->m_Flag & FXPT_CLOSEFIGURE) : TRUE; -} -FX_PATHPOINT* CFDE_Path::AddPoints(int32_t iCount) { - if (iCount < 1) { - return NULL; - } - int32_t iPoints = m_Path.GetPointCount(); - m_Path.AddPointCount(iCount); - return m_Path.GetPoints() + iPoints; -} -void CFDE_Path::MoveTo(FX_FLOAT fx, FX_FLOAT fy) { - FX_PATHPOINT* pPoint = AddPoints(1); - pPoint->m_PointX = fx; - pPoint->m_PointY = fy; - pPoint->m_Flag = FXPT_MOVETO; -} -void CFDE_Path::LineTo(FX_FLOAT fx, FX_FLOAT fy) { - FX_PATHPOINT* pPoint = AddPoints(1); - pPoint->m_PointX = fx; - pPoint->m_PointY = fy; - pPoint->m_Flag = FXPT_LINETO; -} -void CFDE_Path::BezierTo(const CFX_PointF& p1, - const CFX_PointF& p2, - const CFX_PointF& p3) { - FX_PATHPOINT* p = AddPoints(3); - p[0].m_PointX = p1.x; - p[0].m_PointY = p1.y; - p[0].m_Flag = FXPT_BEZIERTO; - p[1].m_PointX = p2.x; - p[1].m_PointY = p2.y; - p[1].m_Flag = FXPT_BEZIERTO; - p[2].m_PointX = p3.x; - p[2].m_PointY = p3.y; - p[2].m_Flag = FXPT_BEZIERTO; -} -void CFDE_Path::ArcTo(FX_BOOL bStart, - const CFX_RectF& rect, - FX_FLOAT startAngle, - FX_FLOAT endAngle) { - FX_FLOAT rx = rect.width / 2; - FX_FLOAT ry = rect.height / 2; - FX_FLOAT cx = rect.left + rx; - FX_FLOAT cy = rect.top + ry; - FX_FLOAT alpha = - FXSYS_atan2(rx * FXSYS_sin(startAngle), ry * FXSYS_cos(startAngle)); - FX_FLOAT beta = - FXSYS_atan2(rx * FXSYS_sin(endAngle), ry * FXSYS_cos(endAngle)); - if (FXSYS_fabs(beta - alpha) > FX_PI) { - if (beta > alpha) { - beta -= 2 * FX_PI; - } else { - alpha -= 2 * FX_PI; - } - } - FX_FLOAT half_delta = (beta - alpha) / 2; - FX_FLOAT bcp = 4.0f / 3 * (1 - FXSYS_cos(half_delta)) / FXSYS_sin(half_delta); - FX_FLOAT sin_alpha = FXSYS_sin(alpha); - FX_FLOAT sin_beta = FXSYS_sin(beta); - FX_FLOAT cos_alpha = FXSYS_cos(alpha); - FX_FLOAT cos_beta = FXSYS_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 CFX_PointsF& points) { - if (points.GetSize() != 4) { - return; - } - const CFX_PointF* p = points.GetData(); - MoveTo(p[0]); - BezierTo(p[1], p[2], p[3]); -} -void CFDE_Path::AddBeziers(const CFX_PointsF& points) { - int32_t iCount = points.GetSize(); - if (iCount < 4) { - return; - } - const CFX_PointF* p = points.GetData(); - 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 CFX_PointsF& points, - CFX_PointsF& tangents, - FX_BOOL bClosed, - FX_FLOAT fTension) const { - int32_t iCount = points.GetSize(); - tangents.SetSize(iCount); - if (iCount < 3) { - return; - } - FX_FLOAT fCoefficient = fTension / 3.0f; - const CFX_PointF* pPoints = points.GetData(); - CFX_PointF* pTangents = tangents.GetData(); - 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 CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension) { - int32_t iLast = points.GetUpperBound(); - if (iLast < 1) { - return; - } - CFX_PointsF tangents; - GetCurveTangents(points, tangents, bClosed, fTension); - const CFX_PointF* pPoints = points.GetData(); - CFX_PointF* pTangents = tangents.GetData(); - 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) { - FX_FLOAT fStartAngle = 0; - FX_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) { - FX_PATHPOINT* pLast = GetLastPoint(); - if (pLast == NULL || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 || - FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) { - MoveTo(pt1); - } - LineTo(pt2); -} -void CFDE_Path::AddPath(const IFDE_Path* pSrc, FX_BOOL bConnect) { - CFDE_Path* pPath = (CFDE_Path*)pSrc; - if (pPath == NULL) { - return; - } - int32_t iCount = pPath->m_Path.GetPointCount(); - if (iCount < 1) { - return; - } - if (bConnect) { - LineTo(pPath->m_Path.GetPointX(0), pPath->m_Path.GetPointY(0)); - } - m_Path.Append(&pPath->m_Path, NULL); -} -void CFDE_Path::AddPolygon(const CFX_PointsF& points) { - int32_t iCount = points.GetSize(); - if (iCount < 2) { - return; - } - AddLines(points); - const CFX_PointF* p = points.GetData(); - if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || - FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { - LineTo(p[0]); - } - CloseFigure(); -} -void CFDE_Path::AddLines(const CFX_PointsF& points) { - int32_t iCount = points.GetSize(); - if (iCount < 2) { - return; - } - const CFX_PointF* p = points.GetData(); - 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(); -} -void CFDE_Path::GetBBox(CFX_RectF& bbox) const { - CFX_FloatRect rect = m_Path.GetBoundingBox(); - bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); - bbox.Normalize(); -} -void CFDE_Path::GetBBox(CFX_RectF& bbox, - FX_FLOAT fLineWidth, - FX_FLOAT fMiterLimit) const { - CFX_FloatRect rect = m_Path.GetBoundingBox(fLineWidth, fMiterLimit); - bbox.Set(rect.left, rect.top, rect.Width(), rect.Height()); - bbox.Normalize(); -} diff --git a/xfa/fde/fde_geobject.h b/xfa/fde/fde_geobject.h deleted file mode 100644 index debec6ab2e..0000000000 --- a/xfa/fde/fde_geobject.h +++ /dev/null @@ -1,57 +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_FDE_GEOBJECT_H_ -#define XFA_FDE_FDE_GEOBJECT_H_ - -#include "core/fxge/include/fx_ge.h" -#include "xfa/fde/fde_path.h" -#include "xfa/fgas/crt/fgas_memory.h" - -class CFDE_Path : public IFDE_Path, public CFX_Target { - public: - virtual void Release() { delete this; } - - virtual FX_BOOL StartFigure(); - virtual FX_BOOL CloseFigure(); - - virtual void AddBezier(const CFX_PointsF& points); - virtual void AddBeziers(const CFX_PointsF& points); - virtual void AddCurve(const CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension = 0.5f); - virtual void AddEllipse(const CFX_RectF& rect); - virtual void AddLines(const CFX_PointsF& points); - virtual void AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2); - virtual void AddPath(const IFDE_Path* pSrc, FX_BOOL bConnect); - virtual void AddPolygon(const CFX_PointsF& points); - virtual void AddRectangle(const CFX_RectF& rect); - virtual void GetBBox(CFX_RectF& bbox) const; - virtual void GetBBox(CFX_RectF& bbox, - FX_FLOAT fLineWidth, - FX_FLOAT fMiterLimit) const; - FX_PATHPOINT* AddPoints(int32_t iCount); - FX_PATHPOINT* GetLastPoint(int32_t iCount = 1) const; - FX_BOOL FigureClosed() const; - void MoveTo(FX_FLOAT fx, FX_FLOAT fy); - void LineTo(FX_FLOAT fx, FX_FLOAT fy); - void BezierTo(const CFX_PointF& p1, - const CFX_PointF& p2, - const CFX_PointF& p3); - void ArcTo(FX_BOOL bStart, - const CFX_RectF& rect, - FX_FLOAT startAngle, - FX_FLOAT endAngle); - void MoveTo(const CFX_PointF& p0) { MoveTo(p0.x, p0.y); } - void LineTo(const CFX_PointF& p1) { LineTo(p1.x, p1.y); } - void GetCurveTangents(const CFX_PointsF& points, - CFX_PointsF& tangents, - FX_BOOL bClosed, - FX_FLOAT fTension) const; - CFX_PathData m_Path; -}; - -#endif // XFA_FDE_FDE_GEOBJECT_H_ diff --git a/xfa/fde/fde_iterator.cpp b/xfa/fde/fde_iterator.cpp index 4356e22ee2..755bff543f 100644 --- a/xfa/fde/fde_iterator.cpp +++ b/xfa/fde/fde_iterator.cpp @@ -8,25 +8,26 @@ #include "xfa/fgas/crt/fgas_utils.h" -IFDE_VisualSetIterator* IFDE_VisualSetIterator::Create() { - return new CFDE_VisualSetIterator; -} CFDE_VisualSetIterator::CFDE_VisualSetIterator() : m_dwFilter(0) {} + CFDE_VisualSetIterator::~CFDE_VisualSetIterator() { m_CanvasStack.RemoveAll(); } + FX_BOOL CFDE_VisualSetIterator::AttachCanvas(IFDE_CanvasSet* pCanvas) { - FXSYS_assert(pCanvas != NULL); + FXSYS_assert(pCanvas); + m_CanvasStack.RemoveAll(); FDE_CANVASITEM canvas; - canvas.hCanvas = NULL; + canvas.hCanvas = nullptr; canvas.pCanvas = pCanvas; - canvas.hPos = pCanvas->GetFirstPosition(NULL); - if (canvas.hPos == NULL) { + canvas.hPos = pCanvas->GetFirstPosition(nullptr); + if (!canvas.hPos) return FALSE; - } + return m_CanvasStack.Push(canvas) == 0; } + FX_BOOL CFDE_VisualSetIterator::FilterObjects(uint32_t dwObjects) { if (m_CanvasStack.GetSize() == 0) return FALSE; @@ -37,30 +38,35 @@ FX_BOOL CFDE_VisualSetIterator::FilterObjects(uint32_t dwObjects) { m_dwFilter = dwObjects; FDE_CANVASITEM* pCanvas = m_CanvasStack.GetTopElement(); - FXSYS_assert(pCanvas != NULL && pCanvas->pCanvas != NULL); - pCanvas->hPos = pCanvas->pCanvas->GetFirstPosition(NULL); - return pCanvas->hPos != NULL; + FXSYS_assert(pCanvas && pCanvas->pCanvas); + + pCanvas->hPos = pCanvas->pCanvas->GetFirstPosition(nullptr); + return !!pCanvas->hPos; } + void CFDE_VisualSetIterator::Reset() { FilterObjects(m_dwFilter); } + FDE_HVISUALOBJ CFDE_VisualSetIterator::GetNext(IFDE_VisualSet*& pVisualSet, FDE_HVISUALOBJ* phCanvasObj, IFDE_CanvasSet** ppCanvasSet) { while (m_CanvasStack.GetSize() > 0) { FDE_CANVASITEM* pCanvas = m_CanvasStack.GetTopElement(); - FXSYS_assert(pCanvas != NULL && pCanvas->pCanvas != NULL); - if (pCanvas->hPos == NULL) { - if (m_CanvasStack.GetSize() == 1) { + FXSYS_assert(pCanvas && pCanvas->pCanvas); + + if (!pCanvas->hPos) { + if (m_CanvasStack.GetSize() == 1) break; - } + m_CanvasStack.Pop(); continue; } do { FDE_HVISUALOBJ hObj = pCanvas->pCanvas->GetNext( pCanvas->hCanvas, pCanvas->hPos, pVisualSet); - FXSYS_assert(hObj != NULL); + FXSYS_assert(hObj); + FDE_VISUALOBJTYPE eType = pVisualSet->GetType(); if (eType == FDE_VISUALOBJ_Canvas) { FDE_CANVASITEM canvas; @@ -72,22 +78,19 @@ FDE_HVISUALOBJ CFDE_VisualSetIterator::GetNext(IFDE_VisualSet*& pVisualSet, } uint32_t dwObj = (uint32_t)eType; if ((m_dwFilter & dwObj) != 0) { - if (ppCanvasSet) { + if (ppCanvasSet) *ppCanvasSet = pCanvas->pCanvas; - } - if (phCanvasObj) { + if (phCanvasObj) *phCanvasObj = pCanvas->hCanvas; - } return hObj; } - } while (pCanvas->hPos != NULL); - } - if (ppCanvasSet) { - *ppCanvasSet = NULL; + } while (pCanvas->hPos); } - if (phCanvasObj) { - *phCanvasObj = NULL; - } - pVisualSet = NULL; - return NULL; + if (ppCanvasSet) + *ppCanvasSet = nullptr; + if (phCanvasObj) + *phCanvasObj = nullptr; + + pVisualSet = nullptr; + return nullptr; } diff --git a/xfa/fde/fde_iterator.h b/xfa/fde/fde_iterator.h index 737fb8935f..4d089254ea 100644 --- a/xfa/fde/fde_iterator.h +++ b/xfa/fde/fde_iterator.h @@ -17,20 +17,20 @@ struct FDE_CANVASITEM { FX_POSITION hPos; }; -class CFDE_VisualSetIterator : public IFDE_VisualSetIterator, - public CFX_Target { +class CFDE_VisualSetIterator : public CFX_Target { public: CFDE_VisualSetIterator(); ~CFDE_VisualSetIterator(); - virtual void Release() { delete this; } - virtual FX_BOOL AttachCanvas(IFDE_CanvasSet* pCanvas); - virtual FX_BOOL FilterObjects(uint32_t dwObjects = 0xFFFFFFFF); + void Release() { delete this; } - virtual void Reset(); - virtual FDE_HVISUALOBJ GetNext(IFDE_VisualSet*& pVisualSet, - FDE_HVISUALOBJ* phCanvasObj = NULL, - IFDE_CanvasSet** ppCanvasSet = NULL); + FX_BOOL AttachCanvas(IFDE_CanvasSet* pCanvas); + FX_BOOL FilterObjects(uint32_t dwObjects = 0xFFFFFFFF); + + void Reset(); + FDE_HVISUALOBJ GetNext(IFDE_VisualSet*& pVisualSet, + FDE_HVISUALOBJ* phCanvasObj = NULL, + IFDE_CanvasSet** ppCanvasSet = NULL); protected: uint32_t m_dwFilter; diff --git a/xfa/fde/fde_path.h b/xfa/fde/fde_path.h deleted file mode 100644 index 41d2a66e0a..0000000000 --- a/xfa/fde/fde_path.h +++ /dev/null @@ -1,37 +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_FDE_PATH_H_ -#define XFA_FDE_FDE_PATH_H_ - -#include "core/fxcrt/include/fx_coordinates.h" -#include "core/fxcrt/include/fx_system.h" - -class IFDE_Path { - public: - static IFDE_Path* Create(); - virtual ~IFDE_Path() {} - virtual void Release() = 0; - virtual FX_BOOL StartFigure() = 0; - virtual FX_BOOL CloseFigure() = 0; - virtual void AddBezier(const CFX_PointsF& points) = 0; - virtual void AddBeziers(const CFX_PointsF& points) = 0; - virtual void AddCurve(const CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension = 0.5f) = 0; - virtual void AddEllipse(const CFX_RectF& rect) = 0; - virtual void AddLines(const CFX_PointsF& points) = 0; - virtual void AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) = 0; - virtual void AddPath(const IFDE_Path* pSrc, FX_BOOL bConnect) = 0; - virtual void AddPolygon(const CFX_PointsF& points) = 0; - virtual void AddRectangle(const CFX_RectF& rect) = 0; - virtual void GetBBox(CFX_RectF& bbox) const = 0; - virtual void GetBBox(CFX_RectF& bbox, - FX_FLOAT fLineWidth, - FX_FLOAT fMiterLimit) const = 0; -}; - -#endif // XFA_FDE_FDE_PATH_H_ diff --git a/xfa/fde/fde_render.cpp b/xfa/fde/fde_render.cpp index b4259f71d9..74c19f60cf 100644 --- a/xfa/fde/fde_render.cpp +++ b/xfa/fde/fde_render.cpp @@ -6,97 +6,13 @@ #include "xfa/fde/fde_render.h" +#include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" -#include "xfa/fde/fde_renderdevice.h" #include "xfa/fgas/crt/fgas_memory.h" #define FDE_PATHRENDER_Stroke 1 #define FDE_PATHRENDER_Fill 2 -namespace { - -class CFDE_RenderContext : public IFDE_RenderContext, public CFX_Target { - public: - CFDE_RenderContext(); - virtual ~CFDE_RenderContext(); - virtual void Release() { delete this; } - virtual FX_BOOL StartRender(IFDE_RenderDevice* pRenderDevice, - IFDE_CanvasSet* pCanvasSet, - const CFX_Matrix& tmDoc2Device); - virtual FDE_RENDERSTATUS GetStatus() const { return m_eStatus; } - virtual FDE_RENDERSTATUS DoRender(IFX_Pause* pPause = nullptr); - virtual void StopRender(); - void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); - FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, - FDE_HVISUALOBJ hObj, - FDE_HDEVICESTATE& hState); - void RestoreClip(FDE_HDEVICESTATE hState); - - protected: - FDE_RENDERSTATUS m_eStatus; - IFDE_RenderDevice* m_pRenderDevice; - CFDE_Brush* m_pBrush; - CFX_Matrix m_Transform; - FXTEXT_CHARPOS* m_pCharPos; - int32_t m_iCharPosCount; - IFDE_VisualSetIterator* m_pIterator; -}; - -} // namespace - -void FDE_GetPageMatrix(CFX_Matrix& pageMatrix, - const CFX_RectF& docPageRect, - const CFX_Rect& devicePageRect, - int32_t iRotate, - uint32_t dwCoordinatesType) { - FXSYS_assert(iRotate >= 0 && iRotate <= 3); - FX_BOOL bFlipX = (dwCoordinatesType & 0x01) != 0; - FX_BOOL bFlipY = (dwCoordinatesType & 0x02) != 0; - CFX_Matrix m; - m.Set((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0); - if (iRotate == 0 || iRotate == 2) { - m.a *= (FX_FLOAT)devicePageRect.width / docPageRect.width; - m.d *= (FX_FLOAT)devicePageRect.height / docPageRect.height; - } else { - m.a *= (FX_FLOAT)devicePageRect.height / docPageRect.width; - m.d *= (FX_FLOAT)devicePageRect.width / docPageRect.height; - } - m.Rotate(iRotate * 1.57079632675f); - switch (iRotate) { - case 0: - m.e = bFlipX ? (FX_FLOAT)devicePageRect.right() - : (FX_FLOAT)devicePageRect.left; - m.f = bFlipY ? (FX_FLOAT)devicePageRect.bottom() - : (FX_FLOAT)devicePageRect.top; - break; - case 1: - m.e = bFlipY ? (FX_FLOAT)devicePageRect.left - : (FX_FLOAT)devicePageRect.right(); - m.f = bFlipX ? (FX_FLOAT)devicePageRect.bottom() - : (FX_FLOAT)devicePageRect.top; - break; - case 2: - m.e = bFlipX ? (FX_FLOAT)devicePageRect.left - : (FX_FLOAT)devicePageRect.right(); - m.f = bFlipY ? (FX_FLOAT)devicePageRect.top - : (FX_FLOAT)devicePageRect.bottom(); - break; - case 3: - m.e = bFlipY ? (FX_FLOAT)devicePageRect.right() - : (FX_FLOAT)devicePageRect.left; - m.f = bFlipX ? (FX_FLOAT)devicePageRect.top - : (FX_FLOAT)devicePageRect.bottom(); - break; - default: - break; - } - pageMatrix = m; -} - -IFDE_RenderContext* IFDE_RenderContext::Create() { - return new CFDE_RenderContext; -} - CFDE_RenderContext::CFDE_RenderContext() : m_eStatus(FDE_RENDERSTATUS_Reset), m_pRenderDevice(nullptr), @@ -112,7 +28,7 @@ CFDE_RenderContext::~CFDE_RenderContext() { StopRender(); } -FX_BOOL CFDE_RenderContext::StartRender(IFDE_RenderDevice* pRenderDevice, +FX_BOOL CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice, IFDE_CanvasSet* pCanvasSet, const CFX_Matrix& tmDoc2Device) { if (m_pRenderDevice) @@ -125,10 +41,9 @@ FX_BOOL CFDE_RenderContext::StartRender(IFDE_RenderDevice* pRenderDevice, m_eStatus = FDE_RENDERSTATUS_Paused; m_pRenderDevice = pRenderDevice; m_Transform = tmDoc2Device; - if (!m_pIterator) { - m_pIterator = IFDE_VisualSetIterator::Create(); - FXSYS_assert(m_pIterator); - } + if (!m_pIterator) + m_pIterator = new CFDE_VisualSetIterator; + return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); } diff --git a/xfa/fde/fde_render.h b/xfa/fde/fde_render.h index 99e4bbe963..c28b4abd16 100644 --- a/xfa/fde/fde_render.h +++ b/xfa/fde/fde_render.h @@ -8,15 +8,12 @@ #define XFA_FDE_FDE_RENDER_H_ #include "core/fxcrt/include/fx_coordinates.h" +#include "xfa/fde/fde_gedevice.h" +#include "xfa/fde/fde_iterator.h" #include "xfa/fde/fde_visualset.h" -class IFDE_RenderDevice; +class CFDE_RenderDevice; -void FDE_GetPageMatrix(CFX_Matrix& pageMatrix, - const CFX_RectF& docPageRect, - const CFX_Rect& devicePageRect, - int32_t iRotate, - uint32_t dwCoordinatesType = 0); enum FDE_RENDERSTATUS { FDE_RENDERSTATUS_Reset = 0, FDE_RENDERSTATUS_Paused, @@ -24,17 +21,32 @@ enum FDE_RENDERSTATUS { FDE_RENDERSTATUS_Failed, }; -class IFDE_RenderContext { +class CFDE_RenderContext : public CFX_Target { public: - static IFDE_RenderContext* Create(); - virtual ~IFDE_RenderContext() {} - virtual void Release() = 0; - virtual FX_BOOL StartRender(IFDE_RenderDevice* pRenderDevice, - IFDE_CanvasSet* pCanvasSet, - const CFX_Matrix& tmDoc2Device) = 0; - virtual FDE_RENDERSTATUS GetStatus() const = 0; - virtual FDE_RENDERSTATUS DoRender(IFX_Pause* pPause = NULL) = 0; - virtual void StopRender() = 0; + CFDE_RenderContext(); + ~CFDE_RenderContext(); + + void Release() { delete this; } + FX_BOOL StartRender(CFDE_RenderDevice* pRenderDevice, + IFDE_CanvasSet* pCanvasSet, + const CFX_Matrix& tmDoc2Device); + FDE_RENDERSTATUS GetStatus() const { return m_eStatus; } + FDE_RENDERSTATUS DoRender(IFX_Pause* pPause = nullptr); + void StopRender(); + void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); + FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, + FDE_HVISUALOBJ hObj, + FDE_HDEVICESTATE& hState); + void RestoreClip(FDE_HDEVICESTATE hState); + + protected: + FDE_RENDERSTATUS m_eStatus; + CFDE_RenderDevice* m_pRenderDevice; + CFDE_Brush* m_pBrush; + CFX_Matrix m_Transform; + FXTEXT_CHARPOS* m_pCharPos; + int32_t m_iCharPosCount; + CFDE_VisualSetIterator* m_pIterator; }; #endif // XFA_FDE_FDE_RENDER_H_ diff --git a/xfa/fde/fde_renderdevice.h b/xfa/fde/fde_renderdevice.h deleted file mode 100644 index f0686597c7..0000000000 --- a/xfa/fde/fde_renderdevice.h +++ /dev/null @@ -1,110 +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_FDE_RENDERDEVICE_H_ -#define XFA_FDE_FDE_RENDERDEVICE_H_ - -#include "core/fxcrt/include/fx_coordinates.h" -#include "core/fxge/include/fx_font.h" -#include "core/fxge/include/fx_ge.h" -#include "xfa/fde/fde_path.h" -#include "xfa/fgas/font/fgas_font.h" - -class CFDE_Pen; -class CFDE_Brush; -class CFX_DIBitmap; -class CFX_DIBSource; - -typedef struct FDE_HDEVICESTATE_ { void* pData; } * FDE_HDEVICESTATE; - -class IFDE_RenderDevice { - public: - static IFDE_RenderDevice* Create(CFX_DIBitmap* pBitmap, - FX_BOOL bRgbByteOrder = FALSE); - static IFDE_RenderDevice* Create(CFX_RenderDevice* pDevice); - virtual ~IFDE_RenderDevice() {} - virtual void Release() = 0; - - virtual int32_t GetWidth() const = 0; - virtual int32_t GetHeight() const = 0; - virtual FDE_HDEVICESTATE SaveState() = 0; - virtual void RestoreState(FDE_HDEVICESTATE hState) = 0; - virtual FX_BOOL SetClipPath(const IFDE_Path* pClip) = 0; - virtual IFDE_Path* GetClipPath() const = 0; - virtual FX_BOOL SetClipRect(const CFX_RectF& rtClip) = 0; - virtual const CFX_RectF& GetClipRect() = 0; - - virtual FX_FLOAT GetDpiX() const = 0; - virtual FX_FLOAT GetDpiY() const = 0; - - virtual FX_BOOL DrawImage(CFX_DIBSource* pDib, - const CFX_RectF* pSrcRect, - const CFX_RectF& dstRect, - const CFX_Matrix* pImgMatrix = NULL, - const CFX_Matrix* pDevMatrix = NULL) = 0; - virtual FX_BOOL DrawString(CFDE_Brush* pBrush, - IFX_Font* pFont, - const FXTEXT_CHARPOS* pCharPos, - int32_t iCount, - FX_FLOAT fFontSize, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawBezier(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_PointF& pt3, - const CFX_PointF& pt4, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawCurve(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - FX_BOOL bClosed, - FX_FLOAT fTension = 0.5f, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawEllipse(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawLines(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawLine(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointF& pt1, - const CFX_PointF& pt2, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawPath(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawPolygon(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL DrawRectangle(CFDE_Pen* pPen, - FX_FLOAT fPenWidth, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL FillClosedCurve(CFDE_Brush* pBrush, - const CFX_PointsF& points, - FX_FLOAT fTension = 0.5f, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL FillEllipse(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL FillPath(CFDE_Brush* pBrush, - const IFDE_Path* pPath, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL FillPolygon(CFDE_Brush* pBrush, - const CFX_PointsF& points, - const CFX_Matrix* pMatrix = NULL) = 0; - virtual FX_BOOL FillRectangle(CFDE_Brush* pBrush, - const CFX_RectF& rect, - const CFX_Matrix* pMatrix = NULL) = 0; -}; - -#endif // XFA_FDE_FDE_RENDERDEVICE_H_ diff --git a/xfa/fde/fde_visualset.h b/xfa/fde/fde_visualset.h index 778d2dcb7a..64f98b9b23 100644 --- a/xfa/fde/fde_visualset.h +++ b/xfa/fde/fde_visualset.h @@ -11,8 +11,8 @@ #include "core/fxcrt/include/fx_system.h" #include "core/fxge/include/fx_dib.h" #include "core/fxge/include/fx_ge.h" +#include "xfa/fde/cfde_path.h" #include "xfa/fde/fde_object.h" -#include "xfa/fde/fde_path.h" #include "xfa/fgas/crt/fgas_memory.h" #include "xfa/fgas/font/fgas_font.h" @@ -57,17 +57,4 @@ class IFDE_TextSet : public IFDE_VisualSet { CFX_RectFArray& rtArray) = 0; }; -class IFDE_VisualSetIterator { - public: - static IFDE_VisualSetIterator* Create(); - virtual ~IFDE_VisualSetIterator() {} - virtual void Release() = 0; - virtual FX_BOOL AttachCanvas(IFDE_CanvasSet* pCanvas) = 0; - virtual FX_BOOL FilterObjects(uint32_t dwObjects = 0xFFFFFFFF) = 0; - virtual void Reset() = 0; - virtual FDE_HVISUALOBJ GetNext(IFDE_VisualSet*& pVisualSet, - FDE_HVISUALOBJ* phCanvasObj = NULL, - IFDE_CanvasSet** ppCanvasSet = NULL) = 0; -}; - #endif // XFA_FDE_FDE_VISUALSET_H_ diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp index 7895b785f3..a18fbbd0ae 100644 --- a/xfa/fde/tto/fde_textout.cpp +++ b/xfa/fde/tto/fde_textout.cpp @@ -10,180 +10,13 @@ #include "core/fxcrt/include/fx_coordinates.h" #include "core/fxcrt/include/fx_system.h" +#include "xfa/fde/cfde_path.h" +#include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" -#include "xfa/fde/fde_renderdevice.h" #include "xfa/fgas/crt/fgas_memory.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/layout/fgas_textbreak.h" -namespace { - -struct FDE_TTOPIECE { - public: - int32_t iStartChar; - int32_t iChars; - uint32_t dwCharStyles; - CFX_RectF rtPiece; -}; -typedef FDE_TTOPIECE* FDE_LPTTOPIECE; -typedef CFX_MassArrayTemplate CFDE_TTOPieceArray; - -class CFDE_TTOLine : public CFX_Target { - public: - CFDE_TTOLine(); - CFDE_TTOLine(const CFDE_TTOLine& ttoLine); - ~CFDE_TTOLine(); - int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); - int32_t GetSize() const; - FDE_LPTTOPIECE GetPtrAt(int32_t index); - void RemoveLast(int32_t iCount); - void RemoveAll(FX_BOOL bLeaveMemory); - FX_BOOL m_bNewReload; - CFDE_TTOPieceArray m_pieces; - - protected: - int32_t m_iPieceCount; -}; -typedef CFX_ObjectMassArrayTemplate CFDE_TTOLineArray; - -class CFDE_TextOut : public IFDE_TextOut, public CFX_Target { - public: - CFDE_TextOut(); - ~CFDE_TextOut(); - virtual void Release() { delete this; } - virtual void SetFont(IFX_Font* pFont); - virtual void SetFontSize(FX_FLOAT fFontSize); - virtual void SetTextColor(FX_ARGB color); - virtual void SetStyles(uint32_t dwStyles); - virtual void SetTabWidth(FX_FLOAT fTabWidth); - virtual void SetEllipsisString(const CFX_WideString& wsEllipsis); - virtual void SetParagraphBreakChar(FX_WCHAR wch); - virtual void SetAlignment(int32_t iAlignment); - virtual void SetLineSpace(FX_FLOAT fLineSpace); - virtual void SetDIBitmap(CFX_DIBitmap* pDIB); - virtual void SetRenderDevice(CFX_RenderDevice* pDevice); - virtual void SetClipRect(const CFX_Rect& rtClip); - virtual void SetClipRect(const CFX_RectF& rtClip); - virtual void SetMatrix(const CFX_Matrix& matrix); - virtual void SetLineBreakTolerance(FX_FLOAT fTolerance); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Size& size); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Rect& rect); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect); - - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - int32_t x, - int32_t y); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_Rect& rect); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect); - - virtual void SetLogicClipRect(const CFX_RectF& rtClip); - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size); - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect); - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y); - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect); - virtual int32_t GetTotalLines(); - - protected: - void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); - FX_BOOL RetrieveLineWidth(uint32_t dwBreakStatus, - FX_FLOAT& fStartPos, - FX_FLOAT& fWidth, - FX_FLOAT& fHeight); - void SetLineWidth(CFX_RectF& rect); - void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect, - const CFX_RectF& rtClip); - void LoadText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect); - void LoadEllipsis(); - void ExpandBuffer(int32_t iSize, int32_t iType); - void RetrieveEllPieces(int32_t*& pCharWidths); - - void Reload(const CFX_RectF& rect); - void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); - FX_BOOL RetriecePieces(uint32_t dwBreakStatus, - int32_t& iStartChar, - int32_t& iPieceWidths, - FX_BOOL bReload, - const CFX_RectF& rect); - void AppendPiece(const FDE_TTOPIECE& ttoPiece, - FX_BOOL bNeedReload, - FX_BOOL bEnd); - void ReplaceWidthEllipsis(); - void DoAlignment(const CFX_RectF& rect); - void OnDraw(const CFX_RectF& rtClip); - int32_t GetDisplayPos(FDE_LPTTOPIECE pPiece); - int32_t GetCharRects(FDE_LPTTOPIECE pPiece); - - FX_TXTRUN ToTextRun(const FDE_LPTTOPIECE pPiece); - void DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen); - - CFX_TxtBreak* m_pTxtBreak; - IFX_Font* m_pFont; - FX_FLOAT m_fFontSize; - FX_FLOAT m_fLineSpace; - FX_FLOAT m_fLinePos; - FX_FLOAT m_fTolerance; - int32_t m_iAlignment; - int32_t m_iTxtBkAlignment; - int32_t* m_pCharWidths; - int32_t m_iChars; - int32_t* m_pEllCharWidths; - int32_t m_iEllChars; - FX_WCHAR m_wParagraphBkChar; - FX_ARGB m_TxtColor; - uint32_t m_dwStyles; - uint32_t m_dwTxtBkStyles; - CFX_WideString m_wsEllipsis; - FX_BOOL m_bElliChanged; - int32_t m_iEllipsisWidth; - CFX_WideString m_wsText; - CFX_RectF m_rtClip; - CFX_RectF m_rtLogicClip; - CFX_Matrix m_Matrix; - CFDE_TTOLineArray m_ttoLines; - int32_t m_iCurLine; - int32_t m_iCurPiece; - int32_t m_iTotalLines; - FXTEXT_CHARPOS* m_pCharPos; - int32_t m_iCharPosSize; - IFDE_RenderDevice* m_pRenderDevice; - CFX_Int32Array m_hotKeys; - CFX_RectFArray m_rectArray; -}; - -} // namespace - -IFDE_TextOut* IFDE_TextOut::Create() { - return new CFDE_TextOut; -} CFDE_TextOut::CFDE_TextOut() : m_pFont(NULL), m_fFontSize(12.0f), @@ -299,19 +132,25 @@ void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { m_fLineSpace = fLineSpace; } void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { - FXSYS_assert(pDIB != NULL); - if (m_pRenderDevice != NULL) { + FXSYS_assert(pDIB); + + if (m_pRenderDevice) m_pRenderDevice->Release(); - } - m_pRenderDevice = IFDE_RenderDevice::Create(pDIB); + + CFX_FxgeDevice* device = new CFX_FxgeDevice; + device->Attach(pDIB, 0, FALSE); + m_pRenderDevice = new CFDE_RenderDevice(device, FALSE); } + void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { - FXSYS_assert(pDevice != NULL); - if (m_pRenderDevice != NULL) { + FXSYS_assert(pDevice); + + if (m_pRenderDevice) m_pRenderDevice->Release(); - } - m_pRenderDevice = IFDE_RenderDevice::Create(pDevice); + + m_pRenderDevice = new CFDE_RenderDevice(pDevice, FALSE); } + void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); @@ -834,7 +673,7 @@ void CFDE_TextOut::ReplaceWidthEllipsis() { int32_t iCharCount = 0; int32_t iPiece = pLine->GetSize(); while (iPiece-- > 0) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(iPiece); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); if (pPiece == NULL) { break; } @@ -876,7 +715,7 @@ void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { const FX_WCHAR* pwsStr = m_wsText.c_str(); FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); int32_t iPieceWidths = 0; - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(0); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); int32_t iStartChar = pPiece->iStartChar; m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; int32_t iPieceCount = pLine->GetSize(); @@ -911,7 +750,7 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { return; } CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(iLines - 1); - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(0); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); if (pPiece == NULL) { return; } @@ -931,7 +770,7 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); int32_t iPieces = pLine->GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); if (bVertical) { pPiece->rtPiece.left += fInc; } else { @@ -959,7 +798,7 @@ void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); int32_t iPieces = pLine->GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); if (pPiece == NULL) { continue; } @@ -976,19 +815,19 @@ void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { delete pPen; } -int32_t CFDE_TextOut::GetDisplayPos(FDE_LPTTOPIECE pPiece) { +int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { FX_TXTRUN tr = ToTextRun(pPiece); ExpandBuffer(tr.iLength, 2); return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); } -int32_t CFDE_TextOut::GetCharRects(FDE_LPTTOPIECE pPiece) { +int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { FX_TXTRUN tr = ToTextRun(pPiece); m_rectArray.RemoveAll(); return m_pTxtBreak->GetCharRects(&tr, m_rectArray); } -FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece) { +FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { FX_TXTRUN tr; tr.wsStr = m_wsText + pPiece->iStartChar; tr.pWidths = m_pCharWidths + pPiece->iStartChar; @@ -1002,7 +841,7 @@ FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece) { return tr; } -void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen) { +void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); @@ -1014,7 +853,7 @@ void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen) { pPen = new CFDE_Pen; pPen->SetColor(m_TxtColor); } - IFDE_Path* pPath = IFDE_Path::Create(); + CFDE_Path* pPath = new CFDE_Path; int32_t iLineCount = 0; CFX_RectF rtText = pPiece->rtPiece; CFX_PointF pt1, pt2; @@ -1100,7 +939,7 @@ int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { int32_t CFDE_TTOLine::GetSize() const { return m_iPieceCount; } -FDE_LPTTOPIECE CFDE_TTOLine::GetPtrAt(int32_t index) { +FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { if (index >= m_iPieceCount) { return NULL; } diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h index e20c00a2e0..e3e87a780a 100644 --- a/xfa/fde/tto/fde_textout.h +++ b/xfa/fde/tto/fde_textout.h @@ -9,7 +9,10 @@ #include "core/fxge/include/fx_dib.h" #include "core/fxge/include/fx_ge.h" +#include "xfa/fde/fde_object.h" +#include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/font/fgas_font.h" +#include "xfa/fgas/layout/fgas_textbreak.h" #define FDE_TTOSTYLE_Underline 0x0001 #define FDE_TTOSTYLE_Strikeout 0x0002 @@ -36,67 +39,149 @@ #define FDE_TTOALIGNMENT_BottomRight 10 #define FDE_TTOALIGNMENT_BottomAuto 11 -class IFDE_TextOut { +class CFDE_RenderDevice; +class CFX_TxtBreak; + +struct FDE_TTOPIECE { + int32_t iStartChar; + int32_t iChars; + uint32_t dwCharStyles; + CFX_RectF rtPiece; +}; +typedef CFX_MassArrayTemplate CFDE_TTOPieceArray; + +class CFDE_TTOLine : public CFX_Target { + public: + CFDE_TTOLine(); + CFDE_TTOLine(const CFDE_TTOLine& ttoLine); + ~CFDE_TTOLine(); + int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); + int32_t GetSize() const; + FDE_TTOPIECE* GetPtrAt(int32_t index); + void RemoveLast(int32_t iCount); + void RemoveAll(FX_BOOL bLeaveMemory); + + FX_BOOL m_bNewReload; + CFDE_TTOPieceArray m_pieces; + + protected: + int32_t m_iPieceCount; +}; +typedef CFX_ObjectMassArrayTemplate CFDE_TTOLineArray; + +class CFDE_TextOut : public CFX_Target { public: - static IFDE_TextOut* Create(); - virtual ~IFDE_TextOut() {} - virtual void Release() = 0; - virtual void SetFont(IFX_Font* pFont) = 0; - virtual void SetFontSize(FX_FLOAT fFontSize) = 0; - virtual void SetTextColor(FX_ARGB color) = 0; - virtual void SetStyles(uint32_t dwStyles) = 0; - virtual void SetTabWidth(FX_FLOAT fTabWidth) = 0; - virtual void SetEllipsisString(const CFX_WideString& wsEllipsis) = 0; - virtual void SetParagraphBreakChar(FX_WCHAR wch) = 0; - virtual void SetAlignment(int32_t iAlignment) = 0; - virtual void SetLineSpace(FX_FLOAT fLineSpace) = 0; - virtual void SetDIBitmap(CFX_DIBitmap* pDIB) = 0; - virtual void SetRenderDevice(CFX_RenderDevice* pDevice) = 0; - virtual void SetClipRect(const CFX_Rect& rtClip) = 0; - virtual void SetClipRect(const CFX_RectF& rtClip) = 0; - virtual void SetMatrix(const CFX_Matrix& matrix) = 0; - virtual void SetLineBreakTolerance(FX_FLOAT fTolerance) = 0; - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Size& size) = 0; - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size) = 0; - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Rect& rect) = 0; - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect) = 0; - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - int32_t x, - int32_t y) = 0; - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y) = 0; - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_Rect& rect) = 0; - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect) = 0; - virtual void SetLogicClipRect(const CFX_RectF& rtClip) = 0; - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size) = 0; - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect) = 0; - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y) = 0; - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect) = 0; - virtual int32_t GetTotalLines() = 0; + CFDE_TextOut(); + ~CFDE_TextOut(); + + void Release() { delete this; } + void SetFont(IFX_Font* pFont); + void SetFontSize(FX_FLOAT fFontSize); + void SetTextColor(FX_ARGB color); + void SetStyles(uint32_t dwStyles); + void SetTabWidth(FX_FLOAT fTabWidth); + void SetEllipsisString(const CFX_WideString& wsEllipsis); + void SetParagraphBreakChar(FX_WCHAR wch); + void SetAlignment(int32_t iAlignment); + void SetLineSpace(FX_FLOAT fLineSpace); + void SetDIBitmap(CFX_DIBitmap* pDIB); + void SetRenderDevice(CFX_RenderDevice* pDevice); + void SetClipRect(const CFX_Rect& rtClip); + void SetClipRect(const CFX_RectF& rtClip); + void SetMatrix(const CFX_Matrix& matrix); + void SetLineBreakTolerance(FX_FLOAT fTolerance); + void CalcSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_Size& size); + void CalcSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_SizeF& size); + void CalcSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_Rect& rect); + void CalcSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); + + void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, int32_t x, int32_t y); + void DrawText(const FX_WCHAR* pwsStr, + int32_t iLength, + FX_FLOAT x, + FX_FLOAT y); + void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_Rect& rect); + void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect); + + void SetLogicClipRect(const CFX_RectF& rtClip); + void CalcLogicSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_SizeF& size); + void CalcLogicSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); + void DrawLogicText(const FX_WCHAR* pwsStr, + int32_t iLength, + FX_FLOAT x, + FX_FLOAT y); + void DrawLogicText(const FX_WCHAR* pwsStr, + int32_t iLength, + const CFX_RectF& rect); + int32_t GetTotalLines(); + + protected: + void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); + FX_BOOL RetrieveLineWidth(uint32_t dwBreakStatus, + FX_FLOAT& fStartPos, + FX_FLOAT& fWidth, + FX_FLOAT& fHeight); + void SetLineWidth(CFX_RectF& rect); + void DrawText(const FX_WCHAR* pwsStr, + int32_t iLength, + const CFX_RectF& rect, + const CFX_RectF& rtClip); + void LoadText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect); + void LoadEllipsis(); + void ExpandBuffer(int32_t iSize, int32_t iType); + void RetrieveEllPieces(int32_t*& pCharWidths); + + void Reload(const CFX_RectF& rect); + void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); + FX_BOOL RetriecePieces(uint32_t dwBreakStatus, + int32_t& iStartChar, + int32_t& iPieceWidths, + FX_BOOL bReload, + const CFX_RectF& rect); + void AppendPiece(const FDE_TTOPIECE& ttoPiece, + FX_BOOL bNeedReload, + FX_BOOL bEnd); + void ReplaceWidthEllipsis(); + void DoAlignment(const CFX_RectF& rect); + void OnDraw(const CFX_RectF& rtClip); + int32_t GetDisplayPos(FDE_TTOPIECE* pPiece); + int32_t GetCharRects(const FDE_TTOPIECE* pPiece); + + FX_TXTRUN ToTextRun(const FDE_TTOPIECE* pPiece); + void DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen); + + CFX_TxtBreak* m_pTxtBreak; + IFX_Font* m_pFont; + FX_FLOAT m_fFontSize; + FX_FLOAT m_fLineSpace; + FX_FLOAT m_fLinePos; + FX_FLOAT m_fTolerance; + int32_t m_iAlignment; + int32_t m_iTxtBkAlignment; + int32_t* m_pCharWidths; + int32_t m_iChars; + int32_t* m_pEllCharWidths; + int32_t m_iEllChars; + FX_WCHAR m_wParagraphBkChar; + FX_ARGB m_TxtColor; + uint32_t m_dwStyles; + uint32_t m_dwTxtBkStyles; + CFX_WideString m_wsEllipsis; + FX_BOOL m_bElliChanged; + int32_t m_iEllipsisWidth; + CFX_WideString m_wsText; + CFX_RectF m_rtClip; + CFX_RectF m_rtLogicClip; + CFX_Matrix m_Matrix; + CFDE_TTOLineArray m_ttoLines; + int32_t m_iCurLine; + int32_t m_iCurPiece; + int32_t m_iTotalLines; + FXTEXT_CHARPOS* m_pCharPos; + int32_t m_iCharPosSize; + CFDE_RenderDevice* m_pRenderDevice; + CFX_Int32Array m_hotKeys; + CFX_RectFArray m_rectArray; }; #endif // XFA_FDE_TTO_FDE_TEXTOUT_H_ diff --git a/xfa/fee/fde_txtedtengine.cpp b/xfa/fee/fde_txtedtengine.cpp index ac3c74f620..adb28ea081 100644 --- a/xfa/fee/fde_txtedtengine.cpp +++ b/xfa/fee/fde_txtedtengine.cpp @@ -1509,7 +1509,7 @@ FX_BOOL CFDE_TxtEdtEngine::MoveEnd() { } FX_BOOL CFDE_TxtEdtEngine::IsFitArea(CFX_WideString& wsText) { - IFDE_TextOut* pTextOut = IFDE_TextOut::Create(); + CFDE_TextOut* pTextOut = new CFDE_TextOut; pTextOut->SetLineSpace(m_Param.fLineSpace); pTextOut->SetFont(m_Param.pFont); pTextOut->SetFontSize(m_Param.fFontSize); diff --git a/xfa/fwl/basewidget/fwl_editimp.cpp b/xfa/fwl/basewidget/fwl_editimp.cpp index d25fd09d29..54e8abcb8b 100644 --- a/xfa/fwl/basewidget/fwl_editimp.cpp +++ b/xfa/fwl/basewidget/fwl_editimp.cpp @@ -9,8 +9,8 @@ #include #include +#include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_render.h" -#include "xfa/fde/fde_renderdevice.h" #include "xfa/fee/ifde_txtedtpage.h" #include "xfa/fwl/basewidget/fwl_caretimp.h" #include "xfa/fwl/basewidget/fwl_comboboximp.h" @@ -1039,12 +1039,8 @@ void CFWL_EditImp::DrawContent(CFX_Graphics* pGraphics, CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice(); if (!pRenderDev) return; - IFDE_RenderDevice* pRenderDevice = IFDE_RenderDevice::Create(pRenderDev); - if (!pRenderDevice) - return; - IFDE_RenderContext* pRenderContext = IFDE_RenderContext::Create(); - if (!pRenderContext) - return; + CFDE_RenderDevice* pRenderDevice = new CFDE_RenderDevice(pRenderDev, FALSE); + CFDE_RenderContext* pRenderContext = new CFDE_RenderContext; pRenderDevice->SetClipRect(rtClip); pRenderContext->StartRender(pRenderDevice, pPage, mt); pRenderContext->DoRender(NULL); diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index 1ce5d46caf..2fc8036763 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -206,7 +206,7 @@ FX_ERR CFWL_WidgetTP::InitTTO() { } m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(FX_WSTRC(L"Helvetica"), 0, 0); - m_pTextOut = IFDE_TextOut::Create(); + m_pTextOut = new CFDE_TextOut; m_pTextOut->SetFont(m_pFDEFont); m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h index bbb3fd7ee6..4e640370b8 100644 --- a/xfa/fwl/theme/cfwl_widgettp.h +++ b/xfa/fwl/theme/cfwl_widgettp.h @@ -20,13 +20,13 @@ enum class CFWL_WidgetCapacity { None = 0, Today, + Sun, Mon, Tue, Wed, Thu, Fri, Sat, - Sun, January, February, @@ -92,7 +92,7 @@ enum class CFWL_WidgetCapacity { }; class IFWL_Widget; -class IFDE_TextOut; +class CFDE_TextOut; class IFX_Font; class IFX_FontMgr; class CFWL_ArrowData; @@ -217,7 +217,7 @@ class CFWL_WidgetTP { FWLTHEME_STATE eState, CFX_Matrix* pMatrix = NULL); uint32_t m_dwRefCount; - IFDE_TextOut* m_pTextOut; + CFDE_TextOut* m_pTextOut; IFX_Font* m_pFDEFont; FX_FLOAT m_fValue; uint32_t m_dwValue; diff --git a/xfa/fxfa/app/xfa_ffpageview.cpp b/xfa/fxfa/app/xfa_ffpageview.cpp index fe2e3ab4b4..a5217abe7a 100644 --- a/xfa/fxfa/app/xfa_ffpageview.cpp +++ b/xfa/fxfa/app/xfa_ffpageview.cpp @@ -18,6 +18,58 @@ #include "xfa/fxfa/include/xfa_ffdocview.h" #include "xfa/fxfa/include/xfa_ffwidget.h" +namespace { + +void GetPageMatrix(CFX_Matrix& pageMatrix, + const CFX_RectF& docPageRect, + const CFX_Rect& devicePageRect, + int32_t iRotate, + uint32_t dwCoordinatesType) { + FXSYS_assert(iRotate >= 0 && iRotate <= 3); + FX_BOOL bFlipX = (dwCoordinatesType & 0x01) != 0; + FX_BOOL bFlipY = (dwCoordinatesType & 0x02) != 0; + CFX_Matrix m; + m.Set((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0); + if (iRotate == 0 || iRotate == 2) { + m.a *= (FX_FLOAT)devicePageRect.width / docPageRect.width; + m.d *= (FX_FLOAT)devicePageRect.height / docPageRect.height; + } else { + m.a *= (FX_FLOAT)devicePageRect.height / docPageRect.width; + m.d *= (FX_FLOAT)devicePageRect.width / docPageRect.height; + } + m.Rotate(iRotate * 1.57079632675f); + switch (iRotate) { + case 0: + m.e = bFlipX ? (FX_FLOAT)devicePageRect.right() + : (FX_FLOAT)devicePageRect.left; + m.f = bFlipY ? (FX_FLOAT)devicePageRect.bottom() + : (FX_FLOAT)devicePageRect.top; + break; + case 1: + m.e = bFlipY ? (FX_FLOAT)devicePageRect.left + : (FX_FLOAT)devicePageRect.right(); + m.f = bFlipX ? (FX_FLOAT)devicePageRect.bottom() + : (FX_FLOAT)devicePageRect.top; + break; + case 2: + m.e = bFlipX ? (FX_FLOAT)devicePageRect.left + : (FX_FLOAT)devicePageRect.right(); + m.f = bFlipY ? (FX_FLOAT)devicePageRect.top + : (FX_FLOAT)devicePageRect.bottom(); + break; + case 3: + m.e = bFlipY ? (FX_FLOAT)devicePageRect.right() + : (FX_FLOAT)devicePageRect.left; + m.f = bFlipX ? (FX_FLOAT)devicePageRect.top + : (FX_FLOAT)devicePageRect.bottom(); + break; + default: + break; + } + pageMatrix = m; +} + +} // namespace CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea) : CXFA_ContainerLayoutItem(pPageArea), m_pDocView(pDocView) {} @@ -43,7 +95,7 @@ void CXFA_FFPageView::GetDisplayMatrix(CFX_Matrix& mt, GetPageSize(sz); CFX_RectF fdePage; fdePage.Set(0, 0, sz.x, sz.y); - FDE_GetPageMatrix(mt, fdePage, rtDisp, iRotate, 0); + GetPageMatrix(mt, fdePage, rtDisp, iRotate, 0); } IXFA_WidgetIterator* CXFA_FFPageView::CreateWidgetIterator( diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index b1214dd685..561db255d8 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -142,7 +142,7 @@ class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { } CXFA_TextLayout* m_pCapTextLayout; CXFA_TextProvider* m_pCapTextProvider; - IFDE_TextOut* m_pTextOut; + CFDE_TextOut* m_pTextOut; CFX_FloatArray* m_pFieldSplitArray; }; class CXFA_TextEditData : public CXFA_FieldLayoutData { @@ -882,9 +882,12 @@ void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { if (wsLast == wcEnter) { wsText = wsText + wcEnter; } - if (!((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut) { - ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut = IFDE_TextOut::Create(); - IFDE_TextOut* pTextOut = ((CXFA_FieldLayoutData*)m_pLayoutData)->m_pTextOut; + + CXFA_FieldLayoutData* layoutData = + static_cast(m_pLayoutData); + if (!layoutData->m_pTextOut) { + layoutData->m_pTextOut = new CFDE_TextOut; + CFDE_TextOut* pTextOut = layoutData->m_pTextOut; pTextOut->SetFont(GetFDEFont()); pTextOut->SetFontSize(fFontSize); pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); @@ -895,8 +898,8 @@ void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { } pTextOut->SetStyles(dwStyles); } - ((CXFA_FieldLayoutData*)m_pLayoutData) - ->m_pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), size); + layoutData->m_pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), + size); } FX_BOOL CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { if (size.x > 0) { diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp index 82cabcc678..462c7cb090 100644 --- a/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/xfa/fxfa/app/xfa_fwltheme.cpp @@ -77,7 +77,7 @@ CXFA_FWLTheme::~CXFA_FWLTheme() { delete m_pBarcodeTP; } FWL_ERR CXFA_FWLTheme::Initialize() { - m_pTextOut = IFDE_TextOut::Create(); + m_pTextOut = new CFDE_TextOut; for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts); ++i) { m_pCalendarFont = IFX_Font::LoadFont(g_FWLTheme_CalFonts[i], 0, 0, diff --git a/xfa/fxfa/app/xfa_fwltheme.h b/xfa/fxfa/app/xfa_fwltheme.h index 5fda005a74..75885a5a9e 100644 --- a/xfa/fxfa/app/xfa_fwltheme.h +++ b/xfa/fxfa/app/xfa_fwltheme.h @@ -78,7 +78,7 @@ class CXFA_FWLTheme : public IFWL_ThemeProvider { CFWL_PushButtonTP* m_pPushButtonTP; CFWL_CaretTP* m_pCaretTP; CFWL_BarcodeTP* m_pBarcodeTP; - IFDE_TextOut* m_pTextOut; + CFDE_TextOut* m_pTextOut; FX_FLOAT m_fCapacity; uint32_t m_dwCapacity; IFX_Font* m_pCalendarFont; diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp index 532d6f54ce..c0a8895bc7 100644 --- a/xfa/fxfa/app/xfa_textlayout.cpp +++ b/xfa/fxfa/app/xfa_textlayout.cpp @@ -9,7 +9,9 @@ #include #include "core/fxcrt/include/fx_ext.h" +#include "xfa/fde/cfde_path.h" #include "xfa/fde/css/fde_csscache.h" +#include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fgas/crt/fgas_algorithm.h" @@ -1216,10 +1218,10 @@ FX_BOOL CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, const CFX_Matrix& tmDoc2Device, const CFX_RectF& rtClip, int32_t iBlock) { - IFDE_RenderDevice* pDevice = IFDE_RenderDevice::Create(pFxDevice); - if (pDevice == NULL) { + if (!pFxDevice) return FALSE; - } + + CFDE_RenderDevice* pDevice = new CFDE_RenderDevice(pFxDevice, FALSE); FDE_HDEVICESTATE state = pDevice->SaveState(); pDevice->SetClipRect(rtClip); CFDE_Brush* pSolidBrush = new CFDE_Brush; @@ -1838,7 +1840,7 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus, } m_iLines++; } -void CXFA_TextLayout::RenderString(IFDE_RenderDevice* pDevice, +void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, CFDE_Brush* pBrush, CXFA_PieceLine* pPieceLine, int32_t iPiece, @@ -1853,7 +1855,7 @@ void CXFA_TextLayout::RenderString(IFDE_RenderDevice* pDevice, } pPieceLine->m_charCounts.Add(iCount); } -void CXFA_TextLayout::RenderPath(IFDE_RenderDevice* pDevice, +void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, CFDE_Pen* pPen, CXFA_PieceLine* pPieceLine, int32_t iPiece, @@ -1866,7 +1868,7 @@ void CXFA_TextLayout::RenderPath(IFDE_RenderDevice* pDevice, return; } pPen->SetColor(pPiece->dwColor); - IFDE_Path* pPath = IFDE_Path::Create(); + CFDE_Path* pPath = new CFDE_Path; int32_t iChars = GetDisplayPos(pPiece, pCharPos); if (iChars > 0) { CFX_PointF pt1, pt2; diff --git a/xfa/fxfa/app/xfa_textlayout.h b/xfa/fxfa/app/xfa_textlayout.h index 88b29e2cd4..9c3184b48b 100644 --- a/xfa/fxfa/app/xfa_textlayout.h +++ b/xfa/fxfa/app/xfa_textlayout.h @@ -8,7 +8,7 @@ #define XFA_FXFA_APP_XFA_TEXTLAYOUT_H_ #include "xfa/fde/css/fde_css.h" -#include "xfa/fde/fde_renderdevice.h" +#include "xfa/fde/fde_gedevice.h" #include "xfa/fgas/layout/fgas_rtfbreak.h" #include "xfa/fxfa/include/xfa_ffdoc.h" #include "xfa/fxfa/parser/xfa_object.h" @@ -375,13 +375,13 @@ class CXFA_TextLayout { FX_BOOL IsEnd(FX_BOOL bSavePieces); void ProcessText(CFX_WideString& wsText); void UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom); - void RenderString(IFDE_RenderDevice* pDevice, + void RenderString(CFDE_RenderDevice* pDevice, CFDE_Brush* pBrush, CXFA_PieceLine* pPieceLine, int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device); - void RenderPath(IFDE_RenderDevice* pDevice, + void RenderPath(CFDE_RenderDevice* pDevice, CFDE_Pen* pPen, CXFA_PieceLine* pPieceLine, int32_t iPiece, -- cgit v1.2.3