PdfGeoCanvas¶
Namespace: ThinkGeo.Core
A GeoCanvas that renders into a vector PDF through SkiaSharp's SKDocument.
public class PdfGeoCanvas : SkiaGeoCanvas, IPrinterLayoutCanvas
Inheritance object → GeoCanvas → SkiaGeoCanvas → PdfGeoCanvas
Implements IPrinterLayoutCanvas
Remarks:
Cross-platform replacement for the PrinterGeoCanvas + "Print to PDF" driver workflow: it does not use GDI+ or any Windows print driver, so it also works on Linux. Geometry and text are written as vector PDF operators (text stays searchable, with font subsets embedded by Skia); images are embedded.
One canvas is one page, of the size set before BeginDrawing(); a layout of several pages is written with PrinterLayoutDocument.ExportPdfAsync. Usage mirrors PrinterGeoCanvas, except the nativeImage argument of BeginDrawing() is a writable Stream that receives the PDF:
var canvas = new PdfGeoCanvas();
canvas.SetPageSize(pagePrinterLayoutAsyncLayer); // page size + orientation taken from the layout
canvas.BeginDrawing(pdfStream, pagePrinterLayoutAsyncLayer.GetBoundingBox(), GeographyUnit.Meter);
await pagePrinterLayoutAsyncLayer.DrawAsync(canvas, labels);
canvas.EndDrawing(); // replays the queued drawing and closes the PDF
All drawing levels share one PDF page canvas, so calls are queued per DrawingLevel and replayed in level order - the same record-and-replay model PrinterGeoCanvas uses to keep z-order correct. Flush() replays the geometry levels; the label level waits for FlushLabels() or the end of the page, so the labels of a map frame's layers land above all of its layers, as on screen. Font resolution, brushes and image drawing are inherited from SkiaGeoCanvas, so output matches the on-screen Skia rendering.
Properties¶
PageWidth¶
Gets or sets the PDF page width in points (1/72 inch). Defaults to US Letter (612).
public float PageWidth { get; set; }
Property Value¶
PageHeight¶
Gets or sets the PDF page height in points (1/72 inch). Defaults to US Letter (792).
public float PageHeight { get; set; }
Property Value¶
SupportKeyColor¶
Gets or sets the SupportKeyColor.
public bool SupportKeyColor { get; }
Property Value¶
FontDisplayDensity¶
Returns the ScaleFactor so that text wrap width is compared in the same physical-pixel units that SkiaGraphics.MeasureString uses (which multiplies font size by ScaleFactor).
public double FontDisplayDensity { get; }
Property Value¶
DrawingQuality¶
Gets or sets the rendering-quality preset for Skia-based drawing.
public DrawingQuality DrawingQuality { get; set; }
Property Value¶
Remarks:
Setting this property applies the matching preset returned by RenderingOptions.FromDrawingQuality(DrawingQuality) and replaces the current SkiaGeoCanvas.RenderingOptions value. Use this property when one of the built-in quality presets is sufficient. For finer control, set SkiaGeoCanvas.RenderingOptions directly instead.
RenderingOptions¶
Gets or sets all Skia rendering options.
public RenderingOptions RenderingOptions { get; set; }
Property Value¶
AntiAlias¶
Gets or sets antialiasing for image, vector, and text rendering.
public bool AntiAlias { get; set; }
Property Value¶
CurrentScale¶
This property gets the current scale of the view.
public double CurrentScale { get; }
Property Value¶
Exceptions¶
InvalidOperationException
In the event you attempt to call this property when the GeoCanvas' IsDrawing mode is false, it will throw an InvalidOperationException.
MapUnit¶
This property returns the MapUnit passed in on the BeginDrawingAPI in the GeoCanvas.
public GeographyUnit MapUnit { get; }
Property Value¶
Width¶
This property gets the width of the view.
public float Width { get; protected set; }
Property Value¶
Exceptions¶
InvalidOperationException
In the event you attempt to call this method when the GeoCanvas' IsDrawing mode is false, it will throw an InvalidOperationException.
Remarks:
This property reflects the width of the view image that was passed in on BeginDrawing.
Height¶
This property gets the height of the view.
public float Height { get; protected set; }
Property Value¶
Exceptions¶
InvalidOperationException
In the event you attempt to call this method when the GeoCanvas' IsDrawing mode is false, it will throw an InvalidOperationException.
Remarks:
This property reflects the height of the view image that was passed in on BeginDrawing.
CurrentWorldExtent¶
This property gets the adjusted current extent based on what was set when BeginDrawing was called.
public RectangleShape CurrentWorldExtent { get; protected set; }
Property Value¶
Exceptions¶
InvalidOperationException
In the event you attempt to call this method when the GeoCanvas' IsDrawing mode is false, it will throw an InvalidOperationException.
Remarks:
The extent that gets passed in on BeginDrawing is adjusted for the height and width of the physical media being drawn on. For example if the current extent is wider than taller but the bitmap being drawn on is square then the current extent needs to be adjusted. The extent will be adjusted larger so that we ensure that the entire original extent will still be represented.
KeyColors¶
Gets a value represents a collection of key colors. If SupportKeyColor property is false, it will throw exception when you use KeyColors.
public Collection<GeoColor> KeyColors { get; }
Property Value¶
Remarks:
It will make these colors transparent when draw image.
NativeImage¶
The same reference to the parameter 'NativeImage' in BeginDrawing function.
public object NativeImage { get; }
Property Value¶
IsDrawing¶
This property gets the drawing status of the GeoCanvas.
public bool IsDrawing { get; protected set; }
Property Value¶
Remarks:
This property is set to true when the BeginDrawing method is called, and false after the EndDrawing method is called.
Dpi¶
The DPI value for the final drawing result, only valid when HasDpi set to true.
public float Dpi { get; set; }
Property Value¶
Remarks:
Defaults to MapUtil.StandardDpi (96). When printing or exporting, raise it to the resolution of the target so that vector-drawn map content is generated at that density rather than at screen density - a 300 DPI print left at the default renders its map content as though for a monitor. It does not affect content drawn in MapPrinterDrawingMode.Raster, which is sized from the layout instead.
ScaleFactor¶
Gets or sets the scale factor, this is a value number of device pixels per logical coordinate point.
public float ScaleFactor { get; set; }
Property Value¶
The scale factory value.
Remarks:
The coordinate space used by application developers is measured in logical points. High-resolution (Retina) displays will have more than a single physical pixel per logical point and this property specifies the scale factor.
CancellationToken¶
Gets or sets the cancellation token source.
public CancellationToken CancellationToken { get; set; }
Property Value¶
The cancellation token source.
ClippingArea¶
It's a property only used in printing related Canvas such as PdfGeoCanvas and PrinterGeoCanvas
public RectangleShape ClippingArea { get; set; }
Property Value¶
Constructors¶
PdfGeoCanvas()¶
public PdfGeoCanvas()
Methods¶
SetPageSize(PagePrinterLayoutAsyncLayer)¶
Sizes the PDF page from a PagePrinterLayoutAsyncLayer, so the exported PDF is the same page the layout was composed on.
public void SetPageSize(PagePrinterLayoutAsyncLayer pageLayer)
Parameters¶
pageLayer PagePrinterLayoutAsyncLayer
The page layer whose ,
and (for ) custom dimensions define the PDF page.
Returns¶
Remarks:
The layout family measures in PrintingUnit.Point, which ThinkGeo defines as 1/96 inch, while a PDF page is measured in typographic points of 1/72 inch. This method does that conversion and applies the orientation, so an ANSI A layout becomes a 612 x 792 PDF page instead of leaving the caller to work the numbers out.
SetPageSize(PrinterPageSize, PrinterOrientation)¶
Sizes the PDF page from a standard page size and orientation.
public void SetPageSize(PrinterPageSize pageSize, PrinterOrientation orientation)
Parameters¶
pageSize PrinterPageSize
The page size. carries no dimensions on its own; use
for a custom page.
orientation PrinterOrientation
The page orientation.
Returns¶
BeginDrawingCore(object, RectangleShape, GeographyUnit)¶
protected void BeginDrawingCore(object nativeImage, RectangleShape worldExtent, GeographyUnit drawingMapUnit)
Parameters¶
nativeImage object
worldExtent RectangleShape
drawingMapUnit GeographyUnit
Returns¶
A(float, float, RectangleShape)¶
internal void A(float , float , RectangleShape )
Parameters¶
`` float
`` float
Returns¶
EndDrawingCore()¶
protected void EndDrawingCore()
Returns¶
FlushCore()¶
Replays the queued geometry - levels one to four - and leaves the label level queued for or the end of the page. A map frame flushes after each of its layers so the layers stack in order; replaying the labels there too laid each layer's labels under every layer drawn after it.
protected void FlushCore()
Returns¶
GetCanvasWidthCore()¶
protected float GetCanvasWidthCore()
Returns¶
GetCanvasHeightCore()¶
protected float GetCanvasHeightCore()
Returns¶
DrawArcCore(GeoPen, float, float, float, float, float, float, DrawingLevel)¶
protected void DrawArcCore(GeoPen pen, float x, float y, float width, float height, float startAngle, float sweepAngle, DrawingLevel drawingLevel)
Parameters¶
pen GeoPen
x float
y float
width float
height float
startAngle float
sweepAngle float
drawingLevel DrawingLevel
Returns¶
DrawAreaCore(IEnumerable<ScreenPointF[]>, GeoPen, GeoBrush, DrawingLevel, float, float, PenBrushDrawingOrder)¶
protected void DrawAreaCore(IEnumerable<ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
Parameters¶
screenPoints IEnumerable<ScreenPointF[]>
outlinePen GeoPen
fillBrush GeoBrush
drawingLevel DrawingLevel
xOffset float
yOffset float
penBrushDrawingOrder PenBrushDrawingOrder
Returns¶
DrawEllipseCore(ScreenPointF, float, float, GeoPen, GeoBrush, DrawingLevel, float, float, PenBrushDrawingOrder)¶
protected void DrawEllipseCore(ScreenPointF screenPoint, float width, float height, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
Parameters¶
screenPoint ScreenPointF
width float
height float
outlinePen GeoPen
fillBrush GeoBrush
drawingLevel DrawingLevel
xOffset float
yOffset float
penBrushDrawingOrder PenBrushDrawingOrder
Returns¶
DrawLineCore(IEnumerable<ScreenPointF>, GeoPen, DrawingLevel, float, float)¶
protected void DrawLineCore(IEnumerable<ScreenPointF> screenPoints, GeoPen linePen, DrawingLevel drawingLevel, float xOffset, float yOffset)
Parameters¶
screenPoints IEnumerable<ScreenPointF>
linePen GeoPen
drawingLevel DrawingLevel
xOffset float
yOffset float
Returns¶
DrawScreenImageCore(GeoImage, float, float, float, float, DrawingLevel, float, float, float, RasterResamplingMode)¶
protected void DrawScreenImageCore(GeoImage image, float centerXInScreen, float centerYInScreen, float widthInScreen, float heightInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, float rotateAngle, RasterResamplingMode resamplingMode)
Parameters¶
image GeoImage
centerXInScreen float
centerYInScreen float
widthInScreen float
heightInScreen float
drawingLevel DrawingLevel
xOffset float
yOffset float
rotateAngle float
resamplingMode RasterResamplingMode
Returns¶
DrawScreenImageWithoutScalingCore(GeoImage, float, float, DrawingLevel, float, float, float, RasterResamplingMode)¶
protected void DrawScreenImageWithoutScalingCore(GeoImage image, float centerXInScreen, float centerYInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, float rotateAngle, RasterResamplingMode resamplingMode)
Parameters¶
image GeoImage
centerXInScreen float
centerYInScreen float
drawingLevel DrawingLevel
xOffset float
yOffset float
rotateAngle float
resamplingMode RasterResamplingMode
Returns¶
DrawTextCore(string, GeoFont, GeoBrush, GeoPen, IEnumerable<ScreenPointF>, DrawingLevel, float, float, DrawingTextAlignment, float)¶
protected void DrawTextCore(string text, GeoFont font, GeoBrush fillBrush, GeoPen haloPen, IEnumerable<ScreenPointF> textPathInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, DrawingTextAlignment drawingTextAlignment, float rotateAngle)
Parameters¶
text string
font GeoFont
fillBrush GeoBrush
haloPen GeoPen
textPathInScreen IEnumerable<ScreenPointF>
drawingLevel DrawingLevel
xOffset float
yOffset float
drawingTextAlignment DrawingTextAlignment
rotateAngle float
Returns¶
Events¶
CreatingSKTypefacesForText¶
Occurs when the CreatingSKTypefacesForText event is raised.
public event EventHandler<CreatingSKTypefacesForTextEventArgs> CreatingSKTypefacesForText;
CreatingSKTypefaceForCharacter¶
Occurs when the CreatingSKTypefaceForCharacter event is raised.
public event EventHandler<CreatingSKTypefaceForCharacterEventArgs> CreatingSKTypefaceForCharacter;
DrawingProgressChanged¶
Occurs when [drawing progress changed].
public event EventHandler<DrawingProgressChangedEventArgs> DrawingProgressChanged;