diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-05-03 17:19:53 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-03 17:19:53 +0000 |
commit | 525147a1f6d6cd736a407d1e189ac25d2f4726e8 (patch) | |
tree | bdc818c52d902a5a4e8ce8a4f0ba29bd11007b05 /fpdfsdk/fpdf_editimg.cpp | |
parent | ccd9421589922b8f35ee5330d7fdac7edea081db (diff) | |
download | pdfium-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_editimg.cpp')
-rw-r--r-- | fpdfsdk/fpdf_editimg.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp index f1d90ece2d..9485a75002 100644 --- a/fpdfsdk/fpdf_editimg.cpp +++ b/fpdfsdk/fpdf_editimg.cpp @@ -57,8 +57,10 @@ bool LoadJpegHelper(FPDF_PAGE* pages, if (!image_object || !fileAccess) return false; - RetainPtr<IFX_SeekableReadStream> pFile = MakeSeekableReadStream(fileAccess); - CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object); + CPDF_ImageObject* pImgObj = + CPDFPageObjectFromFPDFPageObject(image_object)->AsImage(); + if (!pImgObj) + return false; if (pages) { for (int index = 0; index < nCount; index++) { @@ -68,6 +70,7 @@ bool LoadJpegHelper(FPDF_PAGE* pages, } } + RetainPtr<IFX_SeekableReadStream> pFile = MakeSeekableReadStream(fileAccess); if (inlineJpeg) pImgObj->GetImage()->SetJpegImageInline(pFile); else @@ -86,7 +89,9 @@ FPDFPageObj_NewImageObj(FPDF_DOCUMENT document) { auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); pImageObj->SetImage(pdfium::MakeRetain<CPDF_Image>(pDoc)); - return pImageObj.release(); + + // Caller takes ownership. + return FPDFPageObjectFromCPDFPageObject(pImageObj.release()); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV @@ -116,7 +121,11 @@ FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, if (!image_object) return false; - CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object); + CPDF_ImageObject* pImgObj = + CPDFPageObjectFromFPDFPageObject(image_object)->AsImage(); + if (!pImgObj) + return false; + pImgObj->set_matrix(CFX_Matrix(static_cast<float>(a), static_cast<float>(b), static_cast<float>(c), static_cast<float>(d), static_cast<float>(e), static_cast<float>(f))); @@ -133,13 +142,17 @@ FPDFImageObj_SetBitmap(FPDF_PAGE* pages, if (!image_object || !bitmap || !pages) return false; - CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object); + CPDF_ImageObject* pImgObj = + CPDFPageObjectFromFPDFPageObject(image_object)->AsImage(); + if (!pImgObj) + return false; + for (int index = 0; index < nCount; index++) { CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); if (pPage) pImgObj->GetImage()->ResetCache(pPage, nullptr); } - RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap)); + RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap)); pImgObj->GetImage()->SetImage(holder); pImgObj->CalcBoundingBox(); pImgObj->SetDirty(true); @@ -170,7 +183,7 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) { else pBitmap = pSource->Clone(nullptr); - return pBitmap.Leak(); + return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak()); } FPDF_EXPORT unsigned long FPDF_CALLCONV |