summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_edittext.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-05-03 17:19:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-03 17:19:53 +0000
commit525147a1f6d6cd736a407d1e189ac25d2f4726e8 (patch)
treebdc818c52d902a5a4e8ce8a4f0ba29bd11007b05 /fpdfsdk/fpdf_edittext.cpp
parentccd9421589922b8f35ee5330d7fdac7edea081db (diff)
downloadpdfium-525147a1f6d6cd736a407d1e189ac25d2f4726e8.tar.xz
Use strict types in FPDF API, try #3
Rather than messing with actual inheritence, add type-checking wrappers and just blatantly cast to incomplete types. Along the way, this points out places where we would downcast without checking, which I fix. Change-Id: Ieb303eb46ad8522dfe082454f1f10f247ffd52d5 Reviewed-on: https://pdfium-review.googlesource.com/32030 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_edittext.cpp')
-rw-r--r--fpdfsdk/fpdf_edittext.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 648d1dd5d5..2996a505ee 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -416,12 +416,18 @@ FPDFPageObj_NewTextObj(FPDF_DOCUMENT document,
pTextObj->m_TextState.SetFont(pFont);
pTextObj->m_TextState.SetFontSize(font_size);
pTextObj->DefaultStates();
- return pTextObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pTextObj.release());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFText_SetText(FPDF_PAGEOBJECT text_object, FPDF_WIDESTRING text) {
- auto* pTextObj = static_cast<CPDF_TextObject*>(text_object);
+ if (!text_object)
+ return false;
+
+ CPDF_TextObject* pTextObj =
+ CPDFPageObjectFromFPDFPageObject(text_object)->AsText();
if (!pTextObj)
return false;
@@ -455,8 +461,9 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFText_LoadFont(FPDF_DOCUMENT document,
if (!pFont->LoadEmbedded(data, size))
return nullptr;
- return cid ? LoadCompositeFont(pDoc, std::move(pFont), data, size, font_type)
- : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type);
+ return FPDFFontFromCPDFFont(
+ cid ? LoadCompositeFont(pDoc, std::move(pFont), data, size, font_type)
+ : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -469,7 +476,7 @@ FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object,
}
FPDF_EXPORT void FPDF_CALLCONV FPDFFont_Close(FPDF_FONT font) {
- CPDF_Font* pFont = static_cast<CPDF_Font*>(font);
+ CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
if (!pFont)
return;
@@ -487,7 +494,7 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size) {
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
- CPDF_Font* pFont = static_cast<CPDF_Font*>(font);
+ CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
if (!pDoc || !pFont)
return nullptr;
@@ -495,5 +502,5 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
pTextObj->m_TextState.SetFont(pDoc->LoadFont(pFont->GetFontDict()));
pTextObj->m_TextState.SetFontSize(font_size);
pTextObj->DefaultStates();
- return pTextObj.release();
+ return FPDFPageObjectFromCPDFPageObject(pTextObj.release());
}