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 _FX_TEXTBREAK 8 #define _FX_TEXTBREAK 9 10 #include "core/include/fxcrt/fx_ucd.h" 11 12 class IFX_Font; 13 class CFX_Char; 14 class IFX_TxtAccess; 15 class CFX_TxtChar; 16 class CFX_TxtPiece; 17 class IFX_TxtBreak; 18 #define FX_TXTBREAKPOLICY_None 0x00 19 #define FX_TXTBREAKPOLICY_Pagination 0x01 20 #define FX_TXTBREAKPOLICY_SpaceBreak 0x02 21 #define FX_TXTBREAKPOLICY_NumberBreak 0x04 22 #define FX_TXTBREAK_None 0x00 23 #define FX_TXTBREAK_PieceBreak 0x01 24 #define FX_TXTBREAK_LineBreak 0x02 25 #define FX_TXTBREAK_ParagraphBreak 0x03 26 #define FX_TXTBREAK_PageBreak 0x04 27 #define FX_TXTBREAK_ControlChar 0x10 28 #define FX_TXTBREAK_BreakChar 0x20 29 #define FX_TXTBREAK_UnknownChar 0x40 30 #define FX_TXTBREAK_RemoveChar 0x80 31 #define FX_TXTLAYOUTSTYLE_MutipleFormat 0x0001 32 #define FX_TXTLAYOUTSTYLE_VerticalLayout 0x0002 33 #define FX_TXTLAYOUTSTYLE_VerticalChars 0x0004 34 #define FX_TXTLAYOUTSTYLE_ReverseLine 0x0008 35 #define FX_TXTLAYOUTSTYLE_ArabicContext 0x0010 36 #define FX_TXTLAYOUTSTYLE_ArabicShapes 0x0020 37 #define FX_TXTLAYOUTSTYLE_RTLReadingOrder 0x0040 38 #define FX_TXTLAYOUTSTYLE_ExpandTab 0x0100 39 #define FX_TXTLAYOUTSTYLE_SingleLine 0x0200 40 #define FX_TXTLAYOUTSTYLE_CombText 0x0400 41 #define FX_TXTCHARSTYLE_Alignment 0x000F 42 #define FX_TXTCHARSTYLE_ArabicNumber 0x0010 43 #define FX_TXTCHARSTYLE_ArabicShadda 0x0020 44 #define FX_TXTCHARSTYLE_OddBidiLevel 0x0040 45 #define FX_TXTCHARSTYLE_RTLReadingOrder 0x0080 46 #define FX_TXTCHARSTYLE_ArabicContext 0x0300 47 #define FX_TXTCHARSTYLE_ArabicIndic 0x0400 48 #define FX_TXTCHARSTYLE_ArabicComma 0x0800 49 #define FX_TXTLINEALIGNMENT_Left 0 50 #define FX_TXTLINEALIGNMENT_Center 1 51 #define FX_TXTLINEALIGNMENT_Right 2 52 #define FX_TXTLINEALIGNMENT_Justified (1 << 2) 53 #define FX_TXTLINEALIGNMENT_Distributed (2 << 2) 54 #define FX_TXTLINEALIGNMENT_JustifiedLeft \ 55 (FX_TXTLINEALIGNMENT_Left | FX_TXTLINEALIGNMENT_Justified) 56 #define FX_TXTLINEALIGNMENT_JustifiedCenter \ 57 (FX_TXTLINEALIGNMENT_Center | FX_TXTLINEALIGNMENT_Justified) 58 #define FX_TXTLINEALIGNMENT_JustifiedRight \ 59 (FX_TXTLINEALIGNMENT_Right | FX_TXTLINEALIGNMENT_Justified) 60 #define FX_TXTLINEALIGNMENT_DistributedLeft \ 61 (FX_TXTLINEALIGNMENT_Left | FX_TXTLINEALIGNMENT_Distributed) 62 #define FX_TXTLINEALIGNMENT_DistributedCenter \ 63 (FX_TXTLINEALIGNMENT_Center | FX_TXTLINEALIGNMENT_Distributed) 64 #define FX_TXTLINEALIGNMENT_DistributedRight \ 65 (FX_TXTLINEALIGNMENT_Right | FX_TXTLINEALIGNMENT_Distributed) 66 #define FX_TXTLINEALIGNMENT_LowerMask 0x03 67 #define FX_TXTLINEALIGNMENT_HigherMask 0x0C 68 #define FX_TXTBREAK_MinimumTabWidth 160000 69 70 class IFX_TxtAccess { 71 public: ~IFX_TxtAccess()72 virtual ~IFX_TxtAccess() {} 73 virtual FX_WCHAR GetChar(void* pIdentity, int32_t index) const = 0; 74 virtual int32_t GetWidth(void* pIdentity, int32_t index) const = 0; 75 }; 76 typedef struct _FX_TXTRUN { _FX_TXTRUN_FX_TXTRUN77 _FX_TXTRUN() { 78 pAccess = NULL; 79 pIdentity = NULL; 80 pStr = NULL; 81 pWidths = NULL; 82 iLength = 0; 83 pFont = NULL; 84 fFontSize = 12; 85 dwStyles = 0; 86 iHorizontalScale = 100; 87 iVerticalScale = 100; 88 iCharRotation = 0; 89 dwCharStyles = 0; 90 pRect = NULL; 91 wLineBreakChar = L'\n'; 92 bSkipSpace = TRUE; 93 } 94 IFX_TxtAccess* pAccess; 95 void* pIdentity; 96 const FX_WCHAR* pStr; 97 int32_t* pWidths; 98 int32_t iLength; 99 IFX_Font* pFont; 100 FX_FLOAT fFontSize; 101 FX_DWORD dwStyles; 102 int32_t iHorizontalScale; 103 int32_t iVerticalScale; 104 int32_t iCharRotation; 105 FX_DWORD dwCharStyles; 106 FX_LPCRECTF pRect; 107 FX_WCHAR wLineBreakChar; 108 FX_BOOL bSkipSpace; 109 } FX_TXTRUN, *FX_LPTXTRUN; 110 typedef FX_TXTRUN const* FX_LPCTXTRUN; 111 class CFX_TxtPiece : public CFX_Target { 112 public: CFX_TxtPiece()113 CFX_TxtPiece() 114 : m_dwStatus(FX_TXTBREAK_PieceBreak), 115 m_iStartPos(0), 116 m_iWidth(-1), 117 m_iStartChar(0), 118 m_iChars(0), 119 m_iBidiLevel(0), 120 m_iBidiPos(0), 121 m_iHorizontalScale(100), 122 m_iVerticalScale(100), 123 m_dwCharStyles(0), 124 m_pChars(NULL), 125 m_pUserData(NULL) {} GetEndPos()126 int32_t GetEndPos() const { 127 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; 128 } GetLength()129 int32_t GetLength() const { return m_iChars; } GetEndChar()130 int32_t GetEndChar() const { return m_iStartChar + m_iChars; } GetCharPtr(int32_t index)131 CFX_TxtChar* GetCharPtr(int32_t index) const { 132 FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL); 133 return m_pChars->GetDataPtr(m_iStartChar + index); 134 } GetString(FX_WCHAR * pText)135 void GetString(FX_WCHAR* pText) const { 136 FXSYS_assert(pText != NULL); 137 int32_t iEndChar = m_iStartChar + m_iChars; 138 CFX_Char* pChar; 139 for (int32_t i = m_iStartChar; i < iEndChar; i++) { 140 pChar = m_pChars->GetDataPtr(i); 141 *pText++ = (FX_WCHAR)pChar->m_wCharCode; 142 } 143 } 144 GetString(CFX_WideString & wsText)145 void GetString(CFX_WideString& wsText) const { 146 FX_WCHAR* pText = wsText.GetBuffer(m_iChars); 147 GetString(pText); 148 wsText.ReleaseBuffer(m_iChars); 149 } GetWidths(int32_t * pWidths)150 void GetWidths(int32_t* pWidths) const { 151 FXSYS_assert(pWidths != NULL); 152 int32_t iEndChar = m_iStartChar + m_iChars; 153 CFX_Char* pChar; 154 for (int32_t i = m_iStartChar; i < iEndChar; i++) { 155 pChar = m_pChars->GetDataPtr(i); 156 *pWidths++ = pChar->m_iCharWidth; 157 } 158 } 159 FX_DWORD m_dwStatus; 160 int32_t m_iStartPos; 161 int32_t m_iWidth; 162 int32_t m_iStartChar; 163 int32_t m_iChars; 164 int32_t m_iBidiLevel; 165 int32_t m_iBidiPos; 166 int32_t m_iHorizontalScale; 167 int32_t m_iVerticalScale; 168 FX_DWORD m_dwCharStyles; 169 CFX_TxtCharArray* m_pChars; 170 void* m_pUserData; 171 }; 172 typedef CFX_BaseArrayTemplate<CFX_TxtPiece> CFX_TxtPieceArray; 173 class IFX_TxtBreak { 174 public: 175 static IFX_TxtBreak* Create(FX_DWORD dwPolicies); ~IFX_TxtBreak()176 virtual ~IFX_TxtBreak() {} 177 virtual void Release() = 0; 178 virtual void SetLineWidth(FX_FLOAT fLineWidth) = 0; 179 virtual void SetLinePos(FX_FLOAT fLinePos) = 0; 180 virtual FX_DWORD GetLayoutStyles() const = 0; 181 virtual void SetLayoutStyles(FX_DWORD dwLayoutStyles) = 0; 182 virtual void SetFont(IFX_Font* pFont) = 0; 183 virtual void SetFontSize(FX_FLOAT fFontSize) = 0; 184 virtual void SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) = 0; 185 virtual void SetDefaultChar(FX_WCHAR wch) = 0; 186 virtual void SetParagraphBreakChar(FX_WCHAR wch) = 0; 187 virtual void SetLineBreakTolerance(FX_FLOAT fTolerance) = 0; 188 virtual void SetHorizontalScale(int32_t iScale) = 0; 189 virtual void SetVerticalScale(int32_t iScale) = 0; 190 virtual void SetCharRotation(int32_t iCharRotation) = 0; 191 virtual void SetCharSpace(FX_FLOAT fCharSpace) = 0; 192 virtual void SetAlignment(int32_t iAlignment) = 0; 193 virtual FX_DWORD GetContextCharStyles() const = 0; 194 virtual void SetContextCharStyles(FX_DWORD dwCharStyles) = 0; 195 virtual void SetCombWidth(FX_FLOAT fCombWidth) = 0; 196 virtual void SetUserData(void* pUserData) = 0; 197 virtual FX_DWORD AppendChar(FX_WCHAR wch) = 0; 198 virtual FX_DWORD EndBreak(FX_DWORD dwStatus = FX_TXTBREAK_PieceBreak) = 0; 199 virtual int32_t CountBreakChars() const = 0; 200 virtual int32_t CountBreakPieces() const = 0; 201 virtual const CFX_TxtPiece* GetBreakPiece(int32_t index) const = 0; 202 virtual void ClearBreakPieces() = 0; 203 virtual void Reset() = 0; 204 virtual int32_t GetDisplayPos( 205 FX_LPCTXTRUN pTxtRun, 206 FXTEXT_CHARPOS* pCharPos, 207 FX_BOOL bCharCode = FALSE, 208 CFX_WideString* pWSForms = NULL, 209 FX_AdjustCharDisplayPos pAdjustPos = NULL) const = 0; 210 virtual int32_t GetCharRects(FX_LPCTXTRUN pTxtRun, 211 CFX_RectFArray& rtArray, 212 FX_BOOL bCharBBox = FALSE) const = 0; 213 }; 214 #endif 215