Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: core/fpdfapi/fpdf_font/cpdf_cidfont.cpp

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp ('k') | core/fpdfapi/fpdf_font/cpdf_font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 #else 316 #else
317 if (m_pCMap->m_pEmbedMap) { 317 if (m_pCMap->m_pEmbedMap) {
318 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, 318 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset,
319 unicode); 319 unicode);
320 } 320 }
321 #endif 321 #endif
322 return 0; 322 return 0;
323 } 323 }
324 324
325 FX_BOOL CPDF_CIDFont::Load() { 325 FX_BOOL CPDF_CIDFont::Load() {
326 if (m_pFontDict->GetStringBy("Subtype") == "TrueType") { 326 if (m_pFontDict->GetStringFor("Subtype") == "TrueType") {
327 LoadGB2312(); 327 LoadGB2312();
328 return TRUE; 328 return TRUE;
329 } 329 }
330 330
331 CPDF_Array* pFonts = m_pFontDict->GetArrayBy("DescendantFonts"); 331 CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts");
332 if (!pFonts || pFonts->GetCount() != 1) 332 if (!pFonts || pFonts->GetCount() != 1)
333 return FALSE; 333 return FALSE;
334 334
335 CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); 335 CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0);
336 if (!pCIDFontDict) 336 if (!pCIDFontDict)
337 return FALSE; 337 return FALSE;
338 338
339 m_BaseFont = pCIDFontDict->GetStringBy("BaseFont"); 339 m_BaseFont = pCIDFontDict->GetStringFor("BaseFont");
340 if ((m_BaseFont.Compare("CourierStd") == 0 || 340 if ((m_BaseFont.Compare("CourierStd") == 0 ||
341 m_BaseFont.Compare("CourierStd-Bold") == 0 || 341 m_BaseFont.Compare("CourierStd-Bold") == 0 ||
342 m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || 342 m_BaseFont.Compare("CourierStd-BoldOblique") == 0 ||
343 m_BaseFont.Compare("CourierStd-Oblique") == 0) && 343 m_BaseFont.Compare("CourierStd-Oblique") == 0) &&
344 !IsEmbedded()) { 344 !IsEmbedded()) {
345 m_bAdobeCourierStd = true; 345 m_bAdobeCourierStd = true;
346 } 346 }
347 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictBy("FontDescriptor"); 347 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor");
348 if (pFontDesc) 348 if (pFontDesc)
349 LoadFontDescriptor(pFontDesc); 349 LoadFontDescriptor(pFontDesc);
350 350
351 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectBy("Encoding"); 351 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding");
352 if (!pEncoding) 352 if (!pEncoding)
353 return FALSE; 353 return FALSE;
354 354
355 CFX_ByteString subtype = pCIDFontDict->GetStringBy("Subtype"); 355 CFX_ByteString subtype = pCIDFontDict->GetStringFor("Subtype");
356 m_bType1 = (subtype == "CIDFontType0"); 356 m_bType1 = (subtype == "CIDFontType0");
357 357
358 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager; 358 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager;
359 if (pEncoding->IsName()) { 359 if (pEncoding->IsName()) {
360 CFX_ByteString cmap = pEncoding->GetString(); 360 CFX_ByteString cmap = pEncoding->GetString();
361 bool bPromptCJK = m_pFontFile && m_bType1; 361 bool bPromptCJK = m_pFontFile && m_bType1;
362 m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK); 362 m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK);
363 if (!m_pCMap) 363 if (!m_pCMap)
364 return FALSE; 364 return FALSE;
365 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { 365 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
366 m_pCMap = new CPDF_CMap; 366 m_pCMap = new CPDF_CMap;
367 m_pAllocatedCMap.reset(m_pCMap); 367 m_pAllocatedCMap.reset(m_pCMap);
368 CPDF_StreamAcc acc; 368 CPDF_StreamAcc acc;
369 acc.LoadAllData(pStream, FALSE); 369 acc.LoadAllData(pStream, FALSE);
370 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); 370 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
371 } else { 371 } else {
372 return FALSE; 372 return FALSE;
373 } 373 }
374 374
375 m_Charset = m_pCMap->m_Charset; 375 m_Charset = m_pCMap->m_Charset;
376 if (m_Charset == CIDSET_UNKNOWN) { 376 if (m_Charset == CIDSET_UNKNOWN) {
377 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictBy("CIDSystemInfo"); 377 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo");
378 if (pCIDInfo) { 378 if (pCIDInfo) {
379 m_Charset = 379 m_Charset =
380 CharsetFromOrdering(pCIDInfo->GetStringBy("Ordering").AsStringC()); 380 CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC());
381 } 381 }
382 } 382 }
383 if (m_Charset != CIDSET_UNKNOWN) { 383 if (m_Charset != CIDSET_UNKNOWN) {
384 bool bPromptCJK = !m_pFontFile && (m_pCMap->m_Coding == CIDCODING_CID || 384 bool bPromptCJK = !m_pFontFile && (m_pCMap->m_Coding == CIDCODING_CID ||
385 pCIDFontDict->KeyExist("W")); 385 pCIDFontDict->KeyExist("W"));
386 m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, bPromptCJK); 386 m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, bPromptCJK);
387 } 387 }
388 if (m_Font.GetFace()) { 388 if (m_Font.GetFace()) {
389 if (m_bType1) 389 if (m_bType1)
390 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); 390 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE);
391 else 391 else
392 FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding); 392 FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding);
393 } 393 }
394 m_DefaultWidth = pCIDFontDict->GetIntegerBy("DW", 1000); 394 m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000);
395 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayBy("W"); 395 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W");
396 if (pWidthArray) 396 if (pWidthArray)
397 LoadMetricsArray(pWidthArray, m_WidthList, 1); 397 LoadMetricsArray(pWidthArray, m_WidthList, 1);
398 if (!IsEmbedded()) 398 if (!IsEmbedded())
399 LoadSubstFont(); 399 LoadSubstFont();
400 400
401 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { 401 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
402 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectBy("CIDToGIDMap"); 402 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap");
403 if (pmap) { 403 if (pmap) {
404 if (CPDF_Stream* pStream = pmap->AsStream()) { 404 if (CPDF_Stream* pStream = pmap->AsStream()) {
405 m_pStreamAcc.reset(new CPDF_StreamAcc); 405 m_pStreamAcc.reset(new CPDF_StreamAcc);
406 m_pStreamAcc->LoadAllData(pStream, FALSE); 406 m_pStreamAcc->LoadAllData(pStream, FALSE);
407 } else if (pmap->GetString() == "Identity") { 407 } else if (pmap->GetString() == "Identity") {
408 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 408 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
409 if (m_pFontFile) { 409 if (m_pFontFile) {
410 m_bCIDIsGID = true; 410 m_bCIDIsGID = true;
411 } 411 }
412 #else 412 #else
413 m_bCIDIsGID = true; 413 m_bCIDIsGID = true;
414 #endif 414 #endif
415 } 415 }
416 } 416 }
417 } 417 }
418 418
419 CheckFontMetrics(); 419 CheckFontMetrics();
420 if (IsVertWriting()) { 420 if (IsVertWriting()) {
421 pWidthArray = pCIDFontDict->GetArrayBy("W2"); 421 pWidthArray = pCIDFontDict->GetArrayFor("W2");
422 if (pWidthArray) { 422 if (pWidthArray) {
423 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); 423 LoadMetricsArray(pWidthArray, m_VertMetrics, 3);
424 } 424 }
425 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayBy("DW2"); 425 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2");
426 if (pDefaultArray) { 426 if (pDefaultArray) {
427 m_DefaultVY = pDefaultArray->GetIntegerAt(0); 427 m_DefaultVY = pDefaultArray->GetIntegerAt(0);
428 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); 428 m_DefaultW1 = pDefaultArray->GetIntegerAt(1);
429 } else { 429 } else {
430 m_DefaultVY = 880; 430 m_DefaultVY = 880;
431 m_DefaultW1 = -1000; 431 m_DefaultW1 = -1000;
432 } 432 }
433 } 433 }
434 return TRUE; 434 return TRUE;
435 } 435 }
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 825 }
826 } 826 }
827 } 827 }
828 828
829 // static 829 // static
830 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) { 830 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) {
831 return (ch < 128 ? ch : ch - 255) * (1.0f / 127); 831 return (ch < 128 ? ch : ch - 255) * (1.0f / 127);
832 } 832 }
833 833
834 void CPDF_CIDFont::LoadGB2312() { 834 void CPDF_CIDFont::LoadGB2312() {
835 m_BaseFont = m_pFontDict->GetStringBy("BaseFont"); 835 m_BaseFont = m_pFontDict->GetStringFor("BaseFont");
836 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); 836 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor");
837 if (pFontDesc) 837 if (pFontDesc)
838 LoadFontDescriptor(pFontDesc); 838 LoadFontDescriptor(pFontDesc);
839 839
840 m_Charset = CIDSET_GB1; 840 m_Charset = CIDSET_GB1;
841 m_bType1 = false; 841 m_bType1 = false;
842 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager; 842 CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager;
843 m_pCMap = manager.GetPredefinedCMap("GBK-EUC-H", FALSE); 843 m_pCMap = manager.GetPredefinedCMap("GBK-EUC-H", FALSE);
844 m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, FALSE); 844 m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, FALSE);
845 if (!IsEmbedded()) 845 if (!IsEmbedded())
846 LoadSubstFont(); 846 LoadSubstFont();
847 847
848 CheckFontMetrics(); 848 CheckFontMetrics();
849 m_DefaultWidth = 1000; 849 m_DefaultWidth = 1000;
850 m_bAnsiWidthsFixed = true; 850 m_bAnsiWidthsFixed = true;
851 } 851 }
852 852
853 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { 853 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const {
854 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 854 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
855 return nullptr; 855 return nullptr;
856 856
857 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); 857 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs);
858 const auto* pTransform = std::lower_bound( 858 const auto* pTransform = std::lower_bound(
859 g_Japan1_VertCIDs, pEnd, CID, 859 g_Japan1_VertCIDs, pEnd, CID,
860 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); 860 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; });
861 return pTransform < pEnd && CID == pTransform->cid ? &pTransform->a : nullptr; 861 return pTransform < pEnd && CID == pTransform->cid ? &pTransform->a : nullptr;
862 } 862 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp ('k') | core/fpdfapi/fpdf_font/cpdf_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698