Mail Archives: geda-user/2013/06/16/22:28:23
On 06/16/2013 02:59 PM, Dave Curtis wrote:
>
> In order to calculate symbol width and layout text correctly, I need a
> function to correctly compute the width of each character in strings.
> When I originally started the code, I slurped some table out of gschem
> that was a look-up table that returned a character width. It doesn't
> seem very accurate any more, so I suspect gschem has updated character
> rendering since then. Can somebody point me at the code that is the
> current correct way to do a layout measurement on a text string?
So... let me add to this question a bit. After a little bit of time
with google and nosing around in gschem sources, I have some
(potentially misguided) ideas of how to attack this.
1. It seems that gschem has fully converted over to Cairo rendering for
text.
2. I gather that gschem has a default font that it looks for, and that
users can specify a different font if they prefer.
Q: What would the default font name be? And the size?
3. I'm thinking that my symbol generator should use Cairo (which I'll be
doing via pycairo, since my tool is written in Python) to perform text
measurement. My plan is to default to the same font that gschem does,
and allow the user to specify some other font name and size from the
command line.
4. After having spent a full 10 minutes using pycairo, I'm thinking I
need code something like:
import pycairo as cr
fontface = cr.ToyFontFace("foofont")
scaleMatrix = cr.Matrix(xx=magicNumber, yy=MagicNumber)
identityMatrix = cr.Matrix()
fo = cr.FontOptions()
scaledFont = cr.ScaledFont(fontface, scaleMatrix, identityMatrix, fo)
# And now I can get text layout distances from:
metrics = scaledFont.text_extents("I2C1_SCLA") # To pick on a likely
pin name.
Am I close?
So... what would be good values for foofont and MagicNumber?
Clues welcome.
5. If users can specify different fonts, doesn't that make symbol
portability a problem? ?
-dave
- Raw text -