summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-22 16:45:48 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-22 16:45:48 -0400
commitaa435ba7fe0aacd9102e8c73311c5382ca112439 (patch)
treed37573646c6135126d3971358024a70ee222fb21 /core/src/fpdfapi/fpdf_font
parent2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (diff)
downloadpdfium-aa435ba7fe0aacd9102e8c73311c5382ca112439.tar.xz
Merge to XFA: Add type cast definitions for CPDF_Stream.
This Cl adds ToStream, CPDF_Object::AsStream and CPDF_Object::IsStream and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1402413004 . (cherry picked from commit 338805f1366dcdf9a5b48cf591541cf98d7490f1) Review URL: https://codereview.chromium.org/1422513004 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_font')
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp60
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp7
2 files changed, 32 insertions, 35 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index eb1f52333b..0236d4c334 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -119,7 +119,7 @@ CPDF_Font::~CPDF_Font() {
if (m_pFontFile) {
m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
- (CPDF_Stream*)m_pFontFile->GetStream());
+ const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream()));
}
}
FX_BOOL CPDF_Font::IsVertWriting() const {
@@ -258,24 +258,22 @@ void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) {
m_FontBBox.top = pBBox->GetInteger(3);
}
CPDF_Stream* pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile"));
- if (pFontFile == NULL) {
+ if (!pFontFile)
pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile2"));
- }
- if (pFontFile == NULL) {
+ if (!pFontFile)
pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile3"));
- }
- if (pFontFile) {
- m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
- if (m_pFontFile == NULL) {
- return;
- }
- const uint8_t* pFontData = m_pFontFile->GetData();
- FX_DWORD dwFontSize = m_pFontFile->GetSize();
- m_Font.LoadEmbedded(pFontData, dwFontSize);
- if (m_Font.m_Face == NULL) {
- m_pFontFile = NULL;
- }
- }
+ if (!pFontFile)
+ return;
+
+ m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
+ if (!m_pFontFile)
+ return;
+
+ const uint8_t* pFontData = m_pFontFile->GetData();
+ FX_DWORD dwFontSize = m_pFontFile->GetSize();
+ m_Font.LoadEmbedded(pFontData, dwFontSize);
+ if (!m_Font.m_Face)
+ m_pFontFile = nullptr;
}
short TT2PDF(int m, FXFT_Face face) {
int upm = FXFT_Get_Face_UnitsPerEM(face);
@@ -1710,10 +1708,10 @@ void CPDF_Type3Font::CheckType3FontMetrics() {
CheckFontMetrics();
}
CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
- if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) {
- return NULL;
- }
- CPDF_Type3Char* pChar = NULL;
+ if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_)
+ return nullptr;
+
+ CPDF_Type3Char* pChar = nullptr;
if (m_CacheMap.Lookup((void*)(uintptr_t)charcode, (void*&)pChar)) {
if (pChar->m_bPageRequired && m_pPageResources) {
delete pChar;
@@ -1724,19 +1722,19 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
}
const FX_CHAR* name =
GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- return NULL;
- }
+ if (!name)
+ return nullptr;
+
CPDF_Stream* pStream =
- (CPDF_Stream*)(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : NULL);
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
+ ToStream(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : nullptr);
+ if (!pStream)
+ return nullptr;
+
pChar = new CPDF_Type3Char;
pChar->m_pForm = new CPDF_Form(
m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources,
- pStream, NULL);
- pChar->m_pForm->ParseContent(NULL, NULL, pChar, NULL, level + 1);
+ pStream, nullptr);
+ pChar->m_pForm->ParseContent(nullptr, nullptr, pChar, nullptr, level + 1);
FX_FLOAT scale = m_FontMatrix.GetXUnit();
pChar->m_Width = (int32_t)(pChar->m_Width * scale + 0.5f);
FX_RECT& rcBBox = pChar->m_BBox;
@@ -1754,7 +1752,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
m_CacheMap.SetAt((void*)(uintptr_t)charcode, pChar);
if (pChar->m_pForm->CountObjects() == 0) {
delete pChar->m_pForm;
- pChar->m_pForm = NULL;
+ pChar->m_pForm = nullptr;
}
return pChar;
}
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 687e8e1d92..1b1ba8b0a4 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -1215,9 +1215,8 @@ FX_BOOL CPDF_CIDFont::_Load() {
->GetPageModule()
->GetFontGlobals()
->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1);
- } else if (pEncoding->GetType() == PDFOBJ_STREAM) {
+ } else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
m_pAllocatedCMap = m_pCMap = new CPDF_CMap;
- CPDF_Stream* pStream = (CPDF_Stream*)pEncoding;
CPDF_StreamAcc acc;
acc.LoadAllData(pStream, FALSE);
m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
@@ -1265,9 +1264,9 @@ FX_BOOL CPDF_CIDFont::_Load() {
CPDF_Object* pmap =
pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGIDMap"));
if (pmap) {
- if (pmap->GetType() == PDFOBJ_STREAM) {
+ if (CPDF_Stream* pStream = pmap->AsStream()) {
m_pCIDToGIDMap = new CPDF_StreamAcc;
- m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, FALSE);
+ m_pCIDToGIDMap->LoadAllData(pStream, FALSE);
} else if (pmap->GetString() == FX_BSTRC("Identity")) {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
if (m_pFontFile) {