[cairo] Some pango attributes not making it to cairo
Simon Cozens
simon at simon-cozens.org
Thu May 22 20:01:46 PDT 2014
Hello all,
I'm using Pango to shape some text and Cairo to output it (using
pango_cairo_show_glyph_string). I'm using Pango's attributes to determine what
I want the text to look like. Most of the time this works fine, but some
attributes are not working. Here's the (lua) code I have:
local lgi = require("lgi");
local cairo = lgi.cairo;
local surface = cairo.PdfSurface.create("foo.pdf", 300,300)
local cr = cairo.Context.create(surface)
cr:set_source_rgb(0,0,0)
local x = 50
local pango = lgi.Pango
local pal = pango.AttrList.new();
pal:insert(pango.Attribute.style_new(pango.Style.ITALIC))
pal:insert(pango.Attribute.weight_new(700))
pal:insert(pango.Attribute.strikethrough_new(true))
pal:insert(pango.Attribute.underline_new(pango.Underline.DOUBLE))
pal:insert(pango.Attribute.foreground_new(65535,0,0))
local fm = lgi.PangoCairo.FontMap.get_default()
local pango_context = lgi.Pango.FontMap.create_context(fm)
local s = "Hello world"
items = pango.itemize(pango_context, s, 0, string.len(s), pal, nil)
for i in pairs(items) do
local offset = items[i].offset
local length = items[i].length
local analysis = items[i].analysis
local pgs = pango.GlyphString.new()
pango.shape(string.sub(s,1+offset), length, analysis, pgs)
cr:move_to(x, 50)
cr:show_glyph_string(analysis.font, pgs)
x = x + pgs:get_width()/1024
end
cr:show_page();
This produces italic, boldface text, but with no colors and no underline and
strikethrough. Is cairo meant to render those attributes, or am I supposed to
be handling them manually?
Thanks,
Simon
More information about the cairo
mailing list