Re: Pango: how to call the API?



On Sun, Aug 31, 2003 at  0:31:32 -0700, Zitan Broth wrote:
> 
> I am doing some dynamic imaging on the web using SVG and librsvg (which uses
> Pango to render text) that I am calling from the command line (with PHP).
> Basically when a user changes between fonts I want to adjust the size
> accordingly, and I thought as Pango has information on "relative font
> sizing" I could take advantage of it.  Say for example a user has the text
> "welcome", the font "arial" with text size "12".  If they want to change to
> the font "arial black" then I would like to adjust the font size accordingly
> down so that welcome fits in the same space (say to size "10" or whatever).
> It doesn't have to be super exact, just fit okay ....

If you have the exact text then you can lay it out in each
font and compare the sizes. That is the most accurate and is
certainly more efficient than measuring each character.

> 
> > If you want to get the width of every character in a font, the most
> obvious way is to create a layout, set the font, set the text, measure the
> layout extents, repeat 1114111 times. But you don't want to do that.
> 
> I'm not sure what the best approach is  (how did you get 1114111 btw? :-))::

There are 0x110000 = 1114112 Unicode code points.

> (1) kind of taking your suggested approach, layout "welcome" in arial, sum
> the width of each character, layout "welcome" in arial black, sum the total
> width and divide to get the relativity.  But I'd have to do this on the fly.

When you get text extents, it's not divided into characters,
it's for the whole text. THe algorithm you describe is ok
otherwise.

> (2) Which is what I was thinking is get an average character width for each
> required font and load it into a database.

This is fine too, but use the font metrics
approximate_char_width, don't measure each character.

> 
> Does this make sense?  Can I do this from the command line, or do I need to
> write some code ?

You need to write code. You might be able to do it in
straight php; there are php language bindings to gtk+ (don't
know about pango specifically). Or you can write a simple
program and call that from your php.

Noah



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]