diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkDocument.cpp (renamed from src/doc/SkDocument.cpp) | 0 | ||||
-rw-r--r-- | src/pdf/SkDocument_PDF_None.cpp (renamed from src/doc/SkDocument_PDF_None.cpp) | 0 | ||||
-rw-r--r-- | src/pdf/SkPDFDocument.cpp (renamed from src/doc/SkDocument_PDF.cpp) | 35 | ||||
-rw-r--r-- | src/pdf/SkPDFDocument.h | 18 | ||||
-rw-r--r-- | src/xps/SkConstexprMath.h | 54 | ||||
-rw-r--r-- | src/xps/SkDocument_XPS.cpp (renamed from src/doc/SkDocument_XPS.cpp) | 0 | ||||
-rw-r--r-- | src/xps/SkDocument_XPS_None.cpp (renamed from src/doc/SkDocument_XPS_None.cpp) | 0 | ||||
-rw-r--r-- | src/xps/SkXPSDevice.cpp (renamed from src/device/xps/SkXPSDevice.cpp) | 0 | ||||
-rw-r--r-- | src/xps/SkXPSDevice.h | 324 |
9 files changed, 414 insertions, 17 deletions
diff --git a/src/doc/SkDocument.cpp b/src/core/SkDocument.cpp index fa25e44f86..fa25e44f86 100644 --- a/src/doc/SkDocument.cpp +++ b/src/core/SkDocument.cpp diff --git a/src/doc/SkDocument_PDF_None.cpp b/src/pdf/SkDocument_PDF_None.cpp index f146cba018..f146cba018 100644 --- a/src/doc/SkDocument_PDF_None.cpp +++ b/src/pdf/SkDocument_PDF_None.cpp diff --git a/src/doc/SkDocument_PDF.cpp b/src/pdf/SkPDFDocument.cpp index c866648ae7..bacd9eccc7 100644 --- a/src/doc/SkDocument_PDF.cpp +++ b/src/pdf/SkPDFDocument.cpp @@ -5,17 +5,15 @@ * found in the LICENSE file. */ -#include "SkDocument.h" #include "SkPDFCanon.h" #include "SkPDFDevice.h" +#include "SkPDFDocument.h" #include "SkPDFFont.h" +#include "SkPDFMetadata.h" #include "SkPDFStream.h" #include "SkPDFTypes.h" #include "SkPDFUtils.h" #include "SkStream.h" -#include "SkPDFMetadata.h" - -class SkPDFDict; static void emit_pdf_header(SkWStream* stream) { stream->writeText("%PDF-1.4\n%"); @@ -309,9 +307,9 @@ template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp //////////////////////////////////////////////////////////////////////////////// namespace { -class SkDocument_PDF : public SkDocument { +class SkPDFDocument : public SkDocument { public: - SkDocument_PDF(SkWStream* stream, + SkPDFDocument(SkWStream* stream, void (*doneProc)(SkWStream*, bool), SkScalar rasterDpi, SkPixelSerializer* jpegEncoder) @@ -320,7 +318,7 @@ public: fCanon.setPixelSerializer(SkSafeRef(jpegEncoder)); } - virtual ~SkDocument_PDF() { + virtual ~SkPDFDocument() { // subclasses must call close() in their destructors this->close(); } @@ -380,24 +378,27 @@ private: } // namespace /////////////////////////////////////////////////////////////////////////////// +sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, + void (*proc)(SkWStream*, bool), + SkScalar dpi, + SkPixelSerializer* jpeg) { + return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, jpeg) : nullptr; +} + SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { - return stream ? new SkDocument_PDF(stream, nullptr, dpi, nullptr) : nullptr; + return SkPDFMakeDocument(stream, nullptr, dpi, nullptr).release(); } SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi, SkPixelSerializer* jpegEncoder) { - return stream - ? new SkDocument_PDF(stream, nullptr, dpi, jpegEncoder) - : nullptr; + return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); } SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { - SkFILEWStream* stream = new SkFILEWStream(path); - if (!stream->isValid()) { - delete stream; - return nullptr; - } auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; - return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr); + SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); + return stream->isValid() + ? SkPDFMakeDocument(stream.detach(), delete_wstream, dpi, nullptr).release() + : nullptr; } diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h new file mode 100644 index 0000000000..8ed76778fe --- /dev/null +++ b/src/pdf/SkPDFDocument.h @@ -0,0 +1,18 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkPDFDocument_DEFINED +#define SkPDFDocument_DEFINED + +#include "SkDocument.h" + +sk_sp<SkDocument> SkPDFMakeDocument( + SkWStream* stream, + void (*doneProc)(SkWStream*, bool), + SkScalar rasterDpi, + SkPixelSerializer* jpegEncoder); + +#endif // SkPDFDocument_DEFINED diff --git a/src/xps/SkConstexprMath.h b/src/xps/SkConstexprMath.h new file mode 100644 index 0000000000..9625d5112b --- /dev/null +++ b/src/xps/SkConstexprMath.h @@ -0,0 +1,54 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkConstexprMath_DEFINED +#define SkConstexprMath_DEFINED + +#include "SkTypes.h" +#include <limits.h> + +template <uintmax_t N, uintmax_t B> +struct SK_LOG { + //! Compile-time constant ceiling(logB(N)). + static const uintmax_t value = 1 + SK_LOG<N/B, B>::value; +}; +template <uintmax_t B> +struct SK_LOG<1, B> { + static const uintmax_t value = 0; +}; +template <uintmax_t B> +struct SK_LOG<0, B> { + static const uintmax_t value = 0; +}; + +template<uintmax_t N> +struct SK_2N1 { + //! Compile-time constant (2^N)-1. + static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1; +}; +template<> +struct SK_2N1<1> { + static const uintmax_t value = 1; +}; + +/** Compile-time constant number of base n digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_BASE_N_DIGITS_IN(n, t) (\ + SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\ +) +/** Compile-time constant number of base 10 digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) + +// Compile-time constant maximum value of two unsigned values. +template <uintmax_t a, uintmax_t b> struct SkTUMax { + static const uintmax_t value = (b < a) ? a : b; +}; + +#endif diff --git a/src/doc/SkDocument_XPS.cpp b/src/xps/SkDocument_XPS.cpp index 0e241d9aaa..0e241d9aaa 100644 --- a/src/doc/SkDocument_XPS.cpp +++ b/src/xps/SkDocument_XPS.cpp diff --git a/src/doc/SkDocument_XPS_None.cpp b/src/xps/SkDocument_XPS_None.cpp index 32b18fb221..32b18fb221 100644 --- a/src/doc/SkDocument_XPS_None.cpp +++ b/src/xps/SkDocument_XPS_None.cpp diff --git a/src/device/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index e4ac2aa742..e4ac2aa742 100644 --- a/src/device/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp diff --git a/src/xps/SkXPSDevice.h b/src/xps/SkXPSDevice.h new file mode 100644 index 0000000000..57f314851e --- /dev/null +++ b/src/xps/SkXPSDevice.h @@ -0,0 +1,324 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkXPSDevice_DEFINED +#define SkXPSDevice_DEFINED + +#include "SkTypes.h" + +#ifdef SK_BUILD_FOR_WIN + +#include <ObjBase.h> +#include <XpsObjectModel.h> + +#include "SkAutoCoInitialize.h" +#include "SkBitmapDevice.h" +#include "SkBitSet.h" +#include "SkCanvas.h" +#include "SkColor.h" +#include "SkPaint.h" +#include "SkPath.h" +#include "SkPoint.h" +#include "SkShader.h" +#include "SkSize.h" +#include "SkTArray.h" +#include "SkTScopedComPtr.h" +#include "SkTypeface.h" + +//#define SK_XPS_USE_DETERMINISTIC_IDS + +/** \class SkXPSDevice + + The drawing context for the XPS backend. +*/ +class SkXPSDevice : public SkBitmapDevice { +public: + SK_API SkXPSDevice(); + SK_API virtual ~SkXPSDevice(); + + virtual bool beginPortfolio(SkWStream* outputStream); + /** + @param unitsPerMeter converts geometry units into physical units. + @param pixelsPerMeter resolution to use when geometry must be rasterized. + @param trimSize final page size in physical units. + The top left of the trim is the origin of physical space. + @param mediaBox The size of the physical media in physical units. + The top and left must be less than zero. + The bottom and right must be greater than the trimSize. + The default is to coincide with the trimSize. + @param bleedBox The size of the bleed box in physical units. + Must be contained within the mediaBox. + The default is to coincide with the mediaBox. + @param artBox The size of the content box in physical units. + Must be contained within the trimSize. + The default is to coincide with the trimSize. + @param cropBox The size of the recommended view port in physical units. + Must be contained within the mediaBox. + The default is to coincide with the mediaBox. + */ + virtual bool beginSheet( + const SkVector& unitsPerMeter, + const SkVector& pixelsPerMeter, + const SkSize& trimSize, + const SkRect* mediaBox = NULL, + const SkRect* bleedBox = NULL, + const SkRect* artBox = NULL, + const SkRect* cropBox = NULL); + + virtual bool endSheet(); + virtual bool endPortfolio(); + +protected: + void drawPaint(const SkDraw&, const SkPaint& paint) override; + + virtual void drawPoints( + const SkDraw&, + SkCanvas::PointMode mode, + size_t count, const SkPoint[], + const SkPaint& paint) override; + + virtual void drawRect( + const SkDraw&, + const SkRect& r, + const SkPaint& paint) override; + + virtual void drawRRect( + const SkDraw&, + const SkRRect&, + const SkPaint& paint) override; + + virtual void drawPath( + const SkDraw&, + const SkPath& platonicPath, + const SkPaint& paint, + const SkMatrix* prePathMatrix, + bool pathIsMutable) override; + + virtual void drawBitmap( + const SkDraw&, + const SkBitmap& bitmap, + const SkMatrix& matrix, + const SkPaint& paint) override; + + virtual void drawSprite( + const SkDraw&, + const SkBitmap& bitmap, + int x, int y, + const SkPaint& paint) override; + + virtual void drawText( + const SkDraw&, + const void* text, size_t len, + SkScalar x, SkScalar y, + const SkPaint& paint) override; + + virtual void drawPosText( + const SkDraw&, + const void* text, size_t len, + const SkScalar pos[], int scalarsPerPos, + const SkPoint& offset, const SkPaint& paint) override; + + virtual void drawVertices( + const SkDraw&, + SkCanvas::VertexMode, + int vertexCount, const SkPoint verts[], + const SkPoint texs[], const SkColor colors[], + SkXfermode* xmode, + const uint16_t indices[], int indexCount, + const SkPaint& paint) override; + + virtual void drawDevice( + const SkDraw&, + SkBaseDevice* device, + int x, int y, + const SkPaint& paint) override; + +private: + class TypefaceUse : ::SkNoncopyable { + public: + SkFontID typefaceId; + int ttcIndex; + SkStream* fontData; + IXpsOMFontResource* xpsFont; + SkBitSet* glyphsUsed; + + explicit TypefaceUse(); + ~TypefaceUse(); + }; + friend static HRESULT subset_typeface(TypefaceUse* current); + + SkXPSDevice(IXpsOMObjectFactory* xpsFactory); + + SkAutoCoInitialize fAutoCo; + SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory; + SkTScopedComPtr<IStream> fOutputStream; + SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter; + + unsigned int fCurrentPage; + SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas; + SkSize fCurrentCanvasSize; + SkVector fCurrentUnitsPerMeter; + SkVector fCurrentPixelsPerMeter; + + SkTArray<TypefaceUse, true> fTypefaces; + + /** Creates a GUID based id and places it into buffer. + buffer should have space for at least GUID_ID_LEN wide characters. + The string will always be wchar null terminated. + XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0 + The string may begin with a digit, + and so may not be suitable as a bare resource key. + */ + HRESULT createId(wchar_t* buffer, size_t bufferSize, wchar_t sep = '-'); +#ifdef SK_XPS_USE_DETERMINISTIC_IDS + decltype(GUID::Data1) fNextId = 0; +#endif + + HRESULT initXpsDocumentWriter(IXpsOMImageResource* image); + + HRESULT createXpsPage( + const XPS_SIZE& pageSize, + IXpsOMPage** page); + + HRESULT createXpsThumbnail( + IXpsOMPage* page, const unsigned int pageNumber, + IXpsOMImageResource** image); + + void internalDrawRect( + const SkDraw&, + const SkRect& r, + bool transformRect, + const SkPaint& paint); + + HRESULT createXpsBrush( + const SkPaint& skPaint, + IXpsOMBrush** xpsBrush, + const SkMatrix* parentTransform = NULL); + + HRESULT createXpsSolidColorBrush( + const SkColor skColor, const SkAlpha alpha, + IXpsOMBrush** xpsBrush); + + HRESULT createXpsImageBrush( + const SkBitmap& bitmap, + const SkMatrix& localMatrix, + const SkShader::TileMode (&xy)[2], + const SkAlpha alpha, + IXpsOMTileBrush** xpsBrush); + + HRESULT createXpsLinearGradient( + SkShader::GradientInfo info, + const SkAlpha alpha, + const SkMatrix& localMatrix, + IXpsOMMatrixTransform* xpsMatrixToUse, + IXpsOMBrush** xpsBrush); + + HRESULT createXpsRadialGradient( + SkShader::GradientInfo info, + const SkAlpha alpha, + const SkMatrix& localMatrix, + IXpsOMMatrixTransform* xpsMatrixToUse, + IXpsOMBrush** xpsBrush); + + HRESULT createXpsGradientStop( + const SkColor skColor, + const SkScalar offset, + IXpsOMGradientStop** xpsGradStop); + + HRESULT createXpsTransform( + const SkMatrix& matrix, + IXpsOMMatrixTransform ** xpsTransform); + + HRESULT createXpsRect( + const SkRect& rect, + BOOL stroke, BOOL fill, + IXpsOMGeometryFigure** xpsRect); + + HRESULT createXpsQuad( + const SkPoint (&points)[4], + BOOL stroke, BOOL fill, + IXpsOMGeometryFigure** xpsQuad); + + HRESULT CreateTypefaceUse( + const SkPaint& paint, + TypefaceUse** fontResource); + + HRESULT AddGlyphs( + const SkDraw& d, + IXpsOMObjectFactory* xpsFactory, + IXpsOMCanvas* canvas, + TypefaceUse* font, + LPCWSTR text, + XPS_GLYPH_INDEX* xpsGlyphs, + UINT32 xpsGlyphsLen, + XPS_POINT *origin, + FLOAT fontSize, + XPS_STYLE_SIMULATION sims, + const SkMatrix& transform, + const SkPaint& paint); + + HRESULT addXpsPathGeometry( + IXpsOMGeometryFigureCollection* figures, + BOOL stroke, BOOL fill, const SkPath& path); + + HRESULT createPath( + IXpsOMGeometryFigure* figure, + IXpsOMVisualCollection* visuals, + IXpsOMPath** path); + + HRESULT sideOfClamp( + const SkRect& leftPoints, const XPS_RECT& left, + IXpsOMImageResource* imageResource, + IXpsOMVisualCollection* visuals); + + HRESULT cornerOfClamp( + const SkRect& tlPoints, + const SkColor color, + IXpsOMVisualCollection* visuals); + + HRESULT clip( + IXpsOMVisual* xpsVisual, + const SkDraw& d); + HRESULT clipToPath( + IXpsOMVisual* xpsVisual, + const SkPath& clipPath, + XPS_FILL_RULE fillRule); + + HRESULT drawInverseWindingPath( + const SkDraw& d, + const SkPath& devicePath, + IXpsOMPath* xpsPath); + + HRESULT shadePath( + IXpsOMPath* shadedPath, + const SkPaint& shaderPaint, + const SkMatrix& matrix, + BOOL* fill, BOOL* stroke); + + void convertToPpm( + const SkMaskFilter* filter, + SkMatrix* matrix, + SkVector* ppuScale, + const SkIRect& clip, SkIRect* clipIRect); + + HRESULT applyMask( + const SkDraw& d, + const SkMask& mask, + const SkVector& ppuScale, + IXpsOMPath* shadedPath); + + SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; + + // Disable the default copy and assign implementation. + SkXPSDevice(const SkXPSDevice&); + void operator=(const SkXPSDevice&); + + typedef SkBitmapDevice INHERITED; +}; + +#endif // SK_BUILD_FOR_WIN +#endif // SkXPSDevice_DEFINED |