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