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