Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private 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
 
void clipShader (sk_sp< SkShader > sh, SkClipOp op)
 
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 ()
 
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 drawRegion (const SkRegion &r, const SkPaint &paint)
 
virtual void drawArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
 
virtual void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &)
 
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 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 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 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
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 ()
 

Private Member Functions

void onDrawGlyphRunList (SkCanvas *, const sktext::GlyphRunList &, const SkPaint &paint) override
 

Friends

class ScopedContentEntry
 

Detailed Description

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

Definition at line 50 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 322 of file SkPDFDevice.cpp.

323 : SkClipStackDevice(SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()),
325 , fInitialTransform(transform)
326 , fNodeId(0)
327 , fDocument(doc) {
328 SkASSERT(!pageSize.isEmpty());
329}
#define SkASSERT(cond)
Definition SkAssert.h:116
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()

◆ ~SkPDFDevice()

SkPDFDevice::~SkPDFDevice ( )
overridedefault

Member Function Documentation

◆ content()

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

Returns a SkStream with the page contents.

Definition at line 1047 of file SkPDFDevice.cpp.

1047 {
1048 if (fActiveStackState.fContentStream) {
1049 fActiveStackState.drainStack();
1050 fActiveStackState = SkPDFGraphicStackState();
1051 }
1052 if (fContent.bytesWritten() == 0) {
1053 return std::make_unique<SkMemoryStream>();
1054 }
1056 if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) {
1057 SkPDFUtils::AppendTransform(fInitialTransform, &buffer);
1058 }
1059 if (fNeedsExtraSave) {
1060 buffer.writeText("q\n");
1061 }
1062 fContent.writeToAndReset(&buffer);
1063 if (fNeedsExtraSave) {
1064 buffer.writeText("Q\n");
1065 }
1066 fNeedsExtraSave = false;
1067 return std::unique_ptr<SkStreamAsset>(buffer.detachAsStream());
1068}
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
static const uint8_t buffer[]
void AppendTransform(const SkMatrix &, SkWStream *)
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 224 of file SkPDFDevice.cpp.

224 {
225 // PDF does not support image filters, so render them on CPU.
226 // Note that this rendering is done at "screen" resolution (100dpi), not
227 // printer resolution.
228
229 // TODO: It may be possible to express some filters natively using PDF
230 // to improve quality and file size (https://bug.skia.org/3043)
231 if ((layerPaint && (layerPaint->getImageFilter() || layerPaint->getColorFilter()))
232 || (cinfo.fInfo.colorSpace() && !cinfo.fInfo.colorSpace()->isSRGB())) {
233 // need to return a raster device, which we will detect in drawDevice()
234 return SkBitmapDevice::Create(cinfo.fInfo,
236 }
237 return sk_make_sp<SkPDFDevice>(cinfo.fInfo.dimensions(), fDocument);
238}
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 342 of file SkPDFDevice.cpp.

342 {
343 if (!value || !fDocument->hasCurrentPage()) {
344 return;
345 }
346 // Annotations are specified in absolute coordinates, so the page xform maps from device space
347 // to the global space, and applies the document transform.
348 SkMatrix pageXform = this->deviceToGlobal().asM33();
349 pageXform.postConcat(fDocument->currentPageTransform());
350 if (rect.isEmpty()) {
351 if (!strcmp(key, SkPDFGetNodeIdKey())) {
352 int nodeID;
353 if (value->size() != sizeof(nodeID)) { return; }
354 memcpy(&nodeID, value->data(), sizeof(nodeID));
355 fNodeId = nodeID;
356 return;
357 }
359 SkPoint p = this->localToDevice().mapXY(rect.x(), rect.y());
360 pageXform.mapPoints(&p, 1);
361 auto pg = fDocument->currentPage();
362 fDocument->fNamedDestinations.push_back(SkPDFNamedDestination{sk_ref_sp(value), p, pg});
363 }
364 return;
365 }
366 // Convert to path to handle non-90-degree rotations.
368 SkPath clip;
369 SkClipStack_AsPath(this->cs(), &clip);
370 Op(clip, path, kIntersect_SkPathOp, &path);
371 // PDF wants a rectangle only.
372 SkRect transformedRect = pageXform.mapRect(path.getBounds());
373 if (transformedRect.isEmpty()) {
374 return;
375 }
376
378 if (!strcmp(SkAnnotationKeys::URL_Key(), key)) {
379 linkType = SkPDFLink::Type::kUrl;
380 } else if (!strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) {
382 }
383
384 if (linkType != SkPDFLink::Type::kNone) {
385 std::unique_ptr<SkPDFLink> link = std::make_unique<SkPDFLink>(
386 linkType, value, transformedRect, fNodeId);
387 fDocument->fCurrentPageLinks.push_back(std::move(link));
388 }
389}
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:3824
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
SkPDFIndirectReference currentPage() const
const SkMatrix & currentPageTransform() const
std::vector< SkPDFNamedDestination > fNamedDestinations
std::vector< std::unique_ptr< SkPDFLink > > fCurrentPageLinks
bool hasCurrentPage() const
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
SkPath makeTransform(const SkMatrix &m, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.h:1392
uint8_t value
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
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 1719 of file SkPDFDevice.cpp.

1720 {
1721 SkASSERT(!paint.getImageFilter());
1722 SkASSERT(!paint.getMaskFilter());
1723
1724 // Check if the source device is really a bitmapdevice (because that's what we returned
1725 // from createDevice (an image filter would go through drawSpecial, but createDevice uses
1726 // a raster device to apply color filters, too).
1727 SkPixmap pmap;
1728 if (device->peekPixels(&pmap)) {
1729 this->SkClipStackDevice::drawDevice(device, sampling, paint);
1730 return;
1731 }
1732
1733 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses.
1734 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device);
1735
1736 if (pdfDevice->isContentEmpty()) {
1737 return;
1738 }
1739
1740 SkMatrix matrix = device->getRelativeTransform(*this);
1741 ScopedContentEntry content(this, &this->cs(), matrix, paint);
1742 if (!content) {
1743 return;
1744 }
1745 SkPath shape = SkPath::Rect(SkRect::Make(device->imageInfo().dimensions()));
1746 shape.transform(matrix);
1747 if (content.needShape()) {
1748 content.setShape(shape);
1749 }
1750 if (!content.needSource()) {
1751 return;
1752 }
1753 this->drawFormXObject(pdfDevice->makeFormXObjectFromDevice(), content.stream(), &shape);
1754}
virtual void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &)
Definition SkDevice.cpp:330
std::unique_ptr< SkStreamAsset > content()
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
const Paint & paint
VkDevice device
Definition main.cc:53
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
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 643 of file SkPDFDevice.cpp.

648 {
650 this->internalDrawImageRect(SkKeyedImage(sk_ref_sp(const_cast<SkImage*>(image))),
651 src, dst, sampling, paint, this->localToDevice());
652}
sk_sp< SkImage > image
Definition examples.cpp:29

◆ drawMesh()

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

Implements SkDevice.

Definition at line 997 of file SkPDFDevice.cpp.

997 {
998 if (this->hasEmptyClip()) {
999 return;
1000 }
1001 // TODO: implement drawMesh
1002}

◆ drawOval()

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

Implements SkDevice.

Definition at line 497 of file SkPDFDevice.cpp.

497 {
498 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Oval(oval), paint, true);
499}
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition SkPath.cpp:3522

◆ 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 391 of file SkPDFDevice.cpp.

391 {
392 SkMatrix inverse;
393 if (!this->localToDevice().invert(&inverse)) {
394 return;
395 }
396 SkRect bbox = this->cs().bounds(this->bounds());
397 inverse.mapRect(&bbox);
398 bbox.roundOut(&bbox);
399 if (this->hasEmptyClip()) {
400 return;
401 }
402 SkPaint newPaint = srcPaint;
404 this->drawRect(bbox, newPaint);
405}
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 501 of file SkPDFDevice.cpp.

501 {
502 this->internalDrawPath(this->cs(), this->localToDevice(), path, paint, pathIsMutable);
503}

◆ drawPoints()

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

Implements SkDevice.

Definition at line 407 of file SkPDFDevice.cpp.

410 {
411 if (this->hasEmptyClip()) {
412 return;
413 }
414 if (count == 0) {
415 return;
416 }
418
419
420
421 if (SkCanvas::kPoints_PointMode != mode) {
423 }
424
425 // SkDraw::drawPoints converts to multiple calls to fDevice->drawPath.
426 // We only use this when there's a path effect or perspective because of the overhead
427 // of multiple calls to setUpContentEntry it causes.
428 if (paint->getPathEffect() || this->localToDevice().hasPerspective()) {
429 draw_points(mode, count, points, *paint, this->devClipBounds(), this);
430 return;
431 }
432
433
434 if (mode == SkCanvas::kPoints_PointMode && paint->getStrokeCap() != SkPaint::kRound_Cap) {
435 if (paint->getStrokeWidth()) {
436 // PDF won't draw a single point with square/butt caps because the
437 // orientation is ambiguous. Draw a rectangle instead.
439 SkScalar strokeWidth = paint->getStrokeWidth();
440 SkScalar halfStroke = SkScalarHalf(strokeWidth);
441 for (size_t i = 0; i < count; i++) {
442 SkRect r = SkRect::MakeXYWH(points[i].fX, points[i].fY, 0, 0);
443 r.inset(-halfStroke, -halfStroke);
444 this->drawRect(r, *paint);
445 }
446 return;
447 } else {
448 if (paint->getStrokeCap() != SkPaint::kRound_Cap) {
449 paint.writable()->setStrokeCap(SkPaint::kRound_Cap);
450 }
451 }
452 }
453
455 if (!content) {
456 return;
457 }
458 SkDynamicMemoryWStream* contentStream = content.stream();
459 switch (mode) {
461 SkPDFUtils::MoveTo(points[0].fX, points[0].fY, contentStream);
462 for (size_t i = 1; i < count; i++) {
463 SkPDFUtils::AppendLine(points[i].fX, points[i].fY, contentStream);
464 }
465 SkPDFUtils::StrokePath(contentStream);
466 break;
468 for (size_t i = 0; i < count/2; i++) {
469 SkPDFUtils::MoveTo(points[i * 2].fX, points[i * 2].fY, contentStream);
470 SkPDFUtils::AppendLine(points[i * 2 + 1].fX, points[i * 2 + 1].fY, contentStream);
471 SkPDFUtils::StrokePath(contentStream);
472 }
473 break;
475 SkASSERT(paint->getStrokeCap() == SkPaint::kRound_Cap);
476 for (size_t i = 0; i < count; i++) {
477 SkPDFUtils::MoveTo(points[i].fX, points[i].fY, contentStream);
478 SkPDFUtils::ClosePath(contentStream);
479 SkPDFUtils::StrokePath(contentStream);
480 }
481 break;
482 default:
483 SkASSERT(false);
484 }
485}
static const int strokeWidth
Definition BlurTest.cpp:60
int count
static const int points[]
static SkTCopyOnFirstWrite< SkPaint > clean_paint(const SkPaint &srcPaint)
static void set_style(SkTCopyOnFirstWrite< SkPaint > *paint, SkPaint::Style style)
#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
float SkScalar
Definition extension.cpp:12
void MoveTo(SkScalar x, SkScalar y, SkWStream *content)
void AppendLine(SkScalar x, SkScalar y, SkWStream *content)
void ClosePath(SkWStream *content)
void StrokePath(SkWStream *content)
static void draw_points(SkCanvas *canvas, SkImage *image)
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 487 of file SkPDFDevice.cpp.

487 {
488 SkRect r = rect;
489 r.sort();
490 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Rect(r), paint, true);
491}
void sort()
Definition SkRect.h:1313

◆ drawRRect()

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

Implements SkDevice.

Definition at line 493 of file SkPDFDevice.cpp.

493 {
494 this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::RRect(rrect), paint, true);
495}
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3534

◆ 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 1756 of file SkPDFDevice.cpp.

1758 {
1759 if (this->hasEmptyClip()) {
1760 return;
1761 }
1762 SkASSERT(!srcImg->isGaneshBacked() && !srcImg->isGraphiteBacked());
1763 SkASSERT(!paint.getMaskFilter() && !paint.getImageFilter());
1764
1765 SkBitmap resultBM;
1766 if (SkSpecialImages::AsBitmap(srcImg, &resultBM)) {
1767 auto r = SkRect::MakeWH(resultBM.width(), resultBM.height());
1768 this->internalDrawImageRect(SkKeyedImage(resultBM), nullptr, r, sampling, paint,
1770 }
1771}
int width() const
Definition SkBitmap.h:149
int height() const
Definition SkBitmap.h:158
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 654 of file SkPDFDevice.cpp.

654 {
655 SkASSERT(!bm.drawsNothing());
656 auto r = SkRect::MakeXYWH(x, y, bm.width(), bm.height());
657 this->internalDrawImageRect(SkKeyedImage(bm), nullptr, r, SkSamplingOptions(), paint,
658 SkMatrix::I());
659}
static const SkMatrix & I()
double y
double x

◆ 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 990 of file SkPDFDevice.cpp.

990 {
991 if (this->hasEmptyClip()) {
992 return;
993 }
994 // TODO: implement drawVertices
995}

◆ initialTransform()

const SkMatrix & SkPDFDevice::initialTransform ( ) const
inline

Definition at line 115 of file SkPDFDevice.h.

115{ return fInitialTransform; }

◆ makeCongruentDevice()

sk_sp< SkPDFDevice > SkPDFDevice::makeCongruentDevice ( )
inline

Definition at line 65 of file SkPDFDevice.h.

65 {
66 return sk_make_sp<SkPDFDevice>(this->size(), fDocument);
67 }
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 1040 of file SkPDFDevice.cpp.

1040 {
1041 return SkPDFMakeResourceDict(sort(fGraphicStateResources),
1042 sort(fShaderResources),
1043 sort(fXObjectResources),
1044 sort(fFontResources));
1045}
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 1773 of file SkPDFDevice.cpp.

1773 {
1774 return SkSpecialImages::MakeFromRaster(bitmap.bounds(), bitmap, this->surfaceProps());
1775}

◆ makeSpecial() [2/2]

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

Reimplemented from SkDevice.

Definition at line 1777 of file SkPDFDevice.cpp.

1777 {
1778 return SkSpecialImages::MakeFromRaster(
1779 image->bounds(), image->makeNonTextureImage(), this->surfaceProps());
1780}
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 1025 of file SkPDFDevice.cpp.

1025 {
1026 return SkSurfaces::Raster(info, &props);
1027}
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)

◆ onDrawGlyphRunList()

void SkPDFDevice::onDrawGlyphRunList ( SkCanvas ,
const sktext::GlyphRunList glyphRunList,
const SkPaint paint 
)
overrideprivatevirtual

Implements SkDevice.

Definition at line 981 of file SkPDFDevice.cpp.

983 {
984 SkASSERT(!glyphRunList.hasRSXForm());
985 for (const sktext::GlyphRun& glyphRun : glyphRunList) {
986 this->internalDrawGlyphRun(glyphRun, glyphRunList.origin(), paint);
987 }
988}
bool hasRSXForm() const
Definition GlyphRun.h:105
SkPoint origin() const
Definition GlyphRun.h:114

Friends And Related Symbol Documentation

◆ ScopedContentEntry

friend class ScopedContentEntry
friend

Definition at line 124 of file SkPDFDevice.h.


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