[cairo] Cairo move_to(x,Y); show_pango_layout(l) & Output SVG path y do not matchup

Jagan Veeraraghavan jagannathan.v at gmail.com
Sat Aug 8 07:38:16 PDT 2015


Hi,
I am trying to use Cairo-pango to render text as svg. The following ruby
code shows that the ink lbearing=0 & ascent=-16. So i do a move_to (0,+16).
But the output svg has y at 66.40091. I expected output svg y to begin at
16. So the text is not snug fit to right top and there is a vertical
padding of 50 pixels. Is my code wrong or my expectation from the code
wrong. Is it possible to position the text so that it 'hugs' the top & left.

----txt2svg.rb----------
def draw_text(cr)
text1 = "The grass is greener where we're going."
  layout = cr.create_pango_layout
  desc = Pango::FontDescription.new(FONT1)
  layout.set_font_description(desc)
  layout.set_text(text1)
  ink,logical=layout.pixel_extents
  puts ink.lbearing,ink.ascent
  cr.move_to(ink.lbearing*-1,ink.ascent*-1)
  cr.update_pango_layout(layout)
  cr.show_pango_layout(layout)
end
surface = Cairo::SVGSurface.new("text.svg",1080, 720)
cr = Cairo::Context.new(surface);
draw_text(cr)

-----------------

---text.svg---


<?xml version="1.0" encoding="UTF-8"?>

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="
http://www.w3.org/1999/xlink" width="1080pt" height="720pt" viewBox="0 0
1080 720" version="1.1">

<defs>

<g>

<symbol overflow="visible" id="glyph0-0">

<path style="stroke:none;" d="M 11.765625 -7.484375.......

.........

</defs>

<g id="surface1">

<g style="fill:rgb(0%,0%,0%);fill-opacity:1;">

<use xlink:href="#glyph0-1" x="0" y="66.400391"/>

<use xlink:href="#glyph0-2" x="22.65625" y="66.400391"/>

<use xlink:href="#glyph0-3" x="46.416016" y="66.400391"/>

<use xlink:href="#glyph0-4" x="68.832031" y="66.400391"/>
....
</svg>
---------------

Jagan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150808/37114da4/attachment.html>


More information about the cairo mailing list