[cairo] Font matrix difference between 1.0.4 & 1.2.0
Jan Slupski
jslupski at juljas.net
Thu Jul 13 14:01:20 PDT 2006
Hi list,
I found the change in Cairo's behavior between 1.0.4 and 1.2.0 related
to text handling.
Basically I'm trying to use the matrix to setup text rotation.
I use following code:
cairo_move_to()
cairo_matrix_init_identity(&matrix);
//rotate around text center
cairo_matrix_translate(&matrix, size.width/2, -size.height/2);
cairo_matrix_rotate(&matrix, 90/180.*3.1415926);
cairo_matrix_translate(&matrix, -size.width/2, size.height/2);
cairo_matrix_scale(&matrix, fontsize, fontsize);
cairo_set_font_matrix(cr, &matrix);
cairo_show_text (cr, string);
While this code used to work with cairo 1.0.4, it does not in 1.2.0
anymore. Seems like the rotation(?) translation(?) is applied to
every letter separately.
Is this intentional?
Samples and the example code attached.
Thanks,
Jan Slupski
_ _ _ _ _____________________________________________
| |_| |\ | 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;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 400, 300);
cairo_t *cr;
char string[] = "Hello";
cairo_text_extents_t size;
double fontsize = 100.0;
printf("Cairo version: %s\n",cairo_version_string());
cr = cairo_create (surface);
//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);
cairo_text_extents(cr, string, &size);
cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 1.0); //blue opaque
cairo_move_to (cr, 200.0 - size.width/2, 150 + size.height/2);
cairo_show_text (cr, string);
{
cairo_matrix_t matrix;
cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.7); //red a little transparent
cairo_move_to (cr, 200.0 - size.width/2, 150 + size.height/2);
cairo_matrix_init_identity(&matrix);
//rotate around text center
cairo_matrix_translate(&matrix, size.width/2, -size.height/2);
cairo_matrix_rotate(&matrix, 90/180.*3.1415926);
cairo_matrix_translate(&matrix, -size.width/2, size.height/2);
cairo_matrix_scale(&matrix, fontsize, fontsize);
cairo_set_font_matrix(cr, &matrix);
cairo_show_text (cr, string);
}
cairo_surface_write_to_png (surface, "rotlabel.png");
cairo_surface_destroy (surface);
cairo_destroy (cr);
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rotlabel-1.0.4.png
Type: application/octet-stream
Size: 8805 bytes
Desc:
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060713/fe4d96cb/rotlabel-1.0.4-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rotlabel-1.2.0.png
Type: application/octet-stream
Size: 7225 bytes
Desc:
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060713/fe4d96cb/rotlabel-1.2.0-0001.obj
More information about the cairo
mailing list