| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/font/cpdf_cidfont.h" | 7 #include "core/fpdfapi/font/cpdf_cidfont.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 if (m_Font.GetFace()) { | 385 if (m_Font.GetFace()) { |
| 386 if (m_bType1) | 386 if (m_bType1) |
| 387 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); | 387 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); |
| 388 else | 388 else |
| 389 FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding); | 389 FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding); |
| 390 } | 390 } |
| 391 m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000); | 391 m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000); |
| 392 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); | 392 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); |
| 393 if (pWidthArray) | 393 if (pWidthArray) |
| 394 LoadMetricsArray(pWidthArray, m_WidthList, 1); | 394 LoadMetricsArray(pWidthArray, &m_WidthList, 1); |
| 395 if (!IsEmbedded()) | 395 if (!IsEmbedded()) |
| 396 LoadSubstFont(); | 396 LoadSubstFont(); |
| 397 | 397 |
| 398 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { | 398 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { |
| 399 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); | 399 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); |
| 400 if (pmap) { | 400 if (pmap) { |
| 401 if (CPDF_Stream* pStream = pmap->AsStream()) { | 401 if (CPDF_Stream* pStream = pmap->AsStream()) { |
| 402 m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>(); | 402 m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>(); |
| 403 m_pStreamAcc->LoadAllData(pStream, false); | 403 m_pStreamAcc->LoadAllData(pStream, false); |
| 404 } else if (pmap->GetString() == "Identity") { | 404 } else if (pmap->GetString() == "Identity") { |
| 405 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 405 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 406 if (m_pFontFile) | 406 if (m_pFontFile) |
| 407 m_bCIDIsGID = true; | 407 m_bCIDIsGID = true; |
| 408 #else | 408 #else |
| 409 m_bCIDIsGID = true; | 409 m_bCIDIsGID = true; |
| 410 #endif | 410 #endif |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 CheckFontMetrics(); | 415 CheckFontMetrics(); |
| 416 if (IsVertWriting()) { | 416 if (IsVertWriting()) { |
| 417 pWidthArray = pCIDFontDict->GetArrayFor("W2"); | 417 pWidthArray = pCIDFontDict->GetArrayFor("W2"); |
| 418 if (pWidthArray) | 418 if (pWidthArray) |
| 419 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); | 419 LoadMetricsArray(pWidthArray, &m_VertMetrics, 3); |
| 420 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); | 420 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); |
| 421 if (pDefaultArray) { | 421 if (pDefaultArray) { |
| 422 m_DefaultVY = pDefaultArray->GetIntegerAt(0); | 422 m_DefaultVY = pDefaultArray->GetIntegerAt(0); |
| 423 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); | 423 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); |
| 424 } else { | 424 } else { |
| 425 m_DefaultVY = 880; | 425 m_DefaultVY = 880; |
| 426 m_DefaultW1 = -1000; | 426 m_DefaultW1 = -1000; |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 return true; | 429 return true; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 m_CharBBox[charcode] = rect; | 498 m_CharBBox[charcode] = rect; |
| 499 | 499 |
| 500 return rect; | 500 return rect; |
| 501 } | 501 } |
| 502 | 502 |
| 503 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) { | 503 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) { |
| 504 if (charcode < 0x80 && m_bAnsiWidthsFixed) | 504 if (charcode < 0x80 && m_bAnsiWidthsFixed) |
| 505 return (charcode >= 32 && charcode < 127) ? 500 : 0; | 505 return (charcode >= 32 && charcode < 127) ? 500 : 0; |
| 506 | 506 |
| 507 uint16_t cid = CIDFromCharCode(charcode); | 507 uint16_t cid = CIDFromCharCode(charcode); |
| 508 int size = m_WidthList.GetSize(); | 508 size_t size = m_WidthList.size(); |
| 509 const uint32_t* pList = m_WidthList.GetData(); | 509 const uint32_t* pList = m_WidthList.data(); |
| 510 for (int i = 0; i < size; i += 3) { | 510 for (size_t i = 0; i < size; i += 3) { |
| 511 const uint32_t* pEntry = pList + i; | 511 const uint32_t* pEntry = pList + i; |
| 512 if (IsMetricForCID(pEntry, cid)) | 512 if (IsMetricForCID(pEntry, cid)) |
| 513 return static_cast<int>(pEntry[2]); | 513 return static_cast<int>(pEntry[2]); |
| 514 } | 514 } |
| 515 return m_DefaultWidth; | 515 return m_DefaultWidth; |
| 516 } | 516 } |
| 517 | 517 |
| 518 short CPDF_CIDFont::GetVertWidth(uint16_t CID) const { | 518 short CPDF_CIDFont::GetVertWidth(uint16_t CID) const { |
| 519 uint32_t vertsize = m_VertMetrics.GetSize() / 5; | 519 size_t vertsize = m_VertMetrics.size() / 5; |
| 520 if (vertsize) { | 520 if (vertsize) { |
| 521 const uint32_t* pTable = m_VertMetrics.GetData(); | 521 const uint32_t* pTable = m_VertMetrics.data(); |
| 522 for (uint32_t i = 0; i < vertsize; i++) { | 522 for (size_t i = 0; i < vertsize; i++) { |
| 523 const uint32_t* pEntry = pTable + (i * 5); | 523 const uint32_t* pEntry = pTable + (i * 5); |
| 524 if (IsMetricForCID(pEntry, CID)) | 524 if (IsMetricForCID(pEntry, CID)) |
| 525 return static_cast<short>(pEntry[2]); | 525 return static_cast<short>(pEntry[2]); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 return m_DefaultW1; | 528 return m_DefaultW1; |
| 529 } | 529 } |
| 530 | 530 |
| 531 void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const { | 531 void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const { |
| 532 uint32_t vertsize = m_VertMetrics.GetSize() / 5; | 532 size_t vertsize = m_VertMetrics.size() / 5; |
| 533 if (vertsize) { | 533 if (vertsize) { |
| 534 const uint32_t* pTable = m_VertMetrics.GetData(); | 534 const uint32_t* pTable = m_VertMetrics.data(); |
| 535 for (uint32_t i = 0; i < vertsize; i++) { | 535 for (size_t i = 0; i < vertsize; i++) { |
| 536 const uint32_t* pEntry = pTable + (i * 5); | 536 const uint32_t* pEntry = pTable + (i * 5); |
| 537 if (IsMetricForCID(pEntry, CID)) { | 537 if (IsMetricForCID(pEntry, CID)) { |
| 538 vx = static_cast<short>(pEntry[3]); | 538 vx = static_cast<short>(pEntry[3]); |
| 539 vy = static_cast<short>(pEntry[4]); | 539 vy = static_cast<short>(pEntry[4]); |
| 540 return; | 540 return; |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 uint32_t dwWidth = m_DefaultWidth; | 544 uint32_t dwWidth = m_DefaultWidth; |
| 545 int size = m_WidthList.GetSize(); | 545 size_t size = m_WidthList.size(); |
| 546 const uint32_t* pList = m_WidthList.GetData(); | 546 const uint32_t* pList = m_WidthList.data(); |
| 547 for (int i = 0; i < size; i += 3) { | 547 for (size_t i = 0; i < size; i += 3) { |
| 548 const uint32_t* pEntry = pList + i; | 548 const uint32_t* pEntry = pList + i; |
| 549 if (IsMetricForCID(pEntry, CID)) { | 549 if (IsMetricForCID(pEntry, CID)) { |
| 550 dwWidth = pEntry[2]; | 550 dwWidth = pEntry[2]; |
| 551 break; | 551 break; |
| 552 } | 552 } |
| 553 } | 553 } |
| 554 vx = static_cast<short>(dwWidth) / 2; | 554 vx = static_cast<short>(dwWidth) / 2; |
| 555 vy = m_DefaultVY; | 555 vy = m_DefaultVY; |
| 556 } | 556 } |
| 557 | 557 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 764 |
| 765 void CPDF_CIDFont::LoadSubstFont() { | 765 void CPDF_CIDFont::LoadSubstFont() { |
| 766 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); | 766 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); |
| 767 safeStemV *= 5; | 767 safeStemV *= 5; |
| 768 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, | 768 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, |
| 769 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, | 769 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, |
| 770 g_CharsetCPs[m_Charset], IsVertWriting()); | 770 g_CharsetCPs[m_Charset], IsVertWriting()); |
| 771 } | 771 } |
| 772 | 772 |
| 773 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, | 773 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, |
| 774 CFX_ArrayTemplate<uint32_t>& result, | 774 std::vector<uint32_t>* result, |
| 775 int nElements) { | 775 int nElements) { |
| 776 int width_status = 0; | 776 int width_status = 0; |
| 777 int iCurElement = 0; | 777 int iCurElement = 0; |
| 778 int first_code = 0; | 778 int first_code = 0; |
| 779 int last_code = 0; | 779 int last_code = 0; |
| 780 for (size_t i = 0; i < pArray->GetCount(); i++) { | 780 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 781 CPDF_Object* pObj = pArray->GetDirectObjectAt(i); | 781 CPDF_Object* pObj = pArray->GetDirectObjectAt(i); |
| 782 if (!pObj) | 782 if (!pObj) |
| 783 continue; | 783 continue; |
| 784 | 784 |
| 785 if (CPDF_Array* pObjArray = pObj->AsArray()) { | 785 if (CPDF_Array* pObjArray = pObj->AsArray()) { |
| 786 if (width_status != 1) | 786 if (width_status != 1) |
| 787 return; | 787 return; |
| 788 | 788 |
| 789 for (size_t j = 0; j < pObjArray->GetCount(); j += nElements) { | 789 for (size_t j = 0; j < pObjArray->GetCount(); j += nElements) { |
| 790 result.Add(first_code); | 790 result->push_back(first_code); |
| 791 result.Add(first_code); | 791 result->push_back(first_code); |
| 792 for (int k = 0; k < nElements; k++) | 792 for (int k = 0; k < nElements; k++) |
| 793 result.Add(pObjArray->GetIntegerAt(j + k)); | 793 result->push_back(pObjArray->GetIntegerAt(j + k)); |
| 794 first_code++; | 794 first_code++; |
| 795 } | 795 } |
| 796 width_status = 0; | 796 width_status = 0; |
| 797 } else { | 797 } else { |
| 798 if (width_status == 0) { | 798 if (width_status == 0) { |
| 799 first_code = pObj->GetInteger(); | 799 first_code = pObj->GetInteger(); |
| 800 width_status = 1; | 800 width_status = 1; |
| 801 } else if (width_status == 1) { | 801 } else if (width_status == 1) { |
| 802 last_code = pObj->GetInteger(); | 802 last_code = pObj->GetInteger(); |
| 803 width_status = 2; | 803 width_status = 2; |
| 804 iCurElement = 0; | 804 iCurElement = 0; |
| 805 } else { | 805 } else { |
| 806 if (!iCurElement) { | 806 if (!iCurElement) { |
| 807 result.Add(first_code); | 807 result->push_back(first_code); |
| 808 result.Add(last_code); | 808 result->push_back(last_code); |
| 809 } | 809 } |
| 810 result.Add(pObj->GetInteger()); | 810 result->push_back(pObj->GetInteger()); |
| 811 iCurElement++; | 811 iCurElement++; |
| 812 if (iCurElement == nElements) | 812 if (iCurElement == nElements) |
| 813 width_status = 0; | 813 width_status = 0; |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 } | 816 } |
| 817 } | 817 } |
| 818 | 818 |
| 819 // static | 819 // static |
| 820 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) { | 820 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 844 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 844 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
| 845 return nullptr; | 845 return nullptr; |
| 846 | 846 |
| 847 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); | 847 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); |
| 848 const auto* pTransform = std::lower_bound( | 848 const auto* pTransform = std::lower_bound( |
| 849 g_Japan1_VertCIDs, pEnd, CID, | 849 g_Japan1_VertCIDs, pEnd, CID, |
| 850 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); | 850 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); |
| 851 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a | 851 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a |
| 852 : nullptr; | 852 : nullptr; |
| 853 } | 853 } |
| OLD | NEW |