From f8f19dc2c1b66fbcc2be837c324cab3df0ff3671 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 4 Dec 2017 15:20:15 +0000 Subject: Fix nits in CPDF_Type3Font. Change-Id: Ib922184ee844e66a0b29f49025e83e13eb81fdb8 Reviewed-on: https://pdfium-review.googlesource.com/20214 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- core/fpdfapi/font/cpdf_type3font.cpp | 37 +++++++++++++++++++----------------- core/fpdfapi/font/cpdf_type3font.h | 4 ++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index fc2ad0f348..6588493e16 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/font/cpdf_type3font.h" +#include #include #include "core/fpdfapi/font/cpdf_type3char.h" @@ -16,13 +17,13 @@ #include "core/fxcrt/fx_system.h" #include "third_party/base/stl_util.h" -#define FPDF_MAX_TYPE3_FORM_LEVEL 4 +namespace { -CPDF_Type3Font::CPDF_Type3Font() - : m_pCharProcs(nullptr), - m_pPageResources(nullptr), - m_pFontResources(nullptr), - m_CharLoadingDepth(0) { +constexpr int kMaxType3FormLevel = 4; + +} // namespace + +CPDF_Type3Font::CPDF_Type3Font() { memset(m_CharWidthL, 0, sizeof(m_CharWidthL)); } @@ -63,17 +64,17 @@ bool CPDF_Type3Font::Load() { static_cast(pBBox->GetNumberAt(3) * yscale * 1000); } + static constexpr size_t kCharLimit = FX_ArraySize(m_CharWidthL); int StartChar = m_pFontDict->GetIntegerFor("FirstChar"); - CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); - if (pWidthArray && StartChar >= 0 && StartChar < 256) { - size_t count = pWidthArray->GetCount(); - if (count > 256) - count = 256; - if (StartChar + count > 256) - count = 256 - StartChar; - for (size_t i = 0; i < count; i++) { - m_CharWidthL[StartChar + i] = - FXSYS_round(pWidthArray->GetNumberAt(i) * xscale * 1000); + if (StartChar >= 0 && static_cast(StartChar) < kCharLimit) { + CPDF_Array* pWidthArray = m_pFontDict->GetArrayFor("Widths"); + if (pWidthArray) { + size_t count = std::min(pWidthArray->GetCount(), kCharLimit); + count = std::min(count, kCharLimit - StartChar); + for (size_t i = 0; i < count; i++) { + m_CharWidthL[StartChar + i] = + FXSYS_round(pWidthArray->GetNumberAt(i) * xscale * 1000); + } } } m_pCharProcs = m_pFontDict->GetDictFor("CharProcs"); @@ -83,12 +84,14 @@ bool CPDF_Type3Font::Load() { return true; } +void CPDF_Type3Font::LoadGlyphMap() {} + void CPDF_Type3Font::CheckType3FontMetrics() { CheckFontMetrics(); } CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) { - if (m_CharLoadingDepth >= FPDF_MAX_TYPE3_FORM_LEVEL) + if (m_CharLoadingDepth >= kMaxType3FormLevel) return nullptr; auto it = m_CacheMap.find(charcode); diff --git a/core/fpdfapi/font/cpdf_type3font.h b/core/fpdfapi/font/cpdf_type3font.h index 913e0048a3..3f2e018c88 100644 --- a/core/fpdfapi/font/cpdf_type3font.h +++ b/core/fpdfapi/font/cpdf_type3font.h @@ -45,7 +45,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont { bool Load() override; // CPDF_SimpleFont: - void LoadGlyphMap() override {} + void LoadGlyphMap() override; int m_CharWidthL[256]; UnownedPtr m_pCharProcs; @@ -53,7 +53,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont { UnownedPtr m_pFontResources; std::map> m_CacheMap; // The depth char loading is in, to avoid recurive calling LoadChar(). - int m_CharLoadingDepth; + int m_CharLoadingDepth = 0; }; #endif // CORE_FPDFAPI_FONT_CPDF_TYPE3FONT_H_ -- cgit v1.2.3