1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/device/xps/SkXPSDevice.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,322 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkXPSDevice_DEFINED 1.12 +#define SkXPSDevice_DEFINED 1.13 + 1.14 +#include "SkTypes.h" 1.15 +#include <ObjBase.h> 1.16 +#include <XpsObjectModel.h> 1.17 + 1.18 +#include "SkAutoCoInitialize.h" 1.19 +#include "SkBitmapDevice.h" 1.20 +#include "SkBitSet.h" 1.21 +#include "SkCanvas.h" 1.22 +#include "SkColor.h" 1.23 +#include "SkPaint.h" 1.24 +#include "SkPath.h" 1.25 +#include "SkPoint.h" 1.26 +#include "SkShader.h" 1.27 +#include "SkSize.h" 1.28 +#include "SkTArray.h" 1.29 +#include "SkTScopedComPtr.h" 1.30 +#include "SkTypeface.h" 1.31 + 1.32 +/** \class SkXPSDevice 1.33 + 1.34 + The drawing context for the XPS backend. 1.35 +*/ 1.36 +class SkXPSDevice : public SkBitmapDevice { 1.37 +public: 1.38 + SK_API SkXPSDevice(); 1.39 + SK_API virtual ~SkXPSDevice(); 1.40 + 1.41 + virtual bool beginPortfolio(SkWStream* outputStream); 1.42 + /** 1.43 + @param unitsPerMeter converts geometry units into physical units. 1.44 + @param pixelsPerMeter resolution to use when geometry must be rasterized. 1.45 + @param trimSize final page size in physical units. 1.46 + The top left of the trim is the origin of physical space. 1.47 + @param mediaBox The size of the physical media in physical units. 1.48 + The top and left must be less than zero. 1.49 + The bottom and right must be greater than the trimSize. 1.50 + The default is to coincide with the trimSize. 1.51 + @param bleedBox The size of the bleed box in physical units. 1.52 + Must be contained within the mediaBox. 1.53 + The default is to coincide with the mediaBox. 1.54 + @param artBox The size of the content box in physical units. 1.55 + Must be contained within the trimSize. 1.56 + The default is to coincide with the trimSize. 1.57 + @param cropBox The size of the recommended view port in physical units. 1.58 + Must be contained within the mediaBox. 1.59 + The default is to coincide with the mediaBox. 1.60 + */ 1.61 + virtual bool beginSheet( 1.62 + const SkVector& unitsPerMeter, 1.63 + const SkVector& pixelsPerMeter, 1.64 + const SkSize& trimSize, 1.65 + const SkRect* mediaBox = NULL, 1.66 + const SkRect* bleedBox = NULL, 1.67 + const SkRect* artBox = NULL, 1.68 + const SkRect* cropBox = NULL); 1.69 + 1.70 + virtual bool endSheet(); 1.71 + virtual bool endPortfolio(); 1.72 + 1.73 +protected: 1.74 + virtual void clear(SkColor color) SK_OVERRIDE; 1.75 + 1.76 + virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; 1.77 + 1.78 + virtual void drawPoints( 1.79 + const SkDraw&, 1.80 + SkCanvas::PointMode mode, 1.81 + size_t count, const SkPoint[], 1.82 + const SkPaint& paint) SK_OVERRIDE; 1.83 + 1.84 + virtual void drawRect( 1.85 + const SkDraw&, 1.86 + const SkRect& r, 1.87 + const SkPaint& paint) SK_OVERRIDE; 1.88 + 1.89 + virtual void drawRRect( 1.90 + const SkDraw&, 1.91 + const SkRRect&, 1.92 + const SkPaint& paint) SK_OVERRIDE; 1.93 + 1.94 + virtual void drawPath( 1.95 + const SkDraw&, 1.96 + const SkPath& platonicPath, 1.97 + const SkPaint& paint, 1.98 + const SkMatrix* prePathMatrix, 1.99 + bool pathIsMutable) SK_OVERRIDE; 1.100 + 1.101 + virtual void drawBitmap( 1.102 + const SkDraw&, 1.103 + const SkBitmap& bitmap, 1.104 + const SkMatrix& matrix, 1.105 + const SkPaint& paint) SK_OVERRIDE; 1.106 + 1.107 + virtual void drawSprite( 1.108 + const SkDraw&, 1.109 + const SkBitmap& bitmap, 1.110 + int x, int y, 1.111 + const SkPaint& paint) SK_OVERRIDE; 1.112 + 1.113 + virtual void drawText( 1.114 + const SkDraw&, 1.115 + const void* text, size_t len, 1.116 + SkScalar x, SkScalar y, 1.117 + const SkPaint& paint) SK_OVERRIDE; 1.118 + 1.119 + virtual void drawPosText( 1.120 + const SkDraw&, 1.121 + const void* text, size_t len, 1.122 + const SkScalar pos[], SkScalar constY, int scalarsPerPos, 1.123 + const SkPaint& paint) SK_OVERRIDE; 1.124 + 1.125 + virtual void drawTextOnPath( 1.126 + const SkDraw&, 1.127 + const void* text, size_t len, 1.128 + const SkPath& path, 1.129 + const SkMatrix* matrix, 1.130 + const SkPaint& paint) SK_OVERRIDE; 1.131 + 1.132 + virtual void drawVertices( 1.133 + const SkDraw&, 1.134 + SkCanvas::VertexMode, 1.135 + int vertexCount, const SkPoint verts[], 1.136 + const SkPoint texs[], const SkColor colors[], 1.137 + SkXfermode* xmode, 1.138 + const uint16_t indices[], int indexCount, 1.139 + const SkPaint& paint) SK_OVERRIDE; 1.140 + 1.141 + virtual void drawDevice( 1.142 + const SkDraw&, 1.143 + SkBaseDevice* device, 1.144 + int x, int y, 1.145 + const SkPaint& paint) SK_OVERRIDE; 1.146 + 1.147 + virtual bool onReadPixels(const SkBitmap& bitmap, 1.148 + int x, 1.149 + int y, 1.150 + SkCanvas::Config8888) SK_OVERRIDE; 1.151 + 1.152 + virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE; 1.153 + 1.154 +private: 1.155 + class TypefaceUse : ::SkNoncopyable { 1.156 + public: 1.157 + SkFontID typefaceId; 1.158 + int ttcIndex; 1.159 + SkStream* fontData; 1.160 + IXpsOMFontResource* xpsFont; 1.161 + SkBitSet* glyphsUsed; 1.162 + 1.163 + explicit TypefaceUse(); 1.164 + ~TypefaceUse(); 1.165 + }; 1.166 + friend static HRESULT subset_typeface(TypefaceUse* current); 1.167 + 1.168 + SkXPSDevice(IXpsOMObjectFactory* xpsFactory); 1.169 + 1.170 + SkAutoCoInitialize fAutoCo; 1.171 + SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory; 1.172 + SkTScopedComPtr<IStream> fOutputStream; 1.173 + SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter; 1.174 + 1.175 + unsigned int fCurrentPage; 1.176 + SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas; 1.177 + SkSize fCurrentCanvasSize; 1.178 + SkVector fCurrentUnitsPerMeter; 1.179 + SkVector fCurrentPixelsPerMeter; 1.180 + 1.181 + SkTArray<TypefaceUse, true> fTypefaces; 1.182 + 1.183 + HRESULT initXpsDocumentWriter(IXpsOMImageResource* image); 1.184 + 1.185 + HRESULT createXpsPage( 1.186 + const XPS_SIZE& pageSize, 1.187 + IXpsOMPage** page); 1.188 + 1.189 + HRESULT createXpsThumbnail( 1.190 + IXpsOMPage* page, const unsigned int pageNumber, 1.191 + IXpsOMImageResource** image); 1.192 + 1.193 + void internalDrawRect( 1.194 + const SkDraw&, 1.195 + const SkRect& r, 1.196 + bool transformRect, 1.197 + const SkPaint& paint); 1.198 + 1.199 + HRESULT createXpsBrush( 1.200 + const SkPaint& skPaint, 1.201 + IXpsOMBrush** xpsBrush, 1.202 + const SkMatrix* parentTransform = NULL); 1.203 + 1.204 + HRESULT createXpsSolidColorBrush( 1.205 + const SkColor skColor, const SkAlpha alpha, 1.206 + IXpsOMBrush** xpsBrush); 1.207 + 1.208 + HRESULT createXpsImageBrush( 1.209 + const SkBitmap& bitmap, 1.210 + const SkMatrix& localMatrix, 1.211 + const SkShader::TileMode (&xy)[2], 1.212 + const SkAlpha alpha, 1.213 + IXpsOMTileBrush** xpsBrush); 1.214 + 1.215 + HRESULT createXpsLinearGradient( 1.216 + SkShader::GradientInfo info, 1.217 + const SkAlpha alpha, 1.218 + const SkMatrix& localMatrix, 1.219 + IXpsOMMatrixTransform* xpsMatrixToUse, 1.220 + IXpsOMBrush** xpsBrush); 1.221 + 1.222 + HRESULT createXpsRadialGradient( 1.223 + SkShader::GradientInfo info, 1.224 + const SkAlpha alpha, 1.225 + const SkMatrix& localMatrix, 1.226 + IXpsOMMatrixTransform* xpsMatrixToUse, 1.227 + IXpsOMBrush** xpsBrush); 1.228 + 1.229 + HRESULT createXpsGradientStop( 1.230 + const SkColor skColor, 1.231 + const SkScalar offset, 1.232 + IXpsOMGradientStop** xpsGradStop); 1.233 + 1.234 + HRESULT createXpsTransform( 1.235 + const SkMatrix& matrix, 1.236 + IXpsOMMatrixTransform ** xpsTransform); 1.237 + 1.238 + HRESULT createXpsRect( 1.239 + const SkRect& rect, 1.240 + BOOL stroke, BOOL fill, 1.241 + IXpsOMGeometryFigure** xpsRect); 1.242 + 1.243 + HRESULT createXpsQuad( 1.244 + const SkPoint (&points)[4], 1.245 + BOOL stroke, BOOL fill, 1.246 + IXpsOMGeometryFigure** xpsQuad); 1.247 + 1.248 + HRESULT CreateTypefaceUse( 1.249 + const SkPaint& paint, 1.250 + TypefaceUse** fontResource); 1.251 + 1.252 + HRESULT AddGlyphs( 1.253 + const SkDraw& d, 1.254 + IXpsOMObjectFactory* xpsFactory, 1.255 + IXpsOMCanvas* canvas, 1.256 + TypefaceUse* font, 1.257 + LPCWSTR text, 1.258 + XPS_GLYPH_INDEX* xpsGlyphs, 1.259 + UINT32 xpsGlyphsLen, 1.260 + XPS_POINT *origin, 1.261 + FLOAT fontSize, 1.262 + XPS_STYLE_SIMULATION sims, 1.263 + const SkMatrix& transform, 1.264 + const SkPaint& paint); 1.265 + 1.266 + HRESULT addXpsPathGeometry( 1.267 + IXpsOMGeometryFigureCollection* figures, 1.268 + BOOL stroke, BOOL fill, const SkPath& path); 1.269 + 1.270 + HRESULT createPath( 1.271 + IXpsOMGeometryFigure* figure, 1.272 + IXpsOMVisualCollection* visuals, 1.273 + IXpsOMPath** path); 1.274 + 1.275 + HRESULT sideOfClamp( 1.276 + const SkRect& leftPoints, const XPS_RECT& left, 1.277 + IXpsOMImageResource* imageResource, 1.278 + IXpsOMVisualCollection* visuals); 1.279 + 1.280 + HRESULT cornerOfClamp( 1.281 + const SkRect& tlPoints, 1.282 + const SkColor color, 1.283 + IXpsOMVisualCollection* visuals); 1.284 + 1.285 + HRESULT clip( 1.286 + IXpsOMVisual* xpsVisual, 1.287 + const SkDraw& d); 1.288 + HRESULT clipToPath( 1.289 + IXpsOMVisual* xpsVisual, 1.290 + const SkPath& clipPath, 1.291 + XPS_FILL_RULE fillRule); 1.292 + 1.293 + HRESULT drawInverseWindingPath( 1.294 + const SkDraw& d, 1.295 + const SkPath& devicePath, 1.296 + IXpsOMPath* xpsPath); 1.297 + 1.298 + HRESULT shadePath( 1.299 + IXpsOMPath* shadedPath, 1.300 + const SkPaint& shaderPaint, 1.301 + const SkMatrix& matrix, 1.302 + BOOL* fill, BOOL* stroke); 1.303 + 1.304 + void convertToPpm( 1.305 + const SkMaskFilter* filter, 1.306 + SkMatrix* matrix, 1.307 + SkVector* ppuScale, 1.308 + const SkIRect& clip, SkIRect* clipIRect); 1.309 + 1.310 + HRESULT applyMask( 1.311 + const SkDraw& d, 1.312 + const SkMask& mask, 1.313 + const SkVector& ppuScale, 1.314 + IXpsOMPath* shadedPath); 1.315 + 1.316 + virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; 1.317 + 1.318 + // Disable the default copy and assign implementation. 1.319 + SkXPSDevice(const SkXPSDevice&); 1.320 + void operator=(const SkXPSDevice&); 1.321 + 1.322 + typedef SkBitmapDevice INHERITED; 1.323 +}; 1.324 + 1.325 +#endif