Re: Rendering text with an outline



Please create a snapshot of what you mean and preferably also with what you expect.

There are two things to note here though:
  • Antialiasing creates additional gray levels that are a mixture of the background and the color you chose.
  • One pixel shift is far too little to create a visible drop shadow. You need at least 5 pixels.
Related to this I started thinking that it would be cool to create a label that would implement at least some of the effects of SVG filters, see http://www.w3.org/TR/SVG/filters.html , with the effect applied controlled by properties and style sheets. But I guess that I am being carried away. :-)

Regards,
Dov

2009/3/11 jonathan david <jodagm gmail com>
Hi,

I am trying to follow your example to render another font variant: I need font with 2 colors and 1pixel shift in x,y between each color
that would create a shadow.

    cairo_t *cr = gdk_cairo_create(widget->window);
    PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(widget)); 
    int width=-1, height=-1;

    pango_layout_get_size(layout, &width, &height);
    /* add 1 pixel to x and y and draw white shadow */
    cairo_move_to(cr, widget->allocation.x + 
(widget->allocation.width - width / PANGO_SCALE) / 2 +1,  
height / PANGO_SCALE / 2 +1);
    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_set_line_width(cr, 1.0);
    pango_cairo_show_layout(cr, layout);
    pango_cairo_layout_path(cr, layout);
    cairo_stroke(cr);
   
    /* draw black font */
    cairo_set_source_rgb(cr, 0, 0, 0);
    cairo_set_line_width(cr, 1.0);
    cairo_move_to(cr, widget->allocation.x + 
(widget->allocation.width - width / PANGO_SCALE) / 2, 
height / PANGO_SCALE / 2);
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
    pango_cairo_layout_path(cr, layout);
    cairo_stroke(cr); 

the problem is that I get blurred fonts. 

when I draw only one of the colors -  the font looks blurred at the edges, I need all the pixels to be in the same color but what I get is 
black in the middle and gray edges
when I draw the 2 colors one over the other - I get smudged font, looks line the white background emerges through the black foreground

I tried calling cairo_set_line_join with all options but I am probably missing something with the font definition

Thanks for your help,
Jonathan




2009/3/7 Dov Grobgeld <dov grobgeld gmail com>
Note that it is not completely trivial to use pango_show_layout_line instead of pango_show_layout as they have different anchor points. pango_show_layout draws with the current point at the upper logical extent of the layout, and pango_show_layout_line draws with respect to the baseline of the text. See:

http://live.gnome.org/PangoLayoutLineBbox

Thus it does not make sense to create a binding for just one of them.

Regards,
Dov

2009/3/7 Chris Vine <chris cvine freeserve co uk>

On Fri, 06 Mar 2009 12:14:53 +0100
Christian Schaubschlaeger <cs gup uni-linz ac at> wrote:
> Dov Grobgeld schrieb:
> > I cleaned up my example a bit and put it in GnomeLive. See:
> >
> > http://live.gnome.org/OutlineLabel
>
> Thanks for the example!
> I'm just trying to port it to gtkmm. Unfortunately I
> cannot find the corresponding C++ construct for the
> "Pango.cairo_show_layout()" call in Dov's Vala code.
> Would that be a pangocairo function? I could not find
> C++ bindings for the pangocairo lib. Are there any?
> However, I'm not sure if the code snippet below is
> correct at all, I'm (unfortunately) new to Pango and
> Cairo...
>
> Thanks and best regards
> Christian
>
> bool
> OutlineLabel::on_expose(GdkEventExpose *event)
> {
>     //Gdk::cairo_create(this->window);
>     Cairo::RefPtr<Cairo::ImageSurface> surface;
>     Cairo::RefPtr<Cairo::Context> cr;
>     Glib::RefPtr<Pango::Layout> layout;
>     int width,height;
>
>     layout = this->get_layout();
>     width = -1; height = -1;
>     layout->get_size(width,height);
>
>     surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
> width, height); cr = Cairo::Context::create(surface);
>     cr->move_to((this->get_allocation().get_width()-width/Pango::SCALE)/2,0);
>     cr->set_sorce_rgba(1,0,0,1);
>
>     // in VALA: Pango.cairo_show_layout(cr,layout);
>     // in C++?
>     ...
>
> }

pango_cairo_show_layout() does not appear to be wrapped, but
pango_cairo_show_layout_line() is (as
Pango::LayoutLine::show_in_cairo_context()), so I suggest you use that
with Pango::Layout::get_line() and/or Pango::Layout::get_lines().

Chris


_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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