Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: core/fpdfdoc/cpdf_variabletext.cpp

Issue 1860063002: Remove core/include/fpdfdoc/fpdf_vt.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <algorithm> 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 8 #include "core/fpdfdoc/cpvt_wordinfo.h"
9 #include "core/fpdfdoc/pdf_vt.h" 9 #include "core/fpdfdoc/csection.h"
10 #include "core/include/fpdfdoc/fpdf_doc.h" 10 #include "core/fpdfdoc/include/cpdf_variabletext.h"
11 #include "core/include/fpdfdoc/fpdf_vt.h" 11 #include "core/fpdfdoc/include/cpvt_section.h"
12 #include "core/include/fpdfdoc/fpdf_vt.h" 12 #include "core/fpdfdoc/include/cpvt_word.h"
13 #include "core/fpdfdoc/include/ipvt_fontmap.h"
14
15 namespace {
16
17 const float kDefaultFontSize = 18.0f;
18 const float kFontScale = 0.001f;
19
Tom Sepez 2016/04/05 16:58:23 nit: no need for a blank line here.
dsinclair 2016/04/05 17:29:20 Done.
20 const uint8_t kReturnLength = 1;
21 const float kScalePercent = 0.01f;
13 22
14 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20, 23 const uint8_t gFontSizeSteps[] = {4, 6, 8, 9, 10, 12, 14, 18, 20,
15 25, 30, 35, 40, 45, 50, 55, 60, 70, 24 25, 30, 35, 40, 45, 50, 55, 60, 70,
16 80, 90, 100, 110, 120, 130, 144}; 25 80, 90, 100, 110, 120, 130, 144};
17 #define PVT_RETURN_LENGTH 1 26
18 #define PVT_DEFAULT_FONTSIZE 18.0f 27 } // namespace
19 #define PVTWORD_SCRIPT_NORMAL 0 28
20 #define PVTWORD_SCRIPT_SUPER 1 29 CPDF_VariableText::Provider::Provider(IPVT_FontMap* pFontMap)
21 #define PVTWORD_SCRIPT_SUB 2 30 : m_pFontMap(pFontMap) {
22 #define PVT_FONTSCALE 0.001f 31 ASSERT(m_pFontMap);
23 #define PVT_PERCENT 0.01f 32 }
24 #define PVT_HALF 0.5f 33
25 CLine::CLine() {} 34 CPDF_VariableText::Provider::~Provider() {}
26 CLine::~CLine() {} 35
27 CPVT_WordPlace CLine::GetBeginWordPlace() const { 36 int32_t CPDF_VariableText::Provider::GetCharWidth(int32_t nFontIndex,
28 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); 37 uint16_t word,
29 } 38 int32_t nWordStyle) {
30 CPVT_WordPlace CLine::GetEndWordPlace() const { 39 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
31 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, 40 uint32_t charcode = pPDFFont->CharCodeFromUnicode(word);
32 m_LineInfo.nEndWordIndex); 41 if (charcode != CPDF_Font::kInvalidCharCode)
33 } 42 return pPDFFont->GetCharWidthF(charcode);
34 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { 43 }
35 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { 44 return 0;
36 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, 45 }
37 m_LineInfo.nEndWordIndex); 46
38 } 47 int32_t CPDF_VariableText::Provider::GetTypeAscent(int32_t nFontIndex) {
39 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, 48 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
40 place.nWordIndex - 1); 49 return pPDFFont->GetTypeAscent();
41 } 50 return 0;
42 CPVT_WordPlace CLine::GetNextWordPlace(const CPVT_WordPlace& place) const { 51 }
43 if (place.nWordIndex < m_LineInfo.nBeginWordIndex) { 52
44 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, 53 int32_t CPDF_VariableText::Provider::GetTypeDescent(int32_t nFontIndex) {
45 m_LineInfo.nBeginWordIndex); 54 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
46 } 55 return pPDFFont->GetTypeDescent();
47 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, 56 return 0;
48 place.nWordIndex + 1); 57 }
49 } 58
50 CSection::CSection(CPDF_VariableText* pVT) : m_pVT(pVT) {} 59 int32_t CPDF_VariableText::Provider::GetWordFontIndex(uint16_t word,
51 CSection::~CSection() { 60 int32_t charset,
52 ResetAll(); 61 int32_t nFontIndex) {
53 } 62 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) {
54 void CSection::ResetAll() { 63 if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode)
55 ResetWordArray(); 64 return 0;
56 ResetLineArray(); 65 }
57 } 66 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) {
58 void CSection::ResetLineArray() { 67 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode)
59 m_LineArray.RemoveAll(); 68 return 1;
60 } 69 }
61 void CSection::ResetWordArray() { 70 return -1;
62 for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++) { 71 }
63 delete m_WordArray.GetAt(i); 72
64 } 73 FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) {
65 m_WordArray.RemoveAll(); 74 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
66 } 75 word == 0x2D || word == 0x27) {
67 void CSection::ResetLinePlace() { 76 return TRUE;
68 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { 77 }
69 if (CLine* pLine = m_LineArray.GetAt(i)) { 78 return FALSE;
70 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); 79 }
71 } 80
72 } 81 int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() {
73 } 82 return 0;
74 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, 83 }
75 const CPVT_WordInfo& wordinfo) { 84
76 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); 85 CPDF_VariableText::Iterator::Iterator(CPDF_VariableText* pVT)
77 int32_t nWordIndex = 86 : m_CurPos(-1, -1, -1), m_pVT(pVT) {}
78 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); 87
79 if (nWordIndex == m_WordArray.GetSize()) { 88 CPDF_VariableText::Iterator::~Iterator() {}
80 m_WordArray.Add(pWord); 89
81 } else { 90 void CPDF_VariableText::Iterator::SetAt(int32_t nWordIndex) {
82 m_WordArray.InsertAt(nWordIndex, pWord); 91 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex);
83 } 92 }
84 return place; 93
85 } 94 void CPDF_VariableText::Iterator::SetAt(const CPVT_WordPlace& place) {
86 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { 95 ASSERT(m_pVT);
87 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); 96 m_CurPos = place;
88 } 97 }
89 CPVT_FloatRect CSection::Rearrange() { 98
90 if (m_pVT->m_nCharArray > 0) { 99 FX_BOOL CPDF_VariableText::Iterator::NextWord() {
91 return CTypeset(this).CharArray(); 100 if (m_CurPos == m_pVT->GetEndWordPlace())
92 } 101 return FALSE;
93 return CTypeset(this).Typeset(); 102
94 } 103 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos);
95 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) { 104 return TRUE;
96 return CTypeset(this).GetEditSize(fFontSize); 105 }
97 } 106
98 CPVT_WordPlace CSection::GetBeginWordPlace() const { 107 FX_BOOL CPDF_VariableText::Iterator::PrevWord() {
99 if (CLine* pLine = m_LineArray.GetAt(0)) { 108 if (m_CurPos == m_pVT->GetBeginWordPlace())
100 return pLine->GetBeginWordPlace(); 109 return FALSE;
101 } 110
102 return SecPlace; 111 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos);
103 } 112 return TRUE;
104 CPVT_WordPlace CSection::GetEndWordPlace() const { 113 }
105 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) { 114
106 return pLine->GetEndWordPlace(); 115 FX_BOOL CPDF_VariableText::Iterator::NextLine() {
107 } 116 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
108 return SecPlace; 117 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) {
109 } 118 m_CurPos =
110 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { 119 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1);
111 if (place.nLineIndex < 0) { 120 return TRUE;
112 return GetBeginWordPlace(); 121 }
113 } 122 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
114 if (place.nLineIndex >= m_LineArray.GetSize()) { 123 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
115 return GetEndWordPlace(); 124 return TRUE;
116 } 125 }
117 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { 126 }
118 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) { 127 return FALSE;
119 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); 128 }
120 } 129
121 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { 130 FX_BOOL CPDF_VariableText::Iterator::PrevLine() {
122 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) { 131 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
123 return pPrevLine->GetEndWordPlace(); 132 if (m_CurPos.nLineIndex > 0) {
133 m_CurPos =
134 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1);
135 return TRUE;
136 }
137 if (m_CurPos.nSecIndex > 0) {
138 if (CSection* pLastSection =
139 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) {
140 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1,
141 pLastSection->m_LineArray.GetSize() - 1, -1);
142 return TRUE;
124 } 143 }
125 } else { 144 }
126 return pLine->GetPrevWordPlace(place); 145 }
127 } 146 return FALSE;
128 } 147 }
129 return place; 148
130 } 149 FX_BOOL CPDF_VariableText::Iterator::NextSection() {
131 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { 150 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
132 if (place.nLineIndex < 0) { 151 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
133 return GetBeginWordPlace(); 152 return TRUE;
134 } 153 }
135 if (place.nLineIndex >= m_LineArray.GetSize()) { 154 return FALSE;
136 return GetEndWordPlace(); 155 }
137 } 156
138 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { 157 FX_BOOL CPDF_VariableText::Iterator::PrevSection() {
139 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) { 158 ASSERT(m_pVT);
140 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) { 159 if (m_CurPos.nSecIndex > 0) {
141 return pNextLine->GetBeginWordPlace(); 160 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1);
161 return TRUE;
162 }
163 return FALSE;
164 }
165
166 FX_BOOL CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const {
167 word.WordPlace = m_CurPos;
168 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
169 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
170 if (CPVT_WordInfo* pWord =
171 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
172 word.Word = pWord->Word;
173 word.nCharset = pWord->nCharset;
174 word.fWidth = m_pVT->GetWordWidth(*pWord);
175 word.ptWord = m_pVT->InToOut(
176 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left,
177 pWord->fWordY + pSection->m_SecInfo.rcSection.top));
178 word.fAscent = m_pVT->GetWordAscent(*pWord);
179 word.fDescent = m_pVT->GetWordDescent(*pWord);
180 if (pWord->pWordProps)
181 word.WordProps = *pWord->pWordProps;
182
183 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord);
184 word.fFontSize = m_pVT->GetWordFontSize(*pWord);
185 return TRUE;
142 } 186 }
143 } else { 187 }
144 return pLine->GetNextWordPlace(place); 188 }
145 } 189 return FALSE;
146 } 190 }
147 return place; 191
148 } 192 FX_BOOL CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) {
149 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { 193 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
150 int32_t nLeft = 0; 194 if (CPVT_WordInfo* pWord =
151 int32_t nRight = m_LineArray.GetSize() - 1; 195 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
152 int32_t nMid = (nLeft + nRight) / 2; 196 if (pWord->pWordProps)
153 while (nLeft <= nRight) { 197 *pWord->pWordProps = word.WordProps;
154 if (CLine* pLine = m_LineArray.GetAt(nMid)) { 198 return TRUE;
155 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { 199 }
156 nRight = nMid - 1; 200 }
157 nMid = (nLeft + nRight) / 2; 201 return FALSE;
158 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { 202 }
159 nLeft = nMid + 1; 203
160 nMid = (nLeft + nRight) / 2; 204 FX_BOOL CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const {
161 } else {
162 place.nLineIndex = nMid;
163 return;
164 }
165 } else {
166 break;
167 }
168 }
169 }
170 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const {
171 ASSERT(m_pVT); 205 ASSERT(m_pVT);
172 CPVT_WordPlace place = GetBeginWordPlace(); 206 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1);
173 FX_BOOL bUp = TRUE; 207 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
174 FX_BOOL bDown = TRUE; 208 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
175 int32_t nLeft = 0; 209 line.ptLine = m_pVT->InToOut(CFX_FloatPoint(
176 int32_t nRight = m_LineArray.GetSize() - 1; 210 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left,
177 int32_t nMid = m_LineArray.GetSize() / 2; 211 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top));
178 FX_FLOAT fTop = 0; 212 line.fLineWidth = pLine->m_LineInfo.fLineWidth;
179 FX_FLOAT fBottom = 0; 213 line.fLineAscent = pLine->m_LineInfo.fLineAscent;
180 while (nLeft <= nRight) { 214 line.fLineDescent = pLine->m_LineInfo.fLineDescent;
181 if (CLine* pLine = m_LineArray.GetAt(nMid)) { 215 line.lineEnd = pLine->GetEndWordPlace();
182 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - 216 return TRUE;
183 m_pVT->GetLineLeading(m_SecInfo); 217 }
184 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; 218 }
185 if (IsFloatBigger(point.y, fTop)) { 219 return FALSE;
186 bUp = FALSE; 220 }
187 } 221
188 if (IsFloatSmaller(point.y, fBottom)) { 222 FX_BOOL CPDF_VariableText::Iterator::GetSection(CPVT_Section& section) const {
189 bDown = FALSE; 223 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1);
190 } 224 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
191 if (IsFloatSmaller(point.y, fTop)) { 225 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection);
192 nRight = nMid - 1; 226 if (pSection->m_SecInfo.pSecProps)
193 nMid = (nLeft + nRight) / 2; 227 section.SecProps = *pSection->m_SecInfo.pSecProps;
194 continue; 228 if (pSection->m_SecInfo.pWordProps)
195 } else if (IsFloatBigger(point.y, fBottom)) { 229 section.WordProps = *pSection->m_SecInfo.pWordProps;
196 nLeft = nMid + 1; 230 return TRUE;
197 nMid = (nLeft + nRight) / 2; 231 }
198 continue; 232 return FALSE;
199 } else { 233 }
200 place = SearchWordPlace( 234
201 point.x, 235 FX_BOOL CPDF_VariableText::Iterator::SetSection(const CPVT_Section& section) {
202 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), 236 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
203 pLine->GetEndWordPlace())); 237 if (pSection->m_SecInfo.pSecProps)
204 place.nLineIndex = nMid; 238 *pSection->m_SecInfo.pSecProps = section.SecProps;
205 return place; 239 if (pSection->m_SecInfo.pWordProps)
206 } 240 *pSection->m_SecInfo.pWordProps = section.WordProps;
207 } 241 return TRUE;
208 } 242 }
209 if (bUp) { 243 return FALSE;
210 place = GetBeginWordPlace(); 244 }
211 } 245
212 if (bDown) {
213 place = GetEndWordPlace();
214 }
215 return place;
216 }
217 CPVT_WordPlace CSection::SearchWordPlace(
218 FX_FLOAT fx,
219 const CPVT_WordPlace& lineplace) const {
220 if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) {
221 return SearchWordPlace(
222 fx - m_SecInfo.rcSection.left,
223 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()),
224 pLine->GetEndWordPlace()));
225 }
226 return GetBeginWordPlace();
227 }
228 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx,
229 const CPVT_WordRange& range) const {
230 CPVT_WordPlace wordplace = range.BeginPos;
231 wordplace.nWordIndex = -1;
232 if (!m_pVT) {
233 return wordplace;
234 }
235 int32_t nLeft = range.BeginPos.nWordIndex;
236 int32_t nRight = range.EndPos.nWordIndex + 1;
237 int32_t nMid = (nLeft + nRight) / 2;
238 while (nLeft < nRight) {
239 if (nMid == nLeft) {
240 break;
241 }
242 if (nMid == nRight) {
243 nMid--;
244 break;
245 }
246 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) {
247 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) {
248 nLeft = nMid;
249 nMid = (nLeft + nRight) / 2;
250 continue;
251 } else {
252 nRight = nMid;
253 nMid = (nLeft + nRight) / 2;
254 continue;
255 }
256 } else {
257 break;
258 }
259 }
260 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) {
261 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * PVT_HALF) {
262 wordplace.nWordIndex = nMid;
263 }
264 }
265 return wordplace;
266 }
267 void CSection::ClearLeftWords(int32_t nWordIndex) {
268 for (int32_t i = nWordIndex; i >= 0; i--) {
269 delete m_WordArray.GetAt(i);
270 m_WordArray.RemoveAt(i);
271 }
272 }
273 void CSection::ClearRightWords(int32_t nWordIndex) {
274 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) {
275 delete m_WordArray.GetAt(i);
276 m_WordArray.RemoveAt(i);
277 }
278 }
279 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) {
280 for (int32_t i = nEndIndex; i > nBeginIndex; i--) {
281 delete m_WordArray.GetAt(i);
282 m_WordArray.RemoveAt(i);
283 }
284 }
285 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) {
286 CPVT_WordPlace SecBeginPos = GetBeginWordPlace();
287 CPVT_WordPlace SecEndPos = GetEndWordPlace();
288 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) {
289 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
290 ClearMidWords(PlaceRange.BeginPos.nWordIndex,
291 PlaceRange.EndPos.nWordIndex);
292 } else {
293 ClearRightWords(PlaceRange.BeginPos.nWordIndex);
294 }
295 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
296 ClearLeftWords(PlaceRange.EndPos.nWordIndex);
297 } else {
298 ResetWordArray();
299 }
300 }
301 void CSection::ClearWord(const CPVT_WordPlace& place) {
302 delete m_WordArray.GetAt(place.nWordIndex);
303 m_WordArray.RemoveAt(place.nWordIndex);
304 }
305 CTypeset::CTypeset(CSection* pSection)
306 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f),
307 m_pVT(pSection->m_pVT),
308 m_pSection(pSection) {}
309 CTypeset::~CTypeset() {}
310 CPVT_FloatRect CTypeset::CharArray() {
311 ASSERT(m_pSection);
312 FX_FLOAT fLineAscent =
313 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize());
314 FX_FLOAT fLineDescent =
315 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize());
316 m_rcRet.Default();
317 FX_FLOAT x = 0.0f, y = 0.0f;
318 FX_FLOAT fNextWidth;
319 int32_t nStart = 0;
320 FX_FLOAT fNodeWidth = m_pVT->GetPlateWidth() /
321 (m_pVT->m_nCharArray <= 0 ? 1 : m_pVT->m_nCharArray);
322 if (CLine* pLine = m_pSection->m_LineArray.GetAt(0)) {
323 x = 0.0f;
324 y += m_pVT->GetLineLeading(m_pSection->m_SecInfo);
325 y += fLineAscent;
326 nStart = 0;
327 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
328 case 0:
329 pLine->m_LineInfo.fLineX = fNodeWidth * PVT_HALF;
330 break;
331 case 1:
332 nStart = (m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize()) / 2;
333 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF;
334 break;
335 case 2:
336 nStart = m_pVT->m_nCharArray - m_pSection->m_WordArray.GetSize();
337 pLine->m_LineInfo.fLineX = fNodeWidth * nStart - fNodeWidth * PVT_HALF;
338 break;
339 }
340 for (int32_t w = 0, sz = m_pSection->m_WordArray.GetSize(); w < sz; w++) {
341 if (w >= m_pVT->m_nCharArray) {
342 break;
343 }
344 fNextWidth = 0;
345 if (CPVT_WordInfo* pNextWord =
346 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w + 1)) {
347 pNextWord->fWordTail = 0;
348 fNextWidth = m_pVT->GetWordWidth(*pNextWord);
349 }
350 if (CPVT_WordInfo* pWord =
351 (CPVT_WordInfo*)m_pSection->m_WordArray.GetAt(w)) {
352 pWord->fWordTail = 0;
353 FX_FLOAT fWordWidth = m_pVT->GetWordWidth(*pWord);
354 FX_FLOAT fWordAscent = m_pVT->GetWordAscent(*pWord);
355 FX_FLOAT fWordDescent = m_pVT->GetWordDescent(*pWord);
356 x = (FX_FLOAT)(fNodeWidth * (w + nStart + 0.5) - fWordWidth * PVT_HALF);
357 pWord->fWordX = x;
358 pWord->fWordY = y;
359 if (w == 0) {
360 pLine->m_LineInfo.fLineX = x;
361 }
362 if (w != m_pSection->m_WordArray.GetSize() - 1) {
363 pWord->fWordTail =
364 (fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF > 0
365 ? fNodeWidth - (fWordWidth + fNextWidth) * PVT_HALF
366 : 0);
367 } else {
368 pWord->fWordTail = 0;
369 }
370 x += fWordWidth;
371 fLineAscent = std::max(fLineAscent, fWordAscent);
372 fLineDescent = std::min(fLineDescent, fWordDescent);
373 }
374 }
375 pLine->m_LineInfo.nBeginWordIndex = 0;
376 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1;
377 pLine->m_LineInfo.fLineY = y;
378 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX;
379 pLine->m_LineInfo.fLineAscent = fLineAscent;
380 pLine->m_LineInfo.fLineDescent = fLineDescent;
381 y += (-fLineDescent);
382 }
383 return m_rcRet = CPVT_FloatRect(0, 0, x, y);
384 }
385 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) {
386 ASSERT(m_pSection);
387 ASSERT(m_pVT);
388 SplitLines(FALSE, fFontSize);
389 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height());
390 }
391 CPVT_FloatRect CTypeset::Typeset() {
392 ASSERT(m_pVT);
393 m_pSection->m_LineArray.Empty();
394 SplitLines(TRUE, 0.0f);
395 m_pSection->m_LineArray.Clear();
396 OutputLines();
397 return m_rcRet;
398 }
399
400 static const uint8_t special_chars[128] = {
401 0x00, 0x0C, 0x08, 0x0C, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00,
404 0x10, 0x00, 0x00, 0x28, 0x0C, 0x08, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28,
405 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x08, 0x08,
406 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
407 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
408 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00,
409 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
410 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
411 0x01, 0x01, 0x01, 0x0C, 0x00, 0x08, 0x00, 0x00,
412 };
413
414 static bool IsLatin(uint16_t word) {
415 if (word <= 0x007F)
416 return !!(special_chars[word] & 0x01);
417
418 return ((word >= 0x00C0 && word <= 0x00FF) ||
419 (word >= 0x0100 && word <= 0x024F) ||
420 (word >= 0x1E00 && word <= 0x1EFF) ||
421 (word >= 0x2C60 && word <= 0x2C7F) ||
422 (word >= 0xA720 && word <= 0xA7FF) ||
423 (word >= 0xFF21 && word <= 0xFF3A) ||
424 (word >= 0xFF41 && word <= 0xFF5A));
425 }
426
427 static bool IsDigit(uint32_t word) {
428 return word >= 0x0030 && word <= 0x0039;
429 }
430
431 static bool IsCJK(uint32_t word) {
432 if ((word >= 0x1100 && word <= 0x11FF) ||
433 (word >= 0x2E80 && word <= 0x2FFF) ||
434 (word >= 0x3040 && word <= 0x9FBF) ||
435 (word >= 0xAC00 && word <= 0xD7AF) ||
436 (word >= 0xF900 && word <= 0xFAFF) ||
437 (word >= 0xFE30 && word <= 0xFE4F) ||
438 (word >= 0x20000 && word <= 0x2A6DF) ||
439 (word >= 0x2F800 && word <= 0x2FA1F)) {
440 return true;
441 }
442 if (word >= 0x3000 && word <= 0x303F) {
443 return (
444 word == 0x3005 || word == 0x3006 || word == 0x3021 || word == 0x3022 ||
445 word == 0x3023 || word == 0x3024 || word == 0x3025 || word == 0x3026 ||
446 word == 0x3027 || word == 0x3028 || word == 0x3029 || word == 0x3031 ||
447 word == 0x3032 || word == 0x3033 || word == 0x3034 || word == 0x3035);
448 }
449 return word >= 0xFF66 && word <= 0xFF9D;
450 }
451
452 static bool IsPunctuation(uint32_t word) {
453 if (word <= 0x007F)
454 return !!(special_chars[word] & 0x08);
455
456 if (word >= 0x0080 && word <= 0x00FF) {
457 return (word == 0x0082 || word == 0x0084 || word == 0x0085 ||
458 word == 0x0091 || word == 0x0092 || word == 0x0093 ||
459 word <= 0x0094 || word == 0x0096 || word == 0x00B4 ||
460 word == 0x00B8);
461 }
462
463 if (word >= 0x2000 && word <= 0x206F) {
464 return (
465 word == 0x2010 || word == 0x2011 || word == 0x2012 || word == 0x2013 ||
466 word == 0x2018 || word == 0x2019 || word == 0x201A || word == 0x201B ||
467 word == 0x201C || word == 0x201D || word == 0x201E || word == 0x201F ||
468 word == 0x2032 || word == 0x2033 || word == 0x2034 || word == 0x2035 ||
469 word == 0x2036 || word == 0x2037 || word == 0x203C || word == 0x203D ||
470 word == 0x203E || word == 0x2044);
471 }
472
473 if (word >= 0x3000 && word <= 0x303F) {
474 return (
475 word == 0x3001 || word == 0x3002 || word == 0x3003 || word == 0x3005 ||
476 word == 0x3009 || word == 0x300A || word == 0x300B || word == 0x300C ||
477 word == 0x300D || word == 0x300F || word == 0x300E || word == 0x3010 ||
478 word == 0x3011 || word == 0x3014 || word == 0x3015 || word == 0x3016 ||
479 word == 0x3017 || word == 0x3018 || word == 0x3019 || word == 0x301A ||
480 word == 0x301B || word == 0x301D || word == 0x301E || word == 0x301F);
481 }
482
483 if (word >= 0xFE50 && word <= 0xFE6F)
484 return (word >= 0xFE50 && word <= 0xFE5E) || word == 0xFE63;
485
486 if (word >= 0xFF00 && word <= 0xFFEF) {
487 return (
488 word == 0xFF01 || word == 0xFF02 || word == 0xFF07 || word == 0xFF08 ||
489 word == 0xFF09 || word == 0xFF0C || word == 0xFF0E || word == 0xFF0F ||
490 word == 0xFF1A || word == 0xFF1B || word == 0xFF1F || word == 0xFF3B ||
491 word == 0xFF3D || word == 0xFF40 || word == 0xFF5B || word == 0xFF5C ||
492 word == 0xFF5D || word == 0xFF61 || word == 0xFF62 || word == 0xFF63 ||
493 word == 0xFF64 || word == 0xFF65 || word == 0xFF9E || word == 0xFF9F);
494 }
495
496 return false;
497 }
498
499 static bool IsConnectiveSymbol(uint32_t word) {
500 return word <= 0x007F && (special_chars[word] & 0x20);
501 }
502
503 static bool IsOpenStylePunctuation(uint32_t word) {
504 if (word <= 0x007F)
505 return !!(special_chars[word] & 0x04);
506
507 return (word == 0x300A || word == 0x300C || word == 0x300E ||
508 word == 0x3010 || word == 0x3014 || word == 0x3016 ||
509 word == 0x3018 || word == 0x301A || word == 0xFF08 ||
510 word == 0xFF3B || word == 0xFF5B || word == 0xFF62);
511 }
512
513 static bool IsCurrencySymbol(uint16_t word) {
514 return (word == 0x0024 || word == 0x0080 || word == 0x00A2 ||
515 word == 0x00A3 || word == 0x00A4 || word == 0x00A5 ||
516 (word >= 0x20A0 && word <= 0x20CF) || word == 0xFE69 ||
517 word == 0xFF04 || word == 0xFFE0 || word == 0xFFE1 ||
518 word == 0xFFE5 || word == 0xFFE6);
519 }
520
521 static bool IsPrefixSymbol(uint16_t word) {
522 return IsCurrencySymbol(word) || word == 0x2116;
523 }
524
525 static bool IsSpace(uint16_t word) {
526 return word == 0x0020 || word == 0x3000;
527 }
528
529 static bool NeedDivision(uint16_t prevWord, uint16_t curWord) {
530 if ((IsLatin(prevWord) || IsDigit(prevWord)) &&
531 (IsLatin(curWord) || IsDigit(curWord))) {
532 return false;
533 }
534 if (IsSpace(curWord) || IsPunctuation(curWord)) {
535 return false;
536 }
537 if (IsConnectiveSymbol(prevWord) || IsConnectiveSymbol(curWord)) {
538 return false;
539 }
540 if (IsSpace(prevWord) || IsPunctuation(prevWord)) {
541 return true;
542 }
543 if (IsPrefixSymbol(prevWord)) {
544 return false;
545 }
546 if (IsPrefixSymbol(curWord) || IsCJK(curWord)) {
547 return true;
548 }
549 if (IsCJK(prevWord)) {
550 return true;
551 }
552 return false;
553 }
554
555 void CTypeset::SplitLines(FX_BOOL bTypeset, FX_FLOAT fFontSize) {
556 ASSERT(m_pVT);
557 ASSERT(m_pSection);
558 int32_t nLineHead = 0;
559 int32_t nLineTail = 0;
560 FX_FLOAT fMaxX = 0.0f, fMaxY = 0.0f;
561 FX_FLOAT fLineWidth = 0.0f, fBackupLineWidth = 0.0f;
562 FX_FLOAT fLineAscent = 0.0f, fBackupLineAscent = 0.0f;
563 FX_FLOAT fLineDescent = 0.0f, fBackupLineDescent = 0.0f;
564 int32_t nWordStartPos = 0;
565 FX_BOOL bFullWord = FALSE;
566 int32_t nLineFullWordIndex = 0;
567 int32_t nCharIndex = 0;
568 CPVT_LineInfo line;
569 FX_FLOAT fWordWidth = 0;
570 FX_FLOAT fTypesetWidth = std::max(
571 m_pVT->GetPlateWidth() - m_pVT->GetLineIndent(m_pSection->m_SecInfo),
572 0.0f);
573 int32_t nTotalWords = m_pSection->m_WordArray.GetSize();
574 FX_BOOL bOpened = FALSE;
575 if (nTotalWords > 0) {
576 int32_t i = 0;
577 while (i < nTotalWords) {
578 CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(i);
579 CPVT_WordInfo* pOldWord = pWord;
580 if (i > 0) {
581 pOldWord = m_pSection->m_WordArray.GetAt(i - 1);
582 }
583 if (pWord) {
584 if (bTypeset) {
585 fLineAscent =
586 std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, TRUE));
587 fLineDescent =
588 std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, TRUE));
589 fWordWidth = m_pVT->GetWordWidth(*pWord);
590 } else {
591 fLineAscent =
592 std::max(fLineAscent, m_pVT->GetWordAscent(*pWord, fFontSize));
593 fLineDescent =
594 std::min(fLineDescent, m_pVT->GetWordDescent(*pWord, fFontSize));
595 fWordWidth = m_pVT->GetWordWidth(
596 pWord->nFontIndex, pWord->Word, m_pVT->m_wSubWord,
597 m_pVT->m_fCharSpace, m_pVT->m_nHorzScale, fFontSize,
598 pWord->fWordTail, 0);
599 }
600 if (!bOpened) {
601 if (IsOpenStylePunctuation(pWord->Word)) {
602 bOpened = TRUE;
603 bFullWord = TRUE;
604 } else if (pOldWord) {
605 if (NeedDivision(pOldWord->Word, pWord->Word)) {
606 bFullWord = TRUE;
607 }
608 }
609 } else {
610 if (!IsSpace(pWord->Word) && !IsOpenStylePunctuation(pWord->Word)) {
611 bOpened = FALSE;
612 }
613 }
614 if (bFullWord) {
615 bFullWord = FALSE;
616 if (nCharIndex > 0) {
617 nLineFullWordIndex++;
618 }
619 nWordStartPos = i;
620 fBackupLineWidth = fLineWidth;
621 fBackupLineAscent = fLineAscent;
622 fBackupLineDescent = fLineDescent;
623 }
624 nCharIndex++;
625 }
626 if (m_pVT->m_bLimitWidth && fTypesetWidth > 0 &&
627 fLineWidth + fWordWidth > fTypesetWidth) {
628 if (nLineFullWordIndex > 0) {
629 i = nWordStartPos;
630 fLineWidth = fBackupLineWidth;
631 fLineAscent = fBackupLineAscent;
632 fLineDescent = fBackupLineDescent;
633 }
634 if (nCharIndex == 1) {
635 fLineWidth = fWordWidth;
636 i++;
637 }
638 nLineTail = i - 1;
639 if (bTypeset) {
640 line.nBeginWordIndex = nLineHead;
641 line.nEndWordIndex = nLineTail;
642 line.nTotalWord = nLineTail - nLineHead + 1;
643 line.fLineWidth = fLineWidth;
644 line.fLineAscent = fLineAscent;
645 line.fLineDescent = fLineDescent;
646 m_pSection->AddLine(line);
647 }
648 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
649 fMaxY += (-fLineDescent);
650 fMaxX = std::max(fLineWidth, fMaxX);
651 nLineHead = i;
652 fLineWidth = 0.0f;
653 fLineAscent = 0.0f;
654 fLineDescent = 0.0f;
655 nCharIndex = 0;
656 nLineFullWordIndex = 0;
657 bFullWord = FALSE;
658 } else {
659 fLineWidth += fWordWidth;
660 i++;
661 }
662 }
663 if (nLineHead <= nTotalWords - 1) {
664 nLineTail = nTotalWords - 1;
665 if (bTypeset) {
666 line.nBeginWordIndex = nLineHead;
667 line.nEndWordIndex = nLineTail;
668 line.nTotalWord = nLineTail - nLineHead + 1;
669 line.fLineWidth = fLineWidth;
670 line.fLineAscent = fLineAscent;
671 line.fLineDescent = fLineDescent;
672 m_pSection->AddLine(line);
673 }
674 fMaxY += (fLineAscent + m_pVT->GetLineLeading(m_pSection->m_SecInfo));
675 fMaxY += (-fLineDescent);
676 fMaxX = std::max(fLineWidth, fMaxX);
677 }
678 } else {
679 if (bTypeset) {
680 fLineAscent = m_pVT->GetLineAscent(m_pSection->m_SecInfo);
681 fLineDescent = m_pVT->GetLineDescent(m_pSection->m_SecInfo);
682 } else {
683 fLineAscent =
684 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), fFontSize);
685 fLineDescent =
686 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), fFontSize);
687 }
688 if (bTypeset) {
689 line.nBeginWordIndex = -1;
690 line.nEndWordIndex = -1;
691 line.nTotalWord = 0;
692 line.fLineWidth = 0;
693 line.fLineAscent = fLineAscent;
694 line.fLineDescent = fLineDescent;
695 m_pSection->AddLine(line);
696 }
697 fMaxY += (m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent +
698 (-fLineDescent));
699 }
700 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY);
701 }
702 void CTypeset::OutputLines() {
703 ASSERT(m_pVT);
704 ASSERT(m_pSection);
705 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f;
706 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f;
707 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo);
708 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
709 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
710 default:
711 case 0:
712 fMinX = 0.0f;
713 break;
714 case 1:
715 fMinX = (fTypesetWidth - m_rcRet.Width()) * PVT_HALF;
716 break;
717 case 2:
718 fMinX = fTypesetWidth - m_rcRet.Width();
719 break;
720 }
721 fMaxX = fMinX + m_rcRet.Width();
722 fMinY = 0.0f;
723 fMaxY = m_rcRet.Height();
724 int32_t nTotalLines = m_pSection->m_LineArray.GetSize();
725 if (nTotalLines > 0) {
726 m_pSection->m_SecInfo.nTotalLine = nTotalLines;
727 for (int32_t l = 0; l < nTotalLines; l++) {
728 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) {
729 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
730 default:
731 case 0:
732 fPosX = 0;
733 break;
734 case 1:
735 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * PVT_HALF;
736 break;
737 case 2:
738 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth;
739 break;
740 }
741 fPosX += fLineIndent;
742 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo);
743 fPosY += pLine->m_LineInfo.fLineAscent;
744 pLine->m_LineInfo.fLineX = fPosX - fMinX;
745 pLine->m_LineInfo.fLineY = fPosY - fMinY;
746 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex;
747 w <= pLine->m_LineInfo.nEndWordIndex; w++) {
748 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) {
749 pWord->fWordX = fPosX - fMinX;
750 if (pWord->pWordProps) {
751 switch (pWord->pWordProps->nScriptType) {
752 default:
753 case PVTWORD_SCRIPT_NORMAL:
754 pWord->fWordY = fPosY - fMinY;
755 break;
756 case PVTWORD_SCRIPT_SUPER:
757 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY;
758 break;
759 case PVTWORD_SCRIPT_SUB:
760 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY;
761 break;
762 }
763 } else {
764 pWord->fWordY = fPosY - fMinY;
765 }
766 fPosX += m_pVT->GetWordWidth(*pWord);
767 }
768 }
769 fPosY += (-pLine->m_LineInfo.fLineDescent);
770 }
771 }
772 }
773 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY);
774 }
775 CPDF_VariableText::CPDF_VariableText() 246 CPDF_VariableText::CPDF_VariableText()
776 : m_nLimitChar(0), 247 : m_nLimitChar(0),
777 m_nCharArray(0), 248 m_nCharArray(0),
778 m_bMultiLine(FALSE), 249 m_bMultiLine(FALSE),
779 m_bLimitWidth(FALSE), 250 m_bLimitWidth(FALSE),
780 m_bAutoFontSize(FALSE), 251 m_bAutoFontSize(FALSE),
781 m_nAlignment(0), 252 m_nAlignment(0),
782 m_fLineLeading(0.0f), 253 m_fLineLeading(0.0f),
783 m_fCharSpace(0.0f), 254 m_fCharSpace(0.0f),
784 m_nHorzScale(100), 255 m_nHorzScale(100),
785 m_wSubWord(0), 256 m_wSubWord(0),
786 m_fFontSize(0.0f), 257 m_fFontSize(0.0f),
787 m_bInitial(FALSE), 258 m_bInitial(FALSE),
788 m_bRichText(FALSE), 259 m_bRichText(FALSE),
789 m_pVTProvider(NULL), 260 m_pVTProvider(nullptr),
790 m_pVTIterator(NULL) {} 261 m_pVTIterator(nullptr) {}
262
791 CPDF_VariableText::~CPDF_VariableText() { 263 CPDF_VariableText::~CPDF_VariableText() {
792 delete m_pVTIterator; 264 delete m_pVTIterator;
793 m_pVTIterator = NULL;
794 ResetAll(); 265 ResetAll();
795 } 266 }
267
796 void CPDF_VariableText::Initialize() { 268 void CPDF_VariableText::Initialize() {
797 if (!m_bInitial) { 269 if (!m_bInitial) {
798 CPVT_SectionInfo secinfo; 270 CPVT_SectionInfo secinfo;
799 if (m_bRichText) { 271 if (m_bRichText) {
800 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); 272 secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0);
801 secinfo.pWordProps = new CPVT_WordProps(GetDefaultFontIndex(), 273 secinfo.pWordProps = new CPVT_WordProps(
802 PVT_DEFAULT_FONTSIZE, 0, 0, 0); 274 GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0);
803 } 275 }
804 CPVT_WordPlace place; 276 CPVT_WordPlace place;
805 place.nSecIndex = 0; 277 place.nSecIndex = 0;
806 AddSection(place, secinfo); 278 AddSection(place, secinfo);
807 CPVT_LineInfo lineinfo; 279 CPVT_LineInfo lineinfo;
808 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); 280 lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize());
809 lineinfo.fLineDescent = 281 lineinfo.fLineDescent =
810 GetFontDescent(GetDefaultFontIndex(), GetFontSize()); 282 GetFontDescent(GetDefaultFontIndex(), GetFontSize());
811 AddLine(place, lineinfo); 283 AddLine(place, lineinfo);
812 if (CSection* pSection = m_SectionArray.GetAt(0)) { 284 if (CSection* pSection = m_SectionArray.GetAt(0))
813 pSection->ResetLinePlace(); 285 pSection->ResetLinePlace();
814 } 286
815 m_bInitial = TRUE; 287 m_bInitial = TRUE;
816 } 288 }
817 } 289 }
290
818 void CPDF_VariableText::ResetAll() { 291 void CPDF_VariableText::ResetAll() {
819 m_bInitial = FALSE; 292 m_bInitial = FALSE;
820 ResetSectionArray(); 293 ResetSectionArray();
821 } 294 }
295
822 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, 296 CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place,
823 uint16_t word, 297 uint16_t word,
824 int32_t charset, 298 int32_t charset,
825 const CPVT_WordProps* pWordProps) { 299 const CPVT_WordProps* pWordProps) {
826 int32_t nTotlaWords = GetTotalWords(); 300 int32_t nTotlaWords = GetTotalWords();
827 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { 301 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar)
828 return place; 302 return place;
829 } 303 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray)
830 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) {
831 return place; 304 return place;
832 } 305
833 CPVT_WordPlace newplace = place; 306 CPVT_WordPlace newplace = place;
834 newplace.nWordIndex++; 307 newplace.nWordIndex++;
835 if (m_bRichText) { 308 if (m_bRichText) {
836 CPVT_WordProps* pNewProps = 309 CPVT_WordProps* pNewProps =
837 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps(); 310 pWordProps ? new CPVT_WordProps(*pWordProps) : new CPVT_WordProps();
838 pNewProps->nFontIndex = 311 pNewProps->nFontIndex =
839 GetWordFontIndex(word, charset, pWordProps->nFontIndex); 312 GetWordFontIndex(word, charset, pWordProps->nFontIndex);
840 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps)); 313 return AddWord(newplace, CPVT_WordInfo(word, charset, -1, pNewProps));
841 } 314 }
842 int32_t nFontIndex = 315 int32_t nFontIndex =
843 GetSubWord() > 0 ? GetDefaultFontIndex() 316 GetSubWord() > 0 ? GetDefaultFontIndex()
844 : GetWordFontIndex(word, charset, GetDefaultFontIndex()); 317 : GetWordFontIndex(word, charset, GetDefaultFontIndex());
845 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); 318 return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL));
846 } 319 }
320
847 CPVT_WordPlace CPDF_VariableText::InsertSection( 321 CPVT_WordPlace CPDF_VariableText::InsertSection(
848 const CPVT_WordPlace& place, 322 const CPVT_WordPlace& place,
849 const CPVT_SecProps* pSecProps, 323 const CPVT_SecProps* pSecProps,
850 const CPVT_WordProps* pWordProps) { 324 const CPVT_WordProps* pWordProps) {
851 int32_t nTotlaWords = GetTotalWords(); 325 int32_t nTotlaWords = GetTotalWords();
852 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar) { 326 if (m_nLimitChar > 0 && nTotlaWords >= m_nLimitChar)
853 return place; 327 return place;
854 } 328 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray)
855 if (m_nCharArray > 0 && nTotlaWords >= m_nCharArray) {
856 return place; 329 return place;
857 } 330 if (!m_bMultiLine)
858 if (!m_bMultiLine) {
859 return place; 331 return place;
860 } 332
861 CPVT_WordPlace wordplace = place; 333 CPVT_WordPlace wordplace = place;
862 UpdateWordPlace(wordplace); 334 UpdateWordPlace(wordplace);
863 CPVT_WordPlace newplace = place; 335 CPVT_WordPlace newplace = place;
864 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) { 336 if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) {
865 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1); 337 CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1);
866 CPVT_SectionInfo secinfo; 338 CPVT_SectionInfo secinfo;
867 if (m_bRichText) { 339 if (m_bRichText) {
868 if (pSecProps) { 340 if (pSecProps)
869 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); 341 secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
870 } 342 if (pWordProps)
871 if (pWordProps) {
872 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); 343 secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
873 }
874 } 344 }
875 AddSection(NewPlace, secinfo); 345 AddSection(NewPlace, secinfo);
876 newplace = NewPlace; 346 newplace = NewPlace;
877 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) { 347 if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) {
878 for (int32_t w = wordplace.nWordIndex + 1, 348 for (int32_t w = wordplace.nWordIndex + 1,
879 sz = pSection->m_WordArray.GetSize(); 349 sz = pSection->m_WordArray.GetSize();
880 w < sz; w++) { 350 w < sz; w++) {
881 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) { 351 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) {
882 NewPlace.nWordIndex++; 352 NewPlace.nWordIndex++;
883 pNewSection->AddWord(NewPlace, *pWord); 353 pNewSection->AddWord(NewPlace, *pWord);
884 } 354 }
885 } 355 }
886 } 356 }
887 ClearSectionRightWords(wordplace); 357 ClearSectionRightWords(wordplace);
888 } 358 }
889 return newplace; 359 return newplace;
890 } 360 }
361
891 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, 362 CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place,
892 const FX_WCHAR* text, 363 const FX_WCHAR* text,
893 int32_t charset, 364 int32_t charset,
894 const CPVT_SecProps* pSecProps, 365 const CPVT_SecProps* pSecProps,
895 const CPVT_WordProps* pProps) { 366 const CPVT_WordProps* pProps) {
896 CFX_WideString swText = text; 367 CFX_WideString swText = text;
897 CPVT_WordPlace wp = place; 368 CPVT_WordPlace wp = place;
898 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { 369 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
899 CPVT_WordPlace oldwp = wp; 370 CPVT_WordPlace oldwp = wp;
900 uint16_t word = swText.GetAt(i); 371 uint16_t word = swText.GetAt(i);
901 switch (word) { 372 switch (word) {
902 case 0x0D: 373 case 0x0D:
903 if (m_bMultiLine) { 374 if (m_bMultiLine) {
904 if (swText.GetAt(i + 1) == 0x0A) { 375 if (swText.GetAt(i + 1) == 0x0A)
905 i += 1; 376 i += 1;
906 } 377
907 wp = InsertSection(wp, pSecProps, pProps); 378 wp = InsertSection(wp, pSecProps, pProps);
908 } 379 }
909 break; 380 break;
910 case 0x0A: 381 case 0x0A:
911 if (m_bMultiLine) { 382 if (m_bMultiLine) {
912 if (swText.GetAt(i + 1) == 0x0D) { 383 if (swText.GetAt(i + 1) == 0x0D)
913 i += 1; 384 i += 1;
914 } 385
915 wp = InsertSection(wp, pSecProps, pProps); 386 wp = InsertSection(wp, pSecProps, pProps);
916 } 387 }
917 break; 388 break;
918 case 0x09: 389 case 0x09:
919 word = 0x20; 390 word = 0x20;
920 default: 391 default:
921 wp = InsertWord(wp, word, charset, pProps); 392 wp = InsertWord(wp, word, charset, pProps);
922 break; 393 break;
923 } 394 }
924 if (wp == oldwp) { 395 if (wp == oldwp)
925 break; 396 break;
926 }
927 } 397 }
928 return wp; 398 return wp;
929 } 399 }
400
930 CPVT_WordPlace CPDF_VariableText::DeleteWords( 401 CPVT_WordPlace CPDF_VariableText::DeleteWords(
931 const CPVT_WordRange& PlaceRange) { 402 const CPVT_WordRange& PlaceRange) {
932 FX_BOOL bLastSecPos = FALSE; 403 FX_BOOL bLastSecPos = FALSE;
933 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex)) { 404 if (CSection* pSection = m_SectionArray.GetAt(PlaceRange.EndPos.nSecIndex))
934 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace()); 405 bLastSecPos = (PlaceRange.EndPos == pSection->GetEndWordPlace());
935 } 406
936 ClearWords(PlaceRange); 407 ClearWords(PlaceRange);
937 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) { 408 if (PlaceRange.BeginPos.nSecIndex != PlaceRange.EndPos.nSecIndex) {
938 ClearEmptySections(PlaceRange); 409 ClearEmptySections(PlaceRange);
939 if (!bLastSecPos) { 410 if (!bLastSecPos)
940 LinkLatterSection(PlaceRange.BeginPos); 411 LinkLatterSection(PlaceRange.BeginPos);
941 }
942 } 412 }
943 return PlaceRange.BeginPos; 413 return PlaceRange.BeginPos;
944 } 414 }
415
945 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) { 416 CPVT_WordPlace CPDF_VariableText::DeleteWord(const CPVT_WordPlace& place) {
946 return ClearRightWord(AdjustLineHeader(place, TRUE)); 417 return ClearRightWord(AdjustLineHeader(place, TRUE));
947 } 418 }
419
948 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) { 420 CPVT_WordPlace CPDF_VariableText::BackSpaceWord(const CPVT_WordPlace& place) {
949 return ClearLeftWord(AdjustLineHeader(place, TRUE)); 421 return ClearLeftWord(AdjustLineHeader(place, TRUE));
950 } 422 }
423
951 void CPDF_VariableText::SetText(const FX_WCHAR* text, 424 void CPDF_VariableText::SetText(const FX_WCHAR* text,
952 int32_t charset, 425 int32_t charset,
953 const CPVT_SecProps* pSecProps, 426 const CPVT_SecProps* pSecProps,
954 const CPVT_WordProps* pWordProps) { 427 const CPVT_WordProps* pWordProps) {
955 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); 428 DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace()));
956 CFX_WideString swText = text; 429 CFX_WideString swText = text;
957 CPVT_WordPlace wp(0, 0, -1); 430 CPVT_WordPlace wp(0, 0, -1);
958 CPVT_SectionInfo secinfo; 431 CPVT_SectionInfo secinfo;
959 if (m_bRichText) { 432 if (m_bRichText) {
960 if (pSecProps) { 433 if (pSecProps)
961 secinfo.pSecProps = new CPVT_SecProps(*pSecProps); 434 secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
962 } 435 if (pWordProps)
963 if (pWordProps) {
964 secinfo.pWordProps = new CPVT_WordProps(*pWordProps); 436 secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
965 }
966 } 437 }
967 if (CSection* pSection = m_SectionArray.GetAt(0)) { 438 if (CSection* pSection = m_SectionArray.GetAt(0))
968 pSection->m_SecInfo = secinfo; 439 pSection->m_SecInfo = secinfo;
969 } 440
970 int32_t nCharCount = 0; 441 int32_t nCharCount = 0;
971 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { 442 for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) {
972 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) { 443 if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar)
973 break; 444 break;
974 } 445 if (m_nCharArray > 0 && nCharCount >= m_nCharArray)
975 if (m_nCharArray > 0 && nCharCount >= m_nCharArray) {
976 break; 446 break;
977 } 447
978 uint16_t word = swText.GetAt(i); 448 uint16_t word = swText.GetAt(i);
979 switch (word) { 449 switch (word) {
980 case 0x0D: 450 case 0x0D:
981 if (m_bMultiLine) { 451 if (m_bMultiLine) {
982 if (swText.GetAt(i + 1) == 0x0A) { 452 if (swText.GetAt(i + 1) == 0x0A)
983 i += 1; 453 i += 1;
984 } 454
985 wp.nSecIndex++; 455 wp.nSecIndex++;
986 wp.nLineIndex = 0; 456 wp.nLineIndex = 0;
987 wp.nWordIndex = -1; 457 wp.nWordIndex = -1;
988 AddSection(wp, secinfo); 458 AddSection(wp, secinfo);
989 } 459 }
990 break; 460 break;
991 case 0x0A: 461 case 0x0A:
992 if (m_bMultiLine) { 462 if (m_bMultiLine) {
993 if (swText.GetAt(i + 1) == 0x0D) { 463 if (swText.GetAt(i + 1) == 0x0D)
994 i += 1; 464 i += 1;
995 } 465
996 wp.nSecIndex++; 466 wp.nSecIndex++;
997 wp.nLineIndex = 0; 467 wp.nLineIndex = 0;
998 wp.nWordIndex = -1; 468 wp.nWordIndex = -1;
999 AddSection(wp, secinfo); 469 AddSection(wp, secinfo);
1000 } 470 }
1001 break; 471 break;
1002 case 0x09: 472 case 0x09:
1003 word = 0x20; 473 word = 0x20;
1004 default: 474 default:
1005 wp = InsertWord(wp, word, charset, pWordProps); 475 wp = InsertWord(wp, word, charset, pWordProps);
1006 break; 476 break;
1007 } 477 }
1008 nCharCount++; 478 nCharCount++;
1009 } 479 }
1010 } 480 }
481
1011 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const { 482 void CPDF_VariableText::UpdateWordPlace(CPVT_WordPlace& place) const {
1012 if (place.nSecIndex < 0) { 483 if (place.nSecIndex < 0)
1013 place = GetBeginWordPlace(); 484 place = GetBeginWordPlace();
1014 } 485 if (place.nSecIndex >= m_SectionArray.GetSize())
1015 if (place.nSecIndex >= m_SectionArray.GetSize()) {
1016 place = GetEndWordPlace(); 486 place = GetEndWordPlace();
1017 } 487
1018 place = AdjustLineHeader(place, TRUE); 488 place = AdjustLineHeader(place, TRUE);
1019 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 489 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex))
1020 pSection->UpdateWordPlace(place); 490 pSection->UpdateWordPlace(place);
1021 }
1022 } 491 }
492
1023 int32_t CPDF_VariableText::WordPlaceToWordIndex( 493 int32_t CPDF_VariableText::WordPlaceToWordIndex(
1024 const CPVT_WordPlace& place) const { 494 const CPVT_WordPlace& place) const {
1025 CPVT_WordPlace newplace = place; 495 CPVT_WordPlace newplace = place;
1026 UpdateWordPlace(newplace); 496 UpdateWordPlace(newplace);
1027 int32_t nIndex = 0; 497 int32_t nIndex = 0;
1028 int32_t i = 0; 498 int32_t i = 0;
1029 int32_t sz = 0; 499 int32_t sz = 0;
1030 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex; 500 for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex;
1031 i++) { 501 i++) {
1032 if (CSection* pSection = m_SectionArray.GetAt(i)) { 502 if (CSection* pSection = m_SectionArray.GetAt(i)) {
1033 nIndex += pSection->m_WordArray.GetSize(); 503 nIndex += pSection->m_WordArray.GetSize();
1034 if (i != m_SectionArray.GetSize() - 1) { 504 if (i != m_SectionArray.GetSize() - 1)
1035 nIndex += PVT_RETURN_LENGTH; 505 nIndex += kReturnLength;
1036 }
1037 } 506 }
1038 } 507 }
1039 if (i >= 0 && i < m_SectionArray.GetSize()) { 508 if (i >= 0 && i < m_SectionArray.GetSize())
1040 nIndex += newplace.nWordIndex + PVT_RETURN_LENGTH; 509 nIndex += newplace.nWordIndex + kReturnLength;
1041 }
1042 return nIndex; 510 return nIndex;
1043 } 511 }
512
1044 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const { 513 CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const {
1045 CPVT_WordPlace place = GetBeginWordPlace(); 514 CPVT_WordPlace place = GetBeginWordPlace();
1046 int32_t nOldIndex = 0, nIndex = 0; 515 int32_t nOldIndex = 0, nIndex = 0;
1047 FX_BOOL bFind = FALSE; 516 FX_BOOL bFind = FALSE;
1048 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) { 517 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) {
1049 if (CSection* pSection = m_SectionArray.GetAt(i)) { 518 if (CSection* pSection = m_SectionArray.GetAt(i)) {
1050 nIndex += pSection->m_WordArray.GetSize(); 519 nIndex += pSection->m_WordArray.GetSize();
1051 if (nIndex == index) { 520 if (nIndex == index) {
1052 place = pSection->GetEndWordPlace(); 521 place = pSection->GetEndWordPlace();
1053 bFind = TRUE; 522 bFind = TRUE;
1054 break; 523 break;
1055 } else if (nIndex > index) { 524 } else if (nIndex > index) {
1056 place.nSecIndex = i; 525 place.nSecIndex = i;
1057 place.nWordIndex = index - nOldIndex - 1; 526 place.nWordIndex = index - nOldIndex - 1;
1058 pSection->UpdateWordPlace(place); 527 pSection->UpdateWordPlace(place);
1059 bFind = TRUE; 528 bFind = TRUE;
1060 break; 529 break;
1061 } 530 }
1062 if (i != m_SectionArray.GetSize() - 1) { 531 if (i != m_SectionArray.GetSize() - 1)
1063 nIndex += PVT_RETURN_LENGTH; 532 nIndex += kReturnLength;
1064 }
1065 nOldIndex = nIndex; 533 nOldIndex = nIndex;
1066 } 534 }
1067 } 535 }
1068 if (!bFind) { 536 if (!bFind)
1069 place = GetEndWordPlace(); 537 place = GetEndWordPlace();
1070 }
1071 return place; 538 return place;
1072 } 539 }
540
1073 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const { 541 CPVT_WordPlace CPDF_VariableText::GetBeginWordPlace() const {
1074 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace(); 542 return m_bInitial ? CPVT_WordPlace(0, 0, -1) : CPVT_WordPlace();
1075 } 543 }
544
1076 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const { 545 CPVT_WordPlace CPDF_VariableText::GetEndWordPlace() const {
1077 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1)) { 546 if (CSection* pSection = m_SectionArray.GetAt(m_SectionArray.GetSize() - 1))
1078 return pSection->GetEndWordPlace(); 547 return pSection->GetEndWordPlace();
1079 }
1080 return CPVT_WordPlace(); 548 return CPVT_WordPlace();
1081 } 549 }
550
1082 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace( 551 CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace(
1083 const CPVT_WordPlace& place) const { 552 const CPVT_WordPlace& place) const {
1084 if (place.nSecIndex < 0) { 553 if (place.nSecIndex < 0)
1085 return GetBeginWordPlace(); 554 return GetBeginWordPlace();
1086 } 555 if (place.nSecIndex >= m_SectionArray.GetSize())
1087 if (place.nSecIndex >= m_SectionArray.GetSize()) {
1088 return GetEndWordPlace(); 556 return GetEndWordPlace();
1089 }
1090 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 557 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1091 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) { 558 if (place.WordCmp(pSection->GetBeginWordPlace()) <= 0) {
1092 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1)) { 559 if (CSection* pPrevSection = m_SectionArray.GetAt(place.nSecIndex - 1))
1093 return pPrevSection->GetEndWordPlace(); 560 return pPrevSection->GetEndWordPlace();
1094 }
1095 return GetBeginWordPlace(); 561 return GetBeginWordPlace();
1096 } 562 }
1097 return pSection->GetPrevWordPlace(place); 563 return pSection->GetPrevWordPlace(place);
1098 } 564 }
1099 return place; 565 return place;
1100 } 566 }
567
1101 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace( 568 CPVT_WordPlace CPDF_VariableText::GetNextWordPlace(
1102 const CPVT_WordPlace& place) const { 569 const CPVT_WordPlace& place) const {
1103 if (place.nSecIndex < 0) { 570 if (place.nSecIndex < 0)
1104 return GetBeginWordPlace(); 571 return GetBeginWordPlace();
1105 } 572 if (place.nSecIndex >= m_SectionArray.GetSize())
1106 if (place.nSecIndex >= m_SectionArray.GetSize()) {
1107 return GetEndWordPlace(); 573 return GetEndWordPlace();
1108 }
1109 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 574 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1110 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) { 575 if (place.WordCmp(pSection->GetEndWordPlace()) >= 0) {
1111 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { 576 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1))
1112 return pNextSection->GetBeginWordPlace(); 577 return pNextSection->GetBeginWordPlace();
1113 }
1114 return GetEndWordPlace(); 578 return GetEndWordPlace();
1115 } 579 }
1116 return pSection->GetNextWordPlace(place); 580 return pSection->GetNextWordPlace(place);
1117 } 581 }
1118 return place; 582 return place;
1119 } 583 }
584
1120 CPVT_WordPlace CPDF_VariableText::SearchWordPlace( 585 CPVT_WordPlace CPDF_VariableText::SearchWordPlace(
1121 const CFX_FloatPoint& point) const { 586 const CFX_FloatPoint& point) const {
1122 CFX_FloatPoint pt = OutToIn(point); 587 CFX_FloatPoint pt = OutToIn(point);
1123 CPVT_WordPlace place = GetBeginWordPlace(); 588 CPVT_WordPlace place = GetBeginWordPlace();
1124 int32_t nLeft = 0; 589 int32_t nLeft = 0;
1125 int32_t nRight = m_SectionArray.GetSize() - 1; 590 int32_t nRight = m_SectionArray.GetSize() - 1;
1126 int32_t nMid = m_SectionArray.GetSize() / 2; 591 int32_t nMid = m_SectionArray.GetSize() / 2;
1127 FX_BOOL bUp = TRUE; 592 FX_BOOL bUp = TRUE;
1128 FX_BOOL bDown = TRUE; 593 FX_BOOL bDown = TRUE;
1129 while (nLeft <= nRight) { 594 while (nLeft <= nRight) {
(...skipping 16 matching lines...) Expand all
1146 place = pSection->SearchWordPlace( 611 place = pSection->SearchWordPlace(
1147 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, 612 CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left,
1148 pt.y - pSection->m_SecInfo.rcSection.top)); 613 pt.y - pSection->m_SecInfo.rcSection.top));
1149 place.nSecIndex = nMid; 614 place.nSecIndex = nMid;
1150 return place; 615 return place;
1151 } 616 }
1152 } else { 617 } else {
1153 break; 618 break;
1154 } 619 }
1155 } 620 }
1156 if (bUp) { 621 if (bUp)
1157 place = GetBeginWordPlace(); 622 place = GetBeginWordPlace();
1158 } 623 if (bDown)
1159 if (bDown) {
1160 place = GetEndWordPlace(); 624 place = GetEndWordPlace();
1161 }
1162 return place; 625 return place;
1163 } 626 }
627
1164 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace( 628 CPVT_WordPlace CPDF_VariableText::GetUpWordPlace(
1165 const CPVT_WordPlace& place, 629 const CPVT_WordPlace& place,
1166 const CFX_FloatPoint& point) const { 630 const CFX_FloatPoint& point) const {
1167 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 631 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1168 CPVT_WordPlace temp = place; 632 CPVT_WordPlace temp = place;
1169 CFX_FloatPoint pt = OutToIn(point); 633 CFX_FloatPoint pt = OutToIn(point);
1170 if (temp.nLineIndex-- > 0) { 634 if (temp.nLineIndex-- > 0) {
1171 return pSection->SearchWordPlace( 635 return pSection->SearchWordPlace(
1172 pt.x - pSection->m_SecInfo.rcSection.left, temp); 636 pt.x - pSection->m_SecInfo.rcSection.left, temp);
1173 } 637 }
1174 if (temp.nSecIndex-- > 0) { 638 if (temp.nSecIndex-- > 0) {
1175 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) { 639 if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) {
1176 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1; 640 temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1;
1177 return pLastSection->SearchWordPlace( 641 return pLastSection->SearchWordPlace(
1178 pt.x - pLastSection->m_SecInfo.rcSection.left, temp); 642 pt.x - pLastSection->m_SecInfo.rcSection.left, temp);
1179 } 643 }
1180 } 644 }
1181 } 645 }
1182 return place; 646 return place;
1183 } 647 }
648
1184 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( 649 CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(
1185 const CPVT_WordPlace& place, 650 const CPVT_WordPlace& place,
1186 const CFX_FloatPoint& point) const { 651 const CFX_FloatPoint& point) const {
1187 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 652 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1188 CPVT_WordPlace temp = place; 653 CPVT_WordPlace temp = place;
1189 CFX_FloatPoint pt = OutToIn(point); 654 CFX_FloatPoint pt = OutToIn(point);
1190 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { 655 if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) {
1191 return pSection->SearchWordPlace( 656 return pSection->SearchWordPlace(
1192 pt.x - pSection->m_SecInfo.rcSection.left, temp); 657 pt.x - pSection->m_SecInfo.rcSection.left, temp);
1193 } 658 }
1194 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { 659 if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) {
1195 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { 660 if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) {
1196 temp.nLineIndex = 0; 661 temp.nLineIndex = 0;
1197 return pNextSection->SearchWordPlace( 662 return pNextSection->SearchWordPlace(
1198 pt.x - pSection->m_SecInfo.rcSection.left, temp); 663 pt.x - pSection->m_SecInfo.rcSection.left, temp);
1199 } 664 }
1200 } 665 }
1201 } 666 }
1202 return place; 667 return place;
1203 } 668 }
669
1204 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace( 670 CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace(
1205 const CPVT_WordPlace& place) const { 671 const CPVT_WordPlace& place) const {
1206 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); 672 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1);
1207 } 673 }
674
1208 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace( 675 CPVT_WordPlace CPDF_VariableText::GetLineEndPlace(
1209 const CPVT_WordPlace& place) const { 676 const CPVT_WordPlace& place) const {
1210 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 677 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1211 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) 678 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex))
1212 return pLine->GetEndWordPlace(); 679 return pLine->GetEndWordPlace();
1213 } 680 }
1214 return place; 681 return place;
1215 } 682 }
683
1216 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace( 684 CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace(
1217 const CPVT_WordPlace& place) const { 685 const CPVT_WordPlace& place) const {
1218 return CPVT_WordPlace(place.nSecIndex, 0, -1); 686 return CPVT_WordPlace(place.nSecIndex, 0, -1);
1219 } 687 }
688
1220 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace( 689 CPVT_WordPlace CPDF_VariableText::GetSectionEndPlace(
1221 const CPVT_WordPlace& place) const { 690 const CPVT_WordPlace& place) const {
1222 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 691 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex))
1223 return pSection->GetEndWordPlace(); 692 return pSection->GetEndWordPlace();
1224 }
1225 return place; 693 return place;
1226 } 694 }
695
1227 int32_t CPDF_VariableText::GetTotalWords() const { 696 int32_t CPDF_VariableText::GetTotalWords() const {
1228 int32_t nTotal = 0; 697 int32_t nTotal = 0;
1229 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) 698 for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) {
1230 if (CSection* pSection = m_SectionArray.GetAt(i)) { 699 if (CSection* pSection = m_SectionArray.GetAt(i))
1231 nTotal += (pSection->m_WordArray.GetSize() + PVT_RETURN_LENGTH); 700 nTotal += (pSection->m_WordArray.GetSize() + kReturnLength);
1232 } 701 }
1233 return nTotal - PVT_RETURN_LENGTH; 702
703 return nTotal - kReturnLength;
1234 } 704 }
705
1235 void CPDF_VariableText::ResetSectionArray() { 706 void CPDF_VariableText::ResetSectionArray() {
1236 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { 707 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++)
1237 delete m_SectionArray.GetAt(s); 708 delete m_SectionArray.GetAt(s);
1238 } 709
1239 m_SectionArray.RemoveAll(); 710 m_SectionArray.RemoveAll();
1240 } 711 }
712
1241 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place, 713 CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place,
1242 const CPVT_SectionInfo& secinfo) { 714 const CPVT_SectionInfo& secinfo) {
1243 if (IsValid() && !m_bMultiLine) { 715 if (IsValid() && !m_bMultiLine)
1244 return place; 716 return place;
1245 } 717
1246 int32_t nSecIndex = 718 int32_t nSecIndex =
1247 std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0); 719 std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0);
1248 CSection* pSection = new CSection(this); 720 CSection* pSection = new CSection(this);
1249 pSection->m_SecInfo = secinfo; 721 pSection->m_SecInfo = secinfo;
1250 pSection->SecPlace.nSecIndex = nSecIndex; 722 pSection->SecPlace.nSecIndex = nSecIndex;
1251 if (nSecIndex == m_SectionArray.GetSize()) { 723 if (nSecIndex == m_SectionArray.GetSize())
1252 m_SectionArray.Add(pSection); 724 m_SectionArray.Add(pSection);
1253 } else { 725 else
1254 m_SectionArray.InsertAt(nSecIndex, pSection); 726 m_SectionArray.InsertAt(nSecIndex, pSection);
1255 } 727
1256 return place; 728 return place;
1257 } 729 }
730
1258 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place, 731 CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place,
1259 const CPVT_LineInfo& lineinfo) { 732 const CPVT_LineInfo& lineinfo) {
1260 if (m_SectionArray.IsEmpty()) { 733 if (m_SectionArray.IsEmpty())
1261 return place; 734 return place;
1262 } 735 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex))
1263 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1264 return pSection->AddLine(lineinfo); 736 return pSection->AddLine(lineinfo);
1265 }
1266 return place; 737 return place;
1267 } 738 }
739
1268 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place, 740 CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place,
1269 const CPVT_WordInfo& wordinfo) { 741 const CPVT_WordInfo& wordinfo) {
1270 if (m_SectionArray.GetSize() <= 0) { 742 if (m_SectionArray.GetSize() <= 0) {
1271 return place; 743 return place;
1272 } 744 }
1273 CPVT_WordPlace newplace = place; 745 CPVT_WordPlace newplace = place;
1274 newplace.nSecIndex = 746 newplace.nSecIndex =
1275 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0); 747 std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
1276 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex)) { 748 if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex))
1277 return pSection->AddWord(newplace, wordinfo); 749 return pSection->AddWord(newplace, wordinfo);
1278 }
1279 return place; 750 return place;
1280 } 751 }
752
1281 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place, 753 FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place,
1282 CPVT_WordInfo& wordinfo) { 754 CPVT_WordInfo& wordinfo) {
1283 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 755 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1284 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { 756 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) {
1285 wordinfo = *pWord; 757 wordinfo = *pWord;
1286 return TRUE; 758 return TRUE;
1287 } 759 }
1288 } 760 }
1289 return FALSE; 761 return FALSE;
1290 } 762 }
763
1291 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place, 764 FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place,
1292 const CPVT_WordInfo& wordinfo) { 765 const CPVT_WordInfo& wordinfo) {
1293 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 766 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1294 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) { 767 if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) {
1295 *pWord = wordinfo; 768 *pWord = wordinfo;
1296 return TRUE; 769 return TRUE;
1297 } 770 }
1298 } 771 }
1299 return FALSE; 772 return FALSE;
1300 } 773 }
774
1301 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place, 775 FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place,
1302 CPVT_LineInfo& lineinfo) { 776 CPVT_LineInfo& lineinfo) {
1303 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 777 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1304 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) { 778 if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) {
1305 lineinfo = pLine->m_LineInfo; 779 lineinfo = pLine->m_LineInfo;
1306 return TRUE; 780 return TRUE;
1307 } 781 }
1308 } 782 }
1309 return FALSE; 783 return FALSE;
1310 } 784 }
785
1311 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place, 786 FX_BOOL CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place,
1312 CPVT_SectionInfo& secinfo) { 787 CPVT_SectionInfo& secinfo) {
1313 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 788 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1314 secinfo = pSection->m_SecInfo; 789 secinfo = pSection->m_SecInfo;
1315 return TRUE; 790 return TRUE;
1316 } 791 }
1317 return FALSE; 792 return FALSE;
1318 } 793 }
794
1319 CFX_FloatRect CPDF_VariableText::GetContentRect() const { 795 CFX_FloatRect CPDF_VariableText::GetContentRect() const {
1320 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect())); 796 return InToOut(CPVT_FloatRect(CPDF_EditContainer::GetContentRect()));
1321 } 797 }
798
1322 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo, 799 FX_FLOAT CPDF_VariableText::GetWordFontSize(const CPVT_WordInfo& WordInfo,
1323 FX_BOOL bFactFontSize) { 800 FX_BOOL bFactFontSize) {
1324 return m_bRichText && WordInfo.pWordProps 801 return m_bRichText && WordInfo.pWordProps
1325 ? (WordInfo.pWordProps->nScriptType == PVTWORD_SCRIPT_NORMAL || 802 ? (WordInfo.pWordProps->nScriptType == ScriptType::Normal ||
1326 bFactFontSize 803 bFactFontSize
1327 ? WordInfo.pWordProps->fFontSize 804 ? WordInfo.pWordProps->fFontSize
1328 : WordInfo.pWordProps->fFontSize * PVT_HALF) 805 : WordInfo.pWordProps->fFontSize * VARIABLETEXT_HALF)
1329 : GetFontSize(); 806 : GetFontSize();
1330 } 807 }
808
1331 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) { 809 int32_t CPDF_VariableText::GetWordFontIndex(const CPVT_WordInfo& WordInfo) {
1332 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex 810 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nFontIndex
1333 : WordInfo.nFontIndex; 811 : WordInfo.nFontIndex;
1334 } 812 }
813
1335 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex, 814 FX_FLOAT CPDF_VariableText::GetWordWidth(int32_t nFontIndex,
1336 uint16_t Word, 815 uint16_t Word,
1337 uint16_t SubWord, 816 uint16_t SubWord,
1338 FX_FLOAT fCharSpace, 817 FX_FLOAT fCharSpace,
1339 int32_t nHorzScale, 818 int32_t nHorzScale,
1340 FX_FLOAT fFontSize, 819 FX_FLOAT fFontSize,
1341 FX_FLOAT fWordTail, 820 FX_FLOAT fWordTail,
1342 int32_t nWordStyle) { 821 int32_t nWordStyle) {
1343 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize * 822 return (GetCharWidth(nFontIndex, Word, SubWord, nWordStyle) * fFontSize *
1344 PVT_FONTSCALE + 823 kFontScale +
1345 fCharSpace) * 824 fCharSpace) *
1346 nHorzScale * PVT_PERCENT + 825 nHorzScale * kScalePercent +
1347 fWordTail; 826 fWordTail;
1348 } 827 }
828
1349 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) { 829 FX_FLOAT CPDF_VariableText::GetWordWidth(const CPVT_WordInfo& WordInfo) {
1350 return GetWordWidth( 830 return GetWordWidth(
1351 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(), 831 GetWordFontIndex(WordInfo), WordInfo.Word, GetSubWord(),
1352 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo), 832 GetCharSpace(WordInfo), GetHorzScale(WordInfo), GetWordFontSize(WordInfo),
1353 WordInfo.fWordTail, 833 WordInfo.fWordTail,
1354 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0); 834 WordInfo.pWordProps ? WordInfo.pWordProps->nWordStyle : 0);
1355 } 835 }
836
1356 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { 837 FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) {
1357 return m_bRichText && SecInfo.pWordProps 838 return m_bRichText && SecInfo.pWordProps
1358 ? GetFontAscent(SecInfo.pWordProps->nFontIndex, 839 ? GetFontAscent(SecInfo.pWordProps->nFontIndex,
1359 SecInfo.pWordProps->fFontSize) 840 SecInfo.pWordProps->fFontSize)
1360 : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); 841 : GetFontAscent(GetDefaultFontIndex(), GetFontSize());
1361 } 842 }
843
1362 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) { 844 FX_FLOAT CPDF_VariableText::GetLineDescent(const CPVT_SectionInfo& SecInfo) {
1363 return m_bRichText && SecInfo.pWordProps 845 return m_bRichText && SecInfo.pWordProps
1364 ? GetFontDescent(SecInfo.pWordProps->nFontIndex, 846 ? GetFontDescent(SecInfo.pWordProps->nFontIndex,
1365 SecInfo.pWordProps->fFontSize) 847 SecInfo.pWordProps->fFontSize)
1366 : GetFontDescent(GetDefaultFontIndex(), GetFontSize()); 848 : GetFontDescent(GetDefaultFontIndex(), GetFontSize());
1367 } 849 }
850
1368 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex, 851 FX_FLOAT CPDF_VariableText::GetFontAscent(int32_t nFontIndex,
1369 FX_FLOAT fFontSize) { 852 FX_FLOAT fFontSize) {
1370 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * PVT_FONTSCALE; 853 return (FX_FLOAT)GetTypeAscent(nFontIndex) * fFontSize * kFontScale;
1371 } 854 }
855
1372 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex, 856 FX_FLOAT CPDF_VariableText::GetFontDescent(int32_t nFontIndex,
1373 FX_FLOAT fFontSize) { 857 FX_FLOAT fFontSize) {
1374 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * PVT_FONTSCALE; 858 return (FX_FLOAT)GetTypeDescent(nFontIndex) * fFontSize * kFontScale;
1375 } 859 }
860
1376 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, 861 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo,
1377 FX_FLOAT fFontSize) { 862 FX_FLOAT fFontSize) {
1378 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize); 863 return GetFontAscent(GetWordFontIndex(WordInfo), fFontSize);
1379 } 864 }
865
1380 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, 866 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo,
1381 FX_FLOAT fFontSize) { 867 FX_FLOAT fFontSize) {
1382 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize); 868 return GetFontDescent(GetWordFontIndex(WordInfo), fFontSize);
1383 } 869 }
870
1384 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, 871 FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo,
1385 FX_BOOL bFactFontSize) { 872 FX_BOOL bFactFontSize) {
1386 return GetFontAscent(GetWordFontIndex(WordInfo), 873 return GetFontAscent(GetWordFontIndex(WordInfo),
1387 GetWordFontSize(WordInfo, bFactFontSize)); 874 GetWordFontSize(WordInfo, bFactFontSize));
1388 } 875 }
876
1389 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo, 877 FX_FLOAT CPDF_VariableText::GetWordDescent(const CPVT_WordInfo& WordInfo,
1390 FX_BOOL bFactFontSize) { 878 FX_BOOL bFactFontSize) {
1391 return GetFontDescent(GetWordFontIndex(WordInfo), 879 return GetFontDescent(GetWordFontIndex(WordInfo),
1392 GetWordFontSize(WordInfo, bFactFontSize)); 880 GetWordFontSize(WordInfo, bFactFontSize));
1393 } 881 }
882
1394 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) { 883 FX_FLOAT CPDF_VariableText::GetLineLeading(const CPVT_SectionInfo& SecInfo) {
1395 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading 884 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineLeading
1396 : m_fLineLeading; 885 : m_fLineLeading;
1397 } 886 }
887
1398 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) { 888 FX_FLOAT CPDF_VariableText::GetLineIndent(const CPVT_SectionInfo& SecInfo) {
1399 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent 889 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->fLineIndent
1400 : 0.0f; 890 : 0.0f;
1401 } 891 }
892
1402 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) { 893 int32_t CPDF_VariableText::GetAlignment(const CPVT_SectionInfo& SecInfo) {
1403 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment 894 return m_bRichText && SecInfo.pSecProps ? SecInfo.pSecProps->nAlignment
1404 : m_nAlignment; 895 : m_nAlignment;
1405 } 896 }
897
1406 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) { 898 FX_FLOAT CPDF_VariableText::GetCharSpace(const CPVT_WordInfo& WordInfo) {
1407 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace 899 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->fCharSpace
1408 : m_fCharSpace; 900 : m_fCharSpace;
1409 } 901 }
902
1410 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) { 903 int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) {
1411 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale 904 return m_bRichText && WordInfo.pWordProps ? WordInfo.pWordProps->nHorzScale
1412 : m_nHorzScale; 905 : m_nHorzScale;
1413 } 906 }
907
1414 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) { 908 void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) {
1415 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE); 909 CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE);
1416 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 910 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1417 for (int32_t w = pSection->m_WordArray.GetSize() - 1; 911 for (int32_t w = pSection->m_WordArray.GetSize() - 1;
1418 w > wordplace.nWordIndex; w--) { 912 w > wordplace.nWordIndex; w--) {
1419 delete pSection->m_WordArray.GetAt(w); 913 delete pSection->m_WordArray.GetAt(w);
1420 pSection->m_WordArray.RemoveAt(w); 914 pSection->m_WordArray.RemoveAt(w);
1421 } 915 }
1422 } 916 }
1423 } 917 }
918
1424 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place, 919 CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place,
1425 FX_BOOL bPrevOrNext) const { 920 FX_BOOL bPrevOrNext) const {
1426 if (place.nWordIndex < 0 && place.nLineIndex > 0) { 921 if (place.nWordIndex < 0 && place.nLineIndex > 0)
1427 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place); 922 return bPrevOrNext ? GetPrevWordPlace(place) : GetNextWordPlace(place);
1428 }
1429 return place; 923 return place;
1430 } 924 }
925
1431 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) { 926 FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) {
1432 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1) { 927 if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1)
1433 return FALSE; 928 return FALSE;
1434 }
1435 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 929 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1436 if (pSection->m_WordArray.GetSize() == 0) { 930 if (pSection->m_WordArray.GetSize() == 0) {
1437 delete pSection; 931 delete pSection;
1438 m_SectionArray.RemoveAt(place.nSecIndex); 932 m_SectionArray.RemoveAt(place.nSecIndex);
1439 return TRUE; 933 return TRUE;
1440 } 934 }
1441 } 935 }
1442 return FALSE; 936 return FALSE;
1443 } 937 }
938
1444 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) { 939 void CPDF_VariableText::ClearEmptySections(const CPVT_WordRange& PlaceRange) {
1445 CPVT_WordPlace wordplace; 940 CPVT_WordPlace wordplace;
1446 for (int32_t s = PlaceRange.EndPos.nSecIndex; 941 for (int32_t s = PlaceRange.EndPos.nSecIndex;
1447 s > PlaceRange.BeginPos.nSecIndex; s--) { 942 s > PlaceRange.BeginPos.nSecIndex; s--) {
1448 wordplace.nSecIndex = s; 943 wordplace.nSecIndex = s;
1449 ClearEmptySection(wordplace); 944 ClearEmptySection(wordplace);
1450 } 945 }
1451 } 946 }
947
1452 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) { 948 void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) {
1453 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE); 949 CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE);
1454 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) { 950 if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) {
1455 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) { 951 if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) {
1456 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz; 952 for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz;
1457 w++) { 953 w++) {
1458 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) { 954 if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) {
1459 oldplace.nWordIndex++; 955 oldplace.nWordIndex++;
1460 pSection->AddWord(oldplace, *pWord); 956 pSection->AddWord(oldplace, *pWord);
1461 } 957 }
1462 } 958 }
1463 } 959 }
1464 delete pNextSection; 960 delete pNextSection;
1465 m_SectionArray.RemoveAt(place.nSecIndex + 1); 961 m_SectionArray.RemoveAt(place.nSecIndex + 1);
1466 } 962 }
1467 } 963 }
964
1468 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) { 965 void CPDF_VariableText::ClearWords(const CPVT_WordRange& PlaceRange) {
1469 CPVT_WordRange NewRange; 966 CPVT_WordRange NewRange;
1470 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE); 967 NewRange.BeginPos = AdjustLineHeader(PlaceRange.BeginPos, TRUE);
1471 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE); 968 NewRange.EndPos = AdjustLineHeader(PlaceRange.EndPos, TRUE);
1472 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex; 969 for (int32_t s = NewRange.EndPos.nSecIndex; s >= NewRange.BeginPos.nSecIndex;
1473 s--) { 970 s--) {
1474 if (CSection* pSection = m_SectionArray.GetAt(s)) { 971 if (CSection* pSection = m_SectionArray.GetAt(s))
1475 pSection->ClearWords(NewRange); 972 pSection->ClearWords(NewRange);
1476 }
1477 } 973 }
1478 } 974 }
975
1479 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) { 976 CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) {
1480 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 977 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1481 CPVT_WordPlace leftplace = GetPrevWordPlace(place); 978 CPVT_WordPlace leftplace = GetPrevWordPlace(place);
1482 if (leftplace != place) { 979 if (leftplace != place) {
1483 if (leftplace.nSecIndex != place.nSecIndex) { 980 if (leftplace.nSecIndex != place.nSecIndex) {
1484 if (pSection->m_WordArray.GetSize() == 0) { 981 if (pSection->m_WordArray.GetSize() == 0)
1485 ClearEmptySection(place); 982 ClearEmptySection(place);
1486 } else { 983 else
1487 LinkLatterSection(leftplace); 984 LinkLatterSection(leftplace);
1488 }
1489 } else { 985 } else {
1490 pSection->ClearWord(place); 986 pSection->ClearWord(place);
1491 } 987 }
1492 } 988 }
1493 return leftplace; 989 return leftplace;
1494 } 990 }
1495 return place; 991 return place;
1496 } 992 }
993
1497 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) { 994 CPVT_WordPlace CPDF_VariableText::ClearRightWord(const CPVT_WordPlace& place) {
1498 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { 995 if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
1499 CPVT_WordPlace rightplace = 996 CPVT_WordPlace rightplace =
1500 AdjustLineHeader(GetNextWordPlace(place), FALSE); 997 AdjustLineHeader(GetNextWordPlace(place), FALSE);
1501 if (rightplace != place) { 998 if (rightplace != place) {
1502 if (rightplace.nSecIndex != place.nSecIndex) { 999 if (rightplace.nSecIndex != place.nSecIndex)
1503 LinkLatterSection(place); 1000 LinkLatterSection(place);
1504 } else { 1001 else
1505 pSection->ClearWord(rightplace); 1002 pSection->ClearWord(rightplace);
1506 }
1507 } 1003 }
1508 } 1004 }
1509 return place; 1005 return place;
1510 } 1006 }
1007
1511 void CPDF_VariableText::RearrangeAll() { 1008 void CPDF_VariableText::RearrangeAll() {
1512 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); 1009 Rearrange(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace()));
1513 } 1010 }
1011
1514 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) { 1012 void CPDF_VariableText::RearrangePart(const CPVT_WordRange& PlaceRange) {
1515 Rearrange(PlaceRange); 1013 Rearrange(PlaceRange);
1516 } 1014 }
1015
1517 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) { 1016 CPVT_FloatRect CPDF_VariableText::Rearrange(const CPVT_WordRange& PlaceRange) {
1518 CPVT_FloatRect rcRet; 1017 CPVT_FloatRect rcRet;
1519 if (IsValid()) { 1018 if (IsValid()) {
1520 if (m_bAutoFontSize) { 1019 if (m_bAutoFontSize) {
1521 SetFontSize(GetAutoFontSize()); 1020 SetFontSize(GetAutoFontSize());
1522 rcRet = RearrangeSections( 1021 rcRet = RearrangeSections(
1523 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); 1022 CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace()));
1524 } else { 1023 } else {
1525 rcRet = RearrangeSections(PlaceRange); 1024 rcRet = RearrangeSections(PlaceRange);
1526 } 1025 }
1527 } 1026 }
1528 SetContentRect(rcRet); 1027 SetContentRect(rcRet);
1529 return rcRet; 1028 return rcRet;
1530 } 1029 }
1030
1531 FX_FLOAT CPDF_VariableText::GetAutoFontSize() { 1031 FX_FLOAT CPDF_VariableText::GetAutoFontSize() {
1532 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t); 1032 int32_t nTotal = sizeof(gFontSizeSteps) / sizeof(uint8_t);
1533 if (IsMultiLine()) { 1033 if (IsMultiLine())
1534 nTotal /= 4; 1034 nTotal /= 4;
1535 } 1035 if (nTotal <= 0)
1536 if (nTotal <= 0) {
1537 return 0; 1036 return 0;
1538 } 1037 if (GetPlateWidth() <= 0)
1539 if (GetPlateWidth() <= 0) {
1540 return 0; 1038 return 0;
1541 } 1039
1542 int32_t nLeft = 0; 1040 int32_t nLeft = 0;
1543 int32_t nRight = nTotal - 1; 1041 int32_t nRight = nTotal - 1;
1544 int32_t nMid = nTotal / 2; 1042 int32_t nMid = nTotal / 2;
1545 while (nLeft <= nRight) { 1043 while (nLeft <= nRight) {
1546 if (IsBigger(gFontSizeSteps[nMid])) { 1044 if (IsBigger(gFontSizeSteps[nMid])) {
1547 nRight = nMid - 1; 1045 nRight = nMid - 1;
1548 nMid = (nLeft + nRight) / 2; 1046 nMid = (nLeft + nRight) / 2;
1549 continue; 1047 continue;
1550 } else { 1048 } else {
1551 nLeft = nMid + 1; 1049 nLeft = nMid + 1;
1552 nMid = (nLeft + nRight) / 2; 1050 nMid = (nLeft + nRight) / 2;
1553 continue; 1051 continue;
1554 } 1052 }
1555 } 1053 }
1556 return (FX_FLOAT)gFontSizeSteps[nMid]; 1054 return (FX_FLOAT)gFontSizeSteps[nMid];
1557 } 1055 }
1056
1558 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) { 1057 FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) {
1559 FX_BOOL bBigger = FALSE; 1058 FX_BOOL bBigger = FALSE;
1560 CPVT_Size szTotal; 1059 CPVT_Size szTotal;
1561 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { 1060 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) {
1562 if (CSection* pSection = m_SectionArray.GetAt(s)) { 1061 if (CSection* pSection = m_SectionArray.GetAt(s)) {
1563 CPVT_Size size = pSection->GetSectionSize(fFontSize); 1062 CPVT_Size size = pSection->GetSectionSize(fFontSize);
1564 szTotal.x = std::max(size.x, szTotal.x); 1063 szTotal.x = std::max(size.x, szTotal.x);
1565 szTotal.y += size.y; 1064 szTotal.y += size.y;
1566 if (IsFloatBigger(szTotal.x, GetPlateWidth()) || 1065 if (IsFloatBigger(szTotal.x, GetPlateWidth()) ||
1567 IsFloatBigger(szTotal.y, GetPlateHeight())) { 1066 IsFloatBigger(szTotal.y, GetPlateHeight())) {
1568 bBigger = TRUE; 1067 bBigger = TRUE;
1569 break; 1068 break;
1570 } 1069 }
1571 } 1070 }
1572 } 1071 }
1573 return bBigger; 1072 return bBigger;
1574 } 1073 }
1074
1575 CPVT_FloatRect CPDF_VariableText::RearrangeSections( 1075 CPVT_FloatRect CPDF_VariableText::RearrangeSections(
1576 const CPVT_WordRange& PlaceRange) { 1076 const CPVT_WordRange& PlaceRange) {
1577 CPVT_WordPlace place; 1077 CPVT_WordPlace place;
1578 FX_FLOAT fPosY = 0; 1078 FX_FLOAT fPosY = 0;
1579 FX_FLOAT fOldHeight; 1079 FX_FLOAT fOldHeight;
1580 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex; 1080 int32_t nSSecIndex = PlaceRange.BeginPos.nSecIndex;
1581 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex; 1081 int32_t nESecIndex = PlaceRange.EndPos.nSecIndex;
1582 CPVT_FloatRect rcRet; 1082 CPVT_FloatRect rcRet;
1583 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) { 1083 for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) {
1584 place.nSecIndex = s; 1084 place.nSecIndex = s;
(...skipping 20 matching lines...) Expand all
1605 rcRet.left = std::min(rcSec.left, rcRet.left); 1105 rcRet.left = std::min(rcSec.left, rcRet.left);
1606 rcRet.top = std::min(rcSec.top, rcRet.top); 1106 rcRet.top = std::min(rcSec.top, rcRet.top);
1607 rcRet.right = std::max(rcSec.right, rcRet.right); 1107 rcRet.right = std::max(rcSec.right, rcRet.right);
1608 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom); 1108 rcRet.bottom = std::max(rcSec.bottom, rcRet.bottom);
1609 } 1109 }
1610 fPosY += rcSec.Height(); 1110 fPosY += rcSec.Height();
1611 } 1111 }
1612 } 1112 }
1613 return rcRet; 1113 return rcRet;
1614 } 1114 }
1115
1615 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex, 1116 int32_t CPDF_VariableText::GetCharWidth(int32_t nFontIndex,
1616 uint16_t Word, 1117 uint16_t Word,
1617 uint16_t SubWord, 1118 uint16_t SubWord,
1618 int32_t nWordStyle) { 1119 int32_t nWordStyle) {
1619 if (!m_pVTProvider) { 1120 if (!m_pVTProvider)
1620 return 0; 1121 return 0;
1621 } 1122 if (SubWord > 0)
1622 if (SubWord > 0) {
1623 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle); 1123 return m_pVTProvider->GetCharWidth(nFontIndex, SubWord, nWordStyle);
1624 }
1625 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle); 1124 return m_pVTProvider->GetCharWidth(nFontIndex, Word, nWordStyle);
1626 } 1125 }
1126
1627 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) { 1127 int32_t CPDF_VariableText::GetTypeAscent(int32_t nFontIndex) {
1628 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0; 1128 return m_pVTProvider ? m_pVTProvider->GetTypeAscent(nFontIndex) : 0;
1629 } 1129 }
1130
1630 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) { 1131 int32_t CPDF_VariableText::GetTypeDescent(int32_t nFontIndex) {
1631 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0; 1132 return m_pVTProvider ? m_pVTProvider->GetTypeDescent(nFontIndex) : 0;
1632 } 1133 }
1134
1633 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word, 1135 int32_t CPDF_VariableText::GetWordFontIndex(uint16_t word,
1634 int32_t charset, 1136 int32_t charset,
1635 int32_t nFontIndex) { 1137 int32_t nFontIndex) {
1636 return m_pVTProvider 1138 return m_pVTProvider
1637 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex) 1139 ? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex)
1638 : -1; 1140 : -1;
1639 } 1141 }
1142
1640 int32_t CPDF_VariableText::GetDefaultFontIndex() { 1143 int32_t CPDF_VariableText::GetDefaultFontIndex() {
1641 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1; 1144 return m_pVTProvider ? m_pVTProvider->GetDefaultFontIndex() : -1;
1642 } 1145 }
1146
1643 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) { 1147 FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) {
1644 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE; 1148 return m_pVTProvider ? m_pVTProvider->IsLatinWord(word) : FALSE;
1645 } 1149 }
1646 IPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { 1150
1647 if (!m_pVTIterator) { 1151 CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() {
1648 m_pVTIterator = new CPDF_VariableText_Iterator(this); 1152 if (!m_pVTIterator)
1649 } 1153 m_pVTIterator = new CPDF_VariableText::Iterator(this);
1650 return m_pVTIterator; 1154 return m_pVTIterator;
1651 } 1155 }
1652 IPDF_VariableText::Provider* CPDF_VariableText::SetProvider( 1156
1653 IPDF_VariableText::Provider* pProvider) { 1157 CPDF_VariableText::Provider* CPDF_VariableText::SetProvider(
1654 IPDF_VariableText::Provider* pOld = m_pVTProvider; 1158 CPDF_VariableText::Provider* pProvider) {
1159 CPDF_VariableText::Provider* pOld = m_pVTProvider;
1655 m_pVTProvider = pProvider; 1160 m_pVTProvider = pProvider;
1656 return pOld; 1161 return pOld;
1657 } 1162 }
1658 CPDF_VariableText_Iterator::CPDF_VariableText_Iterator(CPDF_VariableText* pVT)
1659 : m_CurPos(-1, -1, -1), m_pVT(pVT) {}
1660 CPDF_VariableText_Iterator::~CPDF_VariableText_Iterator() {}
1661 void CPDF_VariableText_Iterator::SetAt(int32_t nWordIndex) {
1662 m_CurPos = m_pVT->WordIndexToWordPlace(nWordIndex);
1663 }
1664 void CPDF_VariableText_Iterator::SetAt(const CPVT_WordPlace& place) {
1665 ASSERT(m_pVT);
1666 m_CurPos = place;
1667 }
1668 FX_BOOL CPDF_VariableText_Iterator::NextWord() {
1669 if (m_CurPos == m_pVT->GetEndWordPlace()) {
1670 return FALSE;
1671 }
1672 m_CurPos = m_pVT->GetNextWordPlace(m_CurPos);
1673 return TRUE;
1674 }
1675 FX_BOOL CPDF_VariableText_Iterator::PrevWord() {
1676 if (m_CurPos == m_pVT->GetBeginWordPlace()) {
1677 return FALSE;
1678 }
1679 m_CurPos = m_pVT->GetPrevWordPlace(m_CurPos);
1680 return TRUE;
1681 }
1682 FX_BOOL CPDF_VariableText_Iterator::NextLine() {
1683 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1684 if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) {
1685 m_CurPos =
1686 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1);
1687 return TRUE;
1688 }
1689 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
1690 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
1691 return TRUE;
1692 }
1693 }
1694 return FALSE;
1695 }
1696 FX_BOOL CPDF_VariableText_Iterator::PrevLine() {
1697 if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1698 if (m_CurPos.nLineIndex > 0) {
1699 m_CurPos =
1700 CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1);
1701 return TRUE;
1702 }
1703 if (m_CurPos.nSecIndex > 0) {
1704 if (CSection* pLastSection =
1705 m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) {
1706 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1,
1707 pLastSection->m_LineArray.GetSize() - 1, -1);
1708 return TRUE;
1709 }
1710 }
1711 }
1712 return FALSE;
1713 }
1714 FX_BOOL CPDF_VariableText_Iterator::NextSection() {
1715 if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
1716 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
1717 return TRUE;
1718 }
1719 return FALSE;
1720 }
1721 FX_BOOL CPDF_VariableText_Iterator::PrevSection() {
1722 ASSERT(m_pVT);
1723 if (m_CurPos.nSecIndex > 0) {
1724 m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1, 0, -1);
1725 return TRUE;
1726 }
1727 return FALSE;
1728 }
1729 FX_BOOL CPDF_VariableText_Iterator::GetWord(CPVT_Word& word) const {
1730 word.WordPlace = m_CurPos;
1731 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1732 if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
1733 if (CPVT_WordInfo* pWord =
1734 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
1735 word.Word = pWord->Word;
1736 word.nCharset = pWord->nCharset;
1737 word.fWidth = m_pVT->GetWordWidth(*pWord);
1738 word.ptWord = m_pVT->InToOut(
1739 CFX_FloatPoint(pWord->fWordX + pSection->m_SecInfo.rcSection.left,
1740 pWord->fWordY + pSection->m_SecInfo.rcSection.top));
1741 word.fAscent = m_pVT->GetWordAscent(*pWord);
1742 word.fDescent = m_pVT->GetWordDescent(*pWord);
1743 if (pWord->pWordProps) {
1744 word.WordProps = *pWord->pWordProps;
1745 }
1746 word.nFontIndex = m_pVT->GetWordFontIndex(*pWord);
1747 word.fFontSize = m_pVT->GetWordFontSize(*pWord);
1748 return TRUE;
1749 }
1750 }
1751 }
1752 return FALSE;
1753 }
1754 FX_BOOL CPDF_VariableText_Iterator::SetWord(const CPVT_Word& word) {
1755 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1756 if (CPVT_WordInfo* pWord =
1757 pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
1758 if (pWord->pWordProps) {
1759 *pWord->pWordProps = word.WordProps;
1760 }
1761 return TRUE;
1762 }
1763 }
1764 return FALSE;
1765 }
1766 FX_BOOL CPDF_VariableText_Iterator::GetLine(CPVT_Line& line) const {
1767 ASSERT(m_pVT);
1768 line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1);
1769 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1770 if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
1771 line.ptLine = m_pVT->InToOut(CFX_FloatPoint(
1772 pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left,
1773 pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top));
1774 line.fLineWidth = pLine->m_LineInfo.fLineWidth;
1775 line.fLineAscent = pLine->m_LineInfo.fLineAscent;
1776 line.fLineDescent = pLine->m_LineInfo.fLineDescent;
1777 line.lineEnd = pLine->GetEndWordPlace();
1778 return TRUE;
1779 }
1780 }
1781 return FALSE;
1782 }
1783 FX_BOOL CPDF_VariableText_Iterator::GetSection(CPVT_Section& section) const {
1784 section.secplace = CPVT_WordPlace(m_CurPos.nSecIndex, 0, -1);
1785 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1786 section.rcSection = m_pVT->InToOut(pSection->m_SecInfo.rcSection);
1787 if (pSection->m_SecInfo.pSecProps) {
1788 section.SecProps = *pSection->m_SecInfo.pSecProps;
1789 }
1790 if (pSection->m_SecInfo.pWordProps) {
1791 section.WordProps = *pSection->m_SecInfo.pWordProps;
1792 }
1793 return TRUE;
1794 }
1795 return FALSE;
1796 }
1797 FX_BOOL CPDF_VariableText_Iterator::SetSection(const CPVT_Section& section) {
1798 if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
1799 if (pSection->m_SecInfo.pSecProps) {
1800 *pSection->m_SecInfo.pSecProps = section.SecProps;
1801 }
1802 if (pSection->m_SecInfo.pWordProps) {
1803 *pSection->m_SecInfo.pWordProps = section.WordProps;
1804 }
1805 return TRUE;
1806 }
1807 return FALSE;
1808 }
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/fpdfdoc/cpvt_floatrect.h » ('j') | core/fpdfdoc/cpvt_sectioninfo.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698