[cairo] rotated characters does not keep baseline

Jan Slupski jslupski at juljas.net
Wed Apr 4 09:47:32 PDT 2007


Hi list,

Since 1.4 rush seems to slow down, I would like to bring back
a few issues reported before 1.4.0.

Problem:
(http://lists.freedesktop.org/archives/cairo/2007-February/009686.html)

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
    freetype-2.2.1-16
    fontconfig-2.4.1-3


***UPDATE***:
   Tested with cairo 1.4.2
   Use test string "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" to easily see the problem.

   During some (unrelated directly) discussions on the list I have learned that
   the effect can be due to glyph cache, that stores only single image of a letter
   that is later reused.  This seems to be wrong in any (metrics-)unhinted mode
   (rotated or not).

Thanks,
Jan


    _  _  _  _  _____________________________________________
    | |_| |\ |  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>

int
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_paint(cr);


	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_save(cr);

			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_stroke(cr);

			cairo_restore(cr);
		}
		
		//text
		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: 5906 bytes
Desc: 
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070404/d2f48ee4/rotlabel2.obj


More information about the cairo mailing list