in reply to Re: How to get an accurate TTFMetrics values for unicode strings?
in thread How to get an accurate TTFMetrics values for unicode strings?

That's dirty indeed. actually, i was hoping for some simple solution as i'm very new to this and still many things that i don't know. and some Anonymous Monk mentioned that TTFMetrics is 14 years old, so can be there any new perl module that can do this with a single line of code?
  • Comment on Re^2: How to get an accurate TTFMetrics values for unicode strings?

Replies are listed 'Best First'.
Re^3: How to get an accurate TTFMetrics values for unicode strings?
by vr (Curate) on Mar 10, 2017 at 08:10 UTC

    Any reason to expect simple solution for a complex problem? With a "single line of code"? It's not just sum of metrics resulting from arbitrary sequence of Unicode code points, that you are looking for. But layout engine for complex writing systems, with ligatures, contextual substitutions, etc. A magic which happens when you type 4 characters and they "automatically" change their shape (and width, if that's what you are after), after any new character is added.

    Think uniscribe, or pango. Apropos of Pango:

    use strict; use warnings; use feature 'say'; use Pango; my $surface = Cairo::ImageSurface-> create( 'argb32', 200, 100 ); my $cr = Cairo::Context-> create( $surface ); my $layout = Pango::Cairo::create_layout( $cr ); my $font = Pango::FontDescription-> from_string( 'Arial 16' ); #Pango::Cairo::Context-> set_resolution( $cr, 72 ); $layout-> set_font_description( $font ); $layout-> set_text( "\x{0628}\x{0644}\x{062D}\x{0629}" ); say for Pango::Layout::get_pixel_size( $layout );

    Not a single line, is it? But "new", definitely. It says width for a 96 dpi default resolution, and the commented line is there because I didn't figure out how to change it.

    If a "single line of code" is a priority, you can qx( pango-view ... and parse the pgm-file for width, all that fits nicely into a single line.

      did my post make me sound like ungrateful lazy ass? i hope not.
      anyway, Pango's install keeps failing, i'll try to figure it out and try your script, thanks for your help.