Mail Archives: geda-user/2013/06/27/20:00:47
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
- Raw text -