From 1f17bd73afa6b1b79ec4a2f81c995b43d15a9814 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 25 May 2018 21:47:39 +0000 Subject: Mark more CPDF_Objects as const in font code. Change-Id: Id37333ba61ad0d395055acffd75d4d8be5eb2b3e Reviewed-on: https://pdfium-review.googlesource.com/32911 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- core/fpdfapi/font/cpdf_cidfont.cpp | 20 ++++++++++---------- core/fpdfapi/font/cpdf_cidfont.h | 2 +- core/fpdfapi/font/cpdf_font.cpp | 6 +++--- core/fpdfapi/font/cpdf_font.h | 2 +- core/fpdfapi/font/cpdf_simplefont.cpp | 4 ++-- core/fpdfapi/font/cpdf_type1font.cpp | 3 ++- core/fpdfapi/font/cpdf_type3font.cpp | 6 +++--- core/fpdfapi/parser/cpdf_document.cpp | 3 ++- core/fpdfapi/parser/cpdf_document.h | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 77cc6735b5..38a4d65423 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -338,11 +338,11 @@ bool CPDF_CIDFont::Load() { return true; } - CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); + const CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); if (!pFonts || pFonts->GetCount() != 1) return false; - CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); + const CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); if (!pCIDFontDict) return false; @@ -354,7 +354,7 @@ bool CPDF_CIDFont::Load() { !IsEmbedded()) { m_bAdobeCourierStd = true; } - CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); + const CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); if (pFontDesc) LoadFontDescriptor(pFontDesc); @@ -383,7 +383,7 @@ bool CPDF_CIDFont::Load() { m_Charset = m_pCMap->GetCharset(); if (m_Charset == CIDSET_UNKNOWN) { - CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); + const CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); if (pCIDInfo) { m_Charset = CPDF_CMapParser::CharsetFromOrdering( pCIDInfo->GetStringFor("Ordering").AsStringView()); @@ -401,7 +401,7 @@ bool CPDF_CIDFont::Load() { FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->GetCoding()); } m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000); - CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); + const CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_WidthList, 1); if (!IsEmbedded()) @@ -422,7 +422,7 @@ bool CPDF_CIDFont::Load() { pWidthArray = pCIDFontDict->GetArrayFor("W2"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_VertMetrics, 3); - CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); + const CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); if (pDefaultArray) { m_DefaultVY = pDefaultArray->GetIntegerAt(0); m_DefaultW1 = pDefaultArray->GetIntegerAt(1); @@ -775,7 +775,7 @@ void CPDF_CIDFont::LoadSubstFont() { g_CharsetCPs[m_Charset], IsVertWriting()); } -void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, +void CPDF_CIDFont::LoadMetricsArray(const CPDF_Array* pArray, std::vector* result, int nElements) { int width_status = 0; @@ -783,11 +783,11 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, uint32_t first_code = 0; uint32_t last_code = 0; for (size_t i = 0; i < pArray->GetCount(); i++) { - CPDF_Object* pObj = pArray->GetDirectObjectAt(i); + const CPDF_Object* pObj = pArray->GetDirectObjectAt(i); if (!pObj) continue; - if (CPDF_Array* pObjArray = pObj->AsArray()) { + if (const CPDF_Array* pObjArray = pObj->AsArray()) { if (width_status != 1) return; if (first_code > @@ -833,7 +833,7 @@ float CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) { void CPDF_CIDFont::LoadGB2312() { m_BaseFont = m_pFontDict->GetStringFor("BaseFont"); - CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor"); + const CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor"); if (pFontDesc) LoadFontDescriptor(pFontDesc); diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h index fe2e2fed4e..7d7b33eea8 100644 --- a/core/fpdfapi/font/cpdf_cidfont.h +++ b/core/fpdfapi/font/cpdf_cidfont.h @@ -66,7 +66,7 @@ class CPDF_CIDFont : public CPDF_Font { void LoadGB2312(); int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph); int GetVerticalGlyph(int index, bool* pVertGlyph); - void LoadMetricsArray(CPDF_Array* pArray, + void LoadMetricsArray(const CPDF_Array* pArray, std::vector* result, int nElements); void LoadSubstFont(); diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index 35fed75c87..cc867d69d9 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp @@ -164,7 +164,7 @@ bool CPDF_Font::HasFontWidths() const { return true; } -void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { +void CPDF_Font::LoadFontDescriptor(const CPDF_Dictionary* pFontDesc) { m_Flags = pFontDesc->GetIntegerFor("Flags", FXFONT_NONSYMBOLIC); int ItalicAngle = 0; bool bExistItalicAngle = false; @@ -200,7 +200,7 @@ void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { } if (m_Descent > 10) m_Descent = -m_Descent; - CPDF_Array* pBBox = pFontDesc->GetArrayFor("FontBBox"); + const CPDF_Array* pBBox = pFontDesc->GetArrayFor("FontBBox"); if (pBBox) { m_FontBBox.left = pBBox->GetIntegerAt(0); m_FontBBox.bottom = pBBox->GetIntegerAt(1); @@ -208,7 +208,7 @@ void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { m_FontBBox.top = pBBox->GetIntegerAt(3); } - CPDF_Stream* pFontFile = pFontDesc->GetStreamFor("FontFile"); + const CPDF_Stream* pFontFile = pFontDesc->GetStreamFor("FontFile"); if (!pFontFile) pFontFile = pFontDesc->GetStreamFor("FontFile2"); if (!pFontFile) diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h index cda86e6ea3..a137879891 100644 --- a/core/fpdfapi/font/cpdf_font.h +++ b/core/fpdfapi/font/cpdf_font.h @@ -101,7 +101,7 @@ class CPDF_Font { std::vector* pCharNames, bool bEmbedded, bool bTrueType); - void LoadFontDescriptor(CPDF_Dictionary* pDict); + void LoadFontDescriptor(const CPDF_Dictionary* pDict); void CheckFontMetrics(); const char* GetAdobeCharName(int iBaseEncoding, diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp index 89f6fe1205..f7652d2635 100644 --- a/core/fpdfapi/font/cpdf_simplefont.cpp +++ b/core/fpdfapi/font/cpdf_simplefont.cpp @@ -104,11 +104,11 @@ FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode) { } bool CPDF_SimpleFont::LoadCommon() { - CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor"); + const CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor"); if (pFontDesc) { LoadFontDescriptor(pFontDesc); } - CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); + const CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); m_bUseFontWidth = !pWidthArray; if (pWidthArray) { if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) { diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp index 77987bb5dc..8c286edcd0 100644 --- a/core/fpdfapi/font/cpdf_type1font.cpp +++ b/core/fpdfapi/font/cpdf_type1font.cpp @@ -77,7 +77,8 @@ CPDF_Type1Font* CPDF_Type1Font::AsType1Font() { bool CPDF_Type1Font::Load() { m_Base14Font = PDF_GetStandardFontName(&m_BaseFont); if (m_Base14Font >= 0) { - CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor"); + const CPDF_Dictionary* pFontDesc = + m_pFontDict->GetDictFor("FontDescriptor"); if (pFontDesc && pFontDesc->KeyExist("Flags")) m_Flags = pFontDesc->GetIntegerFor("Flags"); else diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index c321f87897..9a79c30cab 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -43,7 +43,7 @@ CPDF_Type3Font* CPDF_Type3Font::AsType3Font() { bool CPDF_Type3Font::Load() { m_pFontResources = m_pFontDict->GetDictFor("Resources"); - CPDF_Array* pMatrix = m_pFontDict->GetArrayFor("FontMatrix"); + const CPDF_Array* pMatrix = m_pFontDict->GetArrayFor("FontMatrix"); float xscale = 1.0f; float yscale = 1.0f; if (pMatrix) { @@ -52,7 +52,7 @@ bool CPDF_Type3Font::Load() { yscale = m_FontMatrix.d; } - CPDF_Array* pBBox = m_pFontDict->GetArrayFor("FontBBox"); + const CPDF_Array* pBBox = m_pFontDict->GetArrayFor("FontBBox"); if (pBBox) { CFX_FloatRect box( pBBox->GetNumberAt(0) * xscale, pBBox->GetNumberAt(1) * yscale, @@ -64,7 +64,7 @@ bool CPDF_Type3Font::Load() { static constexpr size_t kCharLimit = FX_ArraySize(m_CharWidthL); int StartChar = m_pFontDict->GetIntegerFor("FirstChar"); if (StartChar >= 0 && static_cast(StartChar) < kCharLimit) { - CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); + const CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); if (pWidthArray) { size_t count = std::min(pWidthArray->GetCount(), kCharLimit); count = std::min(count, kCharLimit - StartChar); diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 982539cd72..5264d4e795 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -475,7 +475,8 @@ CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) { return m_pDocPage->GetFont(pFontDict); } -RetainPtr CPDF_Document::LoadFontFile(CPDF_Stream* pStream) { +RetainPtr CPDF_Document::LoadFontFile( + const CPDF_Stream* pStream) { return m_pDocPage->GetFontFileStreamAcc(pStream); } diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 4bbc6939e2..b169175668 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -91,7 +91,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { const CFX_Matrix& matrix); RetainPtr LoadImageFromPageData(uint32_t dwStreamObjNum); - RetainPtr LoadFontFile(CPDF_Stream* pStream); + RetainPtr LoadFontFile(const CPDF_Stream* pStream); RetainPtr LoadIccProfile(const CPDF_Stream* pStream); void LoadDoc(); -- cgit v1.2.3