| OLD | NEW |
| (Empty) |
| 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 CORE_INCLUDE_FPDFDOC_FPDF_VT_H_ | |
| 8 #define CORE_INCLUDE_FPDFDOC_FPDF_VT_H_ | |
| 9 | |
| 10 #include "core/include/fxge/fx_dib.h" | |
| 11 | |
| 12 class IPDF_VariableText; | |
| 13 struct CPVT_Line; | |
| 14 struct CPVT_Section; | |
| 15 struct CPVT_Word; | |
| 16 struct CPVT_WordPlace; | |
| 17 struct CPVT_WordRange; | |
| 18 | |
| 19 struct CPVT_WordPlace { | |
| 20 CPVT_WordPlace() : nSecIndex(-1), nLineIndex(-1), nWordIndex(-1) {} | |
| 21 | |
| 22 CPVT_WordPlace(int32_t other_nSecIndex, | |
| 23 int32_t other_nLineIndex, | |
| 24 int32_t other_nWordIndex) { | |
| 25 nSecIndex = other_nSecIndex; | |
| 26 nLineIndex = other_nLineIndex; | |
| 27 nWordIndex = other_nWordIndex; | |
| 28 } | |
| 29 | |
| 30 void Default() { nSecIndex = nLineIndex = nWordIndex = -1; } | |
| 31 | |
| 32 bool operator==(const CPVT_WordPlace& wp) const { | |
| 33 return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex && | |
| 34 wp.nWordIndex == nWordIndex; | |
| 35 } | |
| 36 | |
| 37 FX_BOOL operator!=(const CPVT_WordPlace& wp) const { return !(*this == wp); } | |
| 38 | |
| 39 inline int32_t WordCmp(const CPVT_WordPlace& wp) const { | |
| 40 if (nSecIndex > wp.nSecIndex) | |
| 41 return 1; | |
| 42 if (nSecIndex < wp.nSecIndex) | |
| 43 return -1; | |
| 44 if (nLineIndex > wp.nLineIndex) | |
| 45 return 1; | |
| 46 if (nLineIndex < wp.nLineIndex) | |
| 47 return -1; | |
| 48 if (nWordIndex > wp.nWordIndex) | |
| 49 return 1; | |
| 50 if (nWordIndex < wp.nWordIndex) | |
| 51 return -1; | |
| 52 return 0; | |
| 53 } | |
| 54 | |
| 55 inline int32_t LineCmp(const CPVT_WordPlace& wp) const { | |
| 56 if (nSecIndex > wp.nSecIndex) | |
| 57 return 1; | |
| 58 if (nSecIndex < wp.nSecIndex) | |
| 59 return -1; | |
| 60 if (nLineIndex > wp.nLineIndex) | |
| 61 return 1; | |
| 62 if (nLineIndex < wp.nLineIndex) | |
| 63 return -1; | |
| 64 return 0; | |
| 65 } | |
| 66 | |
| 67 inline int32_t SecCmp(const CPVT_WordPlace& wp) const { | |
| 68 if (nSecIndex > wp.nSecIndex) | |
| 69 return 1; | |
| 70 if (nSecIndex < wp.nSecIndex) | |
| 71 return -1; | |
| 72 return 0; | |
| 73 } | |
| 74 | |
| 75 int32_t nSecIndex; | |
| 76 int32_t nLineIndex; | |
| 77 int32_t nWordIndex; | |
| 78 }; | |
| 79 struct CPVT_WordRange { | |
| 80 CPVT_WordRange() {} | |
| 81 | |
| 82 CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { | |
| 83 Set(begin, end); | |
| 84 } | |
| 85 | |
| 86 void Default() { | |
| 87 BeginPos.Default(); | |
| 88 EndPos.Default(); | |
| 89 } | |
| 90 | |
| 91 void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { | |
| 92 BeginPos = begin; | |
| 93 EndPos = end; | |
| 94 SwapWordPlace(); | |
| 95 } | |
| 96 | |
| 97 void SetBeginPos(const CPVT_WordPlace& begin) { | |
| 98 BeginPos = begin; | |
| 99 SwapWordPlace(); | |
| 100 } | |
| 101 | |
| 102 void SetEndPos(const CPVT_WordPlace& end) { | |
| 103 EndPos = end; | |
| 104 SwapWordPlace(); | |
| 105 } | |
| 106 | |
| 107 FX_BOOL IsExist() const { return BeginPos != EndPos; } | |
| 108 | |
| 109 FX_BOOL operator!=(const CPVT_WordRange& wr) const { | |
| 110 return wr.BeginPos != BeginPos || wr.EndPos != EndPos; | |
| 111 } | |
| 112 | |
| 113 void SwapWordPlace() { | |
| 114 if (BeginPos.WordCmp(EndPos) > 0) { | |
| 115 CPVT_WordPlace place = EndPos; | |
| 116 EndPos = BeginPos; | |
| 117 BeginPos = place; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 CPVT_WordPlace BeginPos; | |
| 122 CPVT_WordPlace EndPos; | |
| 123 }; | |
| 124 struct CPVT_SecProps { | |
| 125 CPVT_SecProps() : fLineLeading(0.0f), fLineIndent(0.0f), nAlignment(0) {} | |
| 126 | |
| 127 CPVT_SecProps(FX_FLOAT lineLeading, FX_FLOAT lineIndent, int32_t alignment) | |
| 128 : fLineLeading(lineLeading), | |
| 129 fLineIndent(lineIndent), | |
| 130 nAlignment(alignment) {} | |
| 131 | |
| 132 CPVT_SecProps(const CPVT_SecProps& other) | |
| 133 : fLineLeading(other.fLineLeading), | |
| 134 fLineIndent(other.fLineIndent), | |
| 135 nAlignment(other.nAlignment) {} | |
| 136 | |
| 137 FX_FLOAT fLineLeading; | |
| 138 FX_FLOAT fLineIndent; | |
| 139 int32_t nAlignment; | |
| 140 }; | |
| 141 struct CPVT_WordProps { | |
| 142 CPVT_WordProps() | |
| 143 : nFontIndex(-1), | |
| 144 fFontSize(0.0f), | |
| 145 dwWordColor(0), | |
| 146 nScriptType(0), | |
| 147 nWordStyle(0), | |
| 148 fCharSpace(0.0f), | |
| 149 nHorzScale(0) {} | |
| 150 | |
| 151 CPVT_WordProps(int32_t fontIndex, | |
| 152 FX_FLOAT fontSize, | |
| 153 FX_COLORREF wordColor = 0, | |
| 154 int32_t scriptType = 0, | |
| 155 int32_t wordStyle = 0, | |
| 156 FX_FLOAT charSpace = 0, | |
| 157 int32_t horzScale = 100) | |
| 158 : nFontIndex(fontIndex), | |
| 159 fFontSize(fontSize), | |
| 160 dwWordColor(wordColor), | |
| 161 nScriptType(scriptType), | |
| 162 nWordStyle(wordStyle), | |
| 163 fCharSpace(charSpace), | |
| 164 nHorzScale(horzScale) {} | |
| 165 | |
| 166 CPVT_WordProps(const CPVT_WordProps& other) | |
| 167 : nFontIndex(other.nFontIndex), | |
| 168 fFontSize(other.fFontSize), | |
| 169 dwWordColor(other.dwWordColor), | |
| 170 nScriptType(other.nScriptType), | |
| 171 nWordStyle(other.nWordStyle), | |
| 172 fCharSpace(other.fCharSpace), | |
| 173 nHorzScale(other.nHorzScale) {} | |
| 174 | |
| 175 int32_t nFontIndex; | |
| 176 FX_FLOAT fFontSize; | |
| 177 FX_COLORREF dwWordColor; | |
| 178 int32_t nScriptType; | |
| 179 int32_t nWordStyle; | |
| 180 FX_FLOAT fCharSpace; | |
| 181 int32_t nHorzScale; | |
| 182 }; | |
| 183 struct CPVT_Word { | |
| 184 CPVT_Word() | |
| 185 : Word(0), | |
| 186 nCharset(0), | |
| 187 ptWord(0, 0), | |
| 188 fAscent(0.0f), | |
| 189 fDescent(0.0f), | |
| 190 fWidth(0.0f), | |
| 191 fFontSize(0), | |
| 192 WordProps() {} | |
| 193 | |
| 194 uint16_t Word; | |
| 195 int32_t nCharset; | |
| 196 CPVT_WordPlace WordPlace; | |
| 197 CFX_FloatPoint ptWord; | |
| 198 FX_FLOAT fAscent; | |
| 199 FX_FLOAT fDescent; | |
| 200 FX_FLOAT fWidth; | |
| 201 int32_t nFontIndex; | |
| 202 FX_FLOAT fFontSize; | |
| 203 CPVT_WordProps WordProps; | |
| 204 }; | |
| 205 struct CPVT_Line { | |
| 206 CPVT_Line() | |
| 207 : ptLine(0, 0), fLineWidth(0.0f), fLineAscent(0.0f), fLineDescent(0.0f) {} | |
| 208 | |
| 209 CPVT_WordPlace lineplace; | |
| 210 CPVT_WordPlace lineEnd; | |
| 211 CFX_FloatPoint ptLine; | |
| 212 FX_FLOAT fLineWidth; | |
| 213 FX_FLOAT fLineAscent; | |
| 214 FX_FLOAT fLineDescent; | |
| 215 }; | |
| 216 struct CPVT_Section { | |
| 217 CPVT_WordPlace secplace; | |
| 218 CFX_FloatRect rcSection; | |
| 219 CPVT_SecProps SecProps; | |
| 220 CPVT_WordProps WordProps; | |
| 221 }; | |
| 222 | |
| 223 class IPDF_VariableText { | |
| 224 public: | |
| 225 class Provider { | |
| 226 public: | |
| 227 virtual ~Provider() {} | |
| 228 | |
| 229 virtual int32_t GetCharWidth(int32_t nFontIndex, | |
| 230 uint16_t word, | |
| 231 int32_t nWordStyle) = 0; | |
| 232 virtual int32_t GetTypeAscent(int32_t nFontIndex) = 0; | |
| 233 virtual int32_t GetTypeDescent(int32_t nFontIndex) = 0; | |
| 234 virtual int32_t GetWordFontIndex(uint16_t word, | |
| 235 int32_t charset, | |
| 236 int32_t nFontIndex) = 0; | |
| 237 virtual int32_t GetDefaultFontIndex() = 0; | |
| 238 virtual FX_BOOL IsLatinWord(uint16_t word) = 0; | |
| 239 }; | |
| 240 | |
| 241 class Iterator { | |
| 242 public: | |
| 243 virtual ~Iterator() {} | |
| 244 | |
| 245 virtual FX_BOOL NextWord() = 0; | |
| 246 virtual FX_BOOL PrevWord() = 0; | |
| 247 virtual FX_BOOL NextLine() = 0; | |
| 248 virtual FX_BOOL PrevLine() = 0; | |
| 249 virtual FX_BOOL NextSection() = 0; | |
| 250 virtual FX_BOOL PrevSection() = 0; | |
| 251 virtual FX_BOOL GetWord(CPVT_Word& word) const = 0; | |
| 252 virtual FX_BOOL SetWord(const CPVT_Word& word) = 0; | |
| 253 virtual FX_BOOL GetLine(CPVT_Line& line) const = 0; | |
| 254 virtual FX_BOOL GetSection(CPVT_Section& section) const = 0; | |
| 255 virtual FX_BOOL SetSection(const CPVT_Section& section) = 0; | |
| 256 virtual void SetAt(int32_t nWordIndex) = 0; | |
| 257 virtual void SetAt(const CPVT_WordPlace& place) = 0; | |
| 258 virtual const CPVT_WordPlace& GetAt() const = 0; | |
| 259 }; | |
| 260 | |
| 261 static IPDF_VariableText* NewVariableText(); | |
| 262 static void DelVariableText(IPDF_VariableText* pVT); | |
| 263 | |
| 264 virtual void Initialize() = 0; | |
| 265 | |
| 266 virtual Provider* SetProvider(Provider* pProvider) = 0; | |
| 267 virtual Iterator* GetIterator() = 0; | |
| 268 | |
| 269 virtual void SetPlateRect(const CFX_FloatRect& rect) = 0; | |
| 270 virtual void SetAlignment(int32_t nFormat = 0) = 0; | |
| 271 virtual void SetPasswordChar(uint16_t wSubWord = '*') = 0; | |
| 272 virtual void SetLimitChar(int32_t nLimitChar = 0) = 0; | |
| 273 virtual void SetCharArray(int32_t nCharArray = 0) = 0; | |
| 274 virtual void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) = 0; | |
| 275 virtual void SetHorzScale(int32_t nHorzScale = 100) = 0; | |
| 276 virtual void SetMultiLine(FX_BOOL bMultiLine = TRUE) = 0; | |
| 277 virtual void SetAutoReturn(FX_BOOL bAuto = TRUE) = 0; | |
| 278 virtual void SetAutoFontSize(FX_BOOL bAuto = TRUE) = 0; | |
| 279 virtual void SetFontSize(FX_FLOAT fFontSize) = 0; | |
| 280 virtual void SetLineLeading(FX_FLOAT fLineLeading) = 0; | |
| 281 virtual void SetRichText(FX_BOOL bRichText) = 0; | |
| 282 | |
| 283 virtual FX_BOOL IsValid() const = 0; | |
| 284 virtual FX_BOOL IsRichText() const = 0; | |
| 285 virtual FX_BOOL IsMultiLine() const = 0; | |
| 286 | |
| 287 virtual void RearrangeAll() = 0; | |
| 288 virtual void RearrangePart(const CPVT_WordRange& PlaceRange) = 0; | |
| 289 | |
| 290 virtual void ResetAll() = 0; | |
| 291 | |
| 292 virtual void SetText(const FX_WCHAR* text, | |
| 293 int32_t charset = 1, | |
| 294 const CPVT_SecProps* pSecProps = NULL, | |
| 295 const CPVT_WordProps* pWordProps = NULL) = 0; | |
| 296 virtual CPVT_WordPlace InsertWord( | |
| 297 const CPVT_WordPlace& place, | |
| 298 uint16_t word, | |
| 299 int32_t charset = 1, | |
| 300 const CPVT_WordProps* pWordProps = NULL) = 0; | |
| 301 virtual CPVT_WordPlace InsertSection( | |
| 302 const CPVT_WordPlace& place, | |
| 303 const CPVT_SecProps* pSecProps = NULL, | |
| 304 const CPVT_WordProps* pWordProps = NULL) = 0; | |
| 305 virtual CPVT_WordPlace InsertText( | |
| 306 const CPVT_WordPlace& place, | |
| 307 const FX_WCHAR* text, | |
| 308 int32_t charset = 1, | |
| 309 const CPVT_SecProps* pSecProps = NULL, | |
| 310 const CPVT_WordProps* pWordProps = NULL) = 0; | |
| 311 | |
| 312 virtual CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange) = 0; | |
| 313 virtual CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place) = 0; | |
| 314 virtual CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place) = 0; | |
| 315 | |
| 316 virtual const CFX_FloatRect& GetPlateRect() const = 0; | |
| 317 virtual CFX_FloatRect GetContentRect() const = 0; | |
| 318 virtual int32_t GetTotalWords() const = 0; | |
| 319 virtual FX_FLOAT GetFontSize() const = 0; | |
| 320 virtual int32_t GetAlignment() const = 0; | |
| 321 virtual uint16_t GetPasswordChar() const = 0; | |
| 322 virtual int32_t GetCharArray() const = 0; | |
| 323 virtual int32_t GetLimitChar() const = 0; | |
| 324 virtual int32_t GetHorzScale() const = 0; | |
| 325 virtual FX_FLOAT GetCharSpace() const = 0; | |
| 326 virtual CPVT_WordPlace GetBeginWordPlace() const = 0; | |
| 327 virtual CPVT_WordPlace GetEndWordPlace() const = 0; | |
| 328 virtual CPVT_WordPlace GetPrevWordPlace( | |
| 329 const CPVT_WordPlace& place) const = 0; | |
| 330 virtual CPVT_WordPlace GetNextWordPlace( | |
| 331 const CPVT_WordPlace& place) const = 0; | |
| 332 | |
| 333 virtual CPVT_WordPlace SearchWordPlace(const CFX_FloatPoint& point) const = 0; | |
| 334 virtual CPVT_WordPlace GetUpWordPlace(const CPVT_WordPlace& place, | |
| 335 const CFX_FloatPoint& point) const = 0; | |
| 336 virtual CPVT_WordPlace GetDownWordPlace( | |
| 337 const CPVT_WordPlace& place, | |
| 338 const CFX_FloatPoint& point) const = 0; | |
| 339 virtual CPVT_WordPlace GetLineBeginPlace( | |
| 340 const CPVT_WordPlace& place) const = 0; | |
| 341 virtual CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace& place) const = 0; | |
| 342 virtual CPVT_WordPlace GetSectionBeginPlace( | |
| 343 const CPVT_WordPlace& place) const = 0; | |
| 344 virtual CPVT_WordPlace GetSectionEndPlace( | |
| 345 const CPVT_WordPlace& place) const = 0; | |
| 346 | |
| 347 virtual void UpdateWordPlace(CPVT_WordPlace& place) const = 0; | |
| 348 virtual CPVT_WordPlace AdjustLineHeader(const CPVT_WordPlace& place, | |
| 349 FX_BOOL bPrevOrNext) const = 0; | |
| 350 | |
| 351 virtual int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const = 0; | |
| 352 virtual CPVT_WordPlace WordIndexToWordPlace(int32_t index) const = 0; | |
| 353 | |
| 354 protected: | |
| 355 ~IPDF_VariableText() {} | |
| 356 }; | |
| 357 | |
| 358 #endif // CORE_INCLUDE_FPDFDOC_FPDF_VT_H_ | |
| OLD | NEW |