Re: [Inkscape-devel] Something special about Cairo glyph draws?
2013/5/8 mathog <mathog@...1176...>:
Hi,
One more question regarding cairo drawing within inkscape. I have most of the text_decoration for CSS 2 and CSS 3 implemented (for drawing, assuming it is already in the SVG; dotted, dashed, and wavy are only represented with more lines for the moment, see attachment) but cannot get the text_decoration_color field to "take". The color data gets all the way to drawing_text.cpp, where the decoration render code does this:
ct.save(); // The next call is SUPPOSED to change the pen color - it does not ct.setSource( _nrstyle.text_decoration_color.color.v.c[0], _nrstyle.text_decoration_color.color.v.c[1], _nrstyle.text_decoration_color.color.v.c[2], 1.0 );
std::cout << "DEBUG RGB {" << _nrstyle.text_decoration_color.color.v.c[0] << "," << _nrstyle.text_decoration_color.color.v.c[1] << "," << _nrstyle.text_decoration_color.color.v.c[2] << "}" <<std::endl;
// code that draws underline, strike-through etc. here
ct.restore();
The output of the program shows:
... DEBUG RGB {0,0,0} DEBUG RGB {0,0,0} DEBUG RGB {0.25098,0.878431,0.815686} DEBUG RGB {0.25098,0.878431,0.815686} DEBUG RGB {1,0.647059,0} DEBUG RGB {1,0.647059,0} DEBUG RGB {0,0.501961,0} DEBUG RGB {1,0,0} DEBUG RGB {0,0,1} ...
which looks to me like the colors are OK, but on the screen all of the lines are the same color as the text. The line draws are between the save and restore too, so that part is working properly, just not the change in color.
Any idea what is wrong with this approach?
Cairo will only actually draw the pixels once you call cairo_stroke or cairo_fill. Before then, the target surface is not modified - only the context's path information is. If the decoration is a different color, you need to call this operator twice - once for text and the second time for the decoration.
One more remark; I don't think implementing this functionality "manually" is the right approach. Pango, the text layout library we're using, has built-in support for decorations, but for historical reasons we are not using the layouts generated by Pango. The proper way to add these features would be to pass along the Pango layout down to the display tree level and then use Pango-Cairo to display it. This would have some additional benefits, e.g. we could configure hinting and antialiasing properties for the displayed text.
https://developer.gnome.org/pango/stable/PangoMarkupFormat.html https://developer.gnome.org/pango/unstable/pango-Cairo-Rendering.html
Regards, Krzysztof
participants (1)
-
Krzysztof Kosiński