PeachDrawing.Core
0.10.0
dotnet add package PeachDrawing.Core --version 0.10.0
NuGet\Install-Package PeachDrawing.Core -Version 0.10.0
<PackageReference Include="PeachDrawing.Core" Version="0.10.0" />
<PackageVersion Include="PeachDrawing.Core" Version="0.10.0" />
<PackageReference Include="PeachDrawing.Core" />
paket add PeachDrawing.Core --version 0.10.0
#r "nuget: PeachDrawing.Core, 0.10.0"
#:package PeachDrawing.Core@0.10.0
#addin nuget:?package=PeachDrawing.Core&version=0.10.0
#tool nuget:?package=PeachDrawing.Core&version=0.10.0
PeachDrawing.Core
The drawing-surface abstraction PeachPDF targets to write PDF, published as its own package so other
renderers can target it too: a Canvas to draw shapes, text and images on, a RenderContext to resolve colors, fonts and paint
objects from, and the paint-ready value types (Brush, Pen, GraphicsPath, PaintColor, Rect and the rest) that connect
them. Write your drawing code once against Canvas and run it on any backend. Its only dependency is
PeachDrawing.Text, for font and typeface types. It is trimmable and Native AOT
compatible.
dotnet add package PeachDrawing.Core
Status: pre-1.0, versioned in lockstep with PeachPDF (the same number for every release); until 1.0 the API may change between releases. Targets .NET 10 and later.
You normally install this package together with a backend that implements it:
| Backend package | Draws to | Canvas / RenderContext |
|---|---|---|
| PeachDrawing.PDF | PDF files | PdfCanvas / PdfRenderContext |
| PeachDrawing | bitmaps (CPU rasterizer), PNG/JPEG/WebP... | RasterCanvas / RasterRenderContext |
| PeachDrawing.Svg | vector SVG documents | SvgCanvas / SvgRenderContext |
| PeachDrawing.Skia | any SKCanvas, CPU or GPU, any platform |
SkiaCanvas / SkiaRenderContext |
| PeachDrawing.Win2D | Win2D on Windows | Win2dCanvas / Win2dRenderContext |
| PeachDrawing.CoreGraphics | a CGContext on macOS and iOS |
CoreGraphicsCanvas / CoreGraphicsRenderContext |
Quick start: draw once, target any backend
using PeachDrawing.Core;
// Works on every backend above; the canvas and context are whatever the backend gave you.
static void Paint(Canvas canvas, RenderContext context)
{
var font = context.GetFont("Arial", size: 24, PaintFontStyle.Regular);
canvas.PushClip(new Rect(0, 0, 200, 100));
canvas.DrawRectangle(context.GetSolidBrush(PaintColor.FromArgb(255, 30, 144, 255)), x: 10, y: 10, width: 180, height: 80);
if (font is not null)
{
canvas.DrawString("Hello", font, PaintColor.Black, new PaintPoint(20, 40), canvas.MeasureString("Hello", font));
}
canvas.PopClip();
}
For example, with the PDF backend: Paint(composer.AddPage(400, 300).Canvas, context); with the bitmap one:
Paint(context.CreateCanvas(400, 300), context).
RenderContext: colors, fonts and paint objects
Font? font = context.GetFont("Source Sans", size: 16, PaintFontStyle.Bold); // CSS Fonts 4 face matching
Font? emoji = context.GetFontForCodepoint("Arial", 16, PaintFontStyle.Regular, new System.Text.Rune(0x1F600)); // per-codepoint fallback
await context.AddFontFromBytes("Brand", File.ReadAllBytes("Brand.ttf")); // or AddFontFamilyFromUrl, AddLocalFontFamily
Brush solid = context.GetSolidBrush(PaintColor.FromArgb(255, 231, 76, 60));
Brush linear = context.GetLinearGradientBrush(new PaintPoint(0, 0), new PaintPoint(200, 0), [(PaintColor.White, 0), (PaintColor.Black, 1)]);
Pen pen = context.GetPen(PaintColor.Black);
pen.Width = 2;
Each backend's context adds its own AddFont(stream, family). Gradients can be linear, radial (with a focal point) or conic, and
repeat. A Pen strokes with any brush and carries width, caps, joins, miter limit and dashes.
Canvas: the drawing surface
canvas.PushTransform(System.Numerics.Matrix3x2.CreateRotation(float.Pi / 6)); // transform, clip and blend mode are stacks:
canvas.PushClip(new Rect(0, 0, 200, 100)); // what you push, you pop, in order
canvas.PushBlendMode(PaintBlendMode.Multiply);
canvas.DrawRectangle(brush, 10, 10, 180, 80);
canvas.DrawLine(pen, 0, 0, 200, 100);
canvas.DrawImage(image, new Rect(20, 20, 64, 64)); // + opacity, blend, color-matrix and mask variants
canvas.PopBlendMode();
canvas.PopClip();
canvas.PopTransform();
- Vector paths:
using var path = canvas.GetGraphicsPath(); path.Start(0, 0); path.LineTo(100, 0); path.AddBezierTo(...); path.CloseFigure();thenDrawPath(brush, path),DrawPath(pen, path)orPushClip(path).path.Flatten(tolerance)andGetCurveContours()read the geometry back;PathOperationsunions, intersects and subtracts paths,PathMeasuresamples them,PathShapesbuilds rounded rectangles and ellipses. - Text:
DrawStringdraws a shaped run (ligatures, kerning, complex scripts);MeasureString,CountShapedGlyphs,GetTextOutlineandGetInkCrossingsmeasure against the same shaping.DrawStringInRectaligns a run in a rectangle byBoxAlignment.DrawGlyphsdraws glyphs you shaped yourself withPeachDrawing.Text. - Layers and effects:
canvas.BeginLayer(new LayerOptions(Opacity: 0.5, Effects: [new BlurEffect(4)]))draws a group that is composited as one piece, with blur, drop-shadow and color-matrix effects. - Tiles:
CreateTile(width, height)returns a canvas and image for content drawn once and reused (an SVG pattern cell, say). - Links, cursors and semantics:
AddLink,AddDestinationLink,AddDestination,AddCursorandAddSemanticRegionsay what is clickable and what things mean; a canvas of pixels ignores them, PDF writes annotations, SVG writes<a>, and the Skia, Win2D and CoreGraphics backends record them for a host to hit-test. - Structure hooks:
BeginArtifactandBeginMarkedContentbracket tagged-PDF content; other backends ignore them.
Paragraphs and color glyphs on any Canvas
using PeachDrawing.Text.Layout;
var layout = new ParagraphBuilder(new RunStyle(typeface, 16))
.AddText("Hello, ").PushRun(new RunStyle(boldTypeface, 16)).AddText("world").PopRun()
.Build().Layout(availableWidth: 300);
canvas.DrawParagraph(layout, new PaintPoint(10, 10), PaintColor.Black); // glyphs exactly where the shaper put them
ColorGlyphPainter walks COLR v0/v1 color glyphs into an IColorGlyphTarget; CanvasColorGlyphTarget paints them on any Canvas.
Implementing your own Canvas
Brush, Pen and GraphicsPath are plain, readable data rather than backend-owned handles, so a Canvas you write can interpret
what another implementation built (pattern-match on SolidBrush, LinearGradientBrush, ... and read path.Flatten). Derive from Canvas and
RenderContext, implement the abstract members, and override the virtual ones you can do better than the default (layers, links,
tiles). The guide has the full list and the contracts, such as units (PixelsPerPoint) and how raster fallbacks are requested.
More
- The PeachDrawing.Core guide: every type, layers and retained layers, tile and hatch brushes, anti-aliasing and sampling, implementing a backend.
- API reference
Sponsorship
PeachPDF is free and open source. If it saves you time, you can sponsor jhaygood86 on GitHub; sponsors can get paid support, see Sponsorship.
License
BSD 3-Clause (see LICENSE).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- PeachDrawing.Text (>= 0.10.0)
-
net11.0
- PeachDrawing.Text (>= 0.10.0)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on PeachDrawing.Core:
| Package | Downloads |
|---|---|
|
PeachPDF
Renders HTML and CSS to PDF in pure .NET, with no browser or external process: HTML parsing, the CSS cascade, layout, SVG, MathML and the PDF writer all run in-process. |
|
|
PeachDrawing
A standalone software raster Canvas for PeachDrawing.Core - draw shapes, text and images onto a bitmap and save it in any PeachImage-supported format, with no PDF, HTML or CSS involved. |
|
|
PeachDrawing.PDF
A PDF Canvas for PeachDrawing.Core: draw shapes, text, images, gradients and effects and write them as PDF, with fonts embedded and subset, PDF/A and PDF/X conformance, encryption and tagged output, in pure .NET. |
|
|
PeachBrackets
Parses HTML, CSS, SVG and MathML, resolves the cascade and lays the document out into pages, then paints them onto any PeachDrawing canvas: PDF, a bitmap, or your own. |
|
|
PeachDrawing.Svg
A vector SVG Canvas for PeachDrawing.Core - draw shapes, gradients, clips, text and images and save them as SVG, with paths, curves, gradients and glyph outlines kept as vector content and no PDF, HTML or CSS involved. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.10.0 | 733 | 11/13/2026 |
| 0.9.27 | 135 | 11/13/2026 |
| 0.9.26 | 3,345 | 11/6/2026 |
| 0.9.26-preview1 | 201 | 11/3/2026 |
| 0.9.25 | 4,874 | 10/31/2026 |
| 0.9.25-preview1 | 176 | 10/27/2026 |
| 0.9.24 | 9,918 | 10/23/2026 |
| 0.9.23 | 7,710 | 10/16/2026 |
| 0.9.22 | 2,678 | 10/9/2026 |
| 0.9.21 | 4,735 | 10/2/2026 |