Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Friends | List of all members
SkPDFDevice Class Referencefinal

#include <SkPDFDevice.h>

Inheritance diagram for SkPDFDevice:
SkClipStackDevice SkDevice SkRefCnt SkRefCntBase

Public Member Functions

 SkPDFDevice (SkISize pageSize, SkPDFDocument *document, const SkMatrix &initialTransform=SkMatrix::I())
 
sk_sp< SkPDFDevicemakeCongruentDevice ()
 
 ~SkPDFDevice () override
 
void drawPaint (const SkPaint &paint) override
 
void drawPoints (SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
 
void drawRect (const SkRect &r, const SkPaint &paint) override
 
void drawOval (const SkRect &oval, const SkPaint &paint) override
 
void drawRRect (const SkRRect &rr, const SkPaint &paint) override
 
void drawPath (const SkPath &origpath, const SkPaint &paint, bool pathIsMutable) override
 
void drawImageRect (const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
void drawVertices (const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
 
void drawMesh (const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
 
void drawAnnotation (const SkRect &, const char key[], SkData *value) override
 
void drawDevice (SkDevice *, const SkSamplingOptions &, const SkPaint &) override
 
void drawSpecial (SkSpecialImage *, const SkMatrix &, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &, const SkSurfaceProps &) override
 
sk_sp< SkDevicecreateDevice (const CreateInfo &, const SkPaint *) override
 
void drawSprite (const SkBitmap &bitmap, int x, int y, const SkPaint &paint)
 
std::unique_ptr< SkPDFDictmakeResourceDict ()
 
std::unique_ptr< SkStreamAssetcontent ()
 
const SkMatrixinitialTransform () const
 
- Public Member Functions inherited from SkClipStackDevice
 SkClipStackDevice (const SkImageInfo &info, const SkSurfaceProps &props)
 
SkClipStackcs ()
 
const SkClipStackcs () const
 
void pushClipStack () override
 
void popClipStack () override
 
void clipRect (const SkRect &rect, SkClipOp, bool aa) override
 
void clipRRect (const SkRRect &rrect, SkClipOp, bool aa) override
 
void clipPath (const SkPath &path, SkClipOp, bool aa) override
 
void clipRegion (const SkRegion &deviceRgn, SkClipOp) override
 
void replaceClip (const SkIRect &rect) override
 
bool isClipAntiAliased () const override
 
bool isClipWideOpen () const override
 
bool isClipEmpty () const override
 
bool isClipRect () const override
 
void android_utils_clipAsRgn (SkRegion *) const override
 
SkIRect devClipBounds () const override
 
- Public Member Functions inherited from SkDevice
 SkDevice (const SkImageInfo &, const SkSurfaceProps &)
 
const SkImageInfoimageInfo () const
 
int width () const
 
int height () const
 
bool isOpaque () const
 
SkIRect bounds () const
 
SkISize size () const
 
const SkSurfacePropssurfaceProps () const
 
SkScalerContextFlags scalerContextFlags () const
 
virtual SkStrikeDeviceInfo strikeDeviceInfo () const
 
bool writePixels (const SkPixmap &src, int x, int y)
 
bool readPixels (const SkPixmap &dst, int x, int y)
 
bool accessPixels (SkPixmap *pmap)
 
bool peekPixels (SkPixmap *)
 
const SkM44localToDevice44 () const
 
const SkMatrixlocalToDevice () const
 
const SkM44deviceToGlobal () const
 
const SkM44globalToDevice () const
 
SkIPoint getOrigin () const
 
bool isPixelAlignedToGlobal () const
 
SkMatrix getRelativeTransform (const SkDevice &) const
 
void setLocalToDevice (const SkM44 &localToDevice)
 
void setGlobalCTM (const SkM44 &ctm)
 
void getGlobalBounds (SkIRect *bounds) const
 
SkIRect getGlobalBounds () const
 
virtual SkIRect devClipBounds () const =0
 
virtual void pushClipStack ()=0
 
virtual void popClipStack ()=0
 
virtual void clipRect (const SkRect &rect, SkClipOp op, bool aa)=0
 
virtual void clipRRect (const SkRRect &rrect, SkClipOp op, bool aa)=0
 
virtual void clipPath (const SkPath &path, SkClipOp op, bool aa)=0
 
virtual void clipRegion (const SkRegion &region, SkClipOp op)=0
 
void clipShader (sk_sp< SkShader > sh, SkClipOp op)
 
virtual void replaceClip (const SkIRect &rect)=0
 
virtual bool isClipAntiAliased () const =0
 
virtual bool isClipEmpty () const =0
 
virtual bool isClipRect () const =0
 
virtual bool isClipWideOpen () const =0
 
virtual void android_utils_clipAsRgn (SkRegion *) const =0
 
virtual bool android_utils_clipWithStencil ()
 
virtual bool useDrawCoverageMaskForMaskFilters () const
 
virtual bool isNoPixelsDevice () const
 
virtual void * getRasterHandle () const
 
virtual GrRecordingContextrecordingContext () const
 
virtual skgpu::graphite::Recorderrecorder () const
 
virtual skgpu::ganesh::DeviceasGaneshDevice ()
 
virtual skgpu::graphite::DeviceasGraphiteDevice ()
 
virtual void setImmutable ()
 
virtual sk_sp< SkSurfacemakeSurface (const SkImageInfo &, const SkSurfaceProps &)
 
virtual sk_sp< SkDevicecreateDevice (const CreateInfo &, const SkPaint *)
 
void drawGlyphRunList (SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual sk_sp< sktext::gpu::SlugconvertGlyphRunListToSlug (const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual void drawSlug (SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
 
virtual void drawPaint (const SkPaint &paint)=0
 
virtual void drawPoints (SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint)=0
 
virtual void drawRect (const SkRect &r, const SkPaint &paint)=0
 
virtual void drawRegion (const SkRegion &r, const SkPaint &paint)
 
virtual void drawOval (const SkRect &oval, const SkPaint &paint)=0
 
virtual void drawArc (const SkArc &arc, const SkPaint &paint)
 
virtual void drawRRect (const SkRRect &rr, const SkPaint &paint)=0
 
virtual void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &)
 
virtual void drawPath (const SkPath &path, const SkPaint &paint, bool pathIsMutable=false)=0
 
virtual void drawImageRect (const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)=0
 
virtual bool shouldDrawAsTiledImageRect () const
 
virtual bool drawAsTiledImageRect (SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawImageLattice (const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
 
virtual void drawVertices (const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool skipColorXform=false)=0
 
virtual void drawMesh (const SkMesh &mesh, sk_sp< SkBlender >, const SkPaint &)=0
 
virtual void drawShadow (const SkPath &, const SkDrawShadowRec &)
 
virtual void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
 
virtual void drawAtlas (const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
 
virtual void drawAnnotation (const SkRect &, const char[], SkData *)
 
virtual void drawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 
virtual void drawEdgeAAImageSet (const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawDrawable (SkCanvas *, SkDrawable *, const SkMatrix *)
 
virtual sk_sp< SkSpecialImagesnapSpecial (const SkIRect &subset, bool forceCopy=false)
 
virtual sk_sp< SkSpecialImagesnapSpecialScaled (const SkIRect &subset, const SkISize &dstDims)
 
sk_sp< SkSpecialImagesnapSpecial ()
 
virtual void drawDevice (SkDevice *, const SkSamplingOptions &, const SkPaint &)
 
virtual void drawSpecial (SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint constraint=SkCanvas::kStrict_SrcRectConstraint)
 
virtual void drawCoverageMask (const SkSpecialImage *, const SkMatrix &maskToDevice, const SkSamplingOptions &, const SkPaint &)
 
virtual bool drawBlurredRRect (const SkRRect &, const SkPaint &, float deviceSigma)
 
void drawFilteredImage (const skif::Mapping &mapping, SkSpecialImage *src, SkColorType ct, const SkImageFilter *, const SkSamplingOptions &, const SkPaint &)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

sk_sp< SkSpecialImagemakeSpecial (const SkBitmap &) override
 
sk_sp< SkSpecialImagemakeSpecial (const SkImage *) override
 
- Protected Member Functions inherited from SkDevice
virtual sk_sp< SkSpecialImagemakeSpecial (const SkBitmap &)
 
virtual sk_sp< SkSpecialImagemakeSpecial (const SkImage *)
 
void setDeviceCoordinateSystem (const SkM44 &deviceToGlobal, const SkM44 &globalToDevice, const SkM44 &localToDevice, int bufferOriginX, int bufferOriginY)
 
void setOrigin (const SkM44 &globalCTM, int x, int y)
 
bool checkLocalToDeviceDirty ()
 

Friends

class ScopedContentEntry
 

Detailed Description

An SkPDFDevice is the drawing context for a page or layer of PDF content.

Definition at line 59 of file SkPDFDevice.h.

Constructor & Destructor Documentation

◆ SkPDFDevice()

SkPDFDevice::SkPDFDevice ( SkISize  pageSize,
SkPDFDocument document,
const SkMatrix initialTransform = SkMatrix::I() 
)
Parameters
pageSizePage size in point units. 1 point == 127/360 mm == 1/72 inch
documentA non-null pointer back to the PDFDocument object. The document is responsible for de-duplicating across pages (via the SkPDFDocument) and for early serializing of large immutable objects, such as images (via SkPDFDocument::serialize()).
initialTransformTransform to be applied to the entire page.

Definition at line 354 of file SkPDFDevice.cpp.

355 : SkClipStackDevice(SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()),
357 , fInitialTransform(transform)
358 , fNodeId(0)
359 , fDocument(doc) {
360 SkASSERT(!pageSize.isEmpty());
361}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkClipStackDevice(const SkImageInfo &info, const SkSurfaceProps &props)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
bool isEmpty() const
Definition: SkSize.h:31
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37
static SkImageInfo MakeUnknown()
Definition: SkImageInfo.h:357

◆ ~SkPDFDevice()

SkPDFDevice::~SkPDFDevice ( )
overridedefault

Member Function Documentation

◆ content()

std::unique_ptr< SkStreamAsset > SkPDFDevice::content ( )

Returns a SkStream with the page contents.

Definition at line 1079 of file SkPDFDevice.cpp.

1079 {
1080 if (fActiveStackState.fContentStream) {
1081 fActiveStackState.drainStack();
1082 fActiveStackState = SkPDFGraphicStackState();
1083 }
1084 if (fContent.bytesWritten() == 0) {
1085 return std::make_unique<SkMemoryStream>();
1086 }
1088 if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) {
1089 SkPDFUtils::AppendTransform(fInitialTransform, &buffer);
1090 }
1091 if (fNeedsExtraSave) {
1092 buffer.writeText("q\n");
1093 }
1094 fContent.writeToAndReset(&buffer);
1095 if (fNeedsExtraSave) {
1096 buffer.writeText("Q\n");
1097 }
1098 fNeedsExtraSave = false;
1099 return std::unique_ptr<SkStreamAsset>(buffer.detachAsStream());
1100}
size_t bytesWritten() const override
Definition: SkStream.cpp:526
bool writeToAndReset(SkWStream *dst)
Definition: SkStream.cpp:689
@ kIdentity_Mask
identity SkMatrix; all bits clear
Definition: SkMatrix.h:192
TypeMask getType() const
Definition: SkMatrix.h:207
void AppendTransform(const SkMatrix &, SkWStream *)
Definition: SkPDFUtils.cpp:399
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
SkDynamicMemoryWStream * fContentStream

◆ createDevice()

sk_sp< SkDevice > SkPDFDevice::createDevice ( const CreateInfo ,
const SkPaint  
)
overridevirtual

Create a new device based on CreateInfo. If the paint is not null, then it represents a preview of how the new device will be composed with its creator device (this).

The subclass may be handed this device in drawDevice(), so it must always return a device that it knows how to draw, and that it knows how to identify if it is not of the same subclass (since drawDevice is passed a SkDevice*). If the subclass cannot fulfill that contract (e.g. PDF cannot support some settings on the paint) it should return NULL, and the caller may then decide to explicitly create a bitmapdevice, knowing that later it could not call drawDevice with it (but it could call drawSprite or drawBitmap).

Reimplemented from SkDevice.

Definition at line 256 of file SkPDFDevice.cpp.

256 {
257 // PDF does not support image filters, so render them on CPU.
258 // Note that this rendering is done at "screen" resolution (100dpi), not
259 // printer resolution.
260
261 // TODO: It may be possible to express some filters natively using PDF
262 // to improve quality and file size (https://bug.skia.org/3043)
263 if ((layerPaint && (layerPaint->getImageFilter() || layerPaint->getColorFilter()))
264 || (cinfo.fInfo.colorSpace() && !cinfo.fInfo.colorSpace()->isSRGB())) {
265 // need to return a raster device, which we will detect in drawDevice()
266 return SkBitmapDevice::Create(cinfo.fInfo,
268 }
269 return sk_make_sp<SkPDFDevice>(cinfo.fInfo.dimensions(), fDocument);
270}
static sk_sp< SkBitmapDevice > Create(const SkImageInfo &, const SkSurfaceProps &, SkRasterHandleAllocator *=nullptr)

◆ drawAnnotation()

void SkPDFDevice::drawAnnotation ( const SkRect rect,
const char  key[],
SkData value 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 374 of file SkPDFDevice.cpp.

374 {
375 if (!value || !fDocument->hasCurrentPage()) {
376 return;
377 }
378 // Annotations are specified in absolute coordinates, so the page xform maps from device space
379 // to the global space, and applies the document transform.
380 SkMatrix pageXform = this->deviceToGlobal().asM33();
381 pageXform.postConcat(fDocument->currentPageTransform());
382 if (rect.isEmpty()) {
383 if (!strcmp(key, SkPDFGetNodeIdKey())) {
384 int nodeID;
385 if (value->size() != sizeof(nodeID)) { return; }
386 memcpy(&nodeID, value->data(), sizeof(nodeID));
387 fNodeId = nodeID;
388 return;
389 }
391 SkPoint p = this->localToDevice().mapXY(rect.x(), rect.y());
392 pageXform.mapPoints(&p, 1);
393 auto pg = fDocument->currentPage();
394 fDocument->fNamedDestinations.push_back(SkPDFNamedDestination{sk_ref_sp(value), p, pg});
395 }
396 return;
397 }
398 // Convert to path to handle non-90-degree rotations.
400 SkPath clip;
401 SkClipStack_AsPath(this->cs(), &clip);
403 // PDF wants a rectangle only.
404 SkRect transformedRect = pageXform.mapRect(path.getBounds());
405 if (transformedRect.isEmpty()) {
406 return;
407 }
408
410 if (!strcmp(SkAnnotationKeys::URL_Key(), key)) {
411 linkType = SkPDFLink::Type::kUrl;
412 } else if (!strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) {
414 }
415
416 if (linkType != SkPDFLink::Type::kNone) {
417 std::unique_ptr<SkPDFLink> link = std::make_unique<SkPDFLink>(
418 linkType, value, transformedRect, fNodeId);
419 fDocument->fCurrentPageLinks.push_back(std::move(link));
420 }
421}
void SkClipStack_AsPath(const SkClipStack &cs, SkPath *path)
const char * SkPDFGetNodeIdKey()
@ kIntersect_SkPathOp
intersect the two paths
Definition: SkPathOps.h:24
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static const char * Define_Named_Dest_Key()
static const char * Link_Named_Dest_Key()
static const char * URL_Key()
SkClipStack & cs()
const SkMatrix & localToDevice() const
Definition: SkDevice.h:179
const SkM44 & deviceToGlobal() const
Definition: SkDevice.h:186
SkMatrix asM33() const
Definition: SkM44.h:409
SkMatrix & postConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:683
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition: SkMatrix.cpp:770
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Definition: SkMatrix.cpp:777
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
SkPDFIndirectReference currentPage() const
const SkMatrix & currentPageTransform() const
std::vector< SkPDFNamedDestination > fNamedDestinations
std::vector< std::unique_ptr< SkPDFLink > > fCurrentPageLinks
bool hasCurrentPage() const
Definition: SkPath.h:59
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition: SkPath.cpp:3586
SkPath makeTransform(const SkMatrix &m, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.h:1400
uint8_t value
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
def link(from_root, to_root)
Definition: dart_pkg.py:44
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
constexpr float x() const
Definition: SkRect.h:720
bool isEmpty() const
Definition: SkRect.h:693

◆ drawDevice()

void SkPDFDevice::drawDevice ( SkDevice device,
const SkSamplingOptions sampling,
const SkPaint paint 
)
overridevirtual

The SkDevice passed will be an SkDevice which was returned by a call to onCreateDevice on this device with kNeverTile_TileExpectation.

The default implementation calls snapSpecial() and drawSpecial() with the relative transform from the input device to this device. The provided SkPaint cannot have a mask filter or image filter, and any shader is ignored.

Reimplemented from SkDevice.

Definition at line 1751 of file SkPDFDevice.cpp.

1752 {
1753 SkASSERT(!paint.getImageFilter());
1754 SkASSERT(!paint.getMaskFilter());
1755
1756 // Check if the source device is really a bitmapdevice (because that's what we returned
1757 // from createDevice (an image filter would go through drawSpecial, but createDevice uses
1758 // a raster device to apply color filters, too).
1759 SkPixmap pmap;
1760 if (device->peekPixels(&pmap)) {
1762 return;
1763 }
1764
1765 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses.
1766 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device);
1767
1768 if (pdfDevice->isContentEmpty()) {
1769 return;
1770 }
1771
1772 SkMatrix matrix = device->getRelativeTransform(*this);
1773 ScopedContentEntry content(this, &this->cs(), matrix, paint);
1774 if (!content) {
1775 return;
1776 }
1777 SkPath shape = SkPath::Rect(SkRect::Make(device->imageInfo().dimensions()));
1778 shape.transform(matrix);
1779 if (content.needShape()) {
1780 content.setShape(shape);
1781 }
1782 if (!content.needSource()) {
1783 return;
1784 }
1785 this->drawFormXObject(pdfDevice->makeFormXObjectFromDevice(), content.stream(), &shape);
1786}
virtual void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &)
Definition: SkDevice.cpp:329
std::unique_ptr< SkStreamAsset > content()
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711
const Paint & paint
Definition: color_source.cc:38
VkDevice device
Definition: main.cc:53
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkSamplingOptions sampling
Definition: SkRecords.h:337
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ drawImageRect()

void SkPDFDevice::drawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint,
SkCanvas::SrcRectConstraint   
)
overridevirtual

Implements SkDevice.

Definition at line 675 of file SkPDFDevice.cpp.

680 {
682 this->internalDrawImageRect(SkKeyedImage(sk_ref_sp(const_cast<SkImage*>(image))),
683 src, dst, sampling, paint, this->localToDevice());
684}
sk_sp< const SkImage > image
Definition: SkRecords.h:269
dst
Definition: cp.py:12

◆ drawMesh()

void SkPDFDevice::drawMesh ( const SkMesh ,
sk_sp< SkBlender ,
const SkPaint  
)
overridevirtual

Implements SkDevice.

Definition at line 1029 of file SkPDFDevice.cpp.

1029 {
1030 if (this->hasEmptyClip()) {
1031 return;
1032 }
1033 // TODO: implement drawMesh
1034}

◆ drawOval()

void SkPDFDevice::drawOval ( const SkRect oval,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 529 of file SkPDFDevice.cpp.

529 {
530 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Oval(oval), paint, true);
531}
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition: SkPath.cpp:3590

◆ drawPaint()

void SkPDFDevice::drawPaint ( const SkPaint paint)
overridevirtual

These are called inside the per-device-layer loop for each draw call. When these are called, we have already applied any saveLayer operations, and are handling any looping from the paint.

Implements SkDevice.

Definition at line 423 of file SkPDFDevice.cpp.

423 {
424 SkMatrix inverse;
425 if (!this->localToDevice().invert(&inverse)) {
426 return;
427 }
428 SkRect bbox = this->cs().bounds(this->bounds());
429 inverse.mapRect(&bbox);
430 bbox.roundOut(&bbox);
431 if (this->hasEmptyClip()) {
432 return;
433 }
434 SkPaint newPaint = srcPaint;
436 this->drawRect(bbox, newPaint);
437}
SkRect bounds(const SkIRect &deviceBounds) const
SkIRect bounds() const
Definition: SkDevice.h:125
void drawRect(const SkRect &r, const SkPaint &paint) override
void setStyle(Style style)
Definition: SkPaint.cpp:105
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
gboolean invert
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ drawPath()

void SkPDFDevice::drawPath ( const SkPath path,
const SkPaint paint,
bool  pathIsMutable 
)
overridevirtual

If pathIsMutable, then the implementation is allowed to cast path to a non-const pointer and modify it in place (as an optimization). Canvas may do this to implement helpers such as drawOval, by placing a temp path on the stack to hold the representation of the oval.

Implements SkDevice.

Definition at line 533 of file SkPDFDevice.cpp.

533 {
534 this->internalDrawPath(this->cs(), this->localToDevice(), path, paint, pathIsMutable);
535}

◆ drawPoints()

void SkPDFDevice::drawPoints ( SkCanvas::PointMode  mode,
size_t  count,
const  SkPoint[],
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 439 of file SkPDFDevice.cpp.

442 {
443 if (this->hasEmptyClip()) {
444 return;
445 }
446 if (count == 0) {
447 return;
448 }
450
451
452
455 }
456
457 // SkDraw::drawPoints converts to multiple calls to fDevice->drawPath.
458 // We only use this when there's a path effect or perspective because of the overhead
459 // of multiple calls to setUpContentEntry it causes.
460 if (paint->getPathEffect() || this->localToDevice().hasPerspective()) {
461 draw_points(mode, count, points, *paint, this->devClipBounds(), this);
462 return;
463 }
464
465
467 if (paint->getStrokeWidth()) {
468 // PDF won't draw a single point with square/butt caps because the
469 // orientation is ambiguous. Draw a rectangle instead.
471 SkScalar strokeWidth = paint->getStrokeWidth();
472 SkScalar halfStroke = SkScalarHalf(strokeWidth);
473 for (size_t i = 0; i < count; i++) {
474 SkRect r = SkRect::MakeXYWH(points[i].fX, points[i].fY, 0, 0);
475 r.inset(-halfStroke, -halfStroke);
476 this->drawRect(r, *paint);
477 }
478 return;
479 } else {
480 if (paint->getStrokeCap() != SkPaint::kRound_Cap) {
481 paint.writable()->setStrokeCap(SkPaint::kRound_Cap);
482 }
483 }
484 }
485
487 if (!content) {
488 return;
489 }
490 SkDynamicMemoryWStream* contentStream = content.stream();
491 switch (mode) {
493 SkPDFUtils::MoveTo(points[0].fX, points[0].fY, contentStream);
494 for (size_t i = 1; i < count; i++) {
495 SkPDFUtils::AppendLine(points[i].fX, points[i].fY, contentStream);
496 }
497 SkPDFUtils::StrokePath(contentStream);
498 break;
500 for (size_t i = 0; i < count/2; i++) {
501 SkPDFUtils::MoveTo(points[i * 2].fX, points[i * 2].fY, contentStream);
502 SkPDFUtils::AppendLine(points[i * 2 + 1].fX, points[i * 2 + 1].fY, contentStream);
503 SkPDFUtils::StrokePath(contentStream);
504 }
505 break;
507 SkASSERT(paint->getStrokeCap() == SkPaint::kRound_Cap);
508 for (size_t i = 0; i < count; i++) {
509 SkPDFUtils::MoveTo(points[i].fX, points[i].fY, contentStream);
510 SkPDFUtils::ClosePath(contentStream);
511 SkPDFUtils::StrokePath(contentStream);
512 }
513 break;
514 default:
515 SkASSERT(false);
516 }
517}
static const int strokeWidth
Definition: BlurTest.cpp:60
int count
Definition: FontMgrTest.cpp:50
static const int points[]
static SkTCopyOnFirstWrite< SkPaint > clean_paint(const SkPaint &srcPaint)
static void set_style(SkTCopyOnFirstWrite< SkPaint > *paint, SkPaint::Style style)
static void draw_points(SkCanvas::PointMode mode, size_t count, const SkPoint *points, const SkPaint &paint, const SkIRect &bounds, SkDevice *device)
#define SkScalarHalf(a)
Definition: SkScalar.h:75
@ kLines_PointMode
draw each pair of points as a line segment
Definition: SkCanvas.h:1242
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition: SkCanvas.h:1243
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
SkIRect devClipBounds() const override
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Cap getStrokeCap() const
Definition: SkPaint.h:372
float SkScalar
Definition: extension.cpp:12
void MoveTo(SkScalar x, SkScalar y, SkWStream *content)
Definition: SkPDFUtils.cpp:75
void AppendLine(SkScalar x, SkScalar y, SkWStream *content)
Definition: SkPDFUtils.cpp:82
void ClosePath(SkWStream *content)
Definition: SkPDFUtils.cpp:227
void StrokePath(SkWStream *content)
Definition: SkPDFUtils.cpp:250
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
void inset(float dx, float dy)
Definition: SkRect.h:1060
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ drawRect()

void SkPDFDevice::drawRect ( const SkRect r,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 519 of file SkPDFDevice.cpp.

519 {
520 SkRect r = rect;
521 r.sort();
522 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Rect(r), paint, true);
523}
void sort()
Definition: SkRect.h:1313

◆ drawRRect()

void SkPDFDevice::drawRRect ( const SkRRect rr,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 525 of file SkPDFDevice.cpp.

525 {
526 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::RRect(rrect), paint, true);
527}
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:3602
SkRRect rrect
Definition: SkRecords.h:232

◆ drawSpecial()

void SkPDFDevice::drawSpecial ( SkSpecialImage ,
const SkMatrix localToDevice,
const SkSamplingOptions ,
const SkPaint ,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Draw the special image's subset to this device, subject to the given matrix transform instead of the device's current local to device matrix.

If 'constraint' is kFast, the rendered geometry of the image still reflects the extent of the SkSpecialImage's subset, but it's assumed that the pixel data beyond the subset is valid (e.g. SkSpecialImage::makeSubset() was called to crop a larger image).

Reimplemented from SkDevice.

Definition at line 1788 of file SkPDFDevice.cpp.

1790 {
1791 if (this->hasEmptyClip()) {
1792 return;
1793 }
1794 SkASSERT(!srcImg->isGaneshBacked() && !srcImg->isGraphiteBacked());
1795 SkASSERT(!paint.getMaskFilter() && !paint.getImageFilter());
1796
1797 SkBitmap resultBM;
1798 if (SkSpecialImages::AsBitmap(srcImg, &resultBM)) {
1799 auto r = SkRect::MakeWH(resultBM.width(), resultBM.height());
1800 this->internalDrawImageRect(SkKeyedImage(resultBM), nullptr, r, sampling, paint,
1802 }
1803}
int width() const
Definition: SkBitmap.h:149
int height() const
Definition: SkBitmap.h:158
bool AsBitmap(const SkSpecialImage *img, SkBitmap *result)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ drawSprite()

void SkPDFDevice::drawSprite ( const SkBitmap bitmap,
int  x,
int  y,
const SkPaint paint 
)

Definition at line 686 of file SkPDFDevice.cpp.

686 {
687 SkASSERT(!bm.drawsNothing());
688 auto r = SkRect::MakeXYWH(x, y, bm.width(), bm.height());
689 this->internalDrawImageRect(SkKeyedImage(bm), nullptr, r, SkSamplingOptions(), paint,
690 SkMatrix::I());
691}
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
double y
double x
SkSamplingOptions(SkFilterMode::kLinear))

◆ drawVertices()

void SkPDFDevice::drawVertices ( const SkVertices ,
sk_sp< SkBlender ,
const SkPaint ,
bool  skipColorXform 
)
overridevirtual

If skipColorXform is true, then the implementation should assume that the provided vertex colors are already in the destination color space.

Implements SkDevice.

Definition at line 1022 of file SkPDFDevice.cpp.

1022 {
1023 if (this->hasEmptyClip()) {
1024 return;
1025 }
1026 // TODO: implement drawVertices
1027}

◆ initialTransform()

const SkMatrix & SkPDFDevice::initialTransform ( ) const
inline

Definition at line 124 of file SkPDFDevice.h.

124{ return fInitialTransform; }

◆ makeCongruentDevice()

sk_sp< SkPDFDevice > SkPDFDevice::makeCongruentDevice ( )
inline

Definition at line 74 of file SkPDFDevice.h.

74 {
75 return sk_make_sp<SkPDFDevice>(this->size(), fDocument);
76 }
SkISize size() const
Definition: SkDevice.h:126

◆ makeResourceDict()

std::unique_ptr< SkPDFDict > SkPDFDevice::makeResourceDict ( )

Create the resource dictionary for this device. Destructive.

Definition at line 1072 of file SkPDFDevice.cpp.

1072 {
1073 return SkPDFMakeResourceDict(sort(fGraphicStateResources),
1074 sort(fShaderResources),
1075 sort(fXObjectResources),
1076 sort(fFontResources));
1077}
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
std::unique_ptr< SkPDFDict > SkPDFMakeResourceDict(const std::vector< SkPDFIndirectReference > &graphicStateResources, const std::vector< SkPDFIndirectReference > &shaderResources, const std::vector< SkPDFIndirectReference > &xObjectResources, const std::vector< SkPDFIndirectReference > &fontResources)

◆ makeSpecial() [1/2]

sk_sp< SkSpecialImage > SkPDFDevice::makeSpecial ( const SkBitmap bitmap)
overrideprotectedvirtual

Reimplemented from SkDevice.

Definition at line 1805 of file SkPDFDevice.cpp.

1805 {
1806 return SkSpecialImages::MakeFromRaster(bitmap.bounds(), bitmap, this->surfaceProps());
1807}
sk_sp< SkSpecialImage > MakeFromRaster(const SkIRect &subset, const SkBitmap &bm, const SkSurfaceProps &props)
Definition: bitmap.py:1

◆ makeSpecial() [2/2]

sk_sp< SkSpecialImage > SkPDFDevice::makeSpecial ( const SkImage image)
overrideprotectedvirtual

Reimplemented from SkDevice.

Definition at line 1809 of file SkPDFDevice.cpp.

1809 {
1811 image->bounds(), image->makeNonTextureImage(), this->surfaceProps());
1812}
sk_sp< SkImage > makeNonTextureImage(GrDirectContext *=nullptr) const
Definition: SkImage.cpp:260
SkIRect bounds() const
Definition: SkImage.h:303

◆ makeSurface()

sk_sp< SkSurface > SkPDFDevice::makeSurface ( const SkImageInfo info,
const SkSurfaceProps props 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 1057 of file SkPDFDevice.cpp.

1057 {
1058 return SkSurfaces::Raster(info, &props);
1059}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

Friends And Related Function Documentation

◆ ScopedContentEntry

friend class ScopedContentEntry
friend

Definition at line 133 of file SkPDFDevice.h.


The documentation for this class was generated from the following files: