| OLD | NEW |
| (Empty) | |
| 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_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_ |
| 8 #define CORE_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_ |
| 9 |
| 10 #include "core/fpdfdoc/cpvt_floatrect.h" |
| 11 #include "core/fpdfdoc/cpvt_lineinfo.h" |
| 12 #include "core/fpdfdoc/include/cpvt_line.h" |
| 13 #include "core/fpdfdoc/include/cpvt_wordplace.h" |
| 14 #include "core/fpdfdoc/include/cpvt_wordrange.h" |
| 15 #include "core/fpdfdoc/pdf_vt.h" |
| 16 #include "core/fxcrt/include/fx_coordinates.h" |
| 17 #include "core/fxcrt/include/fx_string.h" |
| 18 #include "core/fxcrt/include/fx_system.h" |
| 19 |
| 20 class CSection; |
| 21 class IPVT_FontMap; |
| 22 |
| 23 struct CPVT_SecProps; |
| 24 struct CPVT_Section; |
| 25 struct CPVT_SectionInfo; |
| 26 struct CPVT_Word; |
| 27 struct CPVT_WordProps; |
| 28 struct CPVT_WordInfo; |
| 29 |
| 30 #define VARIABLETEXT_HALF 0.5f |
| 31 |
| 32 class CPDF_VariableText : private CPDF_EditContainer { |
| 33 public: |
| 34 enum class ScriptType { Normal, Super, Sub }; |
| 35 |
| 36 class Iterator { |
| 37 public: |
| 38 explicit Iterator(CPDF_VariableText* pVT); |
| 39 ~Iterator(); |
| 40 |
| 41 FX_BOOL NextWord(); |
| 42 FX_BOOL PrevWord(); |
| 43 FX_BOOL NextLine(); |
| 44 FX_BOOL PrevLine(); |
| 45 FX_BOOL NextSection(); |
| 46 FX_BOOL PrevSection(); |
| 47 FX_BOOL SetWord(const CPVT_Word& word); |
| 48 FX_BOOL GetWord(CPVT_Word& word) const; |
| 49 FX_BOOL GetLine(CPVT_Line& line) const; |
| 50 FX_BOOL GetSection(CPVT_Section& section) const; |
| 51 FX_BOOL SetSection(const CPVT_Section& section); |
| 52 void SetAt(int32_t nWordIndex); |
| 53 void SetAt(const CPVT_WordPlace& place); |
| 54 const CPVT_WordPlace& GetAt() const { return m_CurPos; } |
| 55 |
| 56 private: |
| 57 CPVT_WordPlace m_CurPos; |
| 58 CPDF_VariableText* const m_pVT; |
| 59 }; |
| 60 |
| 61 class Provider { |
| 62 public: |
| 63 Provider(IPVT_FontMap* pFontMap); |
| 64 virtual ~Provider(); |
| 65 |
| 66 virtual int32_t GetCharWidth(int32_t nFontIndex, |
| 67 uint16_t word, |
| 68 int32_t nWordStyle); |
| 69 virtual int32_t GetTypeAscent(int32_t nFontIndex); |
| 70 virtual int32_t GetTypeDescent(int32_t nFontIndex); |
| 71 virtual int32_t GetWordFontIndex(uint16_t word, |
| 72 int32_t charset, |
| 73 int32_t nFontIndex); |
| 74 virtual FX_BOOL IsLatinWord(uint16_t word); |
| 75 virtual int32_t GetDefaultFontIndex(); |
| 76 |
| 77 private: |
| 78 IPVT_FontMap* m_pFontMap; |
| 79 }; |
| 80 |
| 81 CPDF_VariableText(); |
| 82 virtual ~CPDF_VariableText(); |
| 83 |
| 84 CPDF_VariableText::Provider* SetProvider( |
| 85 CPDF_VariableText::Provider* pProvider); |
| 86 CPDF_VariableText::Iterator* GetIterator(); |
| 87 |
| 88 // CPDF_EditContainer. |
| 89 void SetPlateRect(const CFX_FloatRect& rect) override { |
| 90 CPDF_EditContainer::SetPlateRect(rect); |
| 91 } |
| 92 CFX_FloatRect GetContentRect() const override; |
| 93 const CFX_FloatRect& GetPlateRect() const override { |
| 94 return CPDF_EditContainer::GetPlateRect(); |
| 95 } |
| 96 |
| 97 void SetAlignment(int32_t nFormat = 0) { m_nAlignment = nFormat; } |
| 98 void SetPasswordChar(uint16_t wSubWord = '*') { m_wSubWord = wSubWord; } |
| 99 void SetLimitChar(int32_t nLimitChar = 0) { m_nLimitChar = nLimitChar; } |
| 100 void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) { m_fCharSpace = fCharSpace; } |
| 101 void SetHorzScale(int32_t nHorzScale = 100) { m_nHorzScale = nHorzScale; } |
| 102 void SetMultiLine(FX_BOOL bMultiLine = TRUE) { m_bMultiLine = bMultiLine; } |
| 103 void SetAutoReturn(FX_BOOL bAuto = TRUE) { m_bLimitWidth = bAuto; } |
| 104 void SetFontSize(FX_FLOAT fFontSize) { m_fFontSize = fFontSize; } |
| 105 void SetCharArray(int32_t nCharArray = 0) { m_nCharArray = nCharArray; } |
| 106 void SetAutoFontSize(FX_BOOL bAuto = TRUE) { m_bAutoFontSize = bAuto; } |
| 107 void SetRichText(FX_BOOL bRichText) { m_bRichText = bRichText; } |
| 108 void SetLineLeading(FX_FLOAT fLineLeading) { m_fLineLeading = fLineLeading; } |
| 109 void Initialize(); |
| 110 FX_BOOL IsValid() const { return m_bInitial; } |
| 111 FX_BOOL IsRichText() const { return m_bRichText; } |
| 112 void RearrangeAll(); |
| 113 void RearrangePart(const CPVT_WordRange& PlaceRange); |
| 114 void ResetAll(); |
| 115 void SetText(const FX_WCHAR* text, |
| 116 int32_t charset = 1, |
| 117 const CPVT_SecProps* pSecProps = NULL, |
| 118 const CPVT_WordProps* pWordProps = NULL); |
| 119 CPVT_WordPlace InsertWord(const CPVT_WordPlace& place, |
| 120 uint16_t word, |
| 121 int32_t charset = 1, |
| 122 const CPVT_WordProps* pWordProps = NULL); |
| 123 CPVT_WordPlace InsertSection(const CPVT_WordPlace& place, |
| 124 const CPVT_SecProps* pSecProps = NULL, |
| 125 const CPVT_WordProps* pWordProps = NULL); |
| 126 CPVT_WordPlace InsertText(const CPVT_WordPlace& place, |
| 127 const FX_WCHAR* text, |
| 128 int32_t charset = 1, |
| 129 const CPVT_SecProps* pSecProps = NULL, |
| 130 const CPVT_WordProps* pWordProps = NULL); |
| 131 CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange); |
| 132 CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place); |
| 133 CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place); |
| 134 |
| 135 int32_t GetTotalWords() const; |
| 136 FX_FLOAT GetFontSize() const { return m_fFontSize; } |
| 137 int32_t GetAlignment() const { return m_nAlignment; } |
| 138 uint16_t GetPasswordChar() const { return GetSubWord(); } |
| 139 int32_t GetCharArray() const { return m_nCharArray; } |
| 140 int32_t GetLimitChar() const { return m_nLimitChar; } |
| 141 FX_BOOL IsMultiLine() const { return m_bMultiLine; } |
| 142 int32_t GetHorzScale() const { return m_nHorzScale; } |
| 143 FX_FLOAT GetCharSpace() const { return m_fCharSpace; } |
| 144 CPVT_WordPlace GetBeginWordPlace() const; |
| 145 CPVT_WordPlace GetEndWordPlace() const; |
| 146 CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; |
| 147 CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const; |
| 148 CPVT_WordPlace SearchWordPlace(const CFX_FloatPoint& point) const; |
| 149 CPVT_WordPlace GetUpWordPlace(const CPVT_WordPlace& place, |
| 150 const CFX_FloatPoint& point) const; |
| 151 CPVT_WordPlace GetDownWordPlace(const CPVT_WordPlace& place, |
| 152 const CFX_FloatPoint& point) const; |
| 153 CPVT_WordPlace GetLineBeginPlace(const CPVT_WordPlace& place) const; |
| 154 CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace& place) const; |
| 155 CPVT_WordPlace GetSectionBeginPlace(const CPVT_WordPlace& place) const; |
| 156 CPVT_WordPlace GetSectionEndPlace(const CPVT_WordPlace& place) const; |
| 157 void UpdateWordPlace(CPVT_WordPlace& place) const; |
| 158 CPVT_WordPlace AdjustLineHeader(const CPVT_WordPlace& place, |
| 159 FX_BOOL bPrevOrNext) const; |
| 160 int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const; |
| 161 CPVT_WordPlace WordIndexToWordPlace(int32_t index) const; |
| 162 |
| 163 uint16_t GetSubWord() const { return m_wSubWord; } |
| 164 |
| 165 private: |
| 166 friend class CTypeset; |
| 167 friend class CSection; |
| 168 |
| 169 int32_t GetCharWidth(int32_t nFontIndex, |
| 170 uint16_t Word, |
| 171 uint16_t SubWord, |
| 172 int32_t nWordStyle); |
| 173 int32_t GetTypeAscent(int32_t nFontIndex); |
| 174 int32_t GetTypeDescent(int32_t nFontIndex); |
| 175 int32_t GetWordFontIndex(uint16_t word, int32_t charset, int32_t nFontIndex); |
| 176 int32_t GetDefaultFontIndex(); |
| 177 FX_BOOL IsLatinWord(uint16_t word); |
| 178 |
| 179 CPVT_WordPlace AddSection(const CPVT_WordPlace& place, |
| 180 const CPVT_SectionInfo& secinfo); |
| 181 CPVT_WordPlace AddLine(const CPVT_WordPlace& place, |
| 182 const CPVT_LineInfo& lineinfo); |
| 183 CPVT_WordPlace AddWord(const CPVT_WordPlace& place, |
| 184 const CPVT_WordInfo& wordinfo); |
| 185 FX_BOOL GetWordInfo(const CPVT_WordPlace& place, CPVT_WordInfo& wordinfo); |
| 186 FX_BOOL SetWordInfo(const CPVT_WordPlace& place, |
| 187 const CPVT_WordInfo& wordinfo); |
| 188 FX_BOOL GetLineInfo(const CPVT_WordPlace& place, CPVT_LineInfo& lineinfo); |
| 189 FX_BOOL GetSectionInfo(const CPVT_WordPlace& place, |
| 190 CPVT_SectionInfo& secinfo); |
| 191 FX_FLOAT GetWordFontSize(const CPVT_WordInfo& WordInfo, |
| 192 FX_BOOL bFactFontSize = FALSE); |
| 193 FX_FLOAT GetWordWidth(int32_t nFontIndex, |
| 194 uint16_t Word, |
| 195 uint16_t SubWord, |
| 196 FX_FLOAT fCharSpace, |
| 197 int32_t nHorzScale, |
| 198 FX_FLOAT fFontSize, |
| 199 FX_FLOAT fWordTail, |
| 200 int32_t nWordStyle); |
| 201 FX_FLOAT GetWordWidth(const CPVT_WordInfo& WordInfo); |
| 202 FX_FLOAT GetWordAscent(const CPVT_WordInfo& WordInfo, FX_FLOAT fFontSize); |
| 203 FX_FLOAT GetWordDescent(const CPVT_WordInfo& WordInfo, FX_FLOAT fFontSize); |
| 204 FX_FLOAT GetWordAscent(const CPVT_WordInfo& WordInfo, |
| 205 FX_BOOL bFactFontSize = FALSE); |
| 206 FX_FLOAT GetWordDescent(const CPVT_WordInfo& WordInfo, |
| 207 FX_BOOL bFactFontSize = FALSE); |
| 208 FX_FLOAT GetLineAscent(const CPVT_SectionInfo& SecInfo); |
| 209 FX_FLOAT GetLineDescent(const CPVT_SectionInfo& SecInfo); |
| 210 FX_FLOAT GetFontAscent(int32_t nFontIndex, FX_FLOAT fFontSize); |
| 211 FX_FLOAT GetFontDescent(int32_t nFontIndex, FX_FLOAT fFontSize); |
| 212 int32_t GetWordFontIndex(const CPVT_WordInfo& WordInfo); |
| 213 FX_FLOAT GetCharSpace(const CPVT_WordInfo& WordInfo); |
| 214 int32_t GetHorzScale(const CPVT_WordInfo& WordInfo); |
| 215 FX_FLOAT GetLineLeading(const CPVT_SectionInfo& SecInfo); |
| 216 FX_FLOAT GetLineIndent(const CPVT_SectionInfo& SecInfo); |
| 217 int32_t GetAlignment(const CPVT_SectionInfo& SecInfo); |
| 218 |
| 219 void ClearSectionRightWords(const CPVT_WordPlace& place); |
| 220 |
| 221 FX_BOOL ClearEmptySection(const CPVT_WordPlace& place); |
| 222 void ClearEmptySections(const CPVT_WordRange& PlaceRange); |
| 223 void LinkLatterSection(const CPVT_WordPlace& place); |
| 224 void ClearWords(const CPVT_WordRange& PlaceRange); |
| 225 CPVT_WordPlace ClearLeftWord(const CPVT_WordPlace& place); |
| 226 CPVT_WordPlace ClearRightWord(const CPVT_WordPlace& place); |
| 227 |
| 228 CPVT_FloatRect Rearrange(const CPVT_WordRange& PlaceRange); |
| 229 FX_FLOAT GetAutoFontSize(); |
| 230 FX_BOOL IsBigger(FX_FLOAT fFontSize); |
| 231 CPVT_FloatRect RearrangeSections(const CPVT_WordRange& PlaceRange); |
| 232 |
| 233 void ResetSectionArray(); |
| 234 |
| 235 CPVT_ArrayTemplate<CSection*> m_SectionArray; |
| 236 int32_t m_nLimitChar; |
| 237 int32_t m_nCharArray; |
| 238 FX_BOOL m_bMultiLine; |
| 239 FX_BOOL m_bLimitWidth; |
| 240 FX_BOOL m_bAutoFontSize; |
| 241 int32_t m_nAlignment; |
| 242 FX_FLOAT m_fLineLeading; |
| 243 FX_FLOAT m_fCharSpace; |
| 244 int32_t m_nHorzScale; |
| 245 uint16_t m_wSubWord; |
| 246 FX_FLOAT m_fFontSize; |
| 247 FX_BOOL m_bInitial; |
| 248 FX_BOOL m_bRichText; |
| 249 CPDF_VariableText::Provider* m_pVTProvider; |
| 250 CPDF_VariableText::Iterator* m_pVTIterator; |
| 251 }; |
| 252 |
| 253 #endif // CORE_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_ |
| OLD | NEW |