From 525147a1f6d6cd736a407d1e189ac25d2f4726e8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 3 May 2018 17:19:53 +0000 Subject: 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 Commit-Queue: Tom Sepez --- fpdfsdk/cpdfsdk_helpers.h | 167 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 6 deletions(-) (limited to 'fpdfsdk/cpdfsdk_helpers.h') diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h index 937ceed75e..0cd2617412 100644 --- a/fpdfsdk/cpdfsdk_helpers.h +++ b/fpdfsdk/cpdfsdk_helpers.h @@ -23,17 +23,28 @@ #endif class CPDF_Annot; +class CPDF_AnnotContext; +class CPDF_ClipPath; +class CPDF_ContentMarkItem; +class CPDF_Object; +class CPDF_Font; +class CPDF_LinkExtract; class CPDF_Page; class CPDF_PageObject; class CPDF_PageRenderContext; class CPDF_PathObject; class CPDF_Stream; +class CPDF_StructElement; +class CPDF_StructTree; +class CPDF_TextPage; +class CPDF_TextPageFind; class IPDFSDK_PauseAdapter; class FX_PATHPOINT; #ifdef PDF_ENABLE_XFA class CPDFXFA_Context; class CPDFXFA_Page; +class CXFA_FFWidget; #endif // PDF_ENABLE_XFA // Object types for public FPDF_ types; these correspond to next layer down @@ -48,17 +59,161 @@ using UnderlyingPageType = CPDFXFA_Page; // Conversions to/from underlying types. UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); FPDF_PAGE FPDFPageFromUnderlying(UnderlyingPageType* page); - -// Conversions to/from FPDF_ types. -CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); +CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page); FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); +CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); + +// Conversions to/from incomplete FPDF_ API types. +inline FPDF_ACTION FPDFActionFromCPDFDictionary(CPDF_Dictionary* action) { + return reinterpret_cast(action); +} +inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) { + return reinterpret_cast(action); +} + +inline FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext( + CPDF_AnnotContext* annot) { + return reinterpret_cast(annot); +} +inline CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation( + FPDF_ANNOTATION annot) { + return reinterpret_cast(annot); +} + +inline FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object* attachment) { + return reinterpret_cast(attachment); +} +inline CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) { + return reinterpret_cast(attachment); +} + +inline FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap* bitmap) { + return reinterpret_cast(bitmap); +} +inline CFX_DIBitmap* CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { + return reinterpret_cast(bitmap); +} + +inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(CPDF_Dictionary* bookmark) { + return reinterpret_cast(bookmark); +} +inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) { + return reinterpret_cast(bookmark); +} + +inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) { + return reinterpret_cast(path); +} +inline CPDF_ClipPath* CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path) { + return reinterpret_cast(path); +} + +inline FPDF_DEST FPDFDestFromCPDFArray(CPDF_Array* dest) { + return reinterpret_cast(dest); +} +inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) { + return reinterpret_cast(dest); +} + +inline FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font* font) { + return reinterpret_cast(font); +} +inline CPDF_Font* CPDFFontFromFPDFFont(FPDF_FONT font) { + return reinterpret_cast(font); +} + +inline FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary* link) { + return reinterpret_cast(link); +} +inline CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) { + return reinterpret_cast(link); +} + +inline FPDF_PAGELINK FPDFPageLinkFromCPDFLinkExtract(CPDF_LinkExtract* link) { + return reinterpret_cast(link); +} +inline CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) { + return reinterpret_cast(link); +} + +inline FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject( + CPDF_PageObject* page_object) { + return reinterpret_cast(page_object); +} +inline CPDF_PageObject* CPDFPageObjectFromFPDFPageObject( + FPDF_PAGEOBJECT page_object) { + return reinterpret_cast(page_object); +} + +inline FPDF_PAGEOBJECTMARK FPDFPageObjectMarkFromCPDFContentMarkItem( + const CPDF_ContentMarkItem* mark) { + return reinterpret_cast(mark); +} +inline const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark( + FPDF_PAGEOBJECTMARK mark) { + return reinterpret_cast(mark); +} + +inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(CPDF_Array* range) { + return reinterpret_cast(range); +} +inline CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) { + return reinterpret_cast(range); +} + +inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint( + const FX_PATHPOINT* segment) { + return reinterpret_cast(segment); +} +inline const FX_PATHPOINT* FXPathPointFromFPDFPathSegment( + FPDF_PATHSEGMENT segment) { + return reinterpret_cast(segment); +} + +inline FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree( + CPDF_StructTree* struct_tree) { + return reinterpret_cast(struct_tree); +} +inline CPDF_StructTree* CPDFStructTreeFromFPDFStructTree( + FPDF_STRUCTTREE struct_tree) { + return reinterpret_cast(struct_tree); +} + +inline FPDF_STRUCTELEMENT FPDFStructElementFromCPDFStructElement( + CPDF_StructElement* struct_element) { + return reinterpret_cast(struct_element); +} +inline CPDF_StructElement* CPDFStructElementFromFPDFStructElement( + FPDF_STRUCTELEMENT struct_element) { + return reinterpret_cast(struct_element); +} + +inline FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage* page) { + return reinterpret_cast(page); +} +inline CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page) { + return reinterpret_cast(page); +} + +inline FPDF_SCHHANDLE FPDFSchHandleFromCPDFTextPageFind( + CPDF_TextPageFind* handle) { + return reinterpret_cast(handle); +} +inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle( + FPDF_SCHHANDLE handle) { + return reinterpret_cast(handle); +} -CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page); -CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object); ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string); -CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap); #ifdef PDF_ENABLE_XFA +inline FPDF_WIDGET FPDFWidgetFromCXFAFFWidget(CXFA_FFWidget* widget) { + return reinterpret_cast(widget); +} +inline CXFA_FFWidget* CXFAFFWidgetFromFPDFWidget(FPDF_WIDGET widget) { + return reinterpret_cast(widget); +} + // Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't // be a static method of IFX_SeekableStream. RetainPtr MakeSeekableStream( -- cgit v1.2.3