[cairo] (Rotated) text always hinted and font antialiasing setting ignored

Jan Slupski jslupski at juljas.net
Fri Feb 16 13:34:40 PST 2007


I wonder if someone could point me what I'm doing wrong, or
confirm these are bugs:

With the attached example, I'm drawing simple text label
over image surface. Text is rotated of 45 degrees.

I noticed two problems:

1. cairo_font_options_set_antialias setting is ignored

I'm trying to get gray antialias, but engine switches
me to subpixel antialiasing.

My code:

   cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY);
   cairo_font_options_set_antialias(font_options, CAIRO_ANTIALIAS_GRAY);
   cairo_set_font_options (cr, font_options);
   cairo_text_extents(cr, string, &size);

seems to be ignored, and setting from _get_pattern_ft_options()

   if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) {
       ft_options.base.subpixel_order = subpixel_order;
       ft_options.base.antialias = CAIRO_ANTIALIAS_SUBPIXEL;

is prefered.

2. I'm trying to force metrics hinting to be OFF for rotated text
    (correct me, but I think that should be default?), but it seems
    that some kind of hinting is still applied (or maybe that's some
    cache effect?)

    On attached picture you can see that letters are not layed out
    on the same baseline.

    Also, looking closely (zoom x8) I noticed that shapes of all
    same letters looks identically (although they are not necessairly
    on the same basline - compare 'l' in "display" and 'l' in "angle").

    The same string with the same font at the same angle look way better
    at bare FreeType.

      ftstring  -m "Hello this is long text to be display at some angle" 10 times.ttf
    and rotate with right cursor until 45 degrees.

My configuration:
   Cairo version: 1.3.14


    _  _  _  _  _____________________________________________
    | |_| |\ |  S L U P S K I             jslupski at juljas.net
  |_| | | | \|                             http://juljas.net/
-------------- next part --------------

#include <cairo.h>
#include <math.h>
#include <stdio.h>

main (int argc, char *argv[]) {
	cairo_surface_t *surface;
	cairo_t *cr;

	char string[] = "Hello this is long text to be display at some angle";
	cairo_text_extents_t size;
	double fontsize = 10.0;

	printf("Cairo version: %s\n",cairo_version_string());

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 400, 300);
	cr = cairo_create (surface);

	cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY);

	//white background
	cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1);

	cairo_select_font_face (cr, "Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fontsize);

	//font options
		cairo_font_options_t *font_options;
		font_options = cairo_font_options_create ();
		cairo_get_font_options (cr, font_options);

		cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
		cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
		cairo_font_options_set_antialias(font_options, CAIRO_ANTIALIAS_GRAY);
		cairo_set_font_options (cr, font_options);
		cairo_font_options_destroy (font_options);

	cairo_text_extents(cr, string, &size);

		int angle = 315;
		//move to the center
		cairo_translate (cr, 200, 150);
		//rotate around text center
		cairo_rotate(cr, angle / 180.*3.1415926);
		//center the text
		cairo_translate(cr, -size.width/2, size.height/2);

		//line below the text
		if(1) {

			cairo_move_to (cr, 0, 1.7);
			cairo_rel_line_to (cr, size.width, 0);

			cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1); 
			cairo_set_line_width(cr, 0.3);

		cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1); 
		cairo_show_text (cr, string);

	cairo_surface_write_to_png (surface, "rotlabel2.png");
	cairo_destroy (cr);
	cairo_surface_destroy (surface);
	return 0;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rotlabel2.png
Type: application/octet-stream
Size: 5978 bytes
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070216/b7c65b77/rotlabel2.obj

More information about the cairo mailing list