summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--core/fpdfapi/parser/cpdf_document.h2
-rw-r--r--fpdfsdk/fpdfedittext.cpp19
5 files changed, 30 insertions, 21 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;
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index 2f54ba7c28..f7fb6308c1 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -58,6 +58,8 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
CPDF_Dictionary* GetPage(int iPage);
int GetPageIndex(uint32_t objnum);
uint32_t GetUserPermissions() const;
+
+ // Returns a valid pointer, unless it is called during destruction.
CPDF_DocPageData* GetPageData() const { return m_pDocPage.get(); }
void SetPageObjNum(int iPage, uint32_t objNum);
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index 4ff2269c9e..9b01775235 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -431,23 +431,28 @@ DLLEXPORT void STDCALL FPDFFont_Close(FPDF_FONT font) {
if (!font)
return;
- CPDF_Font* cpdf_font = reinterpret_cast<CPDF_Font*>(font);
- CPDF_Document* pDoc = cpdf_font->GetDocument();
- CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr;
- if (pPageData && !pPageData->IsForceClear())
- pPageData->ReleaseFont(cpdf_font->GetFontDict());
+ CPDF_Font* pFont = reinterpret_cast<CPDF_Font*>(font);
+ CPDF_Document* pDoc = pFont->GetDocument();
+ if (!pDoc)
+ return;
+
+ CPDF_DocPageData* pPageData = pDoc->GetPageData();
+ if (!pPageData->IsForceClear())
+ pPageData->ReleaseFont(pFont->GetFontDict());
}
DLLEXPORT FPDF_PAGEOBJECT STDCALL
FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size) {
+ if (!font)
+ return nullptr;
+
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
- if (!pDoc || !font)
+ if (!pDoc)
return nullptr;
CPDF_Font* pFont = reinterpret_cast<CPDF_Font*>(font);
-
auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>();
pTextObj->m_TextState.SetFont(pDoc->LoadFont(pFont->GetFontDict()));
pTextObj->m_TextState.SetFontSize(font_size);