开发者

Why do fonts in Pango change weight when text is rotated in Cairo?

I'm having a problem with Pango rendering under a rotated matrix. I'm attempting to draw a label (see code below) which happens inside of an animating Cairo matrix rotation.

As the label rotates, the text jitters, seeming to grow and shrink in weight, becoming thickest at diagonal angles, and thinnest at orthogonal angles. See this comparison:

Why do fonts in Pango change weight when text is rotated in Cairo?

I'd like the rotated text to generate as if it were just rotating shape paths, and not trying to change the look of the text based on the angle. Any ideas of how I could do this?

Thanks, Sean


        //Draw text with Pango
        PangoLayout *layout;
        PangoFontDescription *desc;

        // pCr is the cairomm context ptr.
        // pCr->cobj() is the underlying C Cairo context ptr.
        pCr->set_source_rgb(0.0, 0.0, 1.0);

        layout = pango_cairo_create_layout(pCr->cobj());
        // text is the label string
        pango_layout_set_text(layout, text.c_str(), -1);

        desc = pango_font_description_from_string("Sans Bold 12");
        pango_layout_set_font_description(layout, desc);

        pango_cairo_layout_path(pCr->cobj(), layout);
        pCr->fill();

        pango_font_description_free(desc);
  开发者_运维问答      g_object_unref(layout);


I can only use Cairo and Pango with Python, not C, but my first guess would be to tinker with ANTIALIAS:

pCr.set_antialias(cairo.ANTIALIAS_DEFAULT)

(this is the syntax for python, not C)

You could try cairo.ANTIALIAS_SUBPIXEL or cairo.ANTIALIAS_NONE to see if there is a difference.

Also, I could not find any rotation in your code, but perhaps you are rotating the text after it is rendered, when you should perform rotation first, and then render (pixelize) the text (vector paths).

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜