summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-04 13:30:29 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-04 20:43:36 +0000
commitd74da7bb34abdae254df64ba2c0da7a581f6dae0 (patch)
tree353d21b86c4928e1d23aa54481591ecf7ad907ff
parentd41f4752c81d2dc8635595df7a9ab2b07f571c53 (diff)
downloadpdfium-d74da7bb34abdae254df64ba2c0da7a581f6dae0.tar.xz
Make CPDF_Font member variables protected.
Change-Id: I5d452ea907f4d243645ddae3512776096a827522 Reviewed-on: https://pdfium-review.googlesource.com/4872 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp7
-rw-r--r--core/fpdfapi/font/cpdf_font.h10
-rw-r--r--core/fpdfapi/page/cpdf_textstate.cpp2
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp11
-rw-r--r--core/fpdfapi/render/cpdf_textrenderer.cpp24
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp20
-rw-r--r--fpdfsdk/fpdfedittext.cpp2
-rw-r--r--xfa/fxfa/cxfa_pdffontmgr.cpp2
8 files changed, 46 insertions, 32 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 53186daec6..193ee4a331 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -290,6 +290,7 @@ int CPDF_Font::GetStringWidth(const char* pString, int size) {
return width;
}
+// static
CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc,
const CFX_ByteStringC& name) {
CFX_ByteString fontname(name);
@@ -469,3 +470,9 @@ int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode) {
return glyph;
}
+
+CFX_Font* CPDF_Font::GetFontFallback(int position) {
+ if (position < 0 || static_cast<size_t>(position) >= m_FontFallbacks.size())
+ return nullptr;
+ return m_FontFallbacks[position].get();
+}
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index de29db6e13..be1d91319e 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -78,9 +78,10 @@ class CPDF_Font {
virtual int GetCharWidthF(uint32_t charcode) = 0;
virtual FX_RECT GetCharBBox(uint32_t charcode) = 0;
- CPDF_Document* m_pDocument;
- CFX_Font m_Font;
- std::vector<std::unique_ptr<CFX_Font>> m_FontFallbacks;
+ CPDF_Document* GetDocument() { return m_pDocument; }
+ CFX_Font* GetFont() { return &m_Font; }
+ const CFX_Font* GetFont() const { return &m_Font; }
+ CFX_Font* GetFontFallback(int position);
protected:
CPDF_Font();
@@ -100,6 +101,9 @@ class CPDF_Font {
const std::vector<CFX_ByteString>& charnames,
int charcode);
+ CPDF_Document* m_pDocument;
+ CFX_Font m_Font;
+ std::vector<std::unique_ptr<CFX_Font>> m_FontFallbacks;
CFX_ByteString m_BaseFont;
CFX_RetainPtr<CPDF_StreamAcc> m_pFontFile;
CPDF_Dictionary* m_pFontDict;
diff --git a/core/fpdfapi/page/cpdf_textstate.cpp b/core/fpdfapi/page/cpdf_textstate.cpp
index ed90bd310d..6dbad55ba6 100644
--- a/core/fpdfapi/page/cpdf_textstate.cpp
+++ b/core/fpdfapi/page/cpdf_textstate.cpp
@@ -134,7 +134,7 @@ void CPDF_TextState::TextData::SetFont(CPDF_Font* pFont) {
if (pPageData && m_pFont && !pPageData->IsForceClear())
pPageData->ReleaseFont(m_pFont->GetFontDict());
- m_pDocument = pFont ? pFont->m_pDocument : nullptr;
+ m_pDocument = pFont ? pFont->GetDocument() : nullptr;
m_pFont = pFont;
}
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index d41561c057..0b304747d4 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -66,7 +66,7 @@
namespace {
void ReleaseCachedType3(CPDF_Type3Font* pFont) {
- CPDF_Document* pDoc = pFont->m_pDocument;
+ CPDF_Document* pDoc = pFont->GetDocument();
if (!pDoc)
return;
@@ -1799,7 +1799,7 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
CFX_RetainPtr<CPDF_Type3Cache> CPDF_RenderStatus::GetCachedType3(
CPDF_Type3Font* pFont) {
- CPDF_Document* pDoc = pFont->m_pDocument;
+ CPDF_Document* pDoc = pFont->GetDocument();
if (!pDoc)
return nullptr;
@@ -2000,10 +2000,9 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
CharPosList.Load(textobj->m_CharCodes, textobj->m_CharPos, pFont, font_size);
for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
- auto* font =
- charpos.m_FallbackFontPosition == -1
- ? &pFont->m_Font
- : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get();
+ auto* font = charpos.m_FallbackFontPosition == -1
+ ? pFont->GetFont()
+ : pFont->GetFontFallback(charpos.m_FallbackFontPosition);
const CFX_PathData* pPath =
font->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth);
if (!pPath)
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index c45c1ef792..83e61478da 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -15,6 +15,14 @@
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
+namespace {
+
+CFX_Font* GetFont(CPDF_Font* pFont, int32_t position) {
+ return position == -1 ? pFont->GetFont() : pFont->GetFontFallback(position);
+}
+
+} // namespace
+
// static
bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
const std::vector<uint32_t>& charCodes,
@@ -40,9 +48,8 @@ bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
if (fontPosition == curFontPosition)
continue;
- auto* font = fontPosition == -1
- ? &pFont->m_Font
- : pFont->m_FontFallbacks[fontPosition].get();
+
+ CFX_Font* font = GetFont(pFont, fontPosition);
if (!pDevice->DrawTextPath(i - startIndex,
CharPosList.m_pCharPos + startIndex, font,
font_size, pText2User, pUser2Device, pGraphState,
@@ -52,8 +59,7 @@ bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
fontPosition = curFontPosition;
startIndex = i;
}
- auto* font = fontPosition == -1 ? &pFont->m_Font
- : pFont->m_FontFallbacks[fontPosition].get();
+ CFX_Font* font = GetFont(pFont, fontPosition);
if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex,
CharPosList.m_pCharPos + startIndex, font,
font_size, pText2User, pUser2Device, pGraphState,
@@ -145,9 +151,8 @@ bool CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
if (fontPosition == curFontPosition)
continue;
- auto* font = fontPosition == -1
- ? &pFont->m_Font
- : pFont->m_FontFallbacks[fontPosition].get();
+
+ CFX_Font* font = GetFont(pFont, fontPosition);
if (!pDevice->DrawNormalText(
i - startIndex, CharPosList.m_pCharPos + startIndex, font,
font_size, pText2Device, fill_argb, FXGE_flags)) {
@@ -156,8 +161,7 @@ bool CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
fontPosition = curFontPosition;
startIndex = i;
}
- auto* font = fontPosition == -1 ? &pFont->m_Font
- : pFont->m_FontFallbacks[fontPosition].get();
+ CFX_Font* font = GetFont(pFont, fontPosition);
if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex,
CharPosList.m_pCharPos + startIndex, font,
font_size, pText2Device, fill_argb,
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 383e207f54..05b665b33f 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -554,8 +554,8 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleType1Font) {
// TODO(npm): use other fonts after disallowing loading any font as any type
const CPDF_Font* stock_font =
CPDF_Font::GetStockFont(cpdf_doc(), "Times-Bold");
- const uint8_t* data = stock_font->m_Font.GetFontData();
- const uint32_t size = stock_font->m_Font.GetSize();
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
std::unique_ptr<void, FPDFFontDeleter> font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, false));
ASSERT_TRUE(font.get());
@@ -583,8 +583,8 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleType1Font) {
TEST_F(FPDFEditEmbeddertest, LoadSimpleTrueTypeFont) {
CreateNewDocument();
const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Courier");
- const uint8_t* data = stock_font->m_Font.GetFontData();
- const uint32_t size = stock_font->m_Font.GetSize();
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
std::unique_ptr<void, FPDFFontDeleter> font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, false));
ASSERT_TRUE(font.get());
@@ -613,8 +613,8 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType0Font) {
CreateNewDocument();
const CPDF_Font* stock_font =
CPDF_Font::GetStockFont(cpdf_doc(), "Times-Roman");
- const uint8_t* data = stock_font->m_Font.GetFontData();
- const uint32_t size = stock_font->m_Font.GetSize();
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
std::unique_ptr<void, FPDFFontDeleter> font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, 1));
ASSERT_TRUE(font.get());
@@ -654,8 +654,8 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType2Font) {
CreateNewDocument();
const CPDF_Font* stock_font =
CPDF_Font::GetStockFont(cpdf_doc(), "Helvetica-Oblique");
- const uint8_t* data = stock_font->m_Font.GetFontData();
- const uint32_t size = stock_font->m_Font.GetSize();
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
std::unique_ptr<void, FPDFFontDeleter> font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1));
@@ -707,8 +707,8 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) {
FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
{
const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Arial");
- const uint8_t* data = stock_font->m_Font.GetFontData();
- const uint32_t size = stock_font->m_Font.GetSize();
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
std::unique_ptr<void, FPDFFontDeleter> font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 0));
ASSERT_TRUE(font.get());
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index cfb44f513d..4ff2269c9e 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -432,7 +432,7 @@ DLLEXPORT void STDCALL FPDFFont_Close(FPDF_FONT font) {
return;
CPDF_Font* cpdf_font = reinterpret_cast<CPDF_Font*>(font);
- CPDF_Document* pDoc = cpdf_font->m_pDocument;
+ CPDF_Document* pDoc = cpdf_font->GetDocument();
CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr;
if (pPageData && !pPageData->IsForceClear())
pPageData->ReleaseFont(cpdf_font->GetFontDict());
diff --git a/xfa/fxfa/cxfa_pdffontmgr.cpp b/xfa/fxfa/cxfa_pdffontmgr.cpp
index cadb7cbab5..9e2cf68801 100644
--- a/xfa/fxfa/cxfa_pdffontmgr.cpp
+++ b/xfa/fxfa/cxfa_pdffontmgr.cpp
@@ -67,7 +67,7 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont(
*pDstPDFFont = pPDFFont;
return nullptr;
}
- return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr);
+ return CFGAS_GEFont::LoadFont(pPDFFont->GetFont(), pFDEFontMgr);
}
return nullptr;
}