<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
I have modified my code to set the font after doing the transform
(previously was setting before doing the transform) but doing this
doesn't seem to make any difference.<br>
<br>
Here's an edited version of the code I've implemented outlining key
points for cairo and font interactions...<br>
<br>
<br>
void draw_glyphs( cairo_t *cr, FT_Face face, unsigned int const x,
unsigned int const y, paint_t paint )<br>
{<br>
cairo_save( cr );<br>
<br>
cairo_translate( cr, x, y );<br>
cairo_rotate( cr, 1.5708 );<br>
<br>
/* The freetype {x,y}_scale is a 16.16 value to convert from
font units 26.6 pixels. The cairo scaling factor is the size of the
em square in pixels. */<br>
cairo_matrix_t font_scale;<br>
float units_per_EM_scaled = (float)face->units_per_EM /
64.0f;<br>
double sx = (double)( (float)face->size->metrics.x_scale /
65536.0f * units_per_EM_scaled );<br>
double sy = (double)( (float)face->size->metrics.y_scale /
65536.0f * units_per_EM_scaled );<br>
cairo_matrix_init_scale( &font_scale, sx, sy );<br>
cairo_set_font_matrix( cr, &font_scale);<br>
<br>
cairo_font_face_t *font_face;<br>
font_face = cairo_ft_font_face_create_for_ft_face( face, 0 );<br>
cairo_set_font_face( cr, font_face );<br>
<br>
cairo_set_source_rgba( cr, paint->red, paint->green,
paint->blue, paint->alpha );<br>
cairo_show_glyphs( cr, glyphs, num_glyphs );<br>
<br>
cairo_identity_matrix( cr );<br>
cairo_set_font_face( cr, NULL);<br>
cairo_font_face_destroy( font_face );<br>
<br>
cairo_restore( cr );<br>
}<br>
<br>
<br>
I re-ran the code after commenting out the line:<br>
<br>
/* cairo_set_font_face( cr, font_face ); */<br>
<br>
This resulted in a default font face being used (looks like a
cursive font?), but the rotation worked perfectly. I never saw any
mixed horizontal and vertical characters, which to me, indicates
there's an issue somewhere in Cairo when drawing a "non-default"
font face after being rotated.<br>
<br>
<br>
BTW, I also re-ran the code using a scaled font and locking /
unlocking it, but doing that also shows the issue.<br>
<br>
<br>
Thanks,<br>
Matt.<br>
<br>
<br>
<div class="moz-cite-prefix">On 06/01/16 18:38, Bill Spitzak wrote:<br>
</div>
<blockquote
cite="mid:CAL-8oAhoePpaW2C=U6KA85BvNUoUf+6M3QDby2Oa2c1aadV=fw@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div dir="ltr">
<div>You have to set the font after you do the transform.<br>
<br>
</div>
However I did not expect this mess, I thought what Cairo did was
draw the font as though the transform it was using before was
still in effect (ie "font lock", similar to the proposed "line
width lock").<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Wed, Jan 6, 2016 at 7:45 AM, Matthew
Conway <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:mconway@espial.com" target="_blank">mconway@espial.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">I'm trying
to rotate an array of glyphs (where each glyph represents a
textual character).<br>
<br>
Consider the following:<br>
<br>
----------------<br>
| A TEXT LABEL |<br>
----------------<br>
<br>
Where the rectangle is a solid coloured background and the
text is drawn (centered) on top of the rectangle (think
subtitles being displayed on a TV screen).<br>
<br>
For some situations, I need to rotate the text label
(rectangle and text) 90 degrees clockwise. I do not expect
the text rotation to be vertical as shown here:<br>
<br>
|̄ ̄ ̄ |<br>
| A |<br>
| |<br>
| T |<br>
| E |<br>
| X |<br>
| T |<br>
| |<br>
| L |<br>
| A |<br>
| B |<br>
| E |<br>
| L |<br>
|___|<br>
<br>
Instead, I am expecting the text to be rotated (in position)
with the label.<br>
<br>
Sometimes (about 25% of the time), Cairo seems to be
rotating random text characters and drawing them over the
top of other correctly rotated characters.<br>
<br>
/* Draw the labels background */<br>
cairo_rectangle( cr, x, y, width, height );<br>
cairo_set_source_rgba( cr, red, green, blue, alpha );<br>
cairo_fill( vg->cairo_context );<br>
<br>
/* Rotate 90 degrees clockwise and show the text
*/cairo_translate( cr, x, y );<br>
cairo_rotate( cr, 1.5708 );<br>
cairo_show_glyphs( cr, glyphs, num_glyphs );<br>
<br>
<br>
Notes:<br>
1. The glyphs are created by freetype libraries.<br>
2. The system is using Wayland to draw the text labels.<br>
<br>
<br>
I've tried quite a few things, the most successful was to
add a call to show_glyphs before translating, which reduces
the issue to show approximatley 5% of the time:<br>
<br>
/* Rotate 90 degrees clockwise and show the text */<br>
cairo_show_glyphs( cr, glyphs, num_glyphs );<br>
cairo_translate( cr, x, y );<br>
cairo_rotate( cr, 1.5708 );<br>
cairo_show_glyphs( cr, glyphs, num_glyphs );<br>
<br>
<br>
I've taken a photo of the screen to show what the issue
looks like, it can be viewed here:<br>
<a moz-do-not-send="true"
href="http://postimg.org/image/x4g4fne5h/"
rel="noreferrer" target="_blank">http://postimg.org/image/x4g4fne5h/</a><br>
<br>
<br>
I'm using:<br>
- latest cairo 1.14.6<br>
- freetype to create the font glyphs<br>
- Wayland<br>
<br>
<br>
Thanks,<br>
Matt.<span class="HOEnZb"><font color="#888888"><br>
-- <br>
cairo mailing list<br>
<a moz-do-not-send="true"
href="mailto:cairo@cairographics.org" target="_blank">cairo@cairographics.org</a><br>
<a moz-do-not-send="true"
href="http://lists.cairographics.org/mailman/listinfo/cairo"
rel="noreferrer" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a></font></span></blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>