From: Jeff Godfrey on 28 Apr 2010 17:16 I have some canvas text created using a named, mono spaced font. I'm looking for the fastest possible way to change the size of the named font so that a single character is as close as possible to a specified width. So, for example, maybe: font measure myNamedFont "X" --> 10 (width in pixels of the "X" char). Now, I want to change the named font so that each char is, say, 18 or 25 or 33 pixels wide. What's the fastest way to determine the proper point size needed to match (as closely as possible) the newly specified char width? It's easy to find the best match by just looping through point sizes and checking each with [font measure]. While that works great, it's generally too slow for my needs. Maybe there's some font info available that'll get me *close* to the right value, and from there I can loop to find the best match? The above is related to some dynamic canvas zooming code, so speed is important. Thanks for any input. Jeff
From: Alexandre Ferrieux on 28 Apr 2010 17:32 On Apr 28, 11:16 pm, Jeff Godfrey <jeff_godf...(a)pobox.com> wrote: > I have some canvas text created using a named, mono spaced font. I'm > looking for the fastest possible way to change the size of the named > font so that a single character is as close as possible to a specified > width. > > So, for example, maybe: > > font measure myNamedFont "X" --> 10 (width in pixels of the "X" char). > > Now, I want to change the named font so that each char is, say, 18 or 25 > or 33 pixels wide. > > What's the fastest way to determine the proper point size needed to > match (as closely as possible) the newly specified char width? > > It's easy to find the best match by just looping through point sizes and > checking each with [font measure]. While that works great, it's > generally too slow for my needs. > > Maybe there's some font info available that'll get me *close* to the > right value, and from there I can loop to find the best match? > > The above is related to some dynamic canvas zooming code, so speed is > important. > > Thanks for any input. > > Jeff Isn't there a linear relationship between the point size and actual size for a given character and font ? -Alex
From: Jeff Godfrey on 28 Apr 2010 17:42 Alexandre Ferrieux wrote: > Isn't there a linear relationship between the point size and actual > size for a given character and font ? Alex, Good question - don't know. Maybe that's exactly what I'm looking for. Thanks, Jeff
From: Jeff Godfrey on 28 Apr 2010 17:46 Jeff Godfrey wrote: > Alexandre Ferrieux wrote: > >> Isn't there a linear relationship between the point size and actual >> size for a given character and font ? > > Alex, > > Good question - don't know. Maybe that's exactly what I'm looking for. > > Thanks, > > Jeff Alex, It seems you're right. Other than some rounding to integer point sizes, there definitely is a linear relationship. That should get me moving. Thanks! Jeff
|
Pages: 1 Prev: canvas, [font measure], and vertical text Next: Changing the font of ttk::entry |