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 "../../../third_party/base/nonstd_unique_ptr.h" | 7 #include "../../../third_party/base/nonstd_unique_ptr.h" |
8 #include "../../include/fpdfapi/fpdf_page.h" | 8 #include "../../include/fpdfapi/fpdf_page.h" |
9 #include "../../include/fpdfapi/fpdf_pageobj.h" | 9 #include "../../include/fpdfapi/fpdf_pageobj.h" |
10 #include "../../include/fpdfapi/fpdf_resource.h" | 10 #include "../../include/fpdfapi/fpdf_resource.h" |
11 #include "../../include/fpdftext/fpdf_text.h" | 11 #include "../../include/fpdftext/fpdf_text.h" |
12 #include "../../include/fxcrt/fx_arb.h" | 12 #include "../../include/fxcrt/fx_bidi.h" |
13 #include "../../include/fxcrt/fx_ucd.h" | 13 #include "../../include/fxcrt/fx_ucd.h" |
14 #include "text_int.h" | 14 #include "text_int.h" |
15 #include "txtproc.h" | 15 #include "txtproc.h" |
16 | 16 |
17 CFX_ByteString CharFromUnicodeAlt(FX_WCHAR unicode, | 17 CFX_ByteString CharFromUnicodeAlt(FX_WCHAR unicode, |
18 int destcp, | 18 int destcp, |
19 const FX_CHAR* defchar) { | 19 const FX_CHAR* defchar) { |
20 if (destcp == 0) { | 20 if (destcp == 0) { |
21 if (unicode < 0x80) { | 21 if (unicode < 0x80) { |
22 return CFX_ByteString((char)unicode); | 22 return CFX_ByteString((char)unicode); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 314 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
315 sDest += pDst[nIndex]; | 315 sDest += pDst[nIndex]; |
316 } | 316 } |
317 delete[] pDst; | 317 delete[] pDst; |
318 } | 318 } |
319 void NormalizeString(CFX_WideString& str) { | 319 void NormalizeString(CFX_WideString& str) { |
320 if (str.GetLength() <= 0) { | 320 if (str.GetLength() <= 0) { |
321 return; | 321 return; |
322 } | 322 } |
323 CFX_WideString sBuffer; | 323 CFX_WideString sBuffer; |
324 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 324 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
325 CFX_WordArray order; | 325 CFX_WordArray order; |
326 FX_BOOL bR2L = FALSE; | 326 FX_BOOL bR2L = FALSE; |
327 int32_t start = 0, count = 0, i = 0; | 327 int32_t start = 0, count = 0, i = 0; |
328 int nR2L = 0, nL2R = 0; | 328 int nR2L = 0, nL2R = 0; |
329 for (i = 0; i < str.GetLength(); i++) { | 329 for (i = 0; i < str.GetLength(); i++) { |
330 if (pBidiChar->AppendChar(str.GetAt(i))) { | 330 if (pBidiChar->AppendChar(str.GetAt(i))) { |
331 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 331 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
332 order.Add(start); | 332 order.Add(start); |
333 order.Add(count); | 333 order.Add(count); |
334 order.Add(ret); | 334 order.Add(ret); |
335 if (!bR2L) { | 335 if (!bR2L) { |
336 if (ret == 2) { | 336 if (ret == CFX_BidiChar::RIGHT) { |
337 nR2L++; | 337 nR2L++; |
338 } else if (ret == 1) { | 338 } else if (ret == CFX_BidiChar::LEFT) { |
339 nL2R++; | 339 nL2R++; |
340 } | 340 } |
341 } | 341 } |
342 } | 342 } |
343 } | 343 } |
344 if (pBidiChar->EndChar()) { | 344 if (pBidiChar->EndChar()) { |
345 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 345 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
346 order.Add(start); | 346 order.Add(start); |
347 order.Add(count); | 347 order.Add(count); |
348 order.Add(ret); | 348 order.Add(ret); |
349 if (!bR2L) { | 349 if (!bR2L) { |
350 if (ret == 2) { | 350 if (ret == CFX_BidiChar::RIGHT) { |
351 nR2L++; | 351 nR2L++; |
352 } else if (ret == 1) { | 352 } else if (ret == CFX_BidiChar::LEFT) { |
353 nL2R++; | 353 nL2R++; |
354 } | 354 } |
355 } | 355 } |
356 } | 356 } |
357 if (nR2L > 0 && nR2L >= nL2R) { | 357 if (nR2L > 0 && nR2L >= nL2R) { |
358 bR2L = TRUE; | 358 bR2L = TRUE; |
359 } | 359 } |
360 if (bR2L) { | 360 if (bR2L) { |
361 int count = order.GetSize(); | 361 int count = order.GetSize(); |
362 for (int j = count - 1; j > 0; j -= 3) { | 362 for (int j = count - 1; j > 0; j -= 3) { |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 FX_DWORD flags) { | 793 FX_DWORD flags) { |
794 buffer.EstimateSize(0, 10240); | 794 buffer.EstimateSize(0, 10240); |
795 CPDF_Page page; | 795 CPDF_Page page; |
796 page.Load(pDoc, pPage); | 796 page.Load(pDoc, pPage); |
797 CPDF_ParseOptions options; | 797 CPDF_ParseOptions options; |
798 options.m_bTextOnly = TRUE; | 798 options.m_bTextOnly = TRUE; |
799 options.m_bSeparateForm = FALSE; | 799 options.m_bSeparateForm = FALSE; |
800 page.ParseContent(&options); | 800 page.ParseContent(&options); |
801 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL); | 801 _PDF_GetTextStream_Unicode(buffer, &page, TRUE, NULL); |
802 } | 802 } |
OLD | NEW |