summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-04 14:10:50 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-04 21:25:26 +0000
commitb8a8c43f394277d1f87320a4f01b4d5c38e81113 (patch)
treed7e0ffa2d9ed7aa9e31e506538aa450ecabed937 /core/fpdfapi/page
parentd74da7bb34abdae254df64ba2c0da7a581f6dae0 (diff)
downloadpdfium-b8a8c43f394277d1f87320a4f01b4d5c38e81113.tar.xz
CPDF_Document::GetPageData() normally does not return NULL.
Add a comment to clarify and remove some unneeded checks. Change-Id: I8b0492548b245abc45e161085047c9f36d6c8e2b Reviewed-on: https://pdfium-review.googlesource.com/4871 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_color.cpp3
-rw-r--r--core/fpdfapi/page/cpdf_textstate.cpp24
-rw-r--r--core/fpdfapi/page/cpdf_textstate.h3
3 files changed, 16 insertions, 14 deletions
diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp
index 6e772aadb1..ca0e621530 100644
--- a/core/fpdfapi/page/cpdf_color.cpp
+++ b/core/fpdfapi/page/cpdf_color.cpp
@@ -91,8 +91,7 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, float* comps, int ncomps) {
PatternValue* pvalue = (PatternValue*)m_pBuffer;
if (pvalue->m_pPattern) {
pDocPageData = pvalue->m_pPattern->document()->GetPageData();
- if (pDocPageData)
- pDocPageData->ReleasePattern(pvalue->m_pPattern->pattern_obj());
+ pDocPageData->ReleasePattern(pvalue->m_pPattern->pattern_obj());
}
pvalue->m_nComps = ncomps;
pvalue->m_pPattern = pPattern;
diff --git a/core/fpdfapi/page/cpdf_textstate.cpp b/core/fpdfapi/page/cpdf_textstate.cpp
index 6dbad55ba6..bd236a2f28 100644
--- a/core/fpdfapi/page/cpdf_textstate.cpp
+++ b/core/fpdfapi/page/cpdf_textstate.cpp
@@ -115,25 +115,16 @@ CPDF_TextState::TextData::TextData(const TextData& that)
for (int i = 0; i < 4; ++i)
m_CTM[i] = that.m_CTM[i];
- if (m_pDocument && m_pFont) {
+ if (m_pDocument && m_pFont)
m_pFont = m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict());
- }
}
CPDF_TextState::TextData::~TextData() {
- if (m_pDocument && m_pFont) {
- CPDF_DocPageData* pPageData = m_pDocument->GetPageData();
- if (pPageData && !pPageData->IsForceClear())
- pPageData->ReleaseFont(m_pFont->GetFontDict());
- }
+ ReleaseFont();
}
void CPDF_TextState::TextData::SetFont(CPDF_Font* pFont) {
- CPDF_Document* pDoc = m_pDocument;
- CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr;
- if (pPageData && m_pFont && !pPageData->IsForceClear())
- pPageData->ReleaseFont(m_pFont->GetFontDict());
-
+ ReleaseFont();
m_pDocument = pFont ? pFont->GetDocument() : nullptr;
m_pFont = pFont;
}
@@ -154,6 +145,15 @@ float CPDF_TextState::TextData::GetShearAngle() const {
return GetBaselineAngle() + atan2(m_Matrix[1], m_Matrix[3]);
}
+void CPDF_TextState::TextData::ReleaseFont() {
+ if (!m_pDocument || !m_pFont)
+ return;
+
+ CPDF_DocPageData* pPageData = m_pDocument->GetPageData();
+ if (pPageData && !pPageData->IsForceClear())
+ pPageData->ReleaseFont(m_pFont->GetFontDict());
+}
+
bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode) {
if (iMode < 0 || iMode > 7)
return false;
diff --git a/core/fpdfapi/page/cpdf_textstate.h b/core/fpdfapi/page/cpdf_textstate.h
index 07bee5ed04..84d2c13a6c 100644
--- a/core/fpdfapi/page/cpdf_textstate.h
+++ b/core/fpdfapi/page/cpdf_textstate.h
@@ -79,6 +79,9 @@ class CPDF_TextState {
TextRenderingMode m_TextMode;
float m_Matrix[4];
float m_CTM[4];
+
+ private:
+ void ReleaseFont();
};
CFX_SharedCopyOnWrite<TextData> m_Ref;