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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 308 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
309 sDest += pDst[nIndex]; | 309 sDest += pDst[nIndex]; |
310 } | 310 } |
311 delete[] pDst; | 311 delete[] pDst; |
312 } | 312 } |
313 void NormalizeString(CFX_WideString& str) { | 313 void NormalizeString(CFX_WideString& str) { |
314 if (str.GetLength() <= 0) { | 314 if (str.GetLength() <= 0) { |
315 return; | 315 return; |
316 } | 316 } |
317 CFX_WideString sBuffer; | 317 CFX_WideString sBuffer; |
318 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 318 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
319 CFX_WordArray order; | 319 CFX_WordArray order; |
320 FX_BOOL bR2L = FALSE; | 320 FX_BOOL bR2L = FALSE; |
321 int32_t start = 0, count = 0, i = 0; | 321 int32_t start = 0, count = 0, i = 0; |
322 int nR2L = 0, nL2R = 0; | 322 int nR2L = 0, nL2R = 0; |
323 for (i = 0; i < str.GetLength(); i++) { | 323 for (i = 0; i < str.GetLength(); i++) { |
324 if (pBidiChar->AppendChar(str.GetAt(i))) { | 324 if (pBidiChar->AppendChar(str.GetAt(i))) { |
325 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 325 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
326 order.Add(start); | 326 order.Add(start); |
327 order.Add(count); | 327 order.Add(count); |
328 order.Add(ret); | 328 order.Add(ret); |
329 if (!bR2L) { | 329 if (!bR2L) { |
330 if (ret == 2) { | 330 if (ret == CFX_BidiChar::RIGHT) { |
331 nR2L++; | 331 nR2L++; |
332 } else if (ret == 1) { | 332 } else if (ret == CFX_BidiChar::LEFT) { |
333 nL2R++; | 333 nL2R++; |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 } | 337 } |
338 if (pBidiChar->EndChar()) { | 338 if (pBidiChar->EndChar()) { |
339 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 339 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
340 order.Add(start); | 340 order.Add(start); |
341 order.Add(count); | 341 order.Add(count); |
342 order.Add(ret); | 342 order.Add(ret); |
343 if (!bR2L) { | 343 if (!bR2L) { |
344 if (ret == 2) { | 344 if (ret == CFX_BidiChar::RIGHT) { |
345 nR2L++; | 345 nR2L++; |
346 } else if (ret == 1) { | 346 } else if (ret == CFX_BidiChar::LEFT) { |
347 nL2R++; | 347 nL2R++; |
348 } | 348 } |
349 } | 349 } |
350 } | 350 } |
351 if (nR2L > 0 && nR2L >= nL2R) { | 351 if (nR2L > 0 && nR2L >= nL2R) { |
352 bR2L = TRUE; | 352 bR2L = TRUE; |
353 } | 353 } |
354 if (bR2L) { | 354 if (bR2L) { |
355 int count = order.GetSize(); | 355 int count = order.GetSize(); |
356 for (int j = count - 1; j > 0; j -= 3) { | 356 for (int j = count - 1; j > 0; j -= 3) { |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 FX_DWORD flags) { | 783 FX_DWORD flags) { |
784 buffer.EstimateSize(0, 10240); | 784 buffer.EstimateSize(0, 10240); |
785 CPDF_Page page; | 785 CPDF_Page page; |
786 page.Load(pDoc, pPage); | 786 page.Load(pDoc, pPage); |
787 CPDF_ParseOptions options; | 787 CPDF_ParseOptions options; |
788 options.m_bTextOnly = TRUE; | 788 options.m_bTextOnly = TRUE; |
789 options.m_bSeparateForm = FALSE; | 789 options.m_bSeparateForm = FALSE; |
790 page.ParseContent(&options); | 790 page.ParseContent(&options); |
791 GetTextStream_Unicode(buffer, &page, TRUE, NULL); | 791 GetTextStream_Unicode(buffer, &page, TRUE, NULL); |
792 } | 792 } |
OLD | NEW |