diff options
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/cfde_path.cpp (renamed from xfa/fde/fde_geobject.cpp) | 103 | ||||
-rw-r--r-- | xfa/fde/cfde_path.h (renamed from xfa/fde/fde_geobject.h) | 45 | ||||
-rw-r--r-- | xfa/fde/fde_gedevice.cpp | 183 | ||||
-rw-r--r-- | xfa/fde/fde_gedevice.h | 169 | ||||
-rw-r--r-- | xfa/fde/fde_iterator.cpp | 61 | ||||
-rw-r--r-- | xfa/fde/fde_iterator.h | 18 | ||||
-rw-r--r-- | xfa/fde/fde_path.h | 37 | ||||
-rw-r--r-- | xfa/fde/fde_render.cpp | 95 | ||||
-rw-r--r-- | xfa/fde/fde_render.h | 44 | ||||
-rw-r--r-- | xfa/fde/fde_renderdevice.h | 110 | ||||
-rw-r--r-- | xfa/fde/fde_visualset.h | 15 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.cpp | 215 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.h | 205 |
13 files changed, 501 insertions, 799 deletions
diff --git a/xfa/fde/fde_geobject.cpp b/xfa/fde/cfde_path.cpp index f4aede0ee4..7ea458d485 100644 --- a/xfa/fde/fde_geobject.cpp +++ b/xfa/fde/cfde_path.cpp @@ -4,57 +4,59 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/fde_geobject.h" +#include "xfa/fde/cfde_path.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) { + if (pPoint) pPoint->m_Flag |= FXPT_CLOSEFIGURE; - } return TRUE; } + FX_PATHPOINT* CFDE_Path::GetLastPoint(int32_t iCount) const { - if (iCount < 1) { - return NULL; - } + if (iCount < 1) + return nullptr; + int32_t iPoints = m_Path.GetPointCount(); - if (iCount > iPoints) { - return NULL; - } + 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 NULL; - } + 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) { @@ -69,6 +71,7 @@ void CFDE_Path::BezierTo(const CFX_PointF& p1, 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, @@ -82,11 +85,10 @@ void CFDE_Path::ArcTo(FX_BOOL bStart, FX_FLOAT beta = FXSYS_atan2(rx * FXSYS_sin(endAngle), ry * FXSYS_cos(endAngle)); if (FXSYS_fabs(beta - alpha) > FX_PI) { - if (beta > alpha) { + if (beta > alpha) beta -= 2 * FX_PI; - } else { + 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); @@ -105,57 +107,58 @@ void CFDE_Path::ArcTo(FX_BOOL bStart, } void CFDE_Path::AddBezier(const CFX_PointsF& points) { - if (points.GetSize() != 4) { + 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) { + 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) { + 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) { + 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) { + if (r >= iCount) r = bClosed ? (r - iCount) : (iCount - 1); - } - if (s < 0) { + 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) { + if (iLast < 1) return; - } + CFX_PointsF tangents; GetCurveTangents(points, tangents, bClosed, fTension); const CFX_PointF* pPoints = points.GetData(); @@ -177,6 +180,7 @@ void CFDE_Path::AddCurve(const CFX_PointsF& points, CloseFigure(); } } + void CFDE_Path::AddEllipse(const CFX_RectF& rect) { FX_FLOAT fStartAngle = 0; FX_FLOAT fEndAngle = FX_PI / 2; @@ -187,33 +191,35 @@ void CFDE_Path::AddEllipse(const CFX_RectF& rect) { } 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 || + 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 IFDE_Path* pSrc, FX_BOOL bConnect) { + +void CFDE_Path::AddPath(const CFDE_Path* pSrc, FX_BOOL bConnect) { CFDE_Path* pPath = (CFDE_Path*)pSrc; - if (pPath == NULL) { + if (!pPath) return; - } + int32_t iCount = pPath->m_Path.GetPointCount(); - if (iCount < 1) { + if (iCount < 1) return; - } - if (bConnect) { + if (bConnect) LineTo(pPath->m_Path.GetPointX(0), pPath->m_Path.GetPointY(0)); - } - m_Path.Append(&pPath->m_Path, NULL); + + m_Path.Append(&pPath->m_Path, nullptr); } + void CFDE_Path::AddPolygon(const CFX_PointsF& points) { int32_t iCount = points.GetSize(); - if (iCount < 2) { + if (iCount < 2) return; - } + AddLines(points); const CFX_PointF* p = points.GetData(); if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || @@ -222,18 +228,19 @@ void CFDE_Path::AddPolygon(const CFX_PointsF& points) { } CloseFigure(); } + void CFDE_Path::AddLines(const CFX_PointsF& points) { int32_t iCount = points.GetSize(); - if (iCount < 2) { + if (iCount < 2) return; - } + const CFX_PointF* p = points.GetData(); const CFX_PointF* pEnd = p + iCount; MoveTo(p[0]); - for (++p; p < pEnd; ++p) { + for (++p; p < pEnd; ++p) LineTo(*p); - } } + void CFDE_Path::AddRectangle(const CFX_RectF& rect) { MoveTo(rect.TopLeft()); LineTo(rect.TopRight()); @@ -241,11 +248,13 @@ void CFDE_Path::AddRectangle(const CFX_RectF& rect) { 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 { diff --git a/xfa/fde/fde_geobject.h b/xfa/fde/cfde_path.h index debec6ab2e..c4b66f063e 100644 --- a/xfa/fde/fde_geobject.h +++ b/xfa/fde/cfde_path.h @@ -4,35 +4,34 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_FDE_GEOBJECT_H_ -#define XFA_FDE_FDE_GEOBJECT_H_ +#ifndef XFA_FDE_CFDE_PATH_H_ +#define XFA_FDE_CFDE_PATH_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 { +class CFDE_Path : public CFX_Target { public: - virtual void Release() { delete this; } + void Release() { delete this; } - virtual FX_BOOL StartFigure(); - virtual FX_BOOL CloseFigure(); + FX_BOOL StartFigure(); + 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; + 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; @@ -54,4 +53,4 @@ class CFDE_Path : public IFDE_Path, public CFX_Target { CFX_PathData m_Path; }; -#endif // XFA_FDE_FDE_GEOBJECT_H_ +#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 <algorithm> -#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_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<FDE_TTOPIECE> 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_TTOLine> 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<FDE_TTOPIECE> 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_TTOLine> 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_ |