[cairo] Backwards glyphs?

Ian Britten britten at caris.com
Wed Oct 22 13:10:18 PDT 2008


Carl Worth wrote:

>> - Configuring a Cartesian (lower-left origin) world transform on it.
> 
> I presume this is something like:
> 
> 	cairo_translate (cr, 0, height);
> 	cairo_scale (cr, 1.0, -1.0); 
> 
> or so?

Correct.  The exact (cairomm) code is:
     this->context->translate(0, mmToPoint(viewportHeightMM));
     this->context->scale(a*MM2POINTFACTOR, -c*MM2POINTFACTOR);
     this->context->translate(-this->worldWindow[0][0],
                              -this->worldWindow[0][1]);

>> Generally, everything is working as expected with my rendering.
>> Lines, polygons, and images all draw correctly.  Even for the glyphs,
>> they're at the correct position, with the specified size, colour, etc.
>> It's just that the individual glyphs are backwards... :(
> 
> A transformation like the above would be expected to invert your glyphs,
> yes, (vertically, not horizontally).

Ya, and *if* they were upside down, then that would be my primary
suspect.  However, they are right-side-up, just backwards, which is
what has me scratching my head as to why...
I attached a couple of screenshots to show what I'm seeing.

>> Am I expected to muck about with cairo_set_font_matrix(), even for
>> simple rendering?  I was hoping just setting the size+position would
>> result in the correct output...
> 
> Well, define "simple rendering" I guess. 

Sorry - I simply meant that I just wanted to render the glyphs
naturally, with no stretch, shear, etc, etc.

 > You're the one going outside cairo's default coordinate system. ;-)

Well, all Geographic data is Cartesian, and it seemed easier to
flip the transformation (As we do with MFC/X/etc), than to rewrite
our framework...  ;-)
Seriously though, this should work ok, shouldn't it?  Am I doing
something 'wrong' or unsupported?  I thought the idea was that I
should be able to draw my data in *its* native coordinate system...

> So, cairo_set_font_matrix with a matrix that will again invert the Y
> axis would be one way to solve this, yes. Another possibility would be
> to draw your glyphs with something like this:
> 
> 	cairo_move_to (cr, x, y);
> 	cairo_save (cr);
> 	cairo_scale (cr, 1.0, -1.0);
> 	cairo_show_text (cr, "text here");
> 	cairo_restore (cr);
> 
> Hopefully that's still simple enough and saves you having to muck with
> the font matrix.

I tried that, but now my text is upside down (and still backwards)  :(
So, I tried the next logical guess, of:
         cairo_scale(cr, -1.0, 1.0);
instead, and now my text simply disappears...  :(

> I've not tested this, so if it doesn't work then blame me for typing too
> fast.

I'm thankful for any help, and won't complain!  :)
Ian

-------------- next part --------------
A non-text attachment was scrubbed...
Name: onscreen.png
Type: image/png
Size: 6740 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20081022/909c8c31/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: via_cairo.png
Type: image/png
Size: 4439 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20081022/909c8c31/attachment-0001.png 


More information about the cairo mailing list