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