OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 <ctype.h> | 7 #include <ctype.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "../../../third_party/base/nonstd_unique_ptr.h" | 10 #include "../../../third_party/base/nonstd_unique_ptr.h" |
11 #include "../../include/fpdfapi/fpdf_module.h" | 11 #include "../../include/fpdfapi/fpdf_module.h" |
12 #include "../../include/fpdfapi/fpdf_page.h" | 12 #include "../../include/fpdfapi/fpdf_page.h" |
13 #include "../../include/fpdfapi/fpdf_pageobj.h" | 13 #include "../../include/fpdfapi/fpdf_pageobj.h" |
14 #include "../../include/fpdfapi/fpdf_resource.h" | 14 #include "../../include/fpdfapi/fpdf_resource.h" |
15 #include "../../include/fpdftext/fpdf_text.h" | 15 #include "../../include/fpdftext/fpdf_text.h" |
16 #include "../../include/fxcrt/fx_arb.h" | 16 #include "../../include/fxcrt/fx_arb.h" |
17 #include "../../include/fxcrt/fx_ucd.h" | 17 #include "../../include/fxcrt/fx_ucd.h" |
18 #include "text_int.h" | 18 #include "text_int.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) | 22 bool _IsIgnoreSpaceCharacter(FX_WCHAR curChar) |
23 { | 23 { |
24 if(curChar < 255 ) { | 24 if(curChar < 255 ) { |
25 return FALSE; | 25 return false; |
26 } | 26 } |
27 if ( (curChar >= 0x0600 && curChar <= 0x06FF) | 27 if ( (curChar >= 0x0600 && curChar <= 0x06FF) |
28 || (curChar >= 0xFE70 && curChar <= 0xFEFF) | 28 || (curChar >= 0xFE70 && curChar <= 0xFEFF) |
29 || (curChar >= 0xFB50 && curChar <= 0xFDFF) | 29 || (curChar >= 0xFB50 && curChar <= 0xFDFF) |
30 || (curChar >= 0x0400 && curChar <= 0x04FF) | 30 || (curChar >= 0x0400 && curChar <= 0x04FF) |
31 || (curChar >= 0x0500 && curChar <= 0x052F) | 31 || (curChar >= 0x0500 && curChar <= 0x052F) |
32 || (curChar >= 0xA640 && curChar <= 0xA69F) | 32 || (curChar >= 0xA640 && curChar <= 0xA69F) |
33 || (curChar >= 0x2DE0 && curChar <= 0x2DFF) | 33 || (curChar >= 0x2DE0 && curChar <= 0x2DFF) |
34 || curChar == 8467 | 34 || curChar == 8467 |
35 || (curChar >= 0x2000 && curChar <= 0x206F)) { | 35 || (curChar >= 0x2000 && curChar <= 0x206F)) { |
36 return FALSE; | 36 return false; |
37 } | 37 } |
38 return TRUE; | 38 return true; |
39 } | 39 } |
40 | 40 |
41 FX_FLOAT _NormalizeThreshold(FX_FLOAT threshold) | 41 FX_FLOAT _NormalizeThreshold(FX_FLOAT threshold) |
42 { | 42 { |
43 if (threshold < 300) { | 43 if (threshold < 300) { |
44 return threshold / 2.0f; | 44 return threshold / 2.0f; |
45 } | 45 } |
46 if (threshold < 500) { | 46 if (threshold < 500) { |
47 return threshold / 4.0f; | 47 return threshold / 4.0f; |
48 } | 48 } |
49 if (threshold < 700) { | 49 if (threshold < 700) { |
50 return threshold / 5.0f; | 50 return threshold / 5.0f; |
51 } | 51 } |
52 return threshold / 6.0f; | 52 return threshold / 6.0f; |
53 } | 53 } |
54 | 54 |
55 FX_FLOAT _CalculateBaseSpace(const CPDF_TextObject* pTextObj, | 55 FX_FLOAT _CalculateBaseSpace(const CPDF_TextObject* pTextObj, |
56 const CFX_AffineMatrix& matrix) | 56 const CFX_AffineMatrix& matrix) |
57 { | 57 { |
58 FX_FLOAT baseSpace = 0.0; | 58 FX_FLOAT baseSpace = 0.0; |
59 const int nItems = pTextObj->CountItems(); | 59 const int nItems = pTextObj->CountItems(); |
60 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { | 60 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { |
61 FX_BOOL bAllChar = TRUE; | 61 bool bAllChar = true; |
62 FX_FLOAT spacing = matrix.TransformDistance( | 62 FX_FLOAT spacing = matrix.TransformDistance( |
63 pTextObj->m_TextState.GetObject()->m_CharSpace); | 63 pTextObj->m_TextState.GetObject()->m_CharSpace); |
64 baseSpace = spacing; | 64 baseSpace = spacing; |
65 for (int i = 0; i < nItems; i++) { | 65 for (int i = 0; i < nItems; i++) { |
66 CPDF_TextObjectItem item; | 66 CPDF_TextObjectItem item; |
67 pTextObj->GetItemInfo(i, &item); | 67 pTextObj->GetItemInfo(i, &item); |
68 if (item.m_CharCode == (FX_DWORD) - 1) { | 68 if (item.m_CharCode == (FX_DWORD) - 1) { |
69 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 69 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
70 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; | 70 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; |
71 baseSpace = std::min(baseSpace, kerning + spacing); | 71 baseSpace = std::min(baseSpace, kerning + spacing); |
72 bAllChar = FALSE; | 72 bAllChar = false; |
73 } | 73 } |
74 } | 74 } |
75 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) { | 75 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) { |
76 baseSpace = 0.0; | 76 baseSpace = 0.0; |
77 } | 77 } |
78 } | 78 } |
79 return baseSpace; | 79 return baseSpace; |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 CPDFText_ParseOptions::CPDFText_ParseOptions() | 84 CPDFText_ParseOptions::CPDFText_ParseOptions() |
85 : m_bGetCharCodeOnly(FALSE), m_bNormalizeObjs(TRUE), m_bOutputHyphen(FALSE) | 85 : m_bGetCharCodeOnly(false), m_bNormalizeObjs(true), m_bOutputHyphen(false) |
86 { | 86 { |
87 } | 87 } |
88 IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_Page* pPage, CPDFText_Pa
rseOptions ParserOptions) | 88 IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_Page* pPage, CPDFText_Pa
rseOptions ParserOptions) |
89 { | 89 { |
90 return new CPDF_TextPage(pPage, ParserOptions); | 90 return new CPDF_TextPage(pPage, ParserOptions); |
91 } | 91 } |
92 IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_Page* pPage, int flags) | 92 IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_Page* pPage, int flags) |
93 { | 93 { |
94 return new CPDF_TextPage(pPage, flags); | 94 return new CPDF_TextPage(pPage, flags); |
95 } | 95 } |
(...skipping 17 matching lines...) Expand all Loading... |
113 #define TEXT_RETURN_CHAR L'\r' | 113 #define TEXT_RETURN_CHAR L'\r' |
114 #define TEXT_EMPTY L"" | 114 #define TEXT_EMPTY L"" |
115 #define TEXT_BLANK L" " | 115 #define TEXT_BLANK L" " |
116 #define TEXT_RETURN_LINEFEED L"\r\n" | 116 #define TEXT_RETURN_LINEFEED L"\r\n" |
117 #define TEXT_LINEFEED L"\n" | 117 #define TEXT_LINEFEED L"\n" |
118 #define TEXT_CHARRATIO_GAPDELTA 0.070 | 118 #define TEXT_CHARRATIO_GAPDELTA 0.070 |
119 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags) | 119 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags) |
120 : m_charList(512), | 120 : m_charList(512), |
121 m_TempCharList(50), | 121 m_TempCharList(50), |
122 m_pPreTextObj(NULL), | 122 m_pPreTextObj(NULL), |
123 m_IsParsered(FALSE), | 123 m_IsParsered(false), |
124 m_TextlineDir(-1), | 124 m_TextlineDir(-1), |
125 m_CurlineRect(0, 0, 0, 0) | 125 m_CurlineRect(0, 0, 0, 0) |
126 { | 126 { |
127 m_pPage = pPage; | 127 m_pPage = pPage; |
128 m_parserflag = flags; | 128 m_parserflag = flags; |
129 m_TextBuf.EstimateSize(0, 10240); | 129 m_TextBuf.EstimateSize(0, 10240); |
130 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int) pPage->GetPageWidth(),
(int)pPage->GetPageHeight(), 0); | 130 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int) pPage->GetPageWidth(),
(int)pPage->GetPageHeight(), 0); |
131 } | 131 } |
132 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, CPDFText_ParseOptions Parse
rOptions) | 132 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, CPDFText_ParseOptions Parse
rOptions) |
133 : m_ParseOptions(ParserOptions) | 133 : m_ParseOptions(ParserOptions) |
134 , m_charList(512) | 134 , m_charList(512) |
135 , m_TempCharList(50) | 135 , m_TempCharList(50) |
136 , m_pPreTextObj(NULL) | 136 , m_pPreTextObj(NULL) |
137 , m_IsParsered(FALSE) | 137 , m_IsParsered(false) |
138 , m_TextlineDir(-1) | 138 , m_TextlineDir(-1) |
139 , m_CurlineRect(0, 0, 0, 0) | 139 , m_CurlineRect(0, 0, 0, 0) |
140 { | 140 { |
141 m_pPage = pPage; | 141 m_pPage = pPage; |
142 m_parserflag = 0; | 142 m_parserflag = 0; |
143 m_TextBuf.EstimateSize(0, 10240); | 143 m_TextBuf.EstimateSize(0, 10240); |
144 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int) pPage->GetPageWidth(),
(int)pPage->GetPageHeight(), 0); | 144 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int) pPage->GetPageWidth(),
(int)pPage->GetPageHeight(), 0); |
145 } | 145 } |
146 CPDF_TextPage::CPDF_TextPage(const CPDF_PageObjects* pPage, int flags) | 146 CPDF_TextPage::CPDF_TextPage(const CPDF_PageObjects* pPage, int flags) |
147 : m_charList(512), | 147 : m_charList(512), |
148 m_TempCharList(50), | 148 m_TempCharList(50), |
149 m_pPreTextObj(NULL), | 149 m_pPreTextObj(NULL), |
150 m_IsParsered(FALSE), | 150 m_IsParsered(false), |
151 m_TextlineDir(-1), | 151 m_TextlineDir(-1), |
152 m_CurlineRect(0, 0, 0, 0) | 152 m_CurlineRect(0, 0, 0, 0) |
153 { | 153 { |
154 m_pPage = pPage; | 154 m_pPage = pPage; |
155 m_parserflag = flags; | 155 m_parserflag = flags; |
156 m_TextBuf.EstimateSize(0, 10240); | 156 m_TextBuf.EstimateSize(0, 10240); |
157 CFX_FloatRect pageRect = pPage->CalcBoundingBox(); | 157 CFX_FloatRect pageRect = pPage->CalcBoundingBox(); |
158 m_DisplayMatrix = CFX_AffineMatrix(1, 0, 0, -1, pageRect.right, pageRect.top
); | 158 m_DisplayMatrix = CFX_AffineMatrix(1, 0, 0, -1, pageRect.right, pageRect.top
); |
159 } | 159 } |
160 void CPDF_TextPage::NormalizeObjects(FX_BOOL bNormalize) | 160 void CPDF_TextPage::NormalizeObjects(bool bNormalize) |
161 { | 161 { |
162 m_ParseOptions.m_bNormalizeObjs = bNormalize; | 162 m_ParseOptions.m_bNormalizeObjs = bNormalize; |
163 } | 163 } |
164 bool CPDF_TextPage::IsControlChar(const PAGECHAR_INFO& charInfo) | 164 bool CPDF_TextPage::IsControlChar(const PAGECHAR_INFO& charInfo) |
165 { | 165 { |
166 switch (charInfo.m_Unicode) { | 166 switch (charInfo.m_Unicode) { |
167 case 0x2: | 167 case 0x2: |
168 case 0x3: | 168 case 0x3: |
169 case 0x93: | 169 case 0x93: |
170 case 0x94: | 170 case 0x94: |
171 case 0x96: | 171 case 0x96: |
172 case 0x97: | 172 case 0x97: |
173 case 0x98: | 173 case 0x98: |
174 case 0xfffe: | 174 case 0xfffe: |
175 return charInfo.m_Flag != FPDFTEXT_CHAR_HYPHEN; | 175 return charInfo.m_Flag != FPDFTEXT_CHAR_HYPHEN; |
176 default: | 176 default: |
177 return false; | 177 return false; |
178 } | 178 } |
179 } | 179 } |
180 FX_BOOL CPDF_TextPage::ParseTextPage() | 180 bool CPDF_TextPage::ParseTextPage() |
181 { | 181 { |
182 if (!m_pPage) { | 182 if (!m_pPage) { |
183 m_IsParsered = FALSE; | 183 m_IsParsered = false; |
184 return FALSE; | 184 return false; |
185 } | 185 } |
186 m_IsParsered = FALSE; | 186 m_IsParsered = false; |
187 m_TextBuf.Clear(); | 187 m_TextBuf.Clear(); |
188 m_charList.RemoveAll(); | 188 m_charList.RemoveAll(); |
189 m_pPreTextObj = NULL; | 189 m_pPreTextObj = NULL; |
190 ProcessObject(); | 190 ProcessObject(); |
191 m_IsParsered = TRUE; | 191 m_IsParsered = true; |
192 if(!m_ParseOptions.m_bGetCharCodeOnly) { | 192 if(!m_ParseOptions.m_bGetCharCodeOnly) { |
193 m_CharIndex.RemoveAll(); | 193 m_CharIndex.RemoveAll(); |
194 int nCount = m_charList.GetSize(); | 194 int nCount = m_charList.GetSize(); |
195 if(nCount) { | 195 if(nCount) { |
196 m_CharIndex.Add(0); | 196 m_CharIndex.Add(0); |
197 } | 197 } |
198 for(int i = 0; i < nCount; i++) { | 198 for(int i = 0; i < nCount; i++) { |
199 int indexSize = m_CharIndex.GetSize(); | 199 int indexSize = m_CharIndex.GetSize(); |
200 FX_BOOL bNormal = FALSE; | 200 bool bNormal = false; |
201 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); | 201 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); |
202 if(charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { | 202 if(charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
203 bNormal = TRUE; | 203 bNormal = true; |
204 } | 204 } |
205 else if(charinfo.m_Unicode == 0 || IsControlChar(charinfo)) | 205 else if(charinfo.m_Unicode == 0 || IsControlChar(charinfo)) |
206 bNormal = FALSE; | 206 bNormal = false; |
207 else { | 207 else { |
208 bNormal = TRUE; | 208 bNormal = true; |
209 } | 209 } |
210 if(bNormal) { | 210 if(bNormal) { |
211 if(indexSize % 2) { | 211 if(indexSize % 2) { |
212 m_CharIndex.Add(1); | 212 m_CharIndex.Add(1); |
213 } else { | 213 } else { |
214 if(indexSize <= 0) { | 214 if(indexSize <= 0) { |
215 continue; | 215 continue; |
216 } | 216 } |
217 m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize
- 1) + 1); | 217 m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize
- 1) + 1); |
218 } | 218 } |
219 } else { | 219 } else { |
220 if(indexSize % 2) { | 220 if(indexSize % 2) { |
221 if(indexSize <= 0) { | 221 if(indexSize <= 0) { |
222 continue; | 222 continue; |
223 } | 223 } |
224 m_CharIndex.SetAt(indexSize - 1, i + 1); | 224 m_CharIndex.SetAt(indexSize - 1, i + 1); |
225 } else { | 225 } else { |
226 m_CharIndex.Add(i + 1); | 226 m_CharIndex.Add(i + 1); |
227 } | 227 } |
228 } | 228 } |
229 } | 229 } |
230 int indexSize = m_CharIndex.GetSize(); | 230 int indexSize = m_CharIndex.GetSize(); |
231 if(indexSize % 2) { | 231 if(indexSize % 2) { |
232 m_CharIndex.RemoveAt(indexSize - 1); | 232 m_CharIndex.RemoveAt(indexSize - 1); |
233 } | 233 } |
234 } | 234 } |
235 return TRUE; | 235 return true; |
236 } | 236 } |
237 int CPDF_TextPage::CountChars() const | 237 int CPDF_TextPage::CountChars() const |
238 { | 238 { |
239 if(m_ParseOptions.m_bGetCharCodeOnly) { | 239 if(m_ParseOptions.m_bGetCharCodeOnly) { |
240 return m_TextBuf.GetSize(); | 240 return m_TextBuf.GetSize(); |
241 } | 241 } |
242 return m_charList.GetSize(); | 242 return m_charList.GetSize(); |
243 } | 243 } |
244 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const | 244 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const |
245 { | 245 { |
(...skipping 30 matching lines...) Expand all Loading... |
276 if(start < 0 || nCount == 0) { | 276 if(start < 0 || nCount == 0) { |
277 return; | 277 return; |
278 } | 278 } |
279 if (!m_IsParsered) { | 279 if (!m_IsParsered) { |
280 return; | 280 return; |
281 } | 281 } |
282 PAGECHAR_INFO info_curchar; | 282 PAGECHAR_INFO info_curchar; |
283 CPDF_TextObject* pCurObj = NULL; | 283 CPDF_TextObject* pCurObj = NULL; |
284 CFX_FloatRect rect; | 284 CFX_FloatRect rect; |
285 int curPos = start; | 285 int curPos = start; |
286 FX_BOOL» » » » flagNewRect = TRUE; | 286 bool» » » » flagNewRect = true; |
287 if (nCount + start > m_charList.GetSize() || nCount == -1) { | 287 if (nCount + start > m_charList.GetSize() || nCount == -1) { |
288 nCount = m_charList.GetSize() - start; | 288 nCount = m_charList.GetSize() - start; |
289 } | 289 } |
290 while (nCount--) { | 290 while (nCount--) { |
291 info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(curPos++); | 291 info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(curPos++); |
292 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { | 292 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
293 continue; | 293 continue; |
294 } | 294 } |
295 if(info_curchar.m_CharBox.Width() < 0.01 || info_curchar.m_CharBox.Heigh
t() < 0.01) { | 295 if(info_curchar.m_CharBox.Width() < 0.01 || info_curchar.m_CharBox.Heigh
t() < 0.01) { |
296 continue; | 296 continue; |
297 } | 297 } |
298 if(!pCurObj) { | 298 if(!pCurObj) { |
299 pCurObj = info_curchar.m_pTextObj; | 299 pCurObj = info_curchar.m_pTextObj; |
300 } | 300 } |
301 if (pCurObj != info_curchar.m_pTextObj) { | 301 if (pCurObj != info_curchar.m_pTextObj) { |
302 rectArray.Add(rect); | 302 rectArray.Add(rect); |
303 pCurObj = info_curchar.m_pTextObj; | 303 pCurObj = info_curchar.m_pTextObj; |
304 flagNewRect = TRUE; | 304 flagNewRect = true; |
305 } | 305 } |
306 if (flagNewRect) { | 306 if (flagNewRect) { |
307 FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_Origin
Y; | 307 FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_Origin
Y; |
308 CFX_AffineMatrix matrix, matrix_reverse; | 308 CFX_AffineMatrix matrix, matrix_reverse; |
309 info_curchar.m_pTextObj->GetTextMatrix(&matrix); | 309 info_curchar.m_pTextObj->GetTextMatrix(&matrix); |
310 matrix.Concat(info_curchar.m_Matrix); | 310 matrix.Concat(info_curchar.m_Matrix); |
311 matrix_reverse.SetReverse(matrix); | 311 matrix_reverse.SetReverse(matrix); |
312 matrix_reverse.Transform(orgX, orgY); | 312 matrix_reverse.Transform(orgX, orgY); |
313 rect.left = info_curchar.m_CharBox.left; | 313 rect.left = info_curchar.m_CharBox.left; |
314 rect.right = info_curchar.m_CharBox.right; | 314 rect.right = info_curchar.m_CharBox.right; |
315 if (pCurObj->GetFont()->GetTypeDescent()) { | 315 if (pCurObj->GetFont()->GetTypeDescent()) { |
316 rect.bottom = orgY + pCurObj->GetFont()->GetTypeDescent() * pCur
Obj->GetFontSize() / 1000; | 316 rect.bottom = orgY + pCurObj->GetFont()->GetTypeDescent() * pCur
Obj->GetFontSize() / 1000; |
317 FX_FLOAT xPosTemp = orgX; | 317 FX_FLOAT xPosTemp = orgX; |
318 matrix.Transform(xPosTemp, rect.bottom); | 318 matrix.Transform(xPosTemp, rect.bottom); |
319 } else { | 319 } else { |
320 rect.bottom = info_curchar.m_CharBox.bottom; | 320 rect.bottom = info_curchar.m_CharBox.bottom; |
321 } | 321 } |
322 if (pCurObj->GetFont()->GetTypeAscent()) { | 322 if (pCurObj->GetFont()->GetTypeAscent()) { |
323 rect.top = orgY + pCurObj->GetFont()->GetTypeAscent() * pCurObj-
>GetFontSize() / 1000; | 323 rect.top = orgY + pCurObj->GetFont()->GetTypeAscent() * pCurObj-
>GetFontSize() / 1000; |
324 FX_FLOAT xPosTemp = orgX + GetCharWidth(info_curchar.m_CharCode,
pCurObj->GetFont()) * pCurObj->GetFontSize() / 1000; | 324 FX_FLOAT xPosTemp = orgX + GetCharWidth(info_curchar.m_CharCode,
pCurObj->GetFont()) * pCurObj->GetFontSize() / 1000; |
325 matrix.Transform(xPosTemp, rect.top); | 325 matrix.Transform(xPosTemp, rect.top); |
326 } else { | 326 } else { |
327 rect.top = info_curchar.m_CharBox.top; | 327 rect.top = info_curchar.m_CharBox.top; |
328 } | 328 } |
329 flagNewRect = FALSE; | 329 flagNewRect = false; |
330 rect = info_curchar.m_CharBox; | 330 rect = info_curchar.m_CharBox; |
331 rect.Normalize(); | 331 rect.Normalize(); |
332 } else { | 332 } else { |
333 info_curchar.m_CharBox.Normalize(); | 333 info_curchar.m_CharBox.Normalize(); |
334 if (rect.left > info_curchar.m_CharBox.left) { | 334 if (rect.left > info_curchar.m_CharBox.left) { |
335 rect.left = info_curchar.m_CharBox.left; | 335 rect.left = info_curchar.m_CharBox.left; |
336 } | 336 } |
337 if (rect.right < info_curchar.m_CharBox.right) { | 337 if (rect.right < info_curchar.m_CharBox.right) { |
338 rect.right = info_curchar.m_CharBox.right; | 338 rect.right = info_curchar.m_CharBox.right; |
339 } | 339 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 392 } |
393 CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const | 393 CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const |
394 { | 394 { |
395 CFX_WideString strText; | 395 CFX_WideString strText; |
396 if(m_ParseOptions.m_bGetCharCodeOnly || !m_IsParsered) { | 396 if(m_ParseOptions.m_bGetCharCodeOnly || !m_IsParsered) { |
397 return strText; | 397 return strText; |
398 } | 398 } |
399 int nCount = m_charList.GetSize(); | 399 int nCount = m_charList.GetSize(); |
400 int pos = 0; | 400 int pos = 0; |
401 FX_FLOAT posy = 0; | 401 FX_FLOAT posy = 0; |
402 FX_BOOL IsContainPreChar = FALSE; | 402 bool IsContainPreChar = false; |
403 FX_BOOL» ISAddLineFeed = FALSE; | 403 bool» ISAddLineFeed = false; |
404 while (pos < nCount) { | 404 while (pos < nCount) { |
405 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); | 405 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); |
406 if (IsRectIntersect(rect, charinfo.m_CharBox)) { | 406 if (IsRectIntersect(rect, charinfo.m_CharBox)) { |
407 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar &
& ISAddLineFeed) { | 407 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar &
& ISAddLineFeed) { |
408 posy = charinfo.m_OriginY; | 408 posy = charinfo.m_OriginY; |
409 if (strText.GetLength() > 0) { | 409 if (strText.GetLength() > 0) { |
410 strText += L"\r\n"; | 410 strText += L"\r\n"; |
411 } | 411 } |
412 } | 412 } |
413 IsContainPreChar = TRUE; | 413 IsContainPreChar = true; |
414 ISAddLineFeed = FALSE; | 414 ISAddLineFeed = false; |
415 if (charinfo.m_Unicode) { | 415 if (charinfo.m_Unicode) { |
416 strText += charinfo.m_Unicode; | 416 strText += charinfo.m_Unicode; |
417 } | 417 } |
418 } else if (charinfo.m_Unicode == 32) { | 418 } else if (charinfo.m_Unicode == 32) { |
419 if (IsContainPreChar && charinfo.m_Unicode) { | 419 if (IsContainPreChar && charinfo.m_Unicode) { |
420 strText += charinfo.m_Unicode; | 420 strText += charinfo.m_Unicode; |
421 IsContainPreChar = FALSE; | 421 IsContainPreChar = false; |
422 ISAddLineFeed = FALSE; | 422 ISAddLineFeed = false; |
423 } | 423 } |
424 } else { | 424 } else { |
425 IsContainPreChar = FALSE; | 425 IsContainPreChar = false; |
426 ISAddLineFeed = TRUE; | 426 ISAddLineFeed = true; |
427 } | 427 } |
428 } | 428 } |
429 return strText; | 429 return strText; |
430 } | 430 } |
431 void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray
& resRectArray) const | 431 void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray
& resRectArray) const |
432 { | 432 { |
433 if(m_ParseOptions.m_bGetCharCodeOnly) { | 433 if(m_ParseOptions.m_bGetCharCodeOnly) { |
434 return; | 434 return; |
435 } | 435 } |
436 if (!m_IsParsered) { | 436 if (!m_IsParsered) { |
437 return; | 437 return; |
438 } | 438 } |
439 CFX_FloatRect curRect; | 439 CFX_FloatRect curRect; |
440 FX_BOOL» » » » flagNewRect = TRUE; | 440 bool» » » » flagNewRect = true; |
441 CPDF_TextObject* pCurObj = NULL; | 441 CPDF_TextObject* pCurObj = NULL; |
442 int nCount = m_charList.GetSize(); | 442 int nCount = m_charList.GetSize(); |
443 int pos = 0; | 443 int pos = 0; |
444 while (pos < nCount) { | 444 while (pos < nCount) { |
445 PAGECHAR_INFO info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); | 445 PAGECHAR_INFO info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); |
446 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { | 446 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
447 continue; | 447 continue; |
448 } | 448 } |
449 if (IsRectIntersect(rect, info_curchar.m_CharBox)) { | 449 if (IsRectIntersect(rect, info_curchar.m_CharBox)) { |
450 if(!pCurObj) { | 450 if(!pCurObj) { |
451 pCurObj = info_curchar.m_pTextObj; | 451 pCurObj = info_curchar.m_pTextObj; |
452 } | 452 } |
453 if (pCurObj != info_curchar.m_pTextObj) { | 453 if (pCurObj != info_curchar.m_pTextObj) { |
454 resRectArray.Add(curRect); | 454 resRectArray.Add(curRect); |
455 pCurObj = info_curchar.m_pTextObj; | 455 pCurObj = info_curchar.m_pTextObj; |
456 flagNewRect = TRUE; | 456 flagNewRect = true; |
457 } | 457 } |
458 if (flagNewRect) { | 458 if (flagNewRect) { |
459 curRect = info_curchar.m_CharBox; | 459 curRect = info_curchar.m_CharBox; |
460 flagNewRect = FALSE; | 460 flagNewRect = false; |
461 curRect.Normalize(); | 461 curRect.Normalize(); |
462 } else { | 462 } else { |
463 info_curchar.m_CharBox.Normalize(); | 463 info_curchar.m_CharBox.Normalize(); |
464 if (curRect.left > info_curchar.m_CharBox.left) { | 464 if (curRect.left > info_curchar.m_CharBox.left) { |
465 curRect.left = info_curchar.m_CharBox.left; | 465 curRect.left = info_curchar.m_CharBox.left; |
466 } | 466 } |
467 if (curRect.right < info_curchar.m_CharBox.right) { | 467 if (curRect.right < info_curchar.m_CharBox.right) { |
468 curRect.right = info_curchar.m_CharBox.right; | 468 curRect.right = info_curchar.m_CharBox.right; |
469 } | 469 } |
470 if ( curRect.top < info_curchar.m_CharBox.top) { | 470 if ( curRect.top < info_curchar.m_CharBox.top) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 return ; | 619 return ; |
620 } | 620 } |
621 if (!m_IsParsered || rectIndex < 0 || rectIndex >= m_SelRects.GetSize()) { | 621 if (!m_IsParsered || rectIndex < 0 || rectIndex >= m_SelRects.GetSize()) { |
622 return; | 622 return; |
623 } | 623 } |
624 left = m_SelRects.GetAt(rectIndex).left; | 624 left = m_SelRects.GetAt(rectIndex).left; |
625 top = m_SelRects.GetAt(rectIndex).top; | 625 top = m_SelRects.GetAt(rectIndex).top; |
626 right = m_SelRects.GetAt(rectIndex).right; | 626 right = m_SelRects.GetAt(rectIndex).right; |
627 bottom = m_SelRects.GetAt(rectIndex).bottom; | 627 bottom = m_SelRects.GetAt(rectIndex).bottom; |
628 } | 628 } |
629 FX_BOOL CPDF_TextPage::GetBaselineRotate(int start, int end, int& Rotate) | 629 bool CPDF_TextPage::GetBaselineRotate(int start, int end, int& Rotate) |
630 { | 630 { |
631 if(m_ParseOptions.m_bGetCharCodeOnly) { | 631 if(m_ParseOptions.m_bGetCharCodeOnly) { |
632 return FALSE; | 632 return false; |
633 } | 633 } |
634 if(end == start) { | 634 if(end == start) { |
635 return FALSE; | 635 return false; |
636 } | 636 } |
637 FX_FLOAT dx, dy; | 637 FX_FLOAT dx, dy; |
638 FPDF_CHAR_INFO info1, info2; | 638 FPDF_CHAR_INFO info1, info2; |
639 GetCharInfo(start, info1); | 639 GetCharInfo(start, info1); |
640 GetCharInfo(end, info2); | 640 GetCharInfo(end, info2); |
641 while(info2.m_CharBox.Width() == 0 || info2.m_CharBox.Height() == 0) { | 641 while(info2.m_CharBox.Width() == 0 || info2.m_CharBox.Height() == 0) { |
642 end--; | 642 end--; |
643 if(end <= start) { | 643 if(end <= start) { |
644 return FALSE; | 644 return false; |
645 } | 645 } |
646 GetCharInfo(end, info2); | 646 GetCharInfo(end, info2); |
647 } | 647 } |
648 dx = (info2.m_OriginX - info1.m_OriginX); | 648 dx = (info2.m_OriginX - info1.m_OriginX); |
649 dy = (info2.m_OriginY - info1.m_OriginY); | 649 dy = (info2.m_OriginY - info1.m_OriginY); |
650 if(dx == 0) { | 650 if(dx == 0) { |
651 if(dy > 0) { | 651 if(dy > 0) { |
652 Rotate = 90; | 652 Rotate = 90; |
653 } else if (dy < 0) { | 653 } else if (dy < 0) { |
654 Rotate = 270; | 654 Rotate = 270; |
655 } else { | 655 } else { |
656 Rotate = 0; | 656 Rotate = 0; |
657 } | 657 } |
658 } else { | 658 } else { |
659 float a = FXSYS_atan2(dy, dx); | 659 float a = FXSYS_atan2(dy, dx); |
660 Rotate = (int)(a * 180 / FX_PI + 0.5); | 660 Rotate = (int)(a * 180 / FX_PI + 0.5); |
661 } | 661 } |
662 if(Rotate < 0) { | 662 if(Rotate < 0) { |
663 Rotate = -Rotate; | 663 Rotate = -Rotate; |
664 } else if(Rotate > 0) { | 664 } else if(Rotate > 0) { |
665 Rotate = 360 - Rotate; | 665 Rotate = 360 - Rotate; |
666 } | 666 } |
667 return TRUE; | 667 return true; |
668 } | 668 } |
669 FX_BOOL»CPDF_TextPage::GetBaselineRotate(const CFX_FloatRect& rect , int& Rotate
) | 669 bool» CPDF_TextPage::GetBaselineRotate(const CFX_FloatRect& rect , int& Rotate
) |
670 { | 670 { |
671 if(m_ParseOptions.m_bGetCharCodeOnly) { | 671 if(m_ParseOptions.m_bGetCharCodeOnly) { |
672 return FALSE; | 672 return false; |
673 } | 673 } |
674 int start, end, count, n = CountBoundedSegments(rect.left, rect.top, rect.ri
ght, rect.bottom, TRUE); | 674 int start, end, count, n = CountBoundedSegments(rect.left, rect.top, rect.ri
ght, rect.bottom, true); |
675 if(n < 1) { | 675 if(n < 1) { |
676 return FALSE; | 676 return false; |
677 } | 677 } |
678 if(n > 1) { | 678 if(n > 1) { |
679 GetBoundedSegment(n - 1, start, count); | 679 GetBoundedSegment(n - 1, start, count); |
680 end = start + count - 1; | 680 end = start + count - 1; |
681 GetBoundedSegment(0, start, count); | 681 GetBoundedSegment(0, start, count); |
682 } else { | 682 } else { |
683 GetBoundedSegment(0, start, count); | 683 GetBoundedSegment(0, start, count); |
684 end = start + count - 1; | 684 end = start + count - 1; |
685 } | 685 } |
686 return GetBaselineRotate(start, end, Rotate); | 686 return GetBaselineRotate(start, end, Rotate); |
687 } | 687 } |
688 FX_BOOL»CPDF_TextPage::GetBaselineRotate(int rectIndex, int& Rotate) | 688 bool» CPDF_TextPage::GetBaselineRotate(int rectIndex, int& Rotate) |
689 { | 689 { |
690 if(m_ParseOptions.m_bGetCharCodeOnly) { | 690 if(m_ParseOptions.m_bGetCharCodeOnly) { |
691 return FALSE; | 691 return false; |
692 } | 692 } |
693 if (!m_IsParsered || rectIndex < 0 || rectIndex > m_SelRects.GetSize()) { | 693 if (!m_IsParsered || rectIndex < 0 || rectIndex > m_SelRects.GetSize()) { |
694 return FALSE; | 694 return false; |
695 } | 695 } |
696 CFX_FloatRect rect = m_SelRects.GetAt(rectIndex); | 696 CFX_FloatRect rect = m_SelRects.GetAt(rectIndex); |
697 return GetBaselineRotate(rect , Rotate); | 697 return GetBaselineRotate(rect , Rotate); |
698 } | 698 } |
699 int» CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, FX_FLOAT top, FX_FLOA
T right, FX_FLOAT bottom, FX_BOOL bContains ) | 699 int» CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, FX_FLOAT top, FX_FLOA
T right, FX_FLOAT bottom, bool bContains ) |
700 { | 700 { |
701 if(m_ParseOptions.m_bGetCharCodeOnly) { | 701 if(m_ParseOptions.m_bGetCharCodeOnly) { |
702 return -1; | 702 return -1; |
703 } | 703 } |
704 m_Segment.RemoveAll(); | 704 m_Segment.RemoveAll(); |
705 if (!m_IsParsered) { | 705 if (!m_IsParsered) { |
706 return -1; | 706 return -1; |
707 } | 707 } |
708 CFX_FloatRect rect(left, bottom, right, top); | 708 CFX_FloatRect rect(left, bottom, right, top); |
709 rect.Normalize(); | 709 rect.Normalize(); |
710 int nCount = m_charList.GetSize(); | 710 int nCount = m_charList.GetSize(); |
711 int pos = 0; | 711 int pos = 0; |
712 FPDF_SEGMENT segment; | 712 FPDF_SEGMENT segment; |
713 segment.m_Start = 0; | 713 segment.m_Start = 0; |
714 segment.m_nCount = 0; | 714 segment.m_nCount = 0; |
715 FX_BOOL» » segmentStatus = 0; | 715 bool» » segmentStatus = 0; |
716 FX_BOOL» » IsContainPreChar = FALSE; | 716 bool» » IsContainPreChar = false; |
717 while (pos < nCount) { | 717 while (pos < nCount) { |
718 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos); | 718 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos); |
719 if(bContains && rect.Contains(charinfo.m_CharBox)) { | 719 if(bContains && rect.Contains(charinfo.m_CharBox)) { |
720 if (segmentStatus == 0 || segmentStatus == 2) { | 720 if (segmentStatus == 0 || segmentStatus == 2) { |
721 segment.m_Start = pos; | 721 segment.m_Start = pos; |
722 segment.m_nCount = 1; | 722 segment.m_nCount = 1; |
723 segmentStatus = 1; | 723 segmentStatus = 1; |
724 } else if (segmentStatus == 1) { | 724 } else if (segmentStatus == 1) { |
725 segment.m_nCount++; | 725 segment.m_nCount++; |
726 } | 726 } |
727 IsContainPreChar = TRUE; | 727 IsContainPreChar = true; |
728 } else if (!bContains && (IsRectIntersect(rect, charinfo.m_CharBox) || r
ect.Contains(charinfo.m_OriginX, charinfo.m_OriginY))) { | 728 } else if (!bContains && (IsRectIntersect(rect, charinfo.m_CharBox) || r
ect.Contains(charinfo.m_OriginX, charinfo.m_OriginY))) { |
729 if (segmentStatus == 0 || segmentStatus == 2) { | 729 if (segmentStatus == 0 || segmentStatus == 2) { |
730 segment.m_Start = pos; | 730 segment.m_Start = pos; |
731 segment.m_nCount = 1; | 731 segment.m_nCount = 1; |
732 segmentStatus = 1; | 732 segmentStatus = 1; |
733 } else if (segmentStatus == 1) { | 733 } else if (segmentStatus == 1) { |
734 segment.m_nCount++; | 734 segment.m_nCount++; |
735 } | 735 } |
736 IsContainPreChar = TRUE; | 736 IsContainPreChar = true; |
737 } else if (charinfo.m_Unicode == 32) { | 737 } else if (charinfo.m_Unicode == 32) { |
738 if (IsContainPreChar == TRUE) { | 738 if (IsContainPreChar == true) { |
739 if (segmentStatus == 0 || segmentStatus == 2) { | 739 if (segmentStatus == 0 || segmentStatus == 2) { |
740 segment.m_Start = pos; | 740 segment.m_Start = pos; |
741 segment.m_nCount = 1; | 741 segment.m_nCount = 1; |
742 segmentStatus = 1; | 742 segmentStatus = 1; |
743 } else if (segmentStatus == 1) { | 743 } else if (segmentStatus == 1) { |
744 segment.m_nCount++; | 744 segment.m_nCount++; |
745 } | 745 } |
746 IsContainPreChar = FALSE; | 746 IsContainPreChar = false; |
747 } else { | 747 } else { |
748 if (segmentStatus == 1) { | 748 if (segmentStatus == 1) { |
749 segmentStatus = 2; | 749 segmentStatus = 2; |
750 m_Segment.Add(segment); | 750 m_Segment.Add(segment); |
751 segment.m_Start = 0; | 751 segment.m_Start = 0; |
752 segment.m_nCount = 0; | 752 segment.m_nCount = 0; |
753 } | 753 } |
754 } | 754 } |
755 } else { | 755 } else { |
756 if (segmentStatus == 1) { | 756 if (segmentStatus == 1) { |
757 segmentStatus = 2; | 757 segmentStatus = 2; |
758 m_Segment.Add(segment); | 758 m_Segment.Add(segment); |
759 segment.m_Start = 0; | 759 segment.m_Start = 0; |
760 segment.m_nCount = 0; | 760 segment.m_nCount = 0; |
761 } | 761 } |
762 IsContainPreChar = FALSE; | 762 IsContainPreChar = false; |
763 } | 763 } |
764 pos++; | 764 pos++; |
765 } | 765 } |
766 if (segmentStatus == 1) { | 766 if (segmentStatus == 1) { |
767 segmentStatus = 2; | 767 segmentStatus = 2; |
768 m_Segment.Add(segment); | 768 m_Segment.Add(segment); |
769 segment.m_Start = 0; | 769 segment.m_Start = 0; |
770 segment.m_nCount = 0; | 770 segment.m_nCount = 0; |
771 } | 771 } |
772 return m_Segment.GetSize(); | 772 return m_Segment.GetSize(); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 } | 1046 } |
1047 if( !m_ParseOptions.m_bGetCharCodeOnly) { | 1047 if( !m_ParseOptions.m_bGetCharCodeOnly) { |
1048 m_charList.Add(Info); | 1048 m_charList.Add(Info); |
1049 } | 1049 } |
1050 } | 1050 } |
1051 void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) | 1051 void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) |
1052 { | 1052 { |
1053 PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); | 1053 PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); |
1054 if(!IsControlChar(Info)) { | 1054 if(!IsControlChar(Info)) { |
1055 Info.m_Index = m_TextBuf.GetLength(); | 1055 Info.m_Index = m_TextBuf.GetLength(); |
1056 FX_WCHAR wChar = FX_GetMirrorChar(str.GetAt(i), TRUE, FALSE); | 1056 FX_WCHAR wChar = FX_GetMirrorChar(str.GetAt(i), true, false); |
1057 FX_WCHAR* pDst = NULL; | 1057 FX_WCHAR* pDst = NULL; |
1058 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst); | 1058 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst); |
1059 if (nCount >= 1) { | 1059 if (nCount >= 1) { |
1060 pDst = FX_Alloc(FX_WCHAR, nCount); | 1060 pDst = FX_Alloc(FX_WCHAR, nCount); |
1061 FX_Unicode_GetNormalization(wChar, pDst); | 1061 FX_Unicode_GetNormalization(wChar, pDst); |
1062 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 1062 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
1063 PAGECHAR_INFO Info2 = Info; | 1063 PAGECHAR_INFO Info2 = Info; |
1064 Info2.m_Unicode = pDst[nIndex]; | 1064 Info2.m_Unicode = pDst[nIndex]; |
1065 Info2.m_Flag = FPDFTEXT_CHAR_PIECE; | 1065 Info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
1066 m_TextBuf.AppendChar(Info2.m_Unicode); | 1066 m_TextBuf.AppendChar(Info2.m_Unicode); |
(...skipping 15 matching lines...) Expand all Loading... |
1082 } | 1082 } |
1083 void CPDF_TextPage::CloseTempLine() | 1083 void CPDF_TextPage::CloseTempLine() |
1084 { | 1084 { |
1085 int count1 = m_TempCharList.GetSize(); | 1085 int count1 = m_TempCharList.GetSize(); |
1086 if (count1 <= 0) { | 1086 if (count1 <= 0) { |
1087 return; | 1087 return; |
1088 } | 1088 } |
1089 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 1089 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); |
1090 CFX_WideString str = m_TempTextBuf.GetWideString(); | 1090 CFX_WideString str = m_TempTextBuf.GetWideString(); |
1091 CFX_WordArray order; | 1091 CFX_WordArray order; |
1092 FX_BOOL bR2L = FALSE; | 1092 bool bR2L = false; |
1093 int32_t start = 0, count = 0; | 1093 int32_t start = 0, count = 0; |
1094 int nR2L = 0, nL2R = 0; | 1094 int nR2L = 0, nL2R = 0; |
1095 FX_BOOL bPrevSpace = FALSE; | 1095 bool bPrevSpace = false; |
1096 for (int i = 0; i < str.GetLength(); i++) { | 1096 for (int i = 0; i < str.GetLength(); i++) { |
1097 if(str.GetAt(i) == 32) { | 1097 if(str.GetAt(i) == 32) { |
1098 if(bPrevSpace) { | 1098 if(bPrevSpace) { |
1099 m_TempTextBuf.Delete(i, 1); | 1099 m_TempTextBuf.Delete(i, 1); |
1100 m_TempCharList.Delete(i); | 1100 m_TempCharList.Delete(i); |
1101 str.Delete(i); | 1101 str.Delete(i); |
1102 count1--; | 1102 count1--; |
1103 i--; | 1103 i--; |
1104 continue; | 1104 continue; |
1105 } | 1105 } |
1106 bPrevSpace = TRUE; | 1106 bPrevSpace = true; |
1107 } else { | 1107 } else { |
1108 bPrevSpace = FALSE; | 1108 bPrevSpace = false; |
1109 } | 1109 } |
1110 if(pBidiChar->AppendChar(str.GetAt(i))) { | 1110 if(pBidiChar->AppendChar(str.GetAt(i))) { |
1111 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1111 int32_t ret = pBidiChar->GetBidiInfo(start, count); |
1112 order.Add(start); | 1112 order.Add(start); |
1113 order.Add(count); | 1113 order.Add(count); |
1114 order.Add(ret); | 1114 order.Add(ret); |
1115 if(!bR2L) { | 1115 if(!bR2L) { |
1116 if(ret == 2) { | 1116 if(ret == 2) { |
1117 nR2L++; | 1117 nR2L++; |
1118 } else if (ret == 1) { | 1118 } else if (ret == 1) { |
1119 nL2R++; | 1119 nL2R++; |
1120 } | 1120 } |
1121 } | 1121 } |
1122 } | 1122 } |
1123 } | 1123 } |
1124 if(pBidiChar->EndChar()) { | 1124 if(pBidiChar->EndChar()) { |
1125 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1125 int32_t ret = pBidiChar->GetBidiInfo(start, count); |
1126 order.Add(start); | 1126 order.Add(start); |
1127 order.Add(count); | 1127 order.Add(count); |
1128 order.Add(ret); | 1128 order.Add(ret); |
1129 if(!bR2L) { | 1129 if(!bR2L) { |
1130 if(ret == 2) { | 1130 if(ret == 2) { |
1131 nR2L++; | 1131 nR2L++; |
1132 } else if(ret == 1) { | 1132 } else if(ret == 1) { |
1133 nL2R++; | 1133 nL2R++; |
1134 } | 1134 } |
1135 } | 1135 } |
1136 } | 1136 } |
1137 if(nR2L > 0 && nR2L >= nL2R) { | 1137 if(nR2L > 0 && nR2L >= nL2R) { |
1138 bR2L = TRUE; | 1138 bR2L = true; |
1139 } | 1139 } |
1140 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { | 1140 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { |
1141 int count = order.GetSize(); | 1141 int count = order.GetSize(); |
1142 for(int i = count - 1; i > 0; i -= 3) { | 1142 for(int i = count - 1; i > 0; i -= 3) { |
1143 int ret = order.GetAt(i); | 1143 int ret = order.GetAt(i); |
1144 int start = order.GetAt(i - 2); | 1144 int start = order.GetAt(i - 2); |
1145 int count1 = order.GetAt(i - 1); | 1145 int count1 = order.GetAt(i - 1); |
1146 if(ret == 2 || ret == 0) { | 1146 if(ret == 2 || ret == 0) { |
1147 for(int j = start + count1 - 1; j >= start; j--) { | 1147 for(int j = start + count1 - 1; j >= start; j--) { |
1148 AddCharInfoByRLDirection(str, j); | 1148 AddCharInfoByRLDirection(str, j); |
1149 } | 1149 } |
1150 } else { | 1150 } else { |
1151 int j = i; | 1151 int j = i; |
1152 FX_BOOL bSymbol = FALSE; | 1152 bool bSymbol = false; |
1153 while(j > 0 && order.GetAt(j) != 2) { | 1153 while(j > 0 && order.GetAt(j) != 2) { |
1154 bSymbol = !order.GetAt(j); | 1154 bSymbol = !order.GetAt(j); |
1155 j -= 3; | 1155 j -= 3; |
1156 } | 1156 } |
1157 int end = start + count1 ; | 1157 int end = start + count1 ; |
1158 int n = 0; | 1158 int n = 0; |
1159 if(bSymbol) { | 1159 if(bSymbol) { |
1160 n = j + 6; | 1160 n = j + 6; |
1161 } else { | 1161 } else { |
1162 n = j + 3; | 1162 n = j + 3; |
(...skipping 11 matching lines...) Expand all Loading... |
1174 int end = start + count1 ; | 1174 int end = start + count1 ; |
1175 for(int m = start; m < end; m++) { | 1175 for(int m = start; m < end; m++) { |
1176 AddCharInfoByLRDirection(str, m); | 1176 AddCharInfoByLRDirection(str, m); |
1177 } | 1177 } |
1178 } | 1178 } |
1179 } | 1179 } |
1180 } | 1180 } |
1181 } | 1181 } |
1182 } else { | 1182 } else { |
1183 int count = order.GetSize(); | 1183 int count = order.GetSize(); |
1184 FX_BOOL bL2R = FALSE; | 1184 bool bL2R = false; |
1185 for(int i = 0; i < count; i += 3) { | 1185 for(int i = 0; i < count; i += 3) { |
1186 int ret = order.GetAt(i + 2); | 1186 int ret = order.GetAt(i + 2); |
1187 int start = order.GetAt(i); | 1187 int start = order.GetAt(i); |
1188 int count1 = order.GetAt(i + 1); | 1188 int count1 = order.GetAt(i + 1); |
1189 if(ret == 2 || (i == 0 && ret == 0 && !bL2R)) { | 1189 if(ret == 2 || (i == 0 && ret == 0 && !bL2R)) { |
1190 int j = i + 3; | 1190 int j = i + 3; |
1191 while(bR2L && j < count) { | 1191 while(bR2L && j < count) { |
1192 if(order.GetAt(j + 2) == 1) { | 1192 if(order.GetAt(j + 2) == 1) { |
1193 break; | 1193 break; |
1194 } else { | 1194 } else { |
1195 j += 3; | 1195 j += 3; |
1196 } | 1196 } |
1197 } | 1197 } |
1198 if(j == 3) { | 1198 if(j == 3) { |
1199 i = -3; | 1199 i = -3; |
1200 bL2R = TRUE; | 1200 bL2R = true; |
1201 continue; | 1201 continue; |
1202 } | 1202 } |
1203 int end = m_TempCharList.GetSize() - 1; | 1203 int end = m_TempCharList.GetSize() - 1; |
1204 if(j < count) { | 1204 if(j < count) { |
1205 end = order.GetAt(j) - 1; | 1205 end = order.GetAt(j) - 1; |
1206 } | 1206 } |
1207 i = j - 3; | 1207 i = j - 3; |
1208 for(int n = end; n >= start; n--) { | 1208 for(int n = end; n >= start; n--) { |
1209 AddCharInfoByRLDirection(str, n); | 1209 AddCharInfoByRLDirection(str, n); |
1210 } | 1210 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 CPDF_TextObject* pTextObj = Obj.m_pTextObj; | 1300 CPDF_TextObject* pTextObj = Obj.m_pTextObj; |
1301 CPDF_ContentMarkData* pMarkData = (CPDF_ContentMarkData*)pTextObj->m_Content
Mark.GetObject(); | 1301 CPDF_ContentMarkData* pMarkData = (CPDF_ContentMarkData*)pTextObj->m_Content
Mark.GetObject(); |
1302 if(!pMarkData) { | 1302 if(!pMarkData) { |
1303 return FPDFTEXT_MC_PASS; | 1303 return FPDFTEXT_MC_PASS; |
1304 } | 1304 } |
1305 int nContentMark = pMarkData->CountItems(); | 1305 int nContentMark = pMarkData->CountItems(); |
1306 if (nContentMark < 1) { | 1306 if (nContentMark < 1) { |
1307 return FPDFTEXT_MC_PASS; | 1307 return FPDFTEXT_MC_PASS; |
1308 } | 1308 } |
1309 CFX_WideString actText; | 1309 CFX_WideString actText; |
1310 FX_BOOL bExist = FALSE; | 1310 bool bExist = false; |
1311 CPDF_Dictionary* pDict = NULL; | 1311 CPDF_Dictionary* pDict = NULL; |
1312 int n = 0; | 1312 int n = 0; |
1313 for (n = 0; n < nContentMark; n++) { | 1313 for (n = 0; n < nContentMark; n++) { |
1314 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); | 1314 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); |
1315 CFX_ByteString tagStr = (CFX_ByteString)item.GetName(); | 1315 CFX_ByteString tagStr = (CFX_ByteString)item.GetName(); |
1316 pDict = (CPDF_Dictionary*)item.GetParam(); | 1316 pDict = (CPDF_Dictionary*)item.GetParam(); |
1317 CPDF_String* temp = (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("A
ctualText")) : NULL); | 1317 CPDF_String* temp = (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("A
ctualText")) : NULL); |
1318 if (temp) { | 1318 if (temp) { |
1319 bExist = TRUE; | 1319 bExist = true; |
1320 actText = temp->GetUnicodeText(); | 1320 actText = temp->GetUnicodeText(); |
1321 } | 1321 } |
1322 } | 1322 } |
1323 if (!bExist) { | 1323 if (!bExist) { |
1324 return FPDFTEXT_MC_PASS; | 1324 return FPDFTEXT_MC_PASS; |
1325 } | 1325 } |
1326 if (m_pPreTextObj) { | 1326 if (m_pPreTextObj) { |
1327 if (CPDF_ContentMarkData* pPreMarkData = (CPDF_ContentMarkData*)m_pPreTe
xtObj->m_ContentMark.GetObject()) { | 1327 if (CPDF_ContentMarkData* pPreMarkData = (CPDF_ContentMarkData*)m_pPreTe
xtObj->m_ContentMark.GetObject()) { |
1328 if (pPreMarkData->CountItems() == n) { | 1328 if (pPreMarkData->CountItems() == n) { |
1329 CPDF_ContentMarkItem& item = pPreMarkData->GetItem(n - 1); | 1329 CPDF_ContentMarkItem& item = pPreMarkData->GetItem(n - 1); |
1330 if (pDict == item.GetParam()) { | 1330 if (pDict == item.GetParam()) { |
1331 return FPDFTEXT_MC_DONE; | 1331 return FPDFTEXT_MC_DONE; |
1332 } | 1332 } |
1333 } | 1333 } |
1334 } | 1334 } |
1335 } | 1335 } |
1336 CPDF_Font* pFont = pTextObj->GetFont(); | 1336 CPDF_Font* pFont = pTextObj->GetFont(); |
1337 FX_STRSIZE nItems = actText.GetLength(); | 1337 FX_STRSIZE nItems = actText.GetLength(); |
1338 if (nItems < 1) { | 1338 if (nItems < 1) { |
1339 return FPDFTEXT_MC_PASS; | 1339 return FPDFTEXT_MC_PASS; |
1340 } | 1340 } |
1341 bExist = FALSE; | 1341 bExist = false; |
1342 for (FX_STRSIZE i = 0; i < nItems; i++) { | 1342 for (FX_STRSIZE i = 0; i < nItems; i++) { |
1343 FX_WCHAR wChar = actText.GetAt(i); | 1343 FX_WCHAR wChar = actText.GetAt(i); |
1344 if (-1 == pFont->CharCodeFromUnicode(wChar)) { | 1344 if (-1 == pFont->CharCodeFromUnicode(wChar)) { |
1345 continue; | 1345 continue; |
1346 } else { | 1346 } else { |
1347 bExist = TRUE; | 1347 bExist = true; |
1348 break; | 1348 break; |
1349 } | 1349 } |
1350 } | 1350 } |
1351 if (!bExist) { | 1351 if (!bExist) { |
1352 return FPDFTEXT_MC_PASS; | 1352 return FPDFTEXT_MC_PASS; |
1353 } | 1353 } |
1354 bExist = FALSE; | 1354 bExist = false; |
1355 for (FX_STRSIZE i = 0; i < nItems; i++) { | 1355 for (FX_STRSIZE i = 0; i < nItems; i++) { |
1356 FX_WCHAR wChar = actText.GetAt(i); | 1356 FX_WCHAR wChar = actText.GetAt(i); |
1357 if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar)
)) { | 1357 if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar)
)) { |
1358 bExist = TRUE; | 1358 bExist = true; |
1359 break; | 1359 break; |
1360 } | 1360 } |
1361 } | 1361 } |
1362 if (!bExist) { | 1362 if (!bExist) { |
1363 return FPDFTEXT_MC_DONE; | 1363 return FPDFTEXT_MC_DONE; |
1364 } | 1364 } |
1365 return FPDFTEXT_MC_DELAY; | 1365 return FPDFTEXT_MC_DELAY; |
1366 } | 1366 } |
1367 void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) | 1367 void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) |
1368 { | 1368 { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 ProcessMarkedContent(Obj); | 1532 ProcessMarkedContent(Obj); |
1533 m_pPreTextObj = pTextObj; | 1533 m_pPreTextObj = pTextObj; |
1534 m_perMatrix.Copy(formMatrix); | 1534 m_perMatrix.Copy(formMatrix); |
1535 return; | 1535 return; |
1536 } | 1536 } |
1537 m_pPreTextObj = pTextObj; | 1537 m_pPreTextObj = pTextObj; |
1538 m_perMatrix.Copy(formMatrix); | 1538 m_perMatrix.Copy(formMatrix); |
1539 int nItems = pTextObj->CountItems(); | 1539 int nItems = pTextObj->CountItems(); |
1540 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); | 1540 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); |
1541 | 1541 |
1542 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); | 1542 const bool bR2L = IsRightToLeft(pTextObj, pFont, nItems); |
1543 const FX_BOOL bIsBidiAndMirrorInverse = | 1543 const bool bIsBidiAndMirrorInverse = |
1544 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; | 1544 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; |
1545 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); | 1545 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); |
1546 int32_t iCharListStartAppend = m_TempCharList.GetSize(); | 1546 int32_t iCharListStartAppend = m_TempCharList.GetSize(); |
1547 | 1547 |
1548 FX_FLOAT spacing = 0; | 1548 FX_FLOAT spacing = 0; |
1549 for (int i = 0; i < nItems; i++) { | 1549 for (int i = 0; i < nItems; i++) { |
1550 CPDF_TextObjectItem item; | 1550 CPDF_TextObjectItem item; |
1551 PAGECHAR_INFO charinfo; | 1551 PAGECHAR_INFO charinfo; |
1552 charinfo.m_OriginX = 0; | 1552 charinfo.m_OriginX = 0; |
1553 charinfo.m_OriginY = 0; | 1553 charinfo.m_OriginY = 0; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_Orig
inX, charinfo.m_OriginY); | 1602 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_Orig
inX, charinfo.m_OriginY); |
1603 charinfo.m_CharBox = CFX_FloatRect(charinfo.m_OriginX, charinfo.
m_OriginY, charinfo.m_OriginX, charinfo.m_OriginY); | 1603 charinfo.m_CharBox = CFX_FloatRect(charinfo.m_OriginX, charinfo.
m_OriginY, charinfo.m_OriginX, charinfo.m_OriginY); |
1604 m_TempCharList.Add(charinfo); | 1604 m_TempCharList.Add(charinfo); |
1605 } | 1605 } |
1606 if (item.m_CharCode == (FX_DWORD) - 1) { | 1606 if (item.m_CharCode == (FX_DWORD) - 1) { |
1607 continue; | 1607 continue; |
1608 } | 1608 } |
1609 } | 1609 } |
1610 spacing = 0; | 1610 spacing = 0; |
1611 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | 1611 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
1612 FX_BOOL bNoUnicode = FALSE; | 1612 bool bNoUnicode = false; |
1613 FX_WCHAR wChar = wstrItem.GetAt(0); | 1613 FX_WCHAR wChar = wstrItem.GetAt(0); |
1614 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | 1614 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
1615 if(wstrItem.IsEmpty()) { | 1615 if(wstrItem.IsEmpty()) { |
1616 wstrItem += (FX_WCHAR)item.m_CharCode; | 1616 wstrItem += (FX_WCHAR)item.m_CharCode; |
1617 } else { | 1617 } else { |
1618 wstrItem.SetAt(0, (FX_WCHAR)item.m_CharCode); | 1618 wstrItem.SetAt(0, (FX_WCHAR)item.m_CharCode); |
1619 } | 1619 } |
1620 bNoUnicode = TRUE; | 1620 bNoUnicode = true; |
1621 } | 1621 } |
1622 charinfo.m_Index = -1; | 1622 charinfo.m_Index = -1; |
1623 charinfo.m_CharCode = item.m_CharCode; | 1623 charinfo.m_CharCode = item.m_CharCode; |
1624 if(bNoUnicode) { | 1624 if(bNoUnicode) { |
1625 charinfo.m_Flag = FPDFTEXT_CHAR_UNUNICODE; | 1625 charinfo.m_Flag = FPDFTEXT_CHAR_UNUNICODE; |
1626 } else { | 1626 } else { |
1627 charinfo.m_Flag = FPDFTEXT_CHAR_NORMAL; | 1627 charinfo.m_Flag = FPDFTEXT_CHAR_NORMAL; |
1628 } | 1628 } |
1629 charinfo.m_pTextObj = pTextObj; | 1629 charinfo.m_pTextObj = pTextObj; |
1630 charinfo.m_OriginX = 0, charinfo.m_OriginY = 0; | 1630 charinfo.m_OriginX = 0, charinfo.m_OriginY = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
1644 } | 1644 } |
1645 matrix.TransformRect(charinfo.m_CharBox); | 1645 matrix.TransformRect(charinfo.m_CharBox); |
1646 charinfo.m_Matrix.Copy(matrix); | 1646 charinfo.m_Matrix.Copy(matrix); |
1647 if (wstrItem.IsEmpty()) { | 1647 if (wstrItem.IsEmpty()) { |
1648 charinfo.m_Unicode = 0; | 1648 charinfo.m_Unicode = 0; |
1649 m_TempCharList.Add(charinfo); | 1649 m_TempCharList.Add(charinfo); |
1650 m_TempTextBuf.AppendChar(0xfffe); | 1650 m_TempTextBuf.AppendChar(0xfffe); |
1651 continue; | 1651 continue; |
1652 } else { | 1652 } else { |
1653 int nTotal = wstrItem.GetLength(); | 1653 int nTotal = wstrItem.GetLength(); |
1654 FX_BOOL bDel = FALSE; | 1654 bool bDel = false; |
1655 const int count = std::min(m_TempCharList.GetSize(), 7); | 1655 const int count = std::min(m_TempCharList.GetSize(), 7); |
1656 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance((FX_FLOAT)
TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize()); | 1656 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance((FX_FLOAT)
TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize()); |
1657 for (int n = m_TempCharList.GetSize(); | 1657 for (int n = m_TempCharList.GetSize(); |
1658 n > m_TempCharList.GetSize() - count; | 1658 n > m_TempCharList.GetSize() - count; |
1659 n--) { | 1659 n--) { |
1660 PAGECHAR_INFO* charinfo1 = (PAGECHAR_INFO*)m_TempCharList.GetAt(
n - 1); | 1660 PAGECHAR_INFO* charinfo1 = (PAGECHAR_INFO*)m_TempCharList.GetAt(
n - 1); |
1661 if(charinfo1->m_CharCode == charinfo.m_CharCode && | 1661 if(charinfo1->m_CharCode == charinfo.m_CharCode && |
1662 charinfo1->m_pTextObj->GetFont() == charinfo.m_pTextObj-
>GetFont() && | 1662 charinfo1->m_pTextObj->GetFont() == charinfo.m_pTextObj-
>GetFont() && |
1663 FXSYS_fabs(charinfo1->m_OriginX - charinfo.m_OriginX) <
threshold && | 1663 FXSYS_fabs(charinfo1->m_OriginX - charinfo.m_OriginX) <
threshold && |
1664 FXSYS_fabs(charinfo1->m_OriginY - charinfo.m_OriginY) <
threshold) { | 1664 FXSYS_fabs(charinfo1->m_OriginY - charinfo.m_OriginY) <
threshold) { |
1665 bDel = TRUE; | 1665 bDel = true; |
1666 break; | 1666 break; |
1667 } | 1667 } |
1668 } | 1668 } |
1669 if(!bDel) { | 1669 if(!bDel) { |
1670 for (int nIndex = 0; nIndex < nTotal; nIndex++) { | 1670 for (int nIndex = 0; nIndex < nTotal; nIndex++) { |
1671 charinfo.m_Unicode = wstrItem.GetAt(nIndex); | 1671 charinfo.m_Unicode = wstrItem.GetAt(nIndex); |
1672 if (charinfo.m_Unicode) { | 1672 if (charinfo.m_Unicode) { |
1673 charinfo.m_Index = m_TextBuf.GetLength(); | 1673 charinfo.m_Index = m_TextBuf.GetLength(); |
1674 m_TempTextBuf.AppendChar(charinfo.m_Unicode); | 1674 m_TempTextBuf.AppendChar(charinfo.m_Unicode); |
1675 } else { | 1675 } else { |
(...skipping 24 matching lines...) Expand all Loading... |
1700 std::swap(m_TempCharList[i], m_TempCharList[j]); | 1700 std::swap(m_TempCharList[i], m_TempCharList[j]); |
1701 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); | 1701 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); |
1702 } | 1702 } |
1703 FX_WCHAR * pTempBuffer = m_TempTextBuf.GetBuffer(); | 1703 FX_WCHAR * pTempBuffer = m_TempTextBuf.GetBuffer(); |
1704 i = iBufStartAppend; | 1704 i = iBufStartAppend; |
1705 j = m_TempTextBuf.GetLength() - 1; | 1705 j = m_TempTextBuf.GetLength() - 1; |
1706 for (; i < j; i++, j--) { | 1706 for (; i < j; i++, j--) { |
1707 std::swap(pTempBuffer[i], pTempBuffer[j]); | 1707 std::swap(pTempBuffer[i], pTempBuffer[j]); |
1708 } | 1708 } |
1709 } | 1709 } |
1710 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, | 1710 bool CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
1711 const CPDF_Font* pFont, | 1711 const CPDF_Font* pFont, |
1712 int nItems) const | 1712 int nItems) const |
1713 { | 1713 { |
1714 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 1714 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); |
1715 int32_t nR2L = 0; | 1715 int32_t nR2L = 0; |
1716 int32_t nL2R = 0; | 1716 int32_t nL2R = 0; |
1717 int32_t start = 0, count = 0; | 1717 int32_t start = 0, count = 0; |
1718 CPDF_TextObjectItem item; | 1718 CPDF_TextObjectItem item; |
1719 for (int32_t i = 0; i < nItems; i++) { | 1719 for (int32_t i = 0; i < nItems; i++) { |
1720 pTextObj->GetItemInfo(i, &item); | 1720 pTextObj->GetItemInfo(i, &item); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 v.Set(dX, dY); | 1772 v.Set(dX, dY); |
1773 v.Normalize(); | 1773 v.Normalize(); |
1774 if (v.y <= 0.0872f) { | 1774 if (v.y <= 0.0872f) { |
1775 return v.x <= 0.0872f ? m_TextlineDir : 0; | 1775 return v.x <= 0.0872f ? m_TextlineDir : 0; |
1776 } | 1776 } |
1777 if (v.x <= 0.0872f) { | 1777 if (v.x <= 0.0872f) { |
1778 return 1; | 1778 return 1; |
1779 } | 1779 } |
1780 return m_TextlineDir; | 1780 return m_TextlineDir; |
1781 } | 1781 } |
1782 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) | 1782 bool CPDF_TextPage::IsHyphen(FX_WCHAR curChar) |
1783 { | 1783 { |
1784 CFX_WideString strCurText = m_TempTextBuf.GetWideString(); | 1784 CFX_WideString strCurText = m_TempTextBuf.GetWideString(); |
1785 if(strCurText.GetLength() == 0) { | 1785 if(strCurText.GetLength() == 0) { |
1786 strCurText = m_TextBuf.GetWideString(); | 1786 strCurText = m_TextBuf.GetWideString(); |
1787 } | 1787 } |
1788 FX_STRSIZE nCount = strCurText.GetLength(); | 1788 FX_STRSIZE nCount = strCurText.GetLength(); |
1789 int nIndex = nCount - 1; | 1789 int nIndex = nCount - 1; |
1790 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); | 1790 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); |
1791 while(wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { | 1791 while(wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { |
1792 wcTmp = strCurText.GetAt(--nIndex); | 1792 wcTmp = strCurText.GetAt(--nIndex); |
1793 } | 1793 } |
1794 if (0x2D == wcTmp || 0xAD == wcTmp) { | 1794 if (0x2D == wcTmp || 0xAD == wcTmp) { |
1795 if (--nIndex > 0) { | 1795 if (--nIndex > 0) { |
1796 FX_WCHAR preChar = strCurText.GetAt((nIndex)); | 1796 FX_WCHAR preChar = strCurText.GetAt((nIndex)); |
1797 if (((preChar >= L'A' && preChar <= L'Z') || (preChar >= L'a' && pre
Char <= L'z')) | 1797 if (((preChar >= L'A' && preChar <= L'Z') || (preChar >= L'a' && pre
Char <= L'z')) |
1798 && ((curChar >= L'A' && curChar <= L'Z') || (curChar >= L'a'
&& curChar <= L'z'))) { | 1798 && ((curChar >= L'A' && curChar <= L'Z') || (curChar >= L'a'
&& curChar <= L'z'))) { |
1799 return TRUE; | 1799 return true; |
1800 } | 1800 } |
1801 } | 1801 } |
1802 int size = m_TempCharList.GetSize(); | 1802 int size = m_TempCharList.GetSize(); |
1803 PAGECHAR_INFO preChar; | 1803 PAGECHAR_INFO preChar; |
1804 if (size) { | 1804 if (size) { |
1805 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; | 1805 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; |
1806 } else { | 1806 } else { |
1807 size = m_charList.GetSize(); | 1807 size = m_charList.GetSize(); |
1808 if(size == 0) { | 1808 if(size == 0) { |
1809 return FALSE; | 1809 return false; |
1810 } | 1810 } |
1811 preChar = (PAGECHAR_INFO)m_charList[size - 1]; | 1811 preChar = (PAGECHAR_INFO)m_charList[size - 1]; |
1812 } | 1812 } |
1813 if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag) | 1813 if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag) |
1814 if (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode) { | 1814 if (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode) { |
1815 return TRUE; | 1815 return true; |
1816 } | 1816 } |
1817 } | 1817 } |
1818 return FALSE; | 1818 return false; |
1819 } | 1819 } |
1820 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, const CFX_Af
fineMatrix& formMatrix) | 1820 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, const CFX_Af
fineMatrix& formMatrix) |
1821 { | 1821 { |
1822 FindPreviousTextObject(); | 1822 FindPreviousTextObject(); |
1823 FX_BOOL bNewline = FALSE; | 1823 bool bNewline = false; |
1824 int WritingMode = GetTextObjectWritingMode(pObj); | 1824 int WritingMode = GetTextObjectWritingMode(pObj); |
1825 if(WritingMode == -1) { | 1825 if(WritingMode == -1) { |
1826 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); | 1826 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); |
1827 } | 1827 } |
1828 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pObj->m
_Top); | 1828 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pObj->m
_Top); |
1829 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, m_pP
reTextObj->m_Right, m_pPreTextObj->m_Top); | 1829 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, m_pP
reTextObj->m_Right, m_pPreTextObj->m_Top); |
1830 CPDF_TextObjectItem PrevItem, item; | 1830 CPDF_TextObjectItem PrevItem, item; |
1831 int nItem = m_pPreTextObj->CountItems(); | 1831 int nItem = m_pPreTextObj->CountItems(); |
1832 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); | 1832 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); |
1833 pObj->GetItemInfo(0, &item); | 1833 pObj->GetItemInfo(0, &item); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 prev_reverse.Transform(x, y); | 1877 prev_reverse.Transform(x, y); |
1878 if(last_width < this_width) { | 1878 if(last_width < this_width) { |
1879 threshold = prev_reverse.TransformDistance(threshold); | 1879 threshold = prev_reverse.TransformDistance(threshold); |
1880 } | 1880 } |
1881 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, m_pPreTextObj->m_
Right, pObj->m_Top); | 1881 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, m_pPreTextObj->m_
Right, pObj->m_Top); |
1882 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, m_pPreTe
xtObj->m_Right, m_pPreTextObj->m_Top); | 1882 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, m_pPreTe
xtObj->m_Right, m_pPreTextObj->m_Top); |
1883 CFX_FloatRect rect3 = rect1; | 1883 CFX_FloatRect rect3 = rect1; |
1884 rect1.Intersect(rect2); | 1884 rect1.Intersect(rect2); |
1885 if (WritingMode == 0) { | 1885 if (WritingMode == 0) { |
1886 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) | 1886 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) |
1887 || ((y > threshold * 2 || y < threshold * -3) && (FXSYS_fabs(y)
< 1 ? FXSYS_fabs(x) < FXSYS_fabs(y) : TRUE))) { | 1887 || ((y > threshold * 2 || y < threshold * -3) && (FXSYS_fabs(y)
< 1 ? FXSYS_fabs(x) < FXSYS_fabs(y) : true))) { |
1888 bNewline = TRUE; | 1888 bNewline = true; |
1889 if(nItem > 1 ) { | 1889 if(nItem > 1 ) { |
1890 CPDF_TextObjectItem tempItem; | 1890 CPDF_TextObjectItem tempItem; |
1891 m_pPreTextObj->GetItemInfo(0, &tempItem); | 1891 m_pPreTextObj->GetItemInfo(0, &tempItem); |
1892 CFX_AffineMatrix m; | 1892 CFX_AffineMatrix m; |
1893 m_pPreTextObj->GetTextMatrix(&m); | 1893 m_pPreTextObj->GetTextMatrix(&m); |
1894 if(PrevItem.m_OriginX > tempItem.m_OriginX && | 1894 if(PrevItem.m_OriginX > tempItem.m_OriginX && |
1895 m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && | 1895 m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && |
1896 m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 | 1896 m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 |
1897 && m.b < 0.1 && m.c < 0.1 ) { | 1897 && m.b < 0.1 && m.c < 0.1 ) { |
1898 CFX_FloatRect re(0, m_pPreTextObj->m_Bottom, 1000, m_pPreTex
tObj->m_Top); | 1898 CFX_FloatRect re(0, m_pPreTextObj->m_Bottom, 1000, m_pPreTex
tObj->m_Top); |
1899 if(re.Contains(pObj->GetPosX(), pObj->GetPosY())) { | 1899 if(re.Contains(pObj->GetPosX(), pObj->GetPosY())) { |
1900 bNewline = FALSE; | 1900 bNewline = false; |
1901 } else { | 1901 } else { |
1902 CFX_FloatRect re(0, pObj->m_Bottom, 1000, pObj->m_Top); | 1902 CFX_FloatRect re(0, pObj->m_Bottom, 1000, pObj->m_Top); |
1903 if(re.Contains(m_pPreTextObj->GetPosX(), m_pPreTextObj->
GetPosY())) { | 1903 if(re.Contains(m_pPreTextObj->GetPosX(), m_pPreTextObj->
GetPosY())) { |
1904 bNewline = FALSE; | 1904 bNewline = false; |
1905 } | 1905 } |
1906 } | 1906 } |
1907 } | 1907 } |
1908 } | 1908 } |
1909 } | 1909 } |
1910 } | 1910 } |
1911 if(bNewline) { | 1911 if(bNewline) { |
1912 if(IsHyphen(curChar)) { | 1912 if(IsHyphen(curChar)) { |
1913 return 3; | 1913 return 3; |
1914 } | 1914 } |
(...skipping 30 matching lines...) Expand all Loading... |
1945 } | 1945 } |
1946 if(x < 0 && (last_pos - x - last_width) > threshold) { | 1946 if(x < 0 && (last_pos - x - last_width) > threshold) { |
1947 return 1; | 1947 return 1; |
1948 } | 1948 } |
1949 if((x - last_pos - last_width) > this_width || (x - last_pos - this_
width) > last_width ) { | 1949 if((x - last_pos - last_width) > this_width || (x - last_pos - this_
width) > last_width ) { |
1950 return 1; | 1950 return 1; |
1951 } | 1951 } |
1952 } | 1952 } |
1953 return 0; | 1953 return 0; |
1954 } | 1954 } |
1955 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObj
ect* pTextObj2) | 1955 bool CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject
* pTextObj2) |
1956 { | 1956 { |
1957 if (!pTextObj1 || !pTextObj2) { | 1957 if (!pTextObj1 || !pTextObj2) { |
1958 return FALSE; | 1958 return false; |
1959 } | 1959 } |
1960 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, pTextObj2->m_
Right, pTextObj2->m_Top); | 1960 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, pTextObj2->m_
Right, pTextObj2->m_Top); |
1961 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, pTextObj1->m_
Right, pTextObj1->m_Top); | 1961 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, pTextObj1->m_
Right, pTextObj1->m_Top); |
1962 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty() && !m_ParseOptions.m_bGetCharCo
deOnly) { | 1962 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty() && !m_ParseOptions.m_bGetCharCo
deOnly) { |
1963 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); | 1963 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); |
1964 int nCount = m_charList.GetSize(); | 1964 int nCount = m_charList.GetSize(); |
1965 if (nCount >= 2) { | 1965 if (nCount >= 2) { |
1966 PAGECHAR_INFO perCharTemp = (PAGECHAR_INFO)m_charList[nCount - 2]; | 1966 PAGECHAR_INFO perCharTemp = (PAGECHAR_INFO)m_charList[nCount - 2]; |
1967 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width(); | 1967 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width(); |
1968 if (dbXdif > dbSpace) { | 1968 if (dbXdif > dbSpace) { |
1969 return FALSE; | 1969 return false; |
1970 } | 1970 } |
1971 } | 1971 } |
1972 } | 1972 } |
1973 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { | 1973 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { |
1974 rcPreObj.Intersect(rcCurObj); | 1974 rcPreObj.Intersect(rcCurObj); |
1975 if (rcPreObj.IsEmpty()) { | 1975 if (rcPreObj.IsEmpty()) { |
1976 return FALSE; | 1976 return false; |
1977 } | 1977 } |
1978 if (FXSYS_fabs(rcPreObj.Width() - rcCurObj.Width()) > rcCurObj.Width() /
2) { | 1978 if (FXSYS_fabs(rcPreObj.Width() - rcCurObj.Width()) > rcCurObj.Width() /
2) { |
1979 return FALSE; | 1979 return false; |
1980 } | 1980 } |
1981 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) { | 1981 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) { |
1982 return FALSE; | 1982 return false; |
1983 } | 1983 } |
1984 } | 1984 } |
1985 int nPreCount = pTextObj2->CountItems(); | 1985 int nPreCount = pTextObj2->CountItems(); |
1986 int nCurCount = pTextObj1->CountItems(); | 1986 int nCurCount = pTextObj1->CountItems(); |
1987 if (nPreCount != nCurCount) { | 1987 if (nPreCount != nCurCount) { |
1988 return FALSE; | 1988 return false; |
1989 } | 1989 } |
1990 CPDF_TextObjectItem itemPer, itemCur; | 1990 CPDF_TextObjectItem itemPer, itemCur; |
1991 for (int i = 0; i < nPreCount; i++) { | 1991 for (int i = 0; i < nPreCount; i++) { |
1992 pTextObj2->GetItemInfo(i, &itemPer); | 1992 pTextObj2->GetItemInfo(i, &itemPer); |
1993 pTextObj1->GetItemInfo(i, &itemCur); | 1993 pTextObj1->GetItemInfo(i, &itemCur); |
1994 if (itemCur.m_CharCode != itemPer.m_CharCode) { | 1994 if (itemCur.m_CharCode != itemPer.m_CharCode) { |
1995 return FALSE; | 1995 return false; |
1996 } | 1996 } |
1997 } | 1997 } |
1998 if(FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > GetCharWidth(it
emPer.m_CharCode, pTextObj2->GetFont())*pTextObj2->GetFontSize() / 1000 * 0.9 || | 1998 if(FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > GetCharWidth(it
emPer.m_CharCode, pTextObj2->GetFont())*pTextObj2->GetFontSize() / 1000 * 0.9 || |
1999 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > | 1999 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > |
2000 FX_MAX(FX_MAX(rcPreObj.Height() , rcPreObj.Width()), pTextObj2->GetF
ontSize()) / 8) { | 2000 FX_MAX(FX_MAX(rcPreObj.Height() , rcPreObj.Width()), pTextObj2->GetF
ontSize()) / 8) { |
2001 return FALSE; | 2001 return false; |
2002 } | 2002 } |
2003 return TRUE; | 2003 return true; |
2004 } | 2004 } |
2005 FX_BOOL CPDF_TextPage::IsSameAsPreTextObject(CPDF_TextObject* pTextObj, FX_POSIT
ION ObjPos) | 2005 bool CPDF_TextPage::IsSameAsPreTextObject(CPDF_TextObject* pTextObj, FX_POSITION
ObjPos) |
2006 { | 2006 { |
2007 if (!pTextObj) { | 2007 if (!pTextObj) { |
2008 return FALSE; | 2008 return false; |
2009 } | 2009 } |
2010 int i = 0; | 2010 int i = 0; |
2011 if (!ObjPos) { | 2011 if (!ObjPos) { |
2012 ObjPos = m_pPage->GetLastObjectPosition(); | 2012 ObjPos = m_pPage->GetLastObjectPosition(); |
2013 } | 2013 } |
2014 CPDF_PageObject* pObj = m_pPage->GetPrevObject(ObjPos); | 2014 CPDF_PageObject* pObj = m_pPage->GetPrevObject(ObjPos); |
2015 while (i < 5 && ObjPos) { | 2015 while (i < 5 && ObjPos) { |
2016 pObj = m_pPage->GetPrevObject(ObjPos); | 2016 pObj = m_pPage->GetPrevObject(ObjPos); |
2017 if(pObj == pTextObj) { | 2017 if(pObj == pTextObj) { |
2018 continue; | 2018 continue; |
2019 } | 2019 } |
2020 if(pObj->m_Type != PDFPAGE_TEXT) { | 2020 if(pObj->m_Type != PDFPAGE_TEXT) { |
2021 continue; | 2021 continue; |
2022 } | 2022 } |
2023 if(IsSameTextObject((CPDF_TextObject*)pObj, pTextObj)) { | 2023 if(IsSameTextObject((CPDF_TextObject*)pObj, pTextObj)) { |
2024 return TRUE; | 2024 return true; |
2025 } | 2025 } |
2026 i++; | 2026 i++; |
2027 } | 2027 } |
2028 return FALSE; | 2028 return false; |
2029 } | 2029 } |
2030 FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) | 2030 bool CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) |
2031 { | 2031 { |
2032 int size = m_TempCharList.GetSize(); | 2032 int size = m_TempCharList.GetSize(); |
2033 PAGECHAR_INFO preChar; | 2033 PAGECHAR_INFO preChar; |
2034 if (size) { | 2034 if (size) { |
2035 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; | 2035 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; |
2036 } else { | 2036 } else { |
2037 size = m_charList.GetSize(); | 2037 size = m_charList.GetSize(); |
2038 if(size == 0) { | 2038 if(size == 0) { |
2039 return FALSE; | 2039 return false; |
2040 } | 2040 } |
2041 preChar = (PAGECHAR_INFO)m_charList[size - 1]; | 2041 preChar = (PAGECHAR_INFO)m_charList[size - 1]; |
2042 } | 2042 } |
2043 info.m_Index = m_TextBuf.GetLength(); | 2043 info.m_Index = m_TextBuf.GetLength(); |
2044 info.m_Unicode = unicode; | 2044 info.m_Unicode = unicode; |
2045 info.m_pTextObj = NULL; | 2045 info.m_pTextObj = NULL; |
2046 info.m_CharCode = -1; | 2046 info.m_CharCode = -1; |
2047 info.m_Flag = FPDFTEXT_CHAR_GENERATED; | 2047 info.m_Flag = FPDFTEXT_CHAR_GENERATED; |
2048 int preWidth = 0; | 2048 int preWidth = 0; |
2049 if (preChar.m_pTextObj && preChar.m_CharCode != (FX_DWORD) - 1) { | 2049 if (preChar.m_pTextObj && preChar.m_CharCode != (FX_DWORD) - 1) { |
2050 preWidth = GetCharWidth(preChar.m_CharCode, preChar.m_pTextObj->GetFont(
)); | 2050 preWidth = GetCharWidth(preChar.m_CharCode, preChar.m_pTextObj->GetFont(
)); |
2051 } | 2051 } |
2052 FX_FLOAT fs = 0; | 2052 FX_FLOAT fs = 0; |
2053 if(preChar.m_pTextObj) { | 2053 if(preChar.m_pTextObj) { |
2054 fs = preChar.m_pTextObj->GetFontSize(); | 2054 fs = preChar.m_pTextObj->GetFontSize(); |
2055 } else { | 2055 } else { |
2056 fs = preChar.m_CharBox.Height(); | 2056 fs = preChar.m_CharBox.Height(); |
2057 } | 2057 } |
2058 if(!fs) { | 2058 if(!fs) { |
2059 fs = 1; | 2059 fs = 1; |
2060 } | 2060 } |
2061 info.m_OriginX = preChar.m_OriginX + preWidth * (fs) / 1000; | 2061 info.m_OriginX = preChar.m_OriginX + preWidth * (fs) / 1000; |
2062 info.m_OriginY = preChar.m_OriginY; | 2062 info.m_OriginY = preChar.m_OriginY; |
2063 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_Origin
X, info.m_OriginY); | 2063 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_Origin
X, info.m_OriginY); |
2064 return TRUE; | 2064 return true; |
2065 } | 2065 } |
2066 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, const CFX_Flo
atRect& rect2) | 2066 bool CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, const CFX_FloatR
ect& rect2) |
2067 { | 2067 { |
2068 CFX_FloatRect rect = rect1; | 2068 CFX_FloatRect rect = rect1; |
2069 rect.Intersect(rect2); | 2069 rect.Intersect(rect2); |
2070 return !rect.IsEmpty(); | 2070 return !rect.IsEmpty(); |
2071 } | 2071 } |
2072 FX_BOOL»CPDF_TextPage::IsLetter(FX_WCHAR unicode) | 2072 bool» CPDF_TextPage::IsLetter(FX_WCHAR unicode) |
2073 { | 2073 { |
2074 if (unicode < L'A') { | 2074 if (unicode < L'A') { |
2075 return FALSE; | 2075 return false; |
2076 } | 2076 } |
2077 if (unicode > L'Z' && unicode < L'a') { | 2077 if (unicode > L'Z' && unicode < L'a') { |
2078 return FALSE; | 2078 return false; |
2079 } | 2079 } |
2080 if (unicode > L'z') { | 2080 if (unicode > L'z') { |
2081 return FALSE; | 2081 return false; |
2082 } | 2082 } |
2083 return TRUE; | 2083 return true; |
2084 } | 2084 } |
2085 CPDF_TextPageFind::CPDF_TextPageFind(const IPDF_TextPage* pTextPage) | 2085 CPDF_TextPageFind::CPDF_TextPageFind(const IPDF_TextPage* pTextPage) |
2086 : m_pTextPage(pTextPage), | 2086 : m_pTextPage(pTextPage), |
2087 m_flags(0), | 2087 m_flags(0), |
2088 m_findNextStart(-1), | 2088 m_findNextStart(-1), |
2089 m_findPreStart(-1), | 2089 m_findPreStart(-1), |
2090 m_bMatchCase(FALSE), | 2090 m_bMatchCase(false), |
2091 m_bMatchWholeWord(FALSE), | 2091 m_bMatchWholeWord(false), |
2092 m_resStart(0), | 2092 m_resStart(0), |
2093 m_resEnd(-1), | 2093 m_resEnd(-1), |
2094 m_IsFind(FALSE) | 2094 m_IsFind(false) |
2095 { | 2095 { |
2096 m_strText = m_pTextPage->GetPageText(); | 2096 m_strText = m_pTextPage->GetPageText(); |
2097 int nCount = pTextPage->CountChars(); | 2097 int nCount = pTextPage->CountChars(); |
2098 if(nCount) { | 2098 if(nCount) { |
2099 m_CharIndex.Add(0); | 2099 m_CharIndex.Add(0); |
2100 } | 2100 } |
2101 for(int i = 0; i < nCount; i++) { | 2101 for(int i = 0; i < nCount; i++) { |
2102 FPDF_CHAR_INFO info; | 2102 FPDF_CHAR_INFO info; |
2103 pTextPage->GetCharInfo(i, info); | 2103 pTextPage->GetCharInfo(i, info); |
2104 int indexSize = m_CharIndex.GetSize(); | 2104 int indexSize = m_CharIndex.GetSize(); |
(...skipping 28 matching lines...) Expand all Loading... |
2133 int indexSize = m_CharIndex.GetSize(); | 2133 int indexSize = m_CharIndex.GetSize(); |
2134 int count = 0; | 2134 int count = 0; |
2135 for(int i = 0; i < indexSize; i += 2) { | 2135 for(int i = 0; i < indexSize; i += 2) { |
2136 count += m_CharIndex.GetAt(i + 1); | 2136 count += m_CharIndex.GetAt(i + 1); |
2137 if(count > index) { | 2137 if(count > index) { |
2138 return index - count + m_CharIndex.GetAt(i + 1) + m_CharIndex.G
etAt(i); | 2138 return index - count + m_CharIndex.GetAt(i + 1) + m_CharIndex.G
etAt(i); |
2139 } | 2139 } |
2140 } | 2140 } |
2141 return -1; | 2141 return -1; |
2142 } | 2142 } |
2143 FX_BOOL»CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat, int flags,
int startPos) | 2143 bool» CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat, int flags,
int startPos) |
2144 { | 2144 { |
2145 if (!m_pTextPage) { | 2145 if (!m_pTextPage) { |
2146 return FALSE; | 2146 return false; |
2147 } | 2147 } |
2148 if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE)) { | 2148 if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE)) { |
2149 m_strText = m_pTextPage->GetPageText(); | 2149 m_strText = m_pTextPage->GetPageText(); |
2150 } | 2150 } |
2151 CFX_WideString findwhatStr = findwhat; | 2151 CFX_WideString findwhatStr = findwhat; |
2152 m_findWhat = findwhatStr; | 2152 m_findWhat = findwhatStr; |
2153 m_flags = flags; | 2153 m_flags = flags; |
2154 m_bMatchCase = flags & FPDFTEXT_MATCHCASE; | 2154 m_bMatchCase = flags & FPDFTEXT_MATCHCASE; |
2155 if (m_strText.IsEmpty()) { | 2155 if (m_strText.IsEmpty()) { |
2156 m_IsFind = FALSE; | 2156 m_IsFind = false; |
2157 return TRUE; | 2157 return true; |
2158 } | 2158 } |
2159 FX_STRSIZE len = findwhatStr.GetLength(); | 2159 FX_STRSIZE len = findwhatStr.GetLength(); |
2160 if (!m_bMatchCase) { | 2160 if (!m_bMatchCase) { |
2161 findwhatStr.MakeLower(); | 2161 findwhatStr.MakeLower(); |
2162 m_strText.MakeLower(); | 2162 m_strText.MakeLower(); |
2163 } | 2163 } |
2164 m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD; | 2164 m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD; |
2165 m_findNextStart = startPos; | 2165 m_findNextStart = startPos; |
2166 if (startPos == -1) { | 2166 if (startPos == -1) { |
2167 m_findPreStart = m_strText.GetLength() - 1; | 2167 m_findPreStart = m_strText.GetLength() - 1; |
2168 } else { | 2168 } else { |
2169 m_findPreStart = startPos; | 2169 m_findPreStart = startPos; |
2170 } | 2170 } |
2171 m_csFindWhatArray.RemoveAll(); | 2171 m_csFindWhatArray.RemoveAll(); |
2172 int i = 0; | 2172 int i = 0; |
2173 while(i < len) { | 2173 while(i < len) { |
2174 if(findwhatStr.GetAt(i) != ' ') { | 2174 if(findwhatStr.GetAt(i) != ' ') { |
2175 break; | 2175 break; |
2176 } | 2176 } |
2177 i++; | 2177 i++; |
2178 } | 2178 } |
2179 if(i < len) { | 2179 if(i < len) { |
2180 ExtractFindWhat(findwhatStr); | 2180 ExtractFindWhat(findwhatStr); |
2181 } else { | 2181 } else { |
2182 m_csFindWhatArray.Add(findwhatStr); | 2182 m_csFindWhatArray.Add(findwhatStr); |
2183 } | 2183 } |
2184 if(m_csFindWhatArray.GetSize() <= 0) { | 2184 if(m_csFindWhatArray.GetSize() <= 0) { |
2185 return FALSE; | 2185 return false; |
2186 } | 2186 } |
2187 m_IsFind = TRUE; | 2187 m_IsFind = true; |
2188 m_resStart = 0; | 2188 m_resStart = 0; |
2189 m_resEnd = -1; | 2189 m_resEnd = -1; |
2190 return TRUE; | 2190 return true; |
2191 } | 2191 } |
2192 FX_BOOL CPDF_TextPageFind::FindNext() | 2192 bool CPDF_TextPageFind::FindNext() |
2193 { | 2193 { |
2194 if (!m_pTextPage) { | 2194 if (!m_pTextPage) { |
2195 return FALSE; | 2195 return false; |
2196 } | 2196 } |
2197 m_resArray.RemoveAll(); | 2197 m_resArray.RemoveAll(); |
2198 if(m_findNextStart == -1) { | 2198 if(m_findNextStart == -1) { |
2199 return FALSE; | 2199 return false; |
2200 } | 2200 } |
2201 if(m_strText.IsEmpty()) { | 2201 if(m_strText.IsEmpty()) { |
2202 m_IsFind = FALSE; | 2202 m_IsFind = false; |
2203 return m_IsFind; | 2203 return m_IsFind; |
2204 } | 2204 } |
2205 int strLen = m_strText.GetLength(); | 2205 int strLen = m_strText.GetLength(); |
2206 if (m_findNextStart > strLen - 1) { | 2206 if (m_findNextStart > strLen - 1) { |
2207 m_IsFind = FALSE; | 2207 m_IsFind = false; |
2208 return m_IsFind; | 2208 return m_IsFind; |
2209 } | 2209 } |
2210 int nCount = m_csFindWhatArray.GetSize(); | 2210 int nCount = m_csFindWhatArray.GetSize(); |
2211 int nResultPos = 0; | 2211 int nResultPos = 0; |
2212 int nStartPos = 0; | 2212 int nStartPos = 0; |
2213 nStartPos = m_findNextStart; | 2213 nStartPos = m_findNextStart; |
2214 FX_BOOL bSpaceStart = FALSE; | 2214 bool bSpaceStart = false; |
2215 for(int iWord = 0; iWord < nCount; iWord++) { | 2215 for(int iWord = 0; iWord < nCount; iWord++) { |
2216 CFX_WideString csWord = m_csFindWhatArray[iWord]; | 2216 CFX_WideString csWord = m_csFindWhatArray[iWord]; |
2217 if(csWord.IsEmpty()) { | 2217 if(csWord.IsEmpty()) { |
2218 if(iWord == nCount - 1) { | 2218 if(iWord == nCount - 1) { |
2219 FX_WCHAR strInsert = m_strText.GetAt(nStartPos); | 2219 FX_WCHAR strInsert = m_strText.GetAt(nStartPos); |
2220 if(strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_BLANK_CH
AR || strInsert == TEXT_RETURN_CHAR || strInsert == 160) { | 2220 if(strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_BLANK_CH
AR || strInsert == TEXT_RETURN_CHAR || strInsert == 160) { |
2221 nResultPos = nStartPos + 1; | 2221 nResultPos = nStartPos + 1; |
2222 break; | 2222 break; |
2223 } | 2223 } |
2224 iWord = -1; | 2224 iWord = -1; |
2225 } else if(iWord == 0) { | 2225 } else if(iWord == 0) { |
2226 bSpaceStart = TRUE; | 2226 bSpaceStart = true; |
2227 } | 2227 } |
2228 continue; | 2228 continue; |
2229 } | 2229 } |
2230 int endIndex; | 2230 int endIndex; |
2231 nResultPos = m_strText.Find(csWord.c_str(), nStartPos); | 2231 nResultPos = m_strText.Find(csWord.c_str(), nStartPos); |
2232 if (nResultPos == -1) { | 2232 if (nResultPos == -1) { |
2233 m_IsFind = FALSE; | 2233 m_IsFind = false; |
2234 return m_IsFind; | 2234 return m_IsFind; |
2235 } | 2235 } |
2236 endIndex = nResultPos + csWord.GetLength() - 1; | 2236 endIndex = nResultPos + csWord.GetLength() - 1; |
2237 if(iWord == 0) { | 2237 if(iWord == 0) { |
2238 m_resStart = nResultPos; | 2238 m_resStart = nResultPos; |
2239 } | 2239 } |
2240 FX_BOOL bMatch = TRUE; | 2240 bool bMatch = true; |
2241 if(iWord != 0 && !bSpaceStart) { | 2241 if(iWord != 0 && !bSpaceStart) { |
2242 int PreResEndPos = nStartPos; | 2242 int PreResEndPos = nStartPos; |
2243 int curChar = csWord.GetAt(0); | 2243 int curChar = csWord.GetAt(0); |
2244 CFX_WideString lastWord = m_csFindWhatArray[iWord - 1]; | 2244 CFX_WideString lastWord = m_csFindWhatArray[iWord - 1]; |
2245 int lastChar = lastWord.GetAt(lastWord.GetLength() - 1); | 2245 int lastChar = lastWord.GetAt(lastWord.GetLength() - 1); |
2246 if(nStartPos == nResultPos && !(_IsIgnoreSpaceCharacter(lastChar) ||
_IsIgnoreSpaceCharacter(curChar))) { | 2246 if(nStartPos == nResultPos && !(_IsIgnoreSpaceCharacter(lastChar) ||
_IsIgnoreSpaceCharacter(curChar))) { |
2247 bMatch = FALSE; | 2247 bMatch = false; |
2248 } | 2248 } |
2249 for(int d = PreResEndPos; d < nResultPos; d++) { | 2249 for(int d = PreResEndPos; d < nResultPos; d++) { |
2250 FX_WCHAR strInsert = m_strText.GetAt(d); | 2250 FX_WCHAR strInsert = m_strText.GetAt(d); |
2251 if(strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_BLANK_CH
AR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { | 2251 if(strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_BLANK_CH
AR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { |
2252 bMatch = FALSE; | 2252 bMatch = false; |
2253 break; | 2253 break; |
2254 } | 2254 } |
2255 } | 2255 } |
2256 } else if(bSpaceStart) { | 2256 } else if(bSpaceStart) { |
2257 if(nResultPos > 0) { | 2257 if(nResultPos > 0) { |
2258 FX_WCHAR strInsert = m_strText.GetAt(nResultPos - 1); | 2258 FX_WCHAR strInsert = m_strText.GetAt(nResultPos - 1); |
2259 if(strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_BLANK_CH
AR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { | 2259 if(strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_BLANK_CH
AR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { |
2260 bMatch = FALSE; | 2260 bMatch = false; |
2261 m_resStart = nResultPos; | 2261 m_resStart = nResultPos; |
2262 } else { | 2262 } else { |
2263 m_resStart = nResultPos - 1; | 2263 m_resStart = nResultPos - 1; |
2264 } | 2264 } |
2265 } | 2265 } |
2266 } | 2266 } |
2267 if(m_bMatchWholeWord && bMatch) { | 2267 if(m_bMatchWholeWord && bMatch) { |
2268 bMatch = IsMatchWholeWord(m_strText, nResultPos, endIndex); | 2268 bMatch = IsMatchWholeWord(m_strText, nResultPos, endIndex); |
2269 } | 2269 } |
2270 nStartPos = endIndex + 1; | 2270 nStartPos = endIndex + 1; |
2271 if(!bMatch) { | 2271 if(!bMatch) { |
2272 iWord = -1; | 2272 iWord = -1; |
2273 if(bSpaceStart) { | 2273 if(bSpaceStart) { |
2274 nStartPos = m_resStart + m_csFindWhatArray[1].GetLength(); | 2274 nStartPos = m_resStart + m_csFindWhatArray[1].GetLength(); |
2275 } else { | 2275 } else { |
2276 nStartPos = m_resStart + m_csFindWhatArray[0].GetLength(); | 2276 nStartPos = m_resStart + m_csFindWhatArray[0].GetLength(); |
2277 } | 2277 } |
2278 } | 2278 } |
2279 } | 2279 } |
2280 m_resEnd = nResultPos + m_csFindWhatArray[m_csFindWhatArray.GetSize() - 1].G
etLength() - 1; | 2280 m_resEnd = nResultPos + m_csFindWhatArray[m_csFindWhatArray.GetSize() - 1].G
etLength() - 1; |
2281 m_IsFind = TRUE; | 2281 m_IsFind = true; |
2282 int resStart = GetCharIndex(m_resStart); | 2282 int resStart = GetCharIndex(m_resStart); |
2283 int resEnd = GetCharIndex(m_resEnd); | 2283 int resEnd = GetCharIndex(m_resEnd); |
2284 m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1, m_resArray); | 2284 m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1, m_resArray); |
2285 if(m_flags & FPDFTEXT_CONSECUTIVE) { | 2285 if(m_flags & FPDFTEXT_CONSECUTIVE) { |
2286 m_findNextStart = m_resStart + 1; | 2286 m_findNextStart = m_resStart + 1; |
2287 m_findPreStart = m_resEnd - 1; | 2287 m_findPreStart = m_resEnd - 1; |
2288 } else { | 2288 } else { |
2289 m_findNextStart = m_resEnd + 1; | 2289 m_findNextStart = m_resEnd + 1; |
2290 m_findPreStart = m_resStart - 1; | 2290 m_findPreStart = m_resStart - 1; |
2291 } | 2291 } |
2292 return m_IsFind; | 2292 return m_IsFind; |
2293 } | 2293 } |
2294 FX_BOOL CPDF_TextPageFind::FindPrev() | 2294 bool CPDF_TextPageFind::FindPrev() |
2295 { | 2295 { |
2296 if (!m_pTextPage) { | 2296 if (!m_pTextPage) { |
2297 return FALSE; | 2297 return false; |
2298 } | 2298 } |
2299 m_resArray.RemoveAll(); | 2299 m_resArray.RemoveAll(); |
2300 if(m_strText.IsEmpty() || m_findPreStart < 0) { | 2300 if(m_strText.IsEmpty() || m_findPreStart < 0) { |
2301 m_IsFind = FALSE; | 2301 m_IsFind = false; |
2302 return m_IsFind; | 2302 return m_IsFind; |
2303 } | 2303 } |
2304 CPDF_TextPageFind findEngine(m_pTextPage); | 2304 CPDF_TextPageFind findEngine(m_pTextPage); |
2305 FX_BOOL ret = findEngine.FindFirst(m_findWhat, m_flags); | 2305 bool ret = findEngine.FindFirst(m_findWhat, m_flags); |
2306 if(!ret) { | 2306 if(!ret) { |
2307 m_IsFind = FALSE; | 2307 m_IsFind = false; |
2308 return m_IsFind; | 2308 return m_IsFind; |
2309 } | 2309 } |
2310 int order = -1, MatchedCount = 0; | 2310 int order = -1, MatchedCount = 0; |
2311 while(ret) { | 2311 while(ret) { |
2312 ret = findEngine.FindNext(); | 2312 ret = findEngine.FindNext(); |
2313 if(ret) { | 2313 if(ret) { |
2314 int order1 = findEngine.GetCurOrder() ; | 2314 int order1 = findEngine.GetCurOrder() ; |
2315 int MatchedCount1 = findEngine.GetMatchedCount(); | 2315 int MatchedCount1 = findEngine.GetMatchedCount(); |
2316 if(((order1 + MatchedCount1) - 1) > m_findPreStart) { | 2316 if(((order1 + MatchedCount1) - 1) > m_findPreStart) { |
2317 break; | 2317 break; |
2318 } | 2318 } |
2319 order = order1; | 2319 order = order1; |
2320 MatchedCount = MatchedCount1; | 2320 MatchedCount = MatchedCount1; |
2321 } | 2321 } |
2322 } | 2322 } |
2323 if(order == -1) { | 2323 if(order == -1) { |
2324 m_IsFind = FALSE; | 2324 m_IsFind = false; |
2325 return m_IsFind; | 2325 return m_IsFind; |
2326 } | 2326 } |
2327 m_resStart = m_pTextPage->TextIndexFromCharIndex(order); | 2327 m_resStart = m_pTextPage->TextIndexFromCharIndex(order); |
2328 m_resEnd = m_pTextPage->TextIndexFromCharIndex(order + MatchedCount - 1); | 2328 m_resEnd = m_pTextPage->TextIndexFromCharIndex(order + MatchedCount - 1); |
2329 m_IsFind = TRUE; | 2329 m_IsFind = true; |
2330 m_pTextPage->GetRectArray(order, MatchedCount, m_resArray); | 2330 m_pTextPage->GetRectArray(order, MatchedCount, m_resArray); |
2331 if(m_flags & FPDFTEXT_CONSECUTIVE) { | 2331 if(m_flags & FPDFTEXT_CONSECUTIVE) { |
2332 m_findNextStart = m_resStart + 1; | 2332 m_findNextStart = m_resStart + 1; |
2333 m_findPreStart = m_resEnd - 1; | 2333 m_findPreStart = m_resEnd - 1; |
2334 } else { | 2334 } else { |
2335 m_findNextStart = m_resEnd + 1; | 2335 m_findNextStart = m_resEnd + 1; |
2336 m_findPreStart = m_resStart - 1; | 2336 m_findPreStart = m_resStart - 1; |
2337 } | 2337 } |
2338 return m_IsFind; | 2338 return m_IsFind; |
2339 } | 2339 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2378 continue; | 2378 continue; |
2379 } | 2379 } |
2380 pos++; | 2380 pos++; |
2381 } | 2381 } |
2382 if (!csWord.IsEmpty()) { | 2382 if (!csWord.IsEmpty()) { |
2383 m_csFindWhatArray.Add(csWord); | 2383 m_csFindWhatArray.Add(csWord); |
2384 } | 2384 } |
2385 index++; | 2385 index++; |
2386 } | 2386 } |
2387 } | 2387 } |
2388 FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, in
t startPos, int endPos) | 2388 bool CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, int s
tartPos, int endPos) |
2389 { | 2389 { |
2390 int char_left = 0; | 2390 int char_left = 0; |
2391 int char_right = 0; | 2391 int char_right = 0; |
2392 int char_count = endPos - startPos + 1; | 2392 int char_count = endPos - startPos + 1; |
2393 if(char_count < 1) { | 2393 if(char_count < 1) { |
2394 return FALSE; | 2394 return false; |
2395 } | 2395 } |
2396 if (char_count == 1 && csPageText.GetAt(startPos) > 255) { | 2396 if (char_count == 1 && csPageText.GetAt(startPos) > 255) { |
2397 return TRUE; | 2397 return true; |
2398 } | 2398 } |
2399 if(startPos - 1 >= 0 ) { | 2399 if(startPos - 1 >= 0 ) { |
2400 char_left = csPageText.GetAt(startPos - 1); | 2400 char_left = csPageText.GetAt(startPos - 1); |
2401 } | 2401 } |
2402 if(startPos + char_count < csPageText.GetLength()) { | 2402 if(startPos + char_count < csPageText.GetLength()) { |
2403 char_right = csPageText.GetAt(startPos + char_count); | 2403 char_right = csPageText.GetAt(startPos + char_count); |
2404 } | 2404 } |
2405 if ((char_left > 'A' && char_left < 'a') || (char_left > 'a' && char_left <
'z') || (char_left > 0xfb00 && char_left < 0xfb06) || (char_left >= '0' && char_
left <= '9') || | 2405 if ((char_left > 'A' && char_left < 'a') || (char_left > 'a' && char_left <
'z') || (char_left > 0xfb00 && char_left < 0xfb06) || (char_left >= '0' && char_
left <= '9') || |
2406 (char_right > 'A' && char_right < 'a') || (char_right > 'a' && char_
right < 'z') || (char_right > 0xfb00 && char_right < 0xfb06) || (char_right >= '
0' && char_right <= '9')) { | 2406 (char_right > 'A' && char_right < 'a') || (char_right > 'a' && char_
right < 'z') || (char_right > 0xfb00 && char_right < 0xfb06) || (char_right >= '
0' && char_right <= '9')) { |
2407 return FALSE; | 2407 return false; |
2408 } | 2408 } |
2409 if(!(('A' > char_left || char_left > 'Z') && ('a' > char_left || char_left
> 'z') | 2409 if(!(('A' > char_left || char_left > 'Z') && ('a' > char_left || char_left
> 'z') |
2410 && ('A' > char_right || char_right > 'Z') && ('a' > char_right || c
har_right > 'z'))) { | 2410 && ('A' > char_right || char_right > 'Z') && ('a' > char_right || c
har_right > 'z'))) { |
2411 return FALSE; | 2411 return false; |
2412 } | 2412 } |
2413 if (char_count > 0) { | 2413 if (char_count > 0) { |
2414 if (csPageText.GetAt(startPos) >= L'0' && csPageText.GetAt(startPos) <=
L'9' && char_left >= L'0' && char_left <= L'9') { | 2414 if (csPageText.GetAt(startPos) >= L'0' && csPageText.GetAt(startPos) <=
L'9' && char_left >= L'0' && char_left <= L'9') { |
2415 return FALSE; | 2415 return false; |
2416 } | 2416 } |
2417 if (csPageText.GetAt(endPos) >= L'0' && csPageText.GetAt(endPos) <= L'9'
&& char_right >= L'0' && char_right <= L'9') { | 2417 if (csPageText.GetAt(endPos) >= L'0' && csPageText.GetAt(endPos) <= L'9'
&& char_right >= L'0' && char_right <= L'9') { |
2418 return FALSE; | 2418 return false; |
2419 } | 2419 } |
2420 } | 2420 } |
2421 return TRUE; | 2421 return true; |
2422 } | 2422 } |
2423 FX_BOOL CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString, const FX_WC
HAR* lpszFullString, | 2423 bool CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString, const FX_WCHAR
* lpszFullString, |
2424 int iSubString, FX_WCHAR chSep) | 2424 int iSubString, FX_WCHAR chSep) |
2425 { | 2425 { |
2426 if (lpszFullString == NULL) { | 2426 if (lpszFullString == NULL) { |
2427 return FALSE; | 2427 return false; |
2428 } | 2428 } |
2429 while (iSubString--) { | 2429 while (iSubString--) { |
2430 lpszFullString = FXSYS_wcschr(lpszFullString, chSep); | 2430 lpszFullString = FXSYS_wcschr(lpszFullString, chSep); |
2431 if (lpszFullString == NULL) { | 2431 if (lpszFullString == NULL) { |
2432 rString.Empty(); | 2432 rString.Empty(); |
2433 return FALSE; | 2433 return false; |
2434 } | 2434 } |
2435 lpszFullString++; | 2435 lpszFullString++; |
2436 while(*lpszFullString == chSep) { | 2436 while(*lpszFullString == chSep) { |
2437 lpszFullString++; | 2437 lpszFullString++; |
2438 } | 2438 } |
2439 } | 2439 } |
2440 const FX_WCHAR* lpchEnd = FXSYS_wcschr(lpszFullString, chSep); | 2440 const FX_WCHAR* lpchEnd = FXSYS_wcschr(lpszFullString, chSep); |
2441 int nLen = (lpchEnd == NULL) ? | 2441 int nLen = (lpchEnd == NULL) ? |
2442 (int)FXSYS_wcslen(lpszFullString) : (int)(lpchEnd - lpszFullStrin
g); | 2442 (int)FXSYS_wcslen(lpszFullString) : (int)(lpchEnd - lpszFullStrin
g); |
2443 ASSERT(nLen >= 0); | 2443 ASSERT(nLen >= 0); |
2444 FXSYS_memcpy(rString.GetBuffer(nLen), lpszFullString, nLen * sizeof(FX_WCHAR
)); | 2444 FXSYS_memcpy(rString.GetBuffer(nLen), lpszFullString, nLen * sizeof(FX_WCHAR
)); |
2445 rString.ReleaseBuffer(); | 2445 rString.ReleaseBuffer(); |
2446 return TRUE; | 2446 return true; |
2447 } | 2447 } |
2448 CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str) | 2448 CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str) |
2449 { | 2449 { |
2450 CFX_WideString str2; | 2450 CFX_WideString str2; |
2451 str2.Empty(); | 2451 str2.Empty(); |
2452 int nlen = str.GetLength(); | 2452 int nlen = str.GetLength(); |
2453 for(int i = nlen - 1; i >= 0; i--) { | 2453 for(int i = nlen - 1; i >= 0; i--) { |
2454 str2 += str.GetAt(i); | 2454 str2 += str.GetAt(i); |
2455 } | 2455 } |
2456 return str2; | 2456 return str2; |
2457 } | 2457 } |
2458 void CPDF_TextPageFind::GetRectArray(CFX_RectArray& rects) const | 2458 void CPDF_TextPageFind::GetRectArray(CFX_RectArray& rects) const |
2459 { | 2459 { |
2460 rects.Copy(m_resArray); | 2460 rects.Copy(m_resArray); |
2461 } | 2461 } |
2462 int CPDF_TextPageFind::GetCurOrder() const | 2462 int CPDF_TextPageFind::GetCurOrder() const |
2463 { | 2463 { |
2464 return GetCharIndex(m_resStart); | 2464 return GetCharIndex(m_resStart); |
2465 } | 2465 } |
2466 int CPDF_TextPageFind::GetMatchedCount()const | 2466 int CPDF_TextPageFind::GetMatchedCount()const |
2467 { | 2467 { |
2468 int resStart = GetCharIndex(m_resStart); | 2468 int resStart = GetCharIndex(m_resStart); |
2469 int resEnd = GetCharIndex(m_resEnd); | 2469 int resEnd = GetCharIndex(m_resEnd); |
2470 return resEnd - resStart + 1; | 2470 return resEnd - resStart + 1; |
2471 } | 2471 } |
2472 CPDF_LinkExtract::CPDF_LinkExtract() | 2472 CPDF_LinkExtract::CPDF_LinkExtract() |
2473 : m_pTextPage(NULL), | 2473 : m_pTextPage(NULL), |
2474 m_IsParserd(FALSE) | 2474 m_IsParserd(false) |
2475 { | 2475 { |
2476 } | 2476 } |
2477 CPDF_LinkExtract::~CPDF_LinkExtract() | 2477 CPDF_LinkExtract::~CPDF_LinkExtract() |
2478 { | 2478 { |
2479 DeleteLinkList(); | 2479 DeleteLinkList(); |
2480 } | 2480 } |
2481 FX_BOOL CPDF_LinkExtract::ExtractLinks(const IPDF_TextPage* pTextPage) | 2481 bool CPDF_LinkExtract::ExtractLinks(const IPDF_TextPage* pTextPage) |
2482 { | 2482 { |
2483 if (!pTextPage || !pTextPage->IsParsered()) { | 2483 if (!pTextPage || !pTextPage->IsParsered()) { |
2484 return FALSE; | 2484 return false; |
2485 } | 2485 } |
2486 m_pTextPage = (const CPDF_TextPage*)pTextPage; | 2486 m_pTextPage = (const CPDF_TextPage*)pTextPage; |
2487 m_strPageText = m_pTextPage->GetPageText(0, -1); | 2487 m_strPageText = m_pTextPage->GetPageText(0, -1); |
2488 DeleteLinkList(); | 2488 DeleteLinkList(); |
2489 if (m_strPageText.IsEmpty()) { | 2489 if (m_strPageText.IsEmpty()) { |
2490 return FALSE; | 2490 return false; |
2491 } | 2491 } |
2492 parserLink(); | 2492 parserLink(); |
2493 m_IsParserd = TRUE; | 2493 m_IsParserd = true; |
2494 return TRUE; | 2494 return true; |
2495 } | 2495 } |
2496 void CPDF_LinkExtract::DeleteLinkList() | 2496 void CPDF_LinkExtract::DeleteLinkList() |
2497 { | 2497 { |
2498 while (m_LinkList.GetSize()) { | 2498 while (m_LinkList.GetSize()) { |
2499 CPDF_LinkExt* linkinfo = NULL; | 2499 CPDF_LinkExt* linkinfo = NULL; |
2500 linkinfo = m_LinkList.GetAt(0); | 2500 linkinfo = m_LinkList.GetAt(0); |
2501 m_LinkList.RemoveAt(0); | 2501 m_LinkList.RemoveAt(0); |
2502 delete linkinfo; | 2502 delete linkinfo; |
2503 } | 2503 } |
2504 m_LinkList.RemoveAll(); | 2504 m_LinkList.RemoveAll(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2539 break; | 2539 break; |
2540 } | 2540 } |
2541 } | 2541 } |
2542 } | 2542 } |
2543 start = ++pos; | 2543 start = ++pos; |
2544 } else { | 2544 } else { |
2545 pos++; | 2545 pos++; |
2546 } | 2546 } |
2547 } | 2547 } |
2548 } | 2548 } |
2549 FX_BOOL CPDF_LinkExtract::CheckWebLink(CFX_WideString& strBeCheck) | 2549 bool CPDF_LinkExtract::CheckWebLink(CFX_WideString& strBeCheck) |
2550 { | 2550 { |
2551 CFX_WideString str = strBeCheck; | 2551 CFX_WideString str = strBeCheck; |
2552 str.MakeLower(); | 2552 str.MakeLower(); |
2553 if (str.Find(L"http://www.") != -1) { | 2553 if (str.Find(L"http://www.") != -1) { |
2554 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"http://www.")
); | 2554 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"http://www.")
); |
2555 return TRUE; | 2555 return true; |
2556 } | 2556 } |
2557 if (str.Find(L"http://") != -1) { | 2557 if (str.Find(L"http://") != -1) { |
2558 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"http://")); | 2558 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"http://")); |
2559 return TRUE; | 2559 return true; |
2560 } | 2560 } |
2561 if (str.Find(L"https://www.") != -1) { | 2561 if (str.Find(L"https://www.") != -1) { |
2562 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"https://www."
)); | 2562 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"https://www."
)); |
2563 return TRUE; | 2563 return true; |
2564 } | 2564 } |
2565 if (str.Find(L"https://") != -1) { | 2565 if (str.Find(L"https://") != -1) { |
2566 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"https://")); | 2566 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"https://")); |
2567 return TRUE; | 2567 return true; |
2568 } | 2568 } |
2569 if (str.Find(L"www.") != -1) { | 2569 if (str.Find(L"www.") != -1) { |
2570 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"www.")); | 2570 strBeCheck = strBeCheck.Right(str.GetLength() - str.Find(L"www.")); |
2571 strBeCheck = L"http://" + strBeCheck; | 2571 strBeCheck = L"http://" + strBeCheck; |
2572 return TRUE; | 2572 return true; |
2573 } | 2573 } |
2574 return FALSE; | 2574 return false; |
2575 } | 2575 } |
2576 FX_BOOL CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) | 2576 bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) |
2577 { | 2577 { |
2578 str.MakeLower(); | 2578 str.MakeLower(); |
2579 int aPos = str.Find(L'@'); | 2579 int aPos = str.Find(L'@'); |
2580 if (aPos < 1) { | 2580 if (aPos < 1) { |
2581 return FALSE; | 2581 return false; |
2582 } | 2582 } |
2583 if (str.GetAt(aPos - 1) == L'.' || str.GetAt(aPos - 1) == L'_') { | 2583 if (str.GetAt(aPos - 1) == L'.' || str.GetAt(aPos - 1) == L'_') { |
2584 return FALSE; | 2584 return false; |
2585 } | 2585 } |
2586 int i; | 2586 int i; |
2587 for (i = aPos - 1; i >= 0; i--) { | 2587 for (i = aPos - 1; i >= 0; i--) { |
2588 FX_WCHAR ch = str.GetAt(i); | 2588 FX_WCHAR ch = str.GetAt(i); |
2589 if (ch == L'_' || ch == L'.' || (ch >= L'a' && ch <= L'z') || (ch >= L'0
' && ch <= L'9')) { | 2589 if (ch == L'_' || ch == L'.' || (ch >= L'a' && ch <= L'z') || (ch >= L'0
' && ch <= L'9')) { |
2590 continue; | 2590 continue; |
2591 } else { | 2591 } else { |
2592 if (i == aPos - 1) { | 2592 if (i == aPos - 1) { |
2593 return FALSE; | 2593 return false; |
2594 } | 2594 } |
2595 str = str.Right(str.GetLength() - i - 1); | 2595 str = str.Right(str.GetLength() - i - 1); |
2596 break; | 2596 break; |
2597 } | 2597 } |
2598 } | 2598 } |
2599 aPos = str.Find(L'@'); | 2599 aPos = str.Find(L'@'); |
2600 if (aPos < 1) { | 2600 if (aPos < 1) { |
2601 return FALSE; | 2601 return false; |
2602 } | 2602 } |
2603 CFX_WideString strtemp = L""; | 2603 CFX_WideString strtemp = L""; |
2604 for (i = 0; i < aPos; i++) { | 2604 for (i = 0; i < aPos; i++) { |
2605 FX_WCHAR wch = str.GetAt(i); | 2605 FX_WCHAR wch = str.GetAt(i); |
2606 if (wch >= L'a' && wch <= L'z') { | 2606 if (wch >= L'a' && wch <= L'z') { |
2607 break; | 2607 break; |
2608 } else { | 2608 } else { |
2609 strtemp = str.Right(str.GetLength() - i + 1); | 2609 strtemp = str.Right(str.GetLength() - i + 1); |
2610 } | 2610 } |
2611 } | 2611 } |
2612 if (strtemp != L"") { | 2612 if (strtemp != L"") { |
2613 str = strtemp; | 2613 str = strtemp; |
2614 } | 2614 } |
2615 aPos = str.Find(L'@'); | 2615 aPos = str.Find(L'@'); |
2616 if (aPos < 1) { | 2616 if (aPos < 1) { |
2617 return FALSE; | 2617 return false; |
2618 } | 2618 } |
2619 str.TrimRight(L'.'); | 2619 str.TrimRight(L'.'); |
2620 strtemp = str; | 2620 strtemp = str; |
2621 int ePos = str.Find(L'.'); | 2621 int ePos = str.Find(L'.'); |
2622 if (ePos == -1) { | 2622 if (ePos == -1) { |
2623 return FALSE; | 2623 return false; |
2624 } | 2624 } |
2625 while (ePos != -1) { | 2625 while (ePos != -1) { |
2626 strtemp = strtemp.Right(strtemp.GetLength() - ePos - 1); | 2626 strtemp = strtemp.Right(strtemp.GetLength() - ePos - 1); |
2627 ePos = strtemp.Find('.'); | 2627 ePos = strtemp.Find('.'); |
2628 } | 2628 } |
2629 ePos = strtemp.GetLength(); | 2629 ePos = strtemp.GetLength(); |
2630 for (i = 0; i < ePos; i++) { | 2630 for (i = 0; i < ePos; i++) { |
2631 FX_WCHAR wch = str.GetAt(i); | 2631 FX_WCHAR wch = str.GetAt(i); |
2632 if ((wch >= L'a' && wch <= L'z') || (wch >= L'0' && wch <= L'9')) { | 2632 if ((wch >= L'a' && wch <= L'z') || (wch >= L'0' && wch <= L'9')) { |
2633 continue; | 2633 continue; |
2634 } else { | 2634 } else { |
2635 str = str.Left(str.GetLength() - ePos + i + 1); | 2635 str = str.Left(str.GetLength() - ePos + i + 1); |
2636 ePos = ePos - i - 1; | 2636 ePos = ePos - i - 1; |
2637 break; | 2637 break; |
2638 } | 2638 } |
2639 } | 2639 } |
2640 int nLen = str.GetLength(); | 2640 int nLen = str.GetLength(); |
2641 for (i = aPos + 1; i < nLen - ePos; i++) { | 2641 for (i = aPos + 1; i < nLen - ePos; i++) { |
2642 FX_WCHAR wch = str.GetAt(i); | 2642 FX_WCHAR wch = str.GetAt(i); |
2643 if (wch == L'-' || wch == L'.' || (wch >= L'a' && wch <= L'z') || (wch >
= L'0' && wch <= L'9')) { | 2643 if (wch == L'-' || wch == L'.' || (wch >= L'a' && wch <= L'z') || (wch >
= L'0' && wch <= L'9')) { |
2644 continue; | 2644 continue; |
2645 } else { | 2645 } else { |
2646 return FALSE; | 2646 return false; |
2647 } | 2647 } |
2648 } | 2648 } |
2649 if (str.Find(L"mailto:") == -1) { | 2649 if (str.Find(L"mailto:") == -1) { |
2650 str = L"mailto:" + str; | 2650 str = L"mailto:" + str; |
2651 } | 2651 } |
2652 return TRUE; | 2652 return true; |
2653 } | 2653 } |
2654 FX_BOOL CPDF_LinkExtract::AppendToLinkList(int start, int count, const CFX_WideS
tring& strUrl) | 2654 bool CPDF_LinkExtract::AppendToLinkList(int start, int count, const CFX_WideStri
ng& strUrl) |
2655 { | 2655 { |
2656 CPDF_LinkExt* linkInfo = new CPDF_LinkExt; | 2656 CPDF_LinkExt* linkInfo = new CPDF_LinkExt; |
2657 linkInfo->m_strUrl = strUrl; | 2657 linkInfo->m_strUrl = strUrl; |
2658 linkInfo->m_Start = start; | 2658 linkInfo->m_Start = start; |
2659 linkInfo->m_Count = count; | 2659 linkInfo->m_Count = count; |
2660 m_LinkList.Add(linkInfo); | 2660 m_LinkList.Add(linkInfo); |
2661 return TRUE; | 2661 return true; |
2662 } | 2662 } |
2663 CFX_WideString CPDF_LinkExtract::GetURL(int index) const | 2663 CFX_WideString CPDF_LinkExtract::GetURL(int index) const |
2664 { | 2664 { |
2665 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { | 2665 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { |
2666 return L""; | 2666 return L""; |
2667 } | 2667 } |
2668 CPDF_LinkExt* link = NULL; | 2668 CPDF_LinkExt* link = NULL; |
2669 link = m_LinkList.GetAt(index); | 2669 link = m_LinkList.GetAt(index); |
2670 if (!link) { | 2670 if (!link) { |
2671 return L""; | 2671 return L""; |
(...skipping 18 matching lines...) Expand all Loading... |
2690 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { | 2690 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { |
2691 return; | 2691 return; |
2692 } | 2692 } |
2693 CPDF_LinkExt* link = NULL; | 2693 CPDF_LinkExt* link = NULL; |
2694 link = m_LinkList.GetAt(index); | 2694 link = m_LinkList.GetAt(index); |
2695 if (!link) { | 2695 if (!link) { |
2696 return ; | 2696 return ; |
2697 } | 2697 } |
2698 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2698 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2699 } | 2699 } |
OLD | NEW |