Need help with canvas?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

tdewolff
687 Stars 37 Forks MIT License 706 Commits 5 Opened issues

Description

Cairo in Go: vector to raster, SVG, PDF, EPS, WASM, OpenGL, Gio, Fyne, etc.

Services available

!
?

Need anything else?

Contributors list

# 19,004
XML
js
minify
Shell
626 commits
# 43,374
Visual ...
dropbox
tus
instagr...
34 commits
# 689,642
Go
C
3 commits
# 112,165
golang-...
MySQL
golang
yaml-pa...
2 commits
# 196,506
Ada
lisp-in...
Lisp
mal
2 commits
# 157,662
TeX
C
Shell
svg-ico...
1 commit
# 7,637
Go
Shell
golang
logrus
1 commit
# 196,496
Ruby
ember-c...
Ember
Terrafo...
1 commit
# 271,990
Markdow...
commonm...
golang
Shell
1 commit

Canvas

API reference User guide Go Report Card Coverage Status Donate

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, OpenGL, and Gio. It has a wide range of path manipulation functionality such as flattening, stroking and dashing implemented. Additionally, it has a text formatter and embeds and subsets fonts (TTF, OTF, WOFF, WOFF2, or EOT) or converts them to outlines. It can be considered a Cairo or node-canvas alternative in Go. See the example below in Figure 1 for an overview of the functionality.

Preview

Figure 1: top-left you can see text being fitted into a box, justified using Donald Knuth's linea breaking algorithm to stretch the spaces between words to fill the whole width. You can observe a variety of styles and text decorations applied, as well as support for LTR/RTL mixing and complex scripts. In the bottom-right the word "stroke" is being stroked and drawn as a path. Top-right we see a LaTeX formula that has been converted to a path. Left of that we see an ellipse showcasing precise dashing, notably the length of e.g. the short dash is equal wherever it is on the curve. Note that the dashes themselves are elliptical arcs as well (thus exactly precise even if magnified greatly). To the right we see a closed polygon of four points being smoothed by cubic Béziers that are smooth along the whole path, and the blue line on the left shows a smoothed open path. On the bottom you can see a rotated rasterized image. The result is equivalent for all renderers (PNG, PDF, SVG, etc.).

Back-ends

  • Raster images (PNG, GIF, JPEG, TIFF, ...)
  • PDF
  • SVG
  • EPS
  • HTMLCanvas
  • OpenGL
  • Gio

Front-ends

Sponsors

Please see https://www.patreon.com/tdewolff for ways to contribute, otherwise please contact me directly!

Recent changes

  • Renderers have been moved from
    github.com/tdewolff/canvas/.
    to
    github.com/tdewolff/canvas/renderers/.
  • FontFamily.Use()
    is deprecated, use
    FontFamily.SetFeatures()
    (not yet used)
  • DPMM
    is now a function just like
    DPI
    :
    rasterizer.PNGWriter(5.0 * canvas.DPMM)
    =>
    rasterizer.PNGWriter(canvas.DPMM(5.0))
  • FontFace
    is now passed around as a pointer
  • NewRichText
    now requires a default
    *FontFace
    to be passed
  • Use the
    latex
    build tag to use the original LaTeX expression parser

Documentation

API documentation

User guide

Examples

Street Map: the centre of Amsterdam is drawn from data loaded from the Open Street Map API.

Mauna-Loa CO2 conentration: using data from the Mauna-Loa observatory, carbon dioxide concentrations over time are drawn

Document: an example of a text document.

OpenGL: an example using the OpenGL backend.

Gio: an example using the Gio backend.

TeX/PGF: an example showing the usage of the PGF (TikZ) LaTeX package as renderer in order to generated a PDF using LaTeX.

go-chart: example usage of the go-chart library, plotting a financial graph.

gonum/plot: example usage of the gonum/plot library.

Articles

My own

Papers

License

Released under the MIT license.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.