[cairo] text with outline ?

Carl Worth cworth at cworth.org
Mon Jan 22 14:04:20 PST 2007

On Mon, 22 Jan 2007 13:55:29 -0800, Smon Burton wrote:
> Is there a smarter way to draw text with an outline ?


> def outline_text(ctx, x, y, txt):
>     ctx.set_source_rgba(1, 1, 1, 1)
>     for _x in (x-1, x+1):
>         for _y in (y-1, y+1):
>             ctx.move_to(_x, _y)
>             ctx.show_text(txt)
>             ctx.stroke()

First, what's that ctx.stroke() doing there? It should be having no
effect at all. Please remove it and let me know if anything changes.

Finally, here's what should do what I think you're trying to achieve,
(eliminate both of the nested loops above):

>     ctx.set_source_rgba(0, 0, 0, 1)
>     ctx.move_to(x, y)
>     ctx.show_text(txt)
      ctx.set_source_rgba(1, 1, 1, 1)
      ctx.move_to(x, y)
>     ctx.stroke()

Give that a try and let us know if you're still having trouble.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070122/9e5c1d2a/attachment.pgp

More information about the cairo mailing list