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 <cctype> | 7 #include <cctype> |
8 #include <cwctype> | 8 #include <cwctype> |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | |
10 | 11 |
11 #include "core/include/fpdfapi/fpdf_page.h" | 12 #include "core/include/fpdfapi/fpdf_page.h" |
12 #include "core/include/fpdfapi/fpdf_pageobj.h" | 13 #include "core/include/fpdfapi/fpdf_pageobj.h" |
13 #include "core/include/fpdfapi/fpdf_resource.h" | 14 #include "core/include/fpdfapi/fpdf_resource.h" |
14 #include "core/include/fpdftext/fpdf_text.h" | 15 #include "core/include/fpdftext/fpdf_text.h" |
15 #include "core/include/fxcrt/fx_bidi.h" | 16 #include "core/include/fxcrt/fx_bidi.h" |
16 #include "core/include/fxcrt/fx_ucd.h" | 17 #include "core/include/fxcrt/fx_ucd.h" |
17 #include "core/src/fpdftext/text_int.h" | 18 #include "core/src/fpdftext/text_int.h" |
18 #include "core/src/fpdftext/txtproc.h" | 19 #include "core/src/fpdftext/txtproc.h" |
19 | 20 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 sDest += wChar; | 303 sDest += wChar; |
303 return; | 304 return; |
304 } | 305 } |
305 pDst = new FX_WCHAR[nCount]; | 306 pDst = new FX_WCHAR[nCount]; |
306 FX_Unicode_GetNormalization(wChar, pDst); | 307 FX_Unicode_GetNormalization(wChar, pDst); |
307 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 308 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
308 sDest += pDst[nIndex]; | 309 sDest += pDst[nIndex]; |
309 } | 310 } |
310 delete[] pDst; | 311 delete[] pDst; |
311 } | 312 } |
313 | |
312 void NormalizeString(CFX_WideString& str) { | 314 void NormalizeString(CFX_WideString& str) { |
313 if (str.GetLength() <= 0) { | 315 if (str.GetLength() <= 0) { |
314 return; | 316 return; |
315 } | 317 } |
316 CFX_WideString sBuffer; | 318 CFX_WideString sBuffer; |
317 std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); | 319 std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
318 CFX_WordArray order; | 320 std::vector<FX_WORD> order; |
319 FX_BOOL bR2L = FALSE; | 321 FX_BOOL bR2L = FALSE; |
320 int32_t start = 0, count = 0, i = 0; | 322 int32_t start = 0, count = 0, i = 0; |
321 int nR2L = 0, nL2R = 0; | 323 int nR2L = 0, nL2R = 0; |
322 for (i = 0; i < str.GetLength(); i++) { | 324 for (i = 0; i < str.GetLength(); i++) { |
323 if (pBidiChar->AppendChar(str.GetAt(i))) { | 325 if (pBidiChar->AppendChar(str.GetAt(i))) { |
324 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); | 326 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
325 order.Add(start); | 327 order.push_back(start); |
326 order.Add(count); | 328 order.push_back(count); |
327 order.Add(ret); | 329 order.push_back(ret); |
328 if (!bR2L) { | 330 if (!bR2L) { |
329 if (ret == CFX_BidiChar::RIGHT) { | 331 if (ret == CFX_BidiChar::RIGHT) { |
330 nR2L++; | 332 nR2L++; |
331 } else if (ret == CFX_BidiChar::LEFT) { | 333 } else if (ret == CFX_BidiChar::LEFT) { |
332 nL2R++; | 334 nL2R++; |
333 } | 335 } |
334 } | 336 } |
335 } | 337 } |
336 } | 338 } |
337 if (pBidiChar->EndChar()) { | 339 if (pBidiChar->EndChar()) { |
338 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); | 340 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
339 order.Add(start); | 341 order.push_back(start); |
340 order.Add(count); | 342 order.push_back(count); |
341 order.Add(ret); | 343 order.push_back(ret); |
342 if (!bR2L) { | 344 if (!bR2L) { |
343 if (ret == CFX_BidiChar::RIGHT) { | 345 if (ret == CFX_BidiChar::RIGHT) { |
344 nR2L++; | 346 nR2L++; |
345 } else if (ret == CFX_BidiChar::LEFT) { | 347 } else if (ret == CFX_BidiChar::LEFT) { |
346 nL2R++; | 348 nL2R++; |
347 } | 349 } |
348 } | 350 } |
349 } | 351 } |
350 if (nR2L > 0 && nR2L >= nL2R) { | 352 if (nR2L > 0 && nR2L >= nL2R) { |
351 bR2L = TRUE; | 353 bR2L = TRUE; |
352 } | 354 } |
353 if (bR2L) { | 355 if (bR2L) { |
354 int count = order.GetSize(); | 356 int count = order.size(); |
355 for (int j = count - 1; j > 0; j -= 3) { | 357 for (int j = count - 1; j > 0; j -= 3) { |
356 int ret = order.GetAt(j); | 358 int ret = order[j]; |
357 int start = order.GetAt(j - 2); | 359 int count1 = order[j - 1]; |
358 int count1 = order.GetAt(j - 1); | 360 int start = order[j - 2]; |
359 if (ret == 2 || ret == 0) { | 361 if (ret == 2 || ret == 0) { |
360 for (int i = start + count1 - 1; i >= start; i--) { | 362 for (int i = start + count1 - 1; i >= start; i--) { |
361 NormalizeCompositeChar(str[i], sBuffer); | 363 NormalizeCompositeChar(str[i], sBuffer); |
362 } | 364 } |
363 } else { | 365 } else { |
364 i = j; | 366 i = j; |
365 FX_BOOL bSymbol = FALSE; | 367 FX_BOOL bSymbol = FALSE; |
366 while (i > 0 && order.GetAt(i) != 2) { | 368 while (i > 0 && order[i] != 2) { |
367 bSymbol = !order.GetAt(i); | 369 bSymbol = !order[i]; |
368 i -= 3; | 370 i -= 3; |
369 } | 371 } |
370 int end = start + count1; | 372 int end = start + count1; |
371 int n = 0; | 373 int n = 0; |
372 if (bSymbol) { | 374 if (bSymbol) { |
373 n = i + 6; | 375 n = i + 6; |
374 } else { | 376 } else { |
375 n = i + 3; | 377 n = i + 3; |
376 } | 378 } |
377 if (n >= j) { | 379 if (n >= j) { |
378 for (int m = start; m < end; m++) { | 380 for (int m = start; m < end; m++) { |
379 sBuffer += str[m]; | 381 sBuffer += str[m]; |
380 } | 382 } |
381 } else { | 383 } else { |
382 i = j; | 384 i = j; |
383 j = n; | 385 j = n; |
384 for (; n <= i; n += 3) { | 386 for (; n <= i; n += 3) { |
385 int start = order.GetAt(n - 2); | 387 int start = order[n - 2]; |
386 int count1 = order.GetAt(n - 1); | 388 int count1 = order[n - 1]; |
387 int end = start + count1; | 389 int end = start + count1; |
388 for (int m = start; m < end; m++) { | 390 for (int m = start; m < end; m++) { |
389 sBuffer += str[m]; | 391 sBuffer += str[m]; |
390 } | 392 } |
391 } | 393 } |
392 } | 394 } |
393 } | 395 } |
394 } | 396 } |
395 } else { | 397 } else { |
396 int count = order.GetSize(); | 398 int count = order.size(); |
Lei Zhang
2016/02/09 00:45:21
pdfium::CollectionSize<int>()
Tom Sepez
2016/02/09 00:57:01
Done, also in if-branch above.
| |
397 FX_BOOL bL2R = FALSE; | 399 FX_BOOL bL2R = FALSE; |
398 for (int j = 0; j < count; j += 3) { | 400 for (int j = 0; j < count; j += 3) { |
399 int ret = order.GetAt(j + 2); | 401 int start = order[j]; |
400 int start = order.GetAt(j); | 402 int count1 = order[j + 1]; |
401 int count1 = order.GetAt(j + 1); | 403 int ret = order[j + 2]; |
402 if (ret == 2 || (j == 0 && ret == 0 && !bL2R)) { | 404 if (ret == 2 || (j == 0 && ret == 0 && !bL2R)) { |
403 int i = j + 3; | 405 int i = j + 3; |
404 while (bR2L && i < count) { | 406 while (bR2L && i < count) { |
405 if (order.GetAt(i + 2) == 1) { | 407 if (order[i + 2] == 1) { |
406 break; | 408 break; |
407 } else { | 409 } else { |
408 i += 3; | 410 i += 3; |
409 } | 411 } |
410 } | 412 } |
411 if (i == 3) { | 413 if (i == 3) { |
412 j = -3; | 414 j = -3; |
413 bL2R = TRUE; | 415 bL2R = TRUE; |
414 continue; | 416 continue; |
415 } | 417 } |
416 int end = str.GetLength() - 1; | 418 int end = str.GetLength() - 1; |
417 if (i < count) { | 419 if (i < count) { |
418 end = order.GetAt(i) - 1; | 420 end = order[i] - 1; |
419 } | 421 } |
420 j = i - 3; | 422 j = i - 3; |
421 for (int n = end; n >= start; n--) { | 423 for (int n = end; n >= start; n--) { |
422 NormalizeCompositeChar(str[i], sBuffer); | 424 NormalizeCompositeChar(str[i], sBuffer); |
423 } | 425 } |
424 } else { | 426 } else { |
425 int end = start + count1; | 427 int end = start + count1; |
426 for (int i = start; i < end; i++) { | 428 for (int i = start; i < end; i++) { |
427 sBuffer += str[i]; | 429 sBuffer += str[i]; |
428 } | 430 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 FX_DWORD flags) { | 782 FX_DWORD flags) { |
781 buffer.EstimateSize(0, 10240); | 783 buffer.EstimateSize(0, 10240); |
782 CPDF_Page page; | 784 CPDF_Page page; |
783 page.Load(pDoc, pPage); | 785 page.Load(pDoc, pPage); |
784 CPDF_ParseOptions options; | 786 CPDF_ParseOptions options; |
785 options.m_bTextOnly = TRUE; | 787 options.m_bTextOnly = TRUE; |
786 options.m_bSeparateForm = FALSE; | 788 options.m_bSeparateForm = FALSE; |
787 page.ParseContent(&options); | 789 page.ParseContent(&options); |
788 GetTextStream_Unicode(buffer, &page, TRUE); | 790 GetTextStream_Unicode(buffer, &page, TRUE); |
789 } | 791 } |
OLD | NEW |