Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "xfa/fde/fde_gedevice.h" |
| 8 | |
| 9 | #include <algorithm> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame^] | 10 | #include <memory> |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 11 | |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 12 | #include "core/fxge/cfx_gemodule.h" |
| 13 | #include "core/fxge/cfx_graphstatedata.h" |
| 14 | #include "core/fxge/cfx_renderdevice.h" |
| 15 | #include "core/fxge/cfx_substfont.h" |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 16 | #include "xfa/fde/cfde_path.h" |
dsinclair | 25c223d | 2016-04-12 09:51:45 -0700 | [diff] [blame] | 17 | #include "xfa/fde/fde_object.h" |
npm | 8f3eb60 | 2016-11-11 17:16:23 -0800 | [diff] [blame] | 18 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
thestig | a4fdfc5 | 2016-06-07 17:33:37 -0700 | [diff] [blame] | 19 | #include "xfa/fgas/font/fgas_gefont.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 20 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 21 | CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 22 | bool bOwnerDevice) |
| 23 | : m_pDevice(pDevice), m_bOwnerDevice(bOwnerDevice), m_iCharCount(0) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 24 | ASSERT(pDevice); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 25 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 26 | FX_RECT rt = m_pDevice->GetClipBox(); |
| 27 | m_rtClip.Set((FX_FLOAT)rt.left, (FX_FLOAT)rt.top, (FX_FLOAT)rt.Width(), |
| 28 | (FX_FLOAT)rt.Height()); |
| 29 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 30 | |
| 31 | CFDE_RenderDevice::~CFDE_RenderDevice() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 32 | if (m_bOwnerDevice) |
| 33 | delete m_pDevice; |
| 34 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 35 | int32_t CFDE_RenderDevice::GetWidth() const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 36 | return m_pDevice->GetWidth(); |
| 37 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 38 | int32_t CFDE_RenderDevice::GetHeight() const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | return m_pDevice->GetHeight(); |
| 40 | } |
dsinclair | fe433f1 | 2016-06-06 12:03:31 -0700 | [diff] [blame] | 41 | void CFDE_RenderDevice::SaveState() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 42 | m_pDevice->SaveState(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 43 | } |
dsinclair | fe433f1 | 2016-06-06 12:03:31 -0700 | [diff] [blame] | 44 | void CFDE_RenderDevice::RestoreState() { |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 45 | m_pDevice->RestoreState(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | const FX_RECT& rt = m_pDevice->GetClipBox(); |
| 47 | m_rtClip.Set((FX_FLOAT)rt.left, (FX_FLOAT)rt.top, (FX_FLOAT)rt.Width(), |
| 48 | (FX_FLOAT)rt.Height()); |
| 49 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 50 | bool CFDE_RenderDevice::SetClipRect(const CFX_RectF& rtClip) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 51 | m_rtClip = rtClip; |
| 52 | return m_pDevice->SetClip_Rect(FX_RECT((int32_t)FXSYS_floor(rtClip.left), |
| 53 | (int32_t)FXSYS_floor(rtClip.top), |
| 54 | (int32_t)FXSYS_ceil(rtClip.right()), |
| 55 | (int32_t)FXSYS_ceil(rtClip.bottom()))); |
| 56 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 57 | const CFX_RectF& CFDE_RenderDevice::GetClipRect() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 58 | return m_rtClip; |
| 59 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 60 | bool CFDE_RenderDevice::SetClipPath(const CFDE_Path* pClip) { |
| 61 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 62 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 63 | CFDE_Path* CFDE_RenderDevice::GetClipPath() const { |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 64 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 65 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 66 | FX_FLOAT CFDE_RenderDevice::GetDpiX() const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 67 | return 96; |
| 68 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 69 | FX_FLOAT CFDE_RenderDevice::GetDpiY() const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | return 96; |
| 71 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 72 | bool CFDE_RenderDevice::DrawImage(CFX_DIBSource* pDib, |
| 73 | const CFX_RectF* pSrcRect, |
| 74 | const CFX_RectF& dstRect, |
| 75 | const CFX_Matrix* pImgMatrix, |
| 76 | const CFX_Matrix* pDevMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 77 | CFX_RectF srcRect; |
| 78 | if (pSrcRect) { |
| 79 | srcRect = *pSrcRect; |
| 80 | } else { |
| 81 | srcRect.Set(0, 0, (FX_FLOAT)pDib->GetWidth(), (FX_FLOAT)pDib->GetHeight()); |
| 82 | } |
| 83 | if (srcRect.IsEmpty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 84 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 85 | } |
| 86 | CFX_Matrix dib2fxdev; |
| 87 | if (pImgMatrix) { |
| 88 | dib2fxdev = *pImgMatrix; |
| 89 | } else { |
| 90 | dib2fxdev.SetIdentity(); |
| 91 | } |
| 92 | dib2fxdev.a = dstRect.width; |
| 93 | dib2fxdev.d = -dstRect.height; |
| 94 | dib2fxdev.e = dstRect.left; |
| 95 | dib2fxdev.f = dstRect.bottom(); |
| 96 | if (pDevMatrix) { |
| 97 | dib2fxdev.Concat(*pDevMatrix); |
| 98 | } |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 99 | void* handle = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 100 | m_pDevice->StartDIBits(pDib, 255, 0, (const CFX_Matrix*)&dib2fxdev, 0, |
| 101 | handle); |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 102 | while (m_pDevice->ContinueDIBits(handle, nullptr)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 103 | } |
| 104 | m_pDevice->CancelDIBits(handle); |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 105 | return !!handle; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 106 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 107 | bool CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, |
| 108 | CFGAS_GEFont* pFont, |
| 109 | const FXTEXT_CHARPOS* pCharPos, |
| 110 | int32_t iCount, |
| 111 | FX_FLOAT fFontSize, |
| 112 | const CFX_Matrix* pMatrix) { |
tsepez | 48ddd86 | 2016-06-06 10:51:58 -0700 | [diff] [blame] | 113 | ASSERT(pBrush && pFont && pCharPos && iCount > 0); |
tsepez | 48ddd86 | 2016-06-06 10:51:58 -0700 | [diff] [blame] | 114 | CFX_Font* pFxFont = pFont->GetDevFont(); |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 115 | FX_ARGB argb = pBrush->GetColor(); |
| 116 | if ((pFont->GetFontStyles() & FX_FONTSTYLE_Italic) != 0 && |
| 117 | !pFxFont->IsItalic()) { |
| 118 | FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; |
| 119 | FX_FLOAT* pAM; |
| 120 | for (int32_t i = 0; i < iCount; ++i) { |
| 121 | static const FX_FLOAT mc = 0.267949f; |
| 122 | pAM = pCP->m_AdjustMatrix; |
| 123 | pAM[2] = mc * pAM[0] + pAM[2]; |
| 124 | pAM[3] = mc * pAM[1] + pAM[3]; |
| 125 | pCP++; |
| 126 | } |
| 127 | } |
| 128 | FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 129 | CFGAS_GEFont* pCurFont = nullptr; |
| 130 | CFGAS_GEFont* pSTFont = nullptr; |
| 131 | FXTEXT_CHARPOS* pCurCP = nullptr; |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 132 | int32_t iCurCount = 0; |
| 133 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 134 | #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 135 | uint32_t dwFontStyle = pFont->GetFontStyles(); |
| 136 | CFX_Font FxFont; |
weili | 9b671ac | 2016-07-25 07:40:27 -0700 | [diff] [blame] | 137 | CFX_SubstFont* SubstFxFont = new CFX_SubstFont(); |
| 138 | FxFont.SetSubstFont(std::unique_ptr<CFX_SubstFont>(SubstFxFont)); |
| 139 | SubstFxFont->m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; |
| 140 | SubstFxFont->m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; |
| 141 | SubstFxFont->m_WeightCJK = SubstFxFont->m_Weight; |
| 142 | SubstFxFont->m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 143 | #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 144 | |
| 145 | for (int32_t i = 0; i < iCount; ++i) { |
| 146 | pSTFont = pFont->GetSubstFont((int32_t)pCP->m_GlyphIndex); |
| 147 | pCP->m_GlyphIndex &= 0x00FFFFFF; |
thestig | ec51ac3 | 2016-06-20 10:38:52 -0700 | [diff] [blame] | 148 | pCP->m_bFontStyle = false; |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 149 | if (pCurFont != pSTFont) { |
tsepez | 48ddd86 | 2016-06-06 10:51:58 -0700 | [diff] [blame] | 150 | if (pCurFont) { |
| 151 | pFxFont = pCurFont->GetDevFont(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 152 | #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 153 | FxFont.SetFace(pFxFont->GetFace()); |
art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 154 | m_pDevice->DrawNormalText(iCurCount, pCurCP, &FxFont, -fFontSize, |
| 155 | (const CFX_Matrix*)pMatrix, argb, |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 156 | FXTEXT_CLEARTYPE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 157 | #else |
art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 158 | m_pDevice->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, |
| 159 | (const CFX_Matrix*)pMatrix, argb, |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 160 | FXTEXT_CLEARTYPE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 161 | #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 162 | } |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 163 | pCurFont = pSTFont; |
| 164 | pCurCP = pCP; |
| 165 | iCurCount = 1; |
| 166 | } else { |
| 167 | iCurCount++; |
| 168 | } |
| 169 | pCP++; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 170 | } |
tsepez | 48ddd86 | 2016-06-06 10:51:58 -0700 | [diff] [blame] | 171 | if (pCurFont && iCurCount) { |
| 172 | pFxFont = pCurFont->GetDevFont(); |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 173 | #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 174 | FxFont.SetFace(pFxFont->GetFace()); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 175 | bool bRet = m_pDevice->DrawNormalText( |
art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 176 | iCurCount, pCurCP, &FxFont, -fFontSize, (const CFX_Matrix*)pMatrix, |
| 177 | argb, FXTEXT_CLEARTYPE); |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 178 | FxFont.SetFace(nullptr); |
| 179 | return bRet; |
| 180 | #else |
art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 181 | return m_pDevice->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, |
| 182 | (const CFX_Matrix*)pMatrix, argb, |
| 183 | FXTEXT_CLEARTYPE); |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 184 | #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 185 | } |
| 186 | |
| 187 | #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 188 | FxFont.SetFace(nullptr); |
| 189 | #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 190 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 191 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 192 | } |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 193 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 194 | bool CFDE_RenderDevice::DrawBezier(CFDE_Pen* pPen, |
| 195 | FX_FLOAT fPenWidth, |
| 196 | const CFX_PointF& pt1, |
| 197 | const CFX_PointF& pt2, |
| 198 | const CFX_PointF& pt3, |
| 199 | const CFX_PointF& pt4, |
| 200 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 201 | CFX_PointsF points; |
| 202 | points.Add(pt1); |
| 203 | points.Add(pt2); |
| 204 | points.Add(pt3); |
| 205 | points.Add(pt4); |
| 206 | CFDE_Path path; |
| 207 | path.AddBezier(points); |
| 208 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 209 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 210 | bool CFDE_RenderDevice::DrawCurve(CFDE_Pen* pPen, |
| 211 | FX_FLOAT fPenWidth, |
| 212 | const CFX_PointsF& points, |
| 213 | bool bClosed, |
| 214 | FX_FLOAT fTension, |
| 215 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 216 | CFDE_Path path; |
| 217 | path.AddCurve(points, bClosed, fTension); |
| 218 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 219 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 220 | bool CFDE_RenderDevice::DrawEllipse(CFDE_Pen* pPen, |
| 221 | FX_FLOAT fPenWidth, |
| 222 | const CFX_RectF& rect, |
| 223 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 224 | CFDE_Path path; |
| 225 | path.AddEllipse(rect); |
| 226 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 227 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 228 | bool CFDE_RenderDevice::DrawLines(CFDE_Pen* pPen, |
| 229 | FX_FLOAT fPenWidth, |
| 230 | const CFX_PointsF& points, |
| 231 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 232 | CFDE_Path path; |
| 233 | path.AddLines(points); |
| 234 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 235 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 236 | bool CFDE_RenderDevice::DrawLine(CFDE_Pen* pPen, |
| 237 | FX_FLOAT fPenWidth, |
| 238 | const CFX_PointF& pt1, |
| 239 | const CFX_PointF& pt2, |
| 240 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 241 | CFDE_Path path; |
| 242 | path.AddLine(pt1, pt2); |
| 243 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 244 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 245 | bool CFDE_RenderDevice::DrawPath(CFDE_Pen* pPen, |
| 246 | FX_FLOAT fPenWidth, |
| 247 | const CFDE_Path* pPath, |
| 248 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 249 | CFDE_Path* pGePath = (CFDE_Path*)pPath; |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 250 | if (!pGePath) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 251 | return false; |
thestig | cfb77cc | 2016-06-10 12:21:53 -0700 | [diff] [blame] | 252 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 253 | CFX_GraphStateData graphState; |
| 254 | if (!CreatePen(pPen, fPenWidth, graphState)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 255 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | } |
| 257 | return m_pDevice->DrawPath(&pGePath->m_Path, (const CFX_Matrix*)pMatrix, |
| 258 | &graphState, 0, pPen->GetColor(), 0); |
| 259 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 260 | bool CFDE_RenderDevice::DrawPolygon(CFDE_Pen* pPen, |
| 261 | FX_FLOAT fPenWidth, |
| 262 | const CFX_PointsF& points, |
| 263 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 264 | CFDE_Path path; |
| 265 | path.AddPolygon(points); |
| 266 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 267 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 268 | bool CFDE_RenderDevice::DrawRectangle(CFDE_Pen* pPen, |
| 269 | FX_FLOAT fPenWidth, |
| 270 | const CFX_RectF& rect, |
| 271 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 272 | CFDE_Path path; |
| 273 | path.AddRectangle(rect); |
| 274 | return DrawPath(pPen, fPenWidth, &path, pMatrix); |
| 275 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 276 | bool CFDE_RenderDevice::FillClosedCurve(CFDE_Brush* pBrush, |
| 277 | const CFX_PointsF& points, |
| 278 | FX_FLOAT fTension, |
| 279 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 280 | CFDE_Path path; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 281 | path.AddCurve(points, true, fTension); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 282 | return FillPath(pBrush, &path, pMatrix); |
| 283 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 284 | bool CFDE_RenderDevice::FillEllipse(CFDE_Brush* pBrush, |
| 285 | const CFX_RectF& rect, |
| 286 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 287 | CFDE_Path path; |
| 288 | path.AddEllipse(rect); |
| 289 | return FillPath(pBrush, &path, pMatrix); |
| 290 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 291 | bool CFDE_RenderDevice::FillPolygon(CFDE_Brush* pBrush, |
| 292 | const CFX_PointsF& points, |
| 293 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 294 | CFDE_Path path; |
| 295 | path.AddPolygon(points); |
| 296 | return FillPath(pBrush, &path, pMatrix); |
| 297 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 298 | bool CFDE_RenderDevice::FillRectangle(CFDE_Brush* pBrush, |
| 299 | const CFX_RectF& rect, |
| 300 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 301 | CFDE_Path path; |
| 302 | path.AddRectangle(rect); |
| 303 | return FillPath(pBrush, &path, pMatrix); |
| 304 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 305 | bool CFDE_RenderDevice::CreatePen(CFDE_Pen* pPen, |
| 306 | FX_FLOAT fPenWidth, |
| 307 | CFX_GraphStateData& graphState) { |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 308 | if (!pPen) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 309 | return false; |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 310 | |
| 311 | graphState.m_LineCap = CFX_GraphStateData::LineCapButt; |
| 312 | graphState.m_LineJoin = CFX_GraphStateData::LineJoinMiter; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 313 | graphState.m_LineWidth = fPenWidth; |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 314 | graphState.m_MiterLimit = 10; |
| 315 | graphState.m_DashPhase = 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 316 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 317 | } |
dsinclair | 25c223d | 2016-04-12 09:51:45 -0700 | [diff] [blame] | 318 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 319 | bool CFDE_RenderDevice::FillPath(CFDE_Brush* pBrush, |
| 320 | const CFDE_Path* pPath, |
| 321 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 322 | CFDE_Path* pGePath = (CFDE_Path*)pPath; |
dsinclair | 25c223d | 2016-04-12 09:51:45 -0700 | [diff] [blame] | 323 | if (!pGePath) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 324 | return false; |
dsinclair | 25c223d | 2016-04-12 09:51:45 -0700 | [diff] [blame] | 325 | if (!pBrush) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 326 | return false; |
dsinclair | a5c1323 | 2016-04-12 13:19:36 -0700 | [diff] [blame] | 327 | return m_pDevice->DrawPath(&pGePath->m_Path, pMatrix, nullptr, |
| 328 | pBrush->GetColor(), 0, FXFILL_WINDING); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 329 | } |
dsinclair | 25c223d | 2016-04-12 09:51:45 -0700 | [diff] [blame] | 330 | |