X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f X-Recipient: geda-user AT delorie DOT com Message-ID: <51CCD179.7010903@sonic.net> Date: Thu, 27 Jun 2013 16:57:45 -0700 From: Dave Curtis User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: geda-user AT delorie DOT com Subject: [geda-user] gschem cairo text measure Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: geda-user AT delorie DOT com I'm working on a symbol generator, and trying to match up text width measurement with gschem. I've dug into the gschem code a little, and gschem seems to use Cairo these days. I'm not very familiar with Cairo, but I've managed to come up with something that appears to work, but it relies heavily on a magic number that I arrived at empirically. What is the correct way to match up text measurement? Here is what I have: class FontInfo(object): _gschemScalingConstant = 10000.0/555.0 # Magic number def __init__(self): blah blah blah def measure(self, aString): "Returns the layout length of aString in gschem distance." if self._csf == None: self._build_csf() width = self._csf.text_extents(aString)[2] # item 2 of extents is Cairo 'width' return width def _build_csf(self): "Builds and caches a Cairo Scaled Font." fontFace = cr.ToyFontFace(self.name) # default is Arial identityMatrix = cr.Matrix() fontOptions = cr.FontOptions() # get defaults scaling = self.size * self._gschemScalingConstant # 'size' is gschem font size from 'T' line scalingMatrix = cr.Matrix(xx = scaling, yy = scaling) self._csf = cr.ScaledFont(fontFace, scalingMatrix, identityMatrix, fontOptions) Peter Clifton's name is all over the Cairo commits, but I see he hasn't posted to the list for about a week, so I'm guessing he's on holiday. Any help appreciated. -dave