www.delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2013/06/16/22:28:23

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Message-ID: <51BE73B7.4020905@sonic.net>
Date: Sun, 16 Jun 2013 19:25:59 -0700
From: Dave Curtis <davecurtis AT sonic DOT net>
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: Re: [geda-user] gschem text measure
References: <51BE355E DOT 5040600 AT sonic DOT net>
In-Reply-To: <51BE355E.5040600@sonic.net>
Reply-To: geda-user AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019