1 // Copyright 2016 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 #ifndef CORE_FXGE_CFX_RENDERDEVICE_H_ 8 #define CORE_FXGE_CFX_RENDERDEVICE_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/unowned_ptr.h" 13 #include "core/fxge/cfx_color.h" 14 #include "core/fxge/fx_dib.h" 15 16 class CFX_DIBitmap; 17 class CFX_Font; 18 class CFX_GraphStateData; 19 class CFX_ImageRenderer; 20 class IFX_PauseIndicator; 21 class IFX_RenderDeviceDriver; 22 23 #define FXDC_DEVICE_CLASS 1 24 #define FXDC_PIXEL_WIDTH 2 25 #define FXDC_PIXEL_HEIGHT 3 26 #define FXDC_BITS_PIXEL 4 27 #define FXDC_HORZ_SIZE 5 28 #define FXDC_VERT_SIZE 6 29 #define FXDC_RENDER_CAPS 7 30 #define FXDC_DISPLAY 1 31 #define FXDC_PRINTER 2 32 33 #define FXRC_GET_BITS 0x01 34 #define FXRC_BIT_MASK 0x02 35 #define FXRC_ALPHA_PATH 0x10 36 #define FXRC_ALPHA_IMAGE 0x20 37 #define FXRC_ALPHA_OUTPUT 0x40 38 #define FXRC_BLEND_MODE 0x80 39 #define FXRC_SOFT_CLIP 0x100 40 #define FXRC_CMYK_OUTPUT 0x200 41 #define FXRC_BITMASK_OUTPUT 0x400 42 #define FXRC_BYTEMASK_OUTPUT 0x800 43 #define FXRENDER_IMAGE_LOSSY 0x1000 44 #define FXRC_FILLSTROKE_PATH 0x2000 45 #define FXRC_SHADING 0x4000 46 47 #define FXFILL_ALTERNATE 1 48 #define FXFILL_WINDING 2 49 #define FXFILL_FULLCOVER 4 50 #define FXFILL_RECT_AA 8 51 #define FX_FILL_STROKE 16 52 #define FX_STROKE_ADJUST 32 53 #define FX_STROKE_TEXT_MODE 64 54 #define FX_FILL_TEXT_MODE 128 55 #define FX_ZEROAREA_FILL 256 56 #define FXFILL_NOPATHSMOOTH 512 57 58 #define FXTEXT_CLEARTYPE 0x01 59 #define FXTEXT_BGR_STRIPE 0x02 60 #define FXTEXT_PRINTGRAPHICTEXT 0x04 61 #define FXTEXT_NO_NATIVETEXT 0x08 62 #define FXTEXT_PRINTIMAGETEXT 0x10 63 #define FXTEXT_NOSMOOTH 0x20 64 65 class CFX_PathData; 66 67 enum class FXPT_TYPE : uint8_t { LineTo, BezierTo, MoveTo }; 68 69 class FXTEXT_CHARPOS { 70 public: 71 FXTEXT_CHARPOS(); 72 FXTEXT_CHARPOS(const FXTEXT_CHARPOS&); 73 ~FXTEXT_CHARPOS(); 74 75 float m_AdjustMatrix[4]; 76 CFX_PointF m_Origin; 77 uint32_t m_Unicode; 78 uint32_t m_GlyphIndex; 79 int32_t m_FontCharWidth; 80 #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ 81 uint32_t m_ExtGID; 82 #endif 83 int32_t m_FallbackFontPosition; 84 bool m_bGlyphAdjust; 85 bool m_bFontStyle; 86 }; 87 88 class CFX_RenderDevice { 89 public: 90 class StateRestorer { 91 public: 92 explicit StateRestorer(CFX_RenderDevice* pDevice); 93 ~StateRestorer(); 94 95 private: 96 UnownedPtr<CFX_RenderDevice> m_pDevice; 97 }; 98 99 CFX_RenderDevice(); 100 virtual ~CFX_RenderDevice(); 101 102 // Take ownership of |pDriver|. 103 void SetDeviceDriver(std::unique_ptr<IFX_RenderDeviceDriver> pDriver); GetDeviceDriver()104 IFX_RenderDeviceDriver* GetDeviceDriver() const { 105 return m_pDeviceDriver.get(); 106 } 107 108 void SaveState(); 109 void RestoreState(bool bKeepSaved); 110 GetWidth()111 int GetWidth() const { return m_Width; } GetHeight()112 int GetHeight() const { return m_Height; } GetDeviceClass()113 int GetDeviceClass() const { return m_DeviceClass; } GetRenderCaps()114 int GetRenderCaps() const { return m_RenderCaps; } 115 int GetDeviceCaps(int id) const; 116 CFX_Matrix GetCTM() const; 117 RetainPtr<CFX_DIBitmap> GetBitmap() const; 118 void SetBitmap(const RetainPtr<CFX_DIBitmap>& pBitmap); 119 bool CreateCompatibleBitmap(const RetainPtr<CFX_DIBitmap>& pDIB, 120 int width, 121 int height) const; GetClipBox()122 const FX_RECT& GetClipBox() const { return m_ClipBox; } 123 bool SetClip_PathFill(const CFX_PathData* pPathData, 124 const CFX_Matrix* pObject2Device, 125 int fill_mode); 126 bool SetClip_Rect(const CFX_RectF& pRect); 127 bool SetClip_Rect(const FX_RECT& pRect); 128 bool SetClip_PathStroke(const CFX_PathData* pPathData, 129 const CFX_Matrix* pObject2Device, 130 const CFX_GraphStateData* pGraphState); DrawPath(const CFX_PathData * pPathData,const CFX_Matrix * pObject2Device,const CFX_GraphStateData * pGraphState,uint32_t fill_color,uint32_t stroke_color,int fill_mode)131 bool DrawPath(const CFX_PathData* pPathData, 132 const CFX_Matrix* pObject2Device, 133 const CFX_GraphStateData* pGraphState, 134 uint32_t fill_color, 135 uint32_t stroke_color, 136 int fill_mode) { 137 return DrawPathWithBlend(pPathData, pObject2Device, pGraphState, fill_color, 138 stroke_color, fill_mode, FXDIB_BLEND_NORMAL); 139 } 140 bool DrawPathWithBlend(const CFX_PathData* pPathData, 141 const CFX_Matrix* pObject2Device, 142 const CFX_GraphStateData* pGraphState, 143 uint32_t fill_color, 144 uint32_t stroke_color, 145 int fill_mode, 146 int blend_type); FillRect(const FX_RECT * pRect,uint32_t color)147 bool FillRect(const FX_RECT* pRect, uint32_t color) { 148 return FillRectWithBlend(pRect, color, FXDIB_BLEND_NORMAL); 149 } 150 151 RetainPtr<CFX_DIBitmap> GetBackDrop(); 152 bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top); SetDIBits(const RetainPtr<CFX_DIBSource> & pBitmap,int left,int top)153 bool SetDIBits(const RetainPtr<CFX_DIBSource>& pBitmap, int left, int top) { 154 return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL); 155 } 156 bool SetDIBitsWithBlend(const RetainPtr<CFX_DIBSource>& pBitmap, 157 int left, 158 int top, 159 int blend_type); StretchDIBits(const RetainPtr<CFX_DIBSource> & pBitmap,int left,int top,int dest_width,int dest_height)160 bool StretchDIBits(const RetainPtr<CFX_DIBSource>& pBitmap, 161 int left, 162 int top, 163 int dest_width, 164 int dest_height) { 165 return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width, 166 dest_height, 0, FXDIB_BLEND_NORMAL); 167 } 168 bool StretchDIBitsWithFlagsAndBlend(const RetainPtr<CFX_DIBSource>& pBitmap, 169 int left, 170 int top, 171 int dest_width, 172 int dest_height, 173 uint32_t flags, 174 int blend_type); 175 bool SetBitMask(const RetainPtr<CFX_DIBSource>& pBitmap, 176 int left, 177 int top, 178 uint32_t color); 179 bool StretchBitMask(const RetainPtr<CFX_DIBSource>& pBitmap, 180 int left, 181 int top, 182 int dest_width, 183 int dest_height, 184 uint32_t color); 185 bool StretchBitMaskWithFlags(const RetainPtr<CFX_DIBSource>& pBitmap, 186 int left, 187 int top, 188 int dest_width, 189 int dest_height, 190 uint32_t color, 191 uint32_t flags); StartDIBits(const RetainPtr<CFX_DIBSource> & pBitmap,int bitmap_alpha,uint32_t color,const CFX_Matrix * pMatrix,uint32_t flags,std::unique_ptr<CFX_ImageRenderer> * handle)192 bool StartDIBits(const RetainPtr<CFX_DIBSource>& pBitmap, 193 int bitmap_alpha, 194 uint32_t color, 195 const CFX_Matrix* pMatrix, 196 uint32_t flags, 197 std::unique_ptr<CFX_ImageRenderer>* handle) { 198 return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags, 199 handle, FXDIB_BLEND_NORMAL); 200 } 201 bool StartDIBitsWithBlend(const RetainPtr<CFX_DIBSource>& pBitmap, 202 int bitmap_alpha, 203 uint32_t color, 204 const CFX_Matrix* pMatrix, 205 uint32_t flags, 206 std::unique_ptr<CFX_ImageRenderer>* handle, 207 int blend_type); 208 bool ContinueDIBits(CFX_ImageRenderer* handle, IFX_PauseIndicator* pPause); 209 210 bool DrawNormalText(int nChars, 211 const FXTEXT_CHARPOS* pCharPos, 212 CFX_Font* pFont, 213 float font_size, 214 const CFX_Matrix* pText2Device, 215 uint32_t fill_color, 216 uint32_t text_flags); 217 bool DrawTextPath(int nChars, 218 const FXTEXT_CHARPOS* pCharPos, 219 CFX_Font* pFont, 220 float font_size, 221 const CFX_Matrix* pText2User, 222 const CFX_Matrix* pUser2Device, 223 const CFX_GraphStateData* pGraphState, 224 uint32_t fill_color, 225 uint32_t stroke_color, 226 CFX_PathData* pClippingPath, 227 int nFlag); 228 229 void DrawFillRect(const CFX_Matrix* pUser2Device, 230 const CFX_FloatRect& rect, 231 const CFX_Color& color, 232 int32_t nTransparency); 233 void DrawFillRect(const CFX_Matrix* pUser2Device, 234 const CFX_FloatRect& rect, 235 const FX_COLORREF& color); 236 void DrawStrokeRect(const CFX_Matrix* pUser2Device, 237 const CFX_FloatRect& rect, 238 const FX_COLORREF& color, 239 float fWidth); 240 void DrawStrokeLine(const CFX_Matrix* pUser2Device, 241 const CFX_PointF& ptMoveTo, 242 const CFX_PointF& ptLineTo, 243 const FX_COLORREF& color, 244 float fWidth); 245 void DrawBorder(const CFX_Matrix* pUser2Device, 246 const CFX_FloatRect& rect, 247 float fWidth, 248 const CFX_Color& color, 249 const CFX_Color& crLeftTop, 250 const CFX_Color& crRightBottom, 251 BorderStyle nStyle, 252 int32_t nTransparency); 253 void DrawFillArea(const CFX_Matrix* pUser2Device, 254 const CFX_PointF* pPts, 255 int32_t nCount, 256 const FX_COLORREF& color); 257 void DrawShadow(const CFX_Matrix* pUser2Device, 258 bool bVertical, 259 bool bHorizontal, 260 CFX_FloatRect rect, 261 int32_t nTransparency, 262 int32_t nStartGray, 263 int32_t nEndGray); 264 265 #ifdef _SKIA_SUPPORT_ 266 virtual void DebugVerifyBitmapIsPreMultiplied() const; 267 virtual bool SetBitsWithMask(const RetainPtr<CFX_DIBSource>& pBitmap, 268 const RetainPtr<CFX_DIBSource>& pMask, 269 int left, 270 int top, 271 int bitmap_alpha, 272 int blend_type); 273 #endif 274 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ 275 void Flush(bool release); 276 #endif 277 278 private: 279 void InitDeviceInfo(); 280 void UpdateClipBox(); 281 bool DrawFillStrokePath(const CFX_PathData* pPathData, 282 const CFX_Matrix* pObject2Device, 283 const CFX_GraphStateData* pGraphState, 284 uint32_t fill_color, 285 uint32_t stroke_color, 286 int fill_mode, 287 int blend_type); 288 bool DrawCosmeticLine(const CFX_PointF& ptMoveTo, 289 const CFX_PointF& ptLineTo, 290 uint32_t color, 291 int fill_mode, 292 int blend_type); 293 bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type); 294 295 RetainPtr<CFX_DIBitmap> m_pBitmap; 296 int m_Width; 297 int m_Height; 298 int m_bpp; 299 int m_RenderCaps; 300 int m_DeviceClass; 301 FX_RECT m_ClipBox; 302 std::unique_ptr<IFX_RenderDeviceDriver> m_pDeviceDriver; 303 }; 304 305 #endif // CORE_FXGE_CFX_RENDERDEVICE_H_ 306