[cairo] Using Pango and TrueType Fonts

Olaf Schmidt ng at vbRichClient.com
Sat Feb 28 18:03:41 PST 2015

Am 26.02.2015 um 19:42 schrieb Michael Gerbracht:

>>> I would like to use Pango with Cairo to display data in graphs.[...] ..
> My problem is, that the resulting svg does not use the Wingdings font to
> display the text.

The Toy-API seems to work well enough for such simple purposes...

Using the Windows-Download from:
(on a Win-8-VM) and a slight adaption of example #2, to an SVG-Surface:


local cairo = require"lcairo"
local CAIRO = cairo

w = 480
h = 240
cs = cairo.svg_surface_create('cairo_test.svg', w, h)
cr = cairo.create(cs)

cairo.select_font_face(cr, "WingDings", CAIRO.FONT_SLANT_NORMAL,
cairo.set_font_size(cr, w/8)
cairo.move_to(cr, 0, 3*h/4)
cairo.text_path (cr, "LUA-lua")
cairo.set_source_rgb (cr, 0.5, 0.5, 1)
cairo.fill_preserve (cr)
cairo.set_source_rgb (cr, 0, 0, 0)
cairo.set_line_width (cr, w/200)
cairo.stroke (cr)

cairo.destroy (cr)
cairo.surface_destroy (cs)


The following SVG-Output was produced:

... which looks quite "WingDingish" to me...

Aside from that, you seem to prefer the generation (and positioning)
of different "Point-Types" in your Graphs per Font-Rendering, ...
a better alternative would be (IMO), to write your own little LUA-
function, to construct a regular polygon around a given center-point:

Using only 5 Parameters (cx, cy, rInner, rOuter, nSides) you can
produce a lot of different "Point-Shapes" all with the same function
(which shouldn't take much more than 15-20 lines of code - then
generating a less voluminous SVG-output along the way as well).


More information about the cairo mailing list