Cross-platform pango layout size



Hi everyone,

I am porting to OS X a small PyGTK diagramming app, where it is important for layout sizes to be stable across platforms as the space alloted to a piece of text is fixed.

I've found that the size of an programmatically identical layout differs between win32 and OS X (I haven't tested on linux). I copied the Windows arial.ttf file and variants over to my mac and disabled the system Arial in fontbook in an attempt to ensure that this wasn't due to subtly different font versions. The output of the attached script appears below (note pango 1.26.0 on win32 - I couldn't compile 1.27.1 due to some libtool issue).

Is this a bug? If so, does anyone know how much work a fix would require? If there's a rough handle of what's involved, I would be happy to consider diving into it myself.

many thanks,
Richard.

(OS X version includes Kristian Rietveld's patch for honouring absolute sized font descriptions https://bugzilla.gnome.org/ show_bug.cgi?id=611033)

Pango Version:  1.27.1+f4201009d192300442e76d25a83c0dab8022d0d6
Fontmap:
Object: <pango.CairoATSUIFontMap object at 0x11a7080 (PangoCairoATSUIFontMap at 0x507000)>
Resolution:  100.0

Font Description:
Stringified: 'arial 12px'
Family:  arial
Raw size (pango units):  12288
Size:  12.0
Size units:  pixels

Metrics:
Font Metrics ascent/descent  10.86328125 2.54296875 <---
Font Metrics approx char width  5.4716796875 <---

Layout:
Text: 'The origin of thinking is some perplexity, confusion or doubt.'
Pixel size is  (320, 14) <---

--

Pango Version:  1.26.0
Fontmap:
Object: <pango.CairoWin32FontMap object at 0x9db0a8 (PangoCairoWin32FontMap at 0xbc1120)>
Resolution:  100.0

Font Description:
Stringified: 'arial 12px'
Family:  arial
Raw size (pango units):  12288
Size:  12.0
Size units:  pixels

Metrics:
Font Metrics ascent/descent  12.0 3.0 <---
Font Metrics approx char width  5.59375 <---

Layout:
Text: 'The origin of thinking is some perplexity, confusion or doubt.'
Pixel size is  (327, 15) <---

import pango
import pangocairo 

print "Pango Version: ", pango.version_string()

fm = pangocairo.cairo_font_map_get_default()

fm.set_resolution(100) # irrelevant now due to patch 
print "Fontmap: "
print "Object: ", fm 
print "Resolution: ", fm.get_resolution()
print

context = fm.create_context() 

fd = pango.FontDescription('arial')
fd.set_absolute_size(12 * pango.SCALE) 

print "Font Description: " 
print "Stringified: '%s'" % fd.to_string() 
print "Family: ", fd.get_family() 
print "Raw size (pango units): ", fd.get_size()
print "Size: ", fd.get_size() / float(pango.SCALE)
print "Size units: ", ("points", "pixels")[fd.get_size_is_absolute()] 
print 

metric = context.get_metrics(fd)
print "Metrics: " 
print "Font Metrics ascent/descent ", metric.get_ascent()/float(pango.SCALE), metric.get_descent() / float(pango.SCALE)
print "Font Metrics approx char width ", metric.get_approximate_char_width() / float(pango.SCALE) 
print 

layout = pango.Layout(context)
layout.set_font_description(fd)
layout.set_text("The origin of thinking is some perplexity, confusion or doubt.")

print "Layout: "
print "Text: '%s'" % layout.get_text() 
print "Pixel size is ", layout.get_pixel_size()





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]