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/fpdf_font/cpdf_cidfont.h" | 7 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() { | 221 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() { |
222 return this; | 222 return this; |
223 } | 223 } |
224 | 224 |
225 uint16_t CPDF_CIDFont::CIDFromCharCode(uint32_t charcode) const { | 225 uint16_t CPDF_CIDFont::CIDFromCharCode(uint32_t charcode) const { |
226 return m_pCMap ? m_pCMap->CIDFromCharCode(charcode) | 226 return m_pCMap ? m_pCMap->CIDFromCharCode(charcode) |
227 : static_cast<uint16_t>(charcode); | 227 : static_cast<uint16_t>(charcode); |
228 } | 228 } |
229 | 229 |
230 FX_BOOL CPDF_CIDFont::IsVertWriting() const { | 230 bool CPDF_CIDFont::IsVertWriting() const { |
231 return m_pCMap && m_pCMap->IsVertWriting(); | 231 return m_pCMap && m_pCMap->IsVertWriting(); |
232 } | 232 } |
233 | 233 |
234 CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(uint32_t charcode) const { | 234 CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(uint32_t charcode) const { |
235 CFX_WideString str = CPDF_Font::UnicodeFromCharCode(charcode); | 235 CFX_WideString str = CPDF_Font::UnicodeFromCharCode(charcode); |
236 if (!str.IsEmpty()) | 236 if (!str.IsEmpty()) |
237 return str; | 237 return str; |
238 FX_WCHAR ret = GetUnicodeFromCharCode(charcode); | 238 FX_WCHAR ret = GetUnicodeFromCharCode(charcode); |
239 return ret ? ret : CFX_WideString(); | 239 return ret ? ret : CFX_WideString(); |
240 } | 240 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 return buffer[0] * 256 + buffer[1]; | 311 return buffer[0] * 256 + buffer[1]; |
312 #else | 312 #else |
313 if (m_pCMap->m_pEmbedMap) { | 313 if (m_pCMap->m_pEmbedMap) { |
314 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, | 314 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, |
315 unicode); | 315 unicode); |
316 } | 316 } |
317 #endif | 317 #endif |
318 return 0; | 318 return 0; |
319 } | 319 } |
320 | 320 |
321 FX_BOOL CPDF_CIDFont::Load() { | 321 bool CPDF_CIDFont::Load() { |
322 if (m_pFontDict->GetStringFor("Subtype") == "TrueType") { | 322 if (m_pFontDict->GetStringFor("Subtype") == "TrueType") { |
323 LoadGB2312(); | 323 LoadGB2312(); |
324 return TRUE; | 324 return true; |
325 } | 325 } |
326 | 326 |
327 CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); | 327 CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); |
328 if (!pFonts || pFonts->GetCount() != 1) | 328 if (!pFonts || pFonts->GetCount() != 1) |
329 return FALSE; | 329 return false; |
330 | 330 |
331 CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); | 331 CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); |
332 if (!pCIDFontDict) | 332 if (!pCIDFontDict) |
333 return FALSE; | 333 return false; |
334 | 334 |
335 m_BaseFont = pCIDFontDict->GetStringFor("BaseFont"); | 335 m_BaseFont = pCIDFontDict->GetStringFor("BaseFont"); |
336 if ((m_BaseFont.Compare("CourierStd") == 0 || | 336 if ((m_BaseFont.Compare("CourierStd") == 0 || |
337 m_BaseFont.Compare("CourierStd-Bold") == 0 || | 337 m_BaseFont.Compare("CourierStd-Bold") == 0 || |
338 m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || | 338 m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || |
339 m_BaseFont.Compare("CourierStd-Oblique") == 0) && | 339 m_BaseFont.Compare("CourierStd-Oblique") == 0) && |
340 !IsEmbedded()) { | 340 !IsEmbedded()) { |
341 m_bAdobeCourierStd = true; | 341 m_bAdobeCourierStd = true; |
342 } | 342 } |
343 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); | 343 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); |
344 if (pFontDesc) | 344 if (pFontDesc) |
345 LoadFontDescriptor(pFontDesc); | 345 LoadFontDescriptor(pFontDesc); |
346 | 346 |
347 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding"); | 347 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding"); |
348 if (!pEncoding) | 348 if (!pEncoding) |
349 return FALSE; | 349 return false; |
350 | 350 |
351 CFX_ByteString subtype = pCIDFontDict->GetStringFor("Subtype"); | 351 CFX_ByteString subtype = pCIDFontDict->GetStringFor("Subtype"); |
352 m_bType1 = (subtype == "CIDFontType0"); | 352 m_bType1 = (subtype == "CIDFontType0"); |
353 | 353 |
354 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager; | 354 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager; |
355 if (pEncoding->IsName()) { | 355 if (pEncoding->IsName()) { |
356 CFX_ByteString cmap = pEncoding->GetString(); | 356 CFX_ByteString cmap = pEncoding->GetString(); |
357 bool bPromptCJK = m_pFontFile && m_bType1; | 357 bool bPromptCJK = m_pFontFile && m_bType1; |
358 m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK); | 358 m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK); |
359 if (!m_pCMap) | 359 if (!m_pCMap) |
360 return FALSE; | 360 return false; |
361 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { | 361 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { |
362 m_pCMap = new CPDF_CMap; | 362 m_pCMap = new CPDF_CMap; |
363 m_pAllocatedCMap.reset(m_pCMap); | 363 m_pAllocatedCMap.reset(m_pCMap); |
364 CPDF_StreamAcc acc; | 364 CPDF_StreamAcc acc; |
365 acc.LoadAllData(pStream, FALSE); | 365 acc.LoadAllData(pStream, FALSE); |
366 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); | 366 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); |
367 } else { | 367 } else { |
368 return FALSE; | 368 return false; |
369 } | 369 } |
370 | 370 |
371 m_Charset = m_pCMap->m_Charset; | 371 m_Charset = m_pCMap->m_Charset; |
372 if (m_Charset == CIDSET_UNKNOWN) { | 372 if (m_Charset == CIDSET_UNKNOWN) { |
373 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); | 373 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); |
374 if (pCIDInfo) { | 374 if (pCIDInfo) { |
375 m_Charset = | 375 m_Charset = |
376 CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC()); | 376 CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC()); |
377 } | 377 } |
378 } | 378 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); | 418 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); |
419 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); | 419 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); |
420 if (pDefaultArray) { | 420 if (pDefaultArray) { |
421 m_DefaultVY = pDefaultArray->GetIntegerAt(0); | 421 m_DefaultVY = pDefaultArray->GetIntegerAt(0); |
422 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); | 422 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); |
423 } else { | 423 } else { |
424 m_DefaultVY = 880; | 424 m_DefaultVY = 880; |
425 m_DefaultW1 = -1000; | 425 m_DefaultW1 = -1000; |
426 } | 426 } |
427 } | 427 } |
428 return TRUE; | 428 return true; |
429 } | 429 } |
430 | 430 |
431 FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode, int level) { | 431 FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode, int level) { |
432 if (charcode < 256 && m_CharBBox[charcode].right != -1) | 432 if (charcode < 256 && m_CharBBox[charcode].right != -1) |
433 return m_CharBBox[charcode]; | 433 return m_CharBBox[charcode]; |
434 | 434 |
435 FX_RECT rect; | 435 FX_RECT rect; |
436 bool bVert = false; | 436 bool bVert = false; |
437 int glyph_index = GlyphFromCharCode(charcode, &bVert); | 437 int glyph_index = GlyphFromCharCode(charcode, &bVert); |
438 FXFT_Face face = m_Font.GetFace(); | 438 FXFT_Face face = m_Font.GetFace(); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 } | 748 } |
749 | 749 |
750 int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const { | 750 int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const { |
751 return m_pCMap->CountChar(pString, size); | 751 return m_pCMap->CountChar(pString, size); |
752 } | 752 } |
753 | 753 |
754 int CPDF_CIDFont::AppendChar(FX_CHAR* str, uint32_t charcode) const { | 754 int CPDF_CIDFont::AppendChar(FX_CHAR* str, uint32_t charcode) const { |
755 return m_pCMap->AppendChar(str, charcode); | 755 return m_pCMap->AppendChar(str, charcode); |
756 } | 756 } |
757 | 757 |
758 FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const { | 758 bool CPDF_CIDFont::IsUnicodeCompatible() const { |
759 if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded()) | 759 if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded()) |
760 return TRUE; | 760 return true; |
761 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; | 761 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; |
762 } | 762 } |
763 | 763 |
764 void CPDF_CIDFont::LoadSubstFont() { | 764 void CPDF_CIDFont::LoadSubstFont() { |
765 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); | 765 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); |
766 safeStemV *= 5; | 766 safeStemV *= 5; |
767 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, | 767 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, |
768 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, | 768 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, |
769 g_CharsetCPs[m_Charset], IsVertWriting()); | 769 g_CharsetCPs[m_Charset], IsVertWriting()); |
770 } | 770 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 843 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
844 return nullptr; | 844 return nullptr; |
845 | 845 |
846 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); | 846 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); |
847 const auto* pTransform = std::lower_bound( | 847 const auto* pTransform = std::lower_bound( |
848 g_Japan1_VertCIDs, pEnd, CID, | 848 g_Japan1_VertCIDs, pEnd, CID, |
849 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); | 849 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); |
850 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a | 850 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a |
851 : nullptr; | 851 : nullptr; |
852 } | 852 } |
OLD | NEW |