1/* 2 * Copyright (C) 2004, 2005, 2006, 2013 Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef PDFDocumentImage_h 27#define PDFDocumentImage_h 28 29#include "AffineTransform.h" 30#include "FloatRect.h" 31#include "GraphicsTypes.h" 32#include "Image.h" 33 34#if USE(CG) 35 36#if PLATFORM(MAC) && !PLATFORM(IOS) 37#define WTF_USE_PDFKIT_FOR_PDFDOCUMENTIMAGE 1 38#endif 39 40typedef struct CGPDFDocument *CGPDFDocumentRef; 41OBJC_CLASS PDFDocument; 42 43namespace WebCore { 44 45class GraphicsContext; 46class ImageBuffer; 47 48class PDFDocumentImage FINAL : public Image { 49public: 50 static PassRefPtr<PDFDocumentImage> create(ImageObserver* observer) 51 { 52 return adoptRef(new PDFDocumentImage(observer)); 53 } 54 55private: 56 PDFDocumentImage(ImageObserver*); 57 virtual ~PDFDocumentImage(); 58 59 virtual bool isPDFDocumentImage() const OVERRIDE { return true; } 60 61 virtual String filenameExtension() const OVERRIDE; 62 63 virtual bool hasSingleSecurityOrigin() const OVERRIDE { return true; } 64 65 virtual bool dataChanged(bool allDataReceived) OVERRIDE; 66 67 virtual void destroyDecodedData(bool /*destroyAll*/ = true) OVERRIDE; 68 virtual unsigned decodedSize() const OVERRIDE; 69 70 virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) OVERRIDE; 71 virtual IntSize size() const OVERRIDE; 72 73 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode) OVERRIDE; 74 75 // FIXME: Implement this to be less conservative. 76 virtual bool currentFrameKnownToBeOpaque() OVERRIDE { return false; } 77 78 void createPDFDocument(); 79 void computeBoundsForCurrentPage(); 80 unsigned pageCount() const; 81 void drawPDFPage(GraphicsContext*); 82 83 void updateCachedImageIfNeeded(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect); 84 bool cacheParametersMatch(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect) const; 85 86#if USE(PDFKIT_FOR_PDFDOCUMENTIMAGE) 87 RetainPtr<PDFDocument> m_document; 88#else 89 RetainPtr<CGPDFDocumentRef> m_document; 90#endif 91 92 OwnPtr<ImageBuffer> m_cachedImageBuffer; 93 AffineTransform m_cachedTransform; 94 FloatSize m_cachedDestinationSize; 95 FloatRect m_cachedSourceRect; 96 size_t m_cachedBytes; 97 98 FloatRect m_mediaBox; 99 FloatRect m_cropBox; 100 int m_rotationDegrees; // Can only be 0, 90, 180, or 270 degrees. 101 bool m_hasPage; 102}; 103 104} 105 106#endif // USE(CG) 107 108#endif // PDFDocumentImage_h 109