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 "font_int.h" | 7 #include "font_int.h" |
8 | 8 |
9 #include "../fpdf_page/pageint.h" | 9 #include "../fpdf_page/pageint.h" |
10 #include "core/include/fpdfapi/fpdf_module.h" | 10 #include "core/include/fpdfapi/fpdf_module.h" |
11 #include "core/include/fpdfapi/fpdf_page.h" | 11 #include "core/include/fpdfapi/fpdf_page.h" |
12 #include "core/include/fpdfapi/fpdf_pageobj.h" | 12 #include "core/include/fpdfapi/fpdf_pageobj.h" |
13 #include "core/include/fpdfapi/fpdf_resource.h" | 13 #include "core/include/fpdfapi/fpdf_resource.h" |
| 14 #include "core/include/fxcrt/fx_ext.h" |
14 #include "core/include/fxge/fx_freetype.h" | 15 #include "core/include/fxge/fx_freetype.h" |
15 | 16 |
16 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { | 17 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { |
17 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { | 18 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { |
18 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == | 19 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == |
19 platform_id && | 20 platform_id && |
20 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == | 21 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == |
21 encoding_id) { | 22 encoding_id) { |
22 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); | 23 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); |
23 return TRUE; | 24 return TRUE; |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 if (pair.second == unicode) | 508 if (pair.second == unicode) |
508 return pair.first; | 509 return pair.first; |
509 } | 510 } |
510 return 0; | 511 return 0; |
511 } | 512 } |
512 | 513 |
513 // Static. | 514 // Static. |
514 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { | 515 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { |
515 const FX_CHAR* buf = str.GetCStr(); | 516 const FX_CHAR* buf = str.GetCStr(); |
516 int len = str.GetLength(); | 517 int len = str.GetLength(); |
517 if (len == 0) { | 518 if (len == 0) |
518 return 0; | 519 return 0; |
519 } | 520 |
520 int result = 0; | 521 int result = 0; |
521 if (buf[0] == '<') { | 522 if (buf[0] == '<') { |
522 for (int i = 1; i < len; i++) { | 523 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) |
523 int digit; | 524 result = result * 16 + FXSYS_toHexDigit(buf[i]); |
524 if (buf[i] >= '0' && buf[i] <= '9') { | |
525 digit = buf[i] - '0'; | |
526 } else if (buf[i] >= 'a' && buf[i] <= 'f') { | |
527 digit = buf[i] - 'a' + 10; | |
528 } else if (buf[i] >= 'A' && buf[i] <= 'F') { | |
529 digit = buf[i] - 'A' + 10; | |
530 } else { | |
531 break; | |
532 } | |
533 result = result * 16 + digit; | |
534 } | |
535 return result; | 525 return result; |
536 } | 526 } |
537 for (int i = 0; i < len; i++) { | 527 |
538 if (buf[i] < '0' || buf[i] > '9') { | 528 for (int i = 0; i < len && std::isdigit(buf[i]); ++i) |
539 break; | 529 result = result * 10 + FXSYS_toDecimalDigit(buf[i]); |
540 } | 530 |
541 result = result * 10 + buf[i] - '0'; | |
542 } | |
543 return result; | 531 return result; |
544 } | 532 } |
545 static CFX_WideString StringDataAdd(CFX_WideString str) { | 533 static CFX_WideString StringDataAdd(CFX_WideString str) { |
546 CFX_WideString ret; | 534 CFX_WideString ret; |
547 int len = str.GetLength(); | 535 int len = str.GetLength(); |
548 FX_WCHAR value = 1; | 536 FX_WCHAR value = 1; |
549 for (int i = len - 1; i >= 0; --i) { | 537 for (int i = len - 1; i >= 0; --i) { |
550 FX_WCHAR ch = str[i] + value; | 538 FX_WCHAR ch = str[i] + value; |
551 if (ch < str[i]) { | 539 if (ch < str[i]) { |
552 ret.Insert(0, 0); | 540 ret.Insert(0, 0); |
553 } else { | 541 } else { |
554 ret.Insert(0, ch); | 542 ret.Insert(0, ch); |
555 value = 0; | 543 value = 0; |
556 } | 544 } |
557 } | 545 } |
558 if (value) { | 546 if (value) { |
559 ret.Insert(0, value); | 547 ret.Insert(0, value); |
560 } | 548 } |
561 return ret; | 549 return ret; |
562 } | 550 } |
563 | 551 |
564 // Static. | 552 // Static. |
565 CFX_WideString CPDF_ToUnicodeMap::StringToWideString( | 553 CFX_WideString CPDF_ToUnicodeMap::StringToWideString( |
566 const CFX_ByteStringC& str) { | 554 const CFX_ByteStringC& str) { |
567 const FX_CHAR* buf = str.GetCStr(); | 555 const FX_CHAR* buf = str.GetCStr(); |
568 int len = str.GetLength(); | 556 int len = str.GetLength(); |
569 if (len == 0) { | 557 if (len == 0) |
570 return CFX_WideString(); | 558 return CFX_WideString(); |
571 } | 559 |
572 CFX_WideString result; | 560 CFX_WideString result; |
573 if (buf[0] == '<') { | 561 if (buf[0] == '<') { |
574 int byte_pos = 0; | 562 int byte_pos = 0; |
575 FX_WCHAR ch = 0; | 563 FX_WCHAR ch = 0; |
576 for (int i = 1; i < len; i++) { | 564 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) { |
577 int digit; | 565 ch = ch * 16 + FXSYS_toHexDigit(buf[i]); |
578 if (buf[i] >= '0' && buf[i] <= '9') { | |
579 digit = buf[i] - '0'; | |
580 } else if (buf[i] >= 'a' && buf[i] <= 'f') { | |
581 digit = buf[i] - 'a' + 10; | |
582 } else if (buf[i] >= 'A' && buf[i] <= 'F') { | |
583 digit = buf[i] - 'A' + 10; | |
584 } else { | |
585 break; | |
586 } | |
587 ch = ch * 16 + digit; | |
588 | |
589 byte_pos++; | 566 byte_pos++; |
590 if (byte_pos == 4) { | 567 if (byte_pos == 4) { |
591 result += ch; | 568 result += ch; |
592 byte_pos = 0; | 569 byte_pos = 0; |
593 ch = 0; | 570 ch = 0; |
594 } | 571 } |
595 } | 572 } |
596 return result; | 573 return result; |
597 } | 574 } |
598 if (buf[0] == '(') { | |
599 } | |
600 return result; | 575 return result; |
601 } | 576 } |
602 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { | 577 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { |
603 CIDSet cid_set = CIDSET_UNKNOWN; | 578 CIDSet cid_set = CIDSET_UNKNOWN; |
604 CPDF_StreamAcc stream; | 579 CPDF_StreamAcc stream; |
605 stream.LoadAllData(pStream, FALSE); | 580 stream.LoadAllData(pStream, FALSE); |
606 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); | 581 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); |
607 while (1) { | 582 while (1) { |
608 CFX_ByteStringC word = parser.GetWord(); | 583 CFX_ByteStringC word = parser.GetWord(); |
609 if (word.IsEmpty()) { | 584 if (word.IsEmpty()) { |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 rect = pChar->m_BBox; | 1763 rect = pChar->m_BBox; |
1789 } | 1764 } |
1790 | 1765 |
1791 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) | 1766 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) |
1792 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} | 1767 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} |
1793 | 1768 |
1794 CPDF_Type3Char::~CPDF_Type3Char() { | 1769 CPDF_Type3Char::~CPDF_Type3Char() { |
1795 delete m_pForm; | 1770 delete m_pForm; |
1796 delete m_pBitmap; | 1771 delete m_pBitmap; |
1797 } | 1772 } |
OLD | NEW |