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 #ifndef FPDFSDK_PDFWINDOW_PWL_UTILS_H_ 8 #define FPDFSDK_PDFWINDOW_PWL_UTILS_H_ 9 10 #include "core/fpdfdoc/cpvt_wordrange.h" 11 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" 12 13 class CFX_Edit; 14 struct CPWL_Color; 15 16 #define PWL_MAKEDWORD(low, high) \ 17 ((uint32_t)((uint16_t)(low) | (uint32_t)(((uint16_t)(high)) << 16))) 18 19 // checkbox & radiobutton style 20 #define PCS_CHECK 0 21 #define PCS_CIRCLE 1 22 #define PCS_CROSS 2 23 #define PCS_DIAMOND 3 24 #define PCS_SQUARE 4 25 #define PCS_STAR 5 26 27 // pushbutton layout style 28 #define PPBL_LABEL 0 29 #define PPBL_ICON 1 30 #define PPBL_ICONTOPLABELBOTTOM 2 31 #define PPBL_LABELTOPICONBOTTOM 3 32 #define PPBL_ICONLEFTLABELRIGHT 4 33 #define PPBL_LABELLEFTICONRIGHT 5 34 #define PPBL_LABELOVERICON 6 35 36 class CPWL_Utils { 37 public: 38 static CFX_FloatRect InflateRect(const CFX_FloatRect& rcRect, FX_FLOAT fSize); 39 static CFX_FloatRect DeflateRect(const CFX_FloatRect& rcRect, FX_FLOAT fSize); 40 41 static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1, 42 const CPVT_WordRange& wr2); 43 static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect); 44 45 static CFX_FloatRect OffsetRect(const CFX_FloatRect& rect, 46 FX_FLOAT x, 47 FX_FLOAT y); 48 49 static CFX_ByteString GetColorAppStream(const CPWL_Color& color, 50 const bool& bFillOrStroke = true); 51 static CFX_ByteString GetBorderAppStream(const CFX_FloatRect& rect, 52 FX_FLOAT fWidth, 53 const CPWL_Color& color, 54 const CPWL_Color& crLeftTop, 55 const CPWL_Color& crRightBottom, 56 BorderStyle nStyle, 57 const CPWL_Dash& dash); 58 static CFX_ByteString GetCircleBorderAppStream( 59 const CFX_FloatRect& rect, 60 FX_FLOAT fWidth, 61 const CPWL_Color& color, 62 const CPWL_Color& crLeftTop, 63 const CPWL_Color& crRightBottom, 64 BorderStyle nStyle, 65 const CPWL_Dash& dash); 66 static CFX_ByteString GetRectFillAppStream(const CFX_FloatRect& rect, 67 const CPWL_Color& color); 68 static CFX_ByteString GetCircleFillAppStream(const CFX_FloatRect& rect, 69 const CPWL_Color& color); 70 static CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, 71 IPVT_FontMap* pFontMap, 72 CPDF_Stream* pIconStream, 73 CPDF_IconFit& IconFit, 74 const CFX_WideString& sLabel, 75 const CPWL_Color& crText, 76 FX_FLOAT fFontSize, 77 int32_t nLayOut); 78 static CFX_ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, 79 int32_t nStyle, 80 const CPWL_Color& crText); 81 static CFX_ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, 82 int32_t nStyle, 83 const CPWL_Color& crText); 84 static CFX_ByteString GetEditAppStream(CFX_Edit* pEdit, 85 const CFX_PointF& ptOffset, 86 const CPVT_WordRange* pRange = nullptr, 87 bool bContinuous = true, 88 uint16_t SubWord = 0); 89 static CFX_ByteString GetEditSelAppStream( 90 CFX_Edit* pEdit, 91 const CFX_PointF& ptOffset, 92 const CPVT_WordRange* pRange = nullptr); 93 static CFX_ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox); 94 95 static void DrawFillRect(CFX_RenderDevice* pDevice, 96 CFX_Matrix* pUser2Device, 97 const CFX_FloatRect& rect, 98 const CPWL_Color& color, 99 int32_t nTransparency); 100 static void DrawFillRect(CFX_RenderDevice* pDevice, 101 CFX_Matrix* pUser2Device, 102 const CFX_FloatRect& rect, 103 const FX_COLORREF& color); 104 static void DrawStrokeRect(CFX_RenderDevice* pDevice, 105 CFX_Matrix* pUser2Device, 106 const CFX_FloatRect& rect, 107 const FX_COLORREF& color, 108 FX_FLOAT fWidth); 109 static void DrawStrokeLine(CFX_RenderDevice* pDevice, 110 CFX_Matrix* pUser2Device, 111 const CFX_PointF& ptMoveTo, 112 const CFX_PointF& ptLineTo, 113 const FX_COLORREF& color, 114 FX_FLOAT fWidth); 115 static void DrawBorder(CFX_RenderDevice* pDevice, 116 CFX_Matrix* pUser2Device, 117 const CFX_FloatRect& rect, 118 FX_FLOAT fWidth, 119 const CPWL_Color& color, 120 const CPWL_Color& crLeftTop, 121 const CPWL_Color& crRightBottom, 122 BorderStyle nStyle, 123 int32_t nTransparency); 124 static void DrawFillArea(CFX_RenderDevice* pDevice, 125 CFX_Matrix* pUser2Device, 126 const CFX_PointF* pPts, 127 int32_t nCount, 128 const FX_COLORREF& color); 129 static void DrawShadow(CFX_RenderDevice* pDevice, 130 CFX_Matrix* pUser2Device, 131 bool bVertical, 132 bool bHorizontal, 133 CFX_FloatRect rect, 134 int32_t nTransparency, 135 int32_t nStartGray, 136 int32_t nEndGray); 137 138 private: 139 static CFX_FloatRect ScaleRect(const CFX_FloatRect& rcRect, FX_FLOAT fScale); 140 141 static CFX_ByteString GetAppStream_Check(const CFX_FloatRect& rcBBox, 142 const CPWL_Color& crText); 143 static CFX_ByteString GetAppStream_Circle(const CFX_FloatRect& rcBBox, 144 const CPWL_Color& crText); 145 static CFX_ByteString GetAppStream_Cross(const CFX_FloatRect& rcBBox, 146 const CPWL_Color& crText); 147 static CFX_ByteString GetAppStream_Diamond(const CFX_FloatRect& rcBBox, 148 const CPWL_Color& crText); 149 static CFX_ByteString GetAppStream_Square(const CFX_FloatRect& rcBBox, 150 const CPWL_Color& crText); 151 static CFX_ByteString GetAppStream_Star(const CFX_FloatRect& rcBBox, 152 const CPWL_Color& crText); 153 154 static CFX_ByteString GetAP_Check(const CFX_FloatRect& crBBox); 155 static CFX_ByteString GetAP_Circle(const CFX_FloatRect& crBBox); 156 static CFX_ByteString GetAP_Cross(const CFX_FloatRect& crBBox); 157 static CFX_ByteString GetAP_Diamond(const CFX_FloatRect& crBBox); 158 static CFX_ByteString GetAP_Square(const CFX_FloatRect& crBBox); 159 static CFX_ByteString GetAP_Star(const CFX_FloatRect& crBBox); 160 static CFX_ByteString GetAP_HalfCircle(const CFX_FloatRect& crBBox, 161 FX_FLOAT fRotate); 162 }; 163 164 #endif // FPDFSDK_PDFWINDOW_PWL_UTILS_H_ 165