scalable fonts not scaling



(sorry for empty message)

Hello,

I've got an old perl script for printing plaintext files in monospace.
Its arguments allow specifying the width of lines of text in characters
& millimeters (simultaneously & independently).  This works because it
uses Courier via the normal PostScript operators (scalefont in
particular).

I've been trying to rewrite it using Pango, but I can't get the scaling
to work accurately.  Hoping for some assistance from the list, though I
see that most of the traffic is about Gtk, & I'm interested in
PostScript.

I've golfed it down to the following script (independent of
Gtk/PostScript) ...

      #!/usr/bin/perl
      use Pango;
      use constant PANGO_SCALE => 1024;
      my $fontpat = 'Nimbus Mono L Regular';
      my $fontdesc = Pango::FontDescription->from_string($fontpat);
      my $fontmap = Pango::Cairo::FontMap->new;
      my $context = $fontmap->create_context;
      my $layout = Pango::Layout->new($context);
      my $text = 'A' x 50;
      for my $set_size (1 .. 10) {
        $fontdesc->set_size($set_size * PANGO_SCALE);
        $layout->set_font_description($fontdesc);
        $layout->set_text($text);
        my $textwidth = ($layout->get_size)[0] / PANGO_SCALE;
        print "$set_size $textwidth\n";
      }

The output is ...

     $set_size  $textwidth
         1          50
         2         100
         3         100
         4         150
         5         200
         6         250
         7         300
         8         300
         9         350
        10         400

Why is this so non-linear when Nimbus Mono L is supposedly scalable?
And when my old script works via CUPS to a non-postscript printer.

Thanks for any help,
Brian Keck




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