PDFDocumentImage.h [plain text]
#ifndef PDFDocumentImage_h
#define PDFDocumentImage_h
#include "AffineTransform.h"
#include "FloatRect.h"
#include "GraphicsTypes.h"
#include "Image.h"
#if USE(CG)
#if PLATFORM(MAC)
#define USE_PDFKIT_FOR_PDFDOCUMENTIMAGE 1
#endif
typedef struct CGPDFDocument *CGPDFDocumentRef;
OBJC_CLASS PDFDocument;
namespace WebCore {
class GraphicsContext;
class ImageBuffer;
class PDFDocumentImage final : public Image {
public:
static PassRefPtr<PDFDocumentImage> create(ImageObserver* observer)
{
return adoptRef(new PDFDocumentImage(observer));
}
void setCachedPDFImageEnabled(bool);
private:
PDFDocumentImage(ImageObserver*);
virtual ~PDFDocumentImage();
bool isPDFDocumentImage() const override { return true; }
String filenameExtension() const override;
bool hasSingleSecurityOrigin() const override { return true; }
bool dataChanged(bool allDataReceived) override;
void destroyDecodedData(bool = true) override;
void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) override;
FloatSize size() const override;
void draw(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientationDescription) override;
bool currentFrameKnownToBeOpaque() override { return false; }
void dump(TextStream&) const override;
void createPDFDocument();
void computeBoundsForCurrentPage();
unsigned pageCount() const;
void drawPDFPage(GraphicsContext&);
void decodedSizeChanged(size_t newCachedBytes);
void updateCachedImageIfNeeded(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect);
bool cacheParametersMatch(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect) const;
bool m_isCachedPDFImageEnabled { true };
#if USE(PDFKIT_FOR_PDFDOCUMENTIMAGE)
RetainPtr<PDFDocument> m_document;
#else
RetainPtr<CGPDFDocumentRef> m_document;
#endif
std::unique_ptr<ImageBuffer> m_cachedImageBuffer;
FloatRect m_cachedImageRect;
AffineTransform m_cachedTransform;
FloatSize m_cachedDestinationSize;
FloatRect m_cachedSourceRect;
size_t m_cachedBytes;
FloatRect m_cropBox;
int m_rotationDegrees; bool m_hasPage;
};
}
SPECIALIZE_TYPE_TRAITS_IMAGE(PDFDocumentImage)
#endif // USE(CG)
#endif // PDFDocumentImage_h