Re: Drawing a halo around text



On 10/26/07, Behdad Esfahbod <behdad behdad org> wrote:
> On Fri, 2007-10-26 at 10:11 -0500, Matt Hoosier wrote:
> > Hi,
> >
> > I'd like to draw some text over the top of a user-supplied splash
> > screen. Because I can't know what the color scheme contained in that
> > image will be, I need to do something like paint a small (1-pixel ?)
> > border of known color around the edges of my glyphs, in order to
> > guarantee that the lettering is visible.
> >
> > Is there a way to convince Pango to do that sort of thing?
>
> Yes and no. You need to do it yourself, but pango gives you the tools
> for.
>
> First, use pangocairo with gdk.  Then you can do things like:
>
>   cairo_move_to (cr, x, y);
>   cairo_pango_layout_path (cr, layout);
>
>   /* blue halo */
>   cairo_set_source_rgba (cr, 0., 0., 1., .5);
>   cairo_set_line_width (cr, 2.);
>   cairo_stroke_preserve (cr);
>
>   /* green letters */
>   cairo_set_source_rgb (cr, 0., 1., 0.);
>   cairo_fill (cr);
>
> An uglier but possibly faster option is to render the text 5 times:
>
>   /* blue halo */
>   cairo_set_source_rgb (cr, 0., 0., 1.);
>   cairo_move_to (cr, x-1, y); cairo_pango_show_layout (cr, layout);
>   cairo_move_to (cr, x+1, y); cairo_pango_show_layout (cr, layout);
>   cairo_move_to (cr, x, y-1); cairo_pango_show_layout (cr, layout);
>   cairo_move_to (cr, x, y+1); cairo_pango_show_layout (cr, layout);
>
>   /* green letters */
>   cairo_set_source_rgb (cr, 0., 1., 0.);
>   cairo_move_to (cr, x, y); cairo_pango_show_layout (cr, layout);

Thanks, that's exactly what I was looking for.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]