[cairo] transforming text

Behdad Esfahbod behdad at behdad.org
Wed Aug 5 11:08:31 PDT 2009


On 08/05/2009 01:47 PM, Matt Bartolome wrote:
> Hi,
> I'm drawing in geographic units so I applied a transform and translate
> to draw correctly in pixel space. This works fine. When I draw the
> text using the same transformation it appears vertically reflected
> (this is what I would expect it to do). How would you go about drawing
> the text so it doesn't appear flipped, but still in the correct x,y
> position and rotation? Attached is a clip of the image I'm getting,
> obviously the text is wrong and is what I'm trying to correct.

Hi Matt,

Use a font matrix that reflects it back to normal.  cairo_set_font_matrix() 
for example.  It normally is just a scale the size of the font size.

Cheers,
behdad


> Hints, pointers appreciated!
> Thanks,
> Matt
>
> #bounds in geographic units
> xmin, ymin, xmax, ymax = max_bounds(sticks)
>
> #scale factor
> scale_x = width / (xmax-xmin)
> scale_y = height / (ymax-ymin)
> scale = min([scale_x, scale_y])
>
> ctx.save()
> ctx.scale(scale,scale)
> #flip y
> matrix = cairo.Matrix(1, 0, 0, -1, 0, 0)
> ctx.transform(matrix)
> #output from 0,0
> ctx.translate(xmin, -ymax)
>
> #draw 2d profile components
> ctx = horizontal_center(ctx, sticks)
> ctx = stick_head(ctx, sticks)
> ctx = surface_elevations(ctx, sticks)
> ctx.restore()
>
> #at this point I would like to draw the text somehow with the proper
> transform, rotation etc...
> ctx = draw_text(ctx,sticks)
>
> surface.finish()
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list