Changeset 95ed2ba in git


Ignore:
Timestamp:
20/09/11 01:12:19 (8 years ago)
Author:
Olly Betts <olly@…>
Branches:
add-show-splays, line_contents, master, stereo, svn/github/master, svn/origin/master, svn/tags/1.2.0, svn/tags/1.2.1, svn/tags/1.2.2, svn/tags/1.2.3, svn/tags/1.2.4, svn/tags/1.2.5, svn/trunk, travis-osx
Children:
120c1c6
Parents:
9062bef
Message:

lib/afm2txf.pl: Fix to correctly handle non-ASCII glyphs by using
glyphshow in the generated PostScript? code rather than relying on the
numeric encoding order of the font to match Unicode (which doesn't
generally seem to be the case). Tweak to process files without
slurping them all into memory where that's easy to do.

git-svn-id: file:///home/survex-svn/survex/trunk@3662 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r9062bef r95ed2ba  
     1Tue Sep 20 00:09:42 GMT 2011  Olly Betts <olly@survex.com>
     2
     3        * lib/afm2txf.pl: Fix to correctly handle non-ASCII glyphs by using
     4          glyphshow in the generated PostScript code rather than relying on the
     5          numeric encoding order of the font to match Unicode (which doesn't
     6          generally seem to be the case).  Tweak to process files without
     7          slurping them all into memory where that's easy to do.
     8
    19Mon Sep 19 23:15:46 GMT 2011  Olly Betts <olly@survex.com>
    210
  • lib/afm2txf.pl

    r9062bef r95ed2ba  
    1414#
    1515# Copyright (C) 2002 Andrew James Ross
    16 # Copyright (C) 2010 Olly Betts
     16# Copyright (C) 2010,2011 Olly Betts
    1717#
    1818# This program is free software; you can redistribute it and/or modify
     
    117117print STDERR "Reading font metrics...\n";
    118118my $FONT;
    119 my @lines = `cat $METRICS`
    120     or die "Couldn't read metrics";
    121 foreach my $m (grep {/^(C|FontName) /} @lines) {
     119open METRICS, '<', $METRICS or die $!;
     120my $m;
     121while (defined($m = <METRICS>)) {
     122    if ($m =~ /^FontName (\S*)/) { $FONT = $1; next; }
     123    next unless $m =~ /^C /;
    122124    chomp $m;
    123     if($m =~ /^FontName ([^\s]*)/) { $FONT = $1; next; }
    124125
    125126    die "No name: $m" if $m !~ /N\s+([^\s]+)\s+;/;
     
    140141    $metrics{$name} = [$nomwid, $x, $y, $w, $h];
    141142}
     143close METRICS;
    142144
    143145die "No FontName found in metrics" if not defined $FONT;
     
    180182my $pid = open PS, "|gs -r$res -g${res}x${res} -sDEVICE=ppm -sOutputFile=\Q$FONT\E.ppm > /dev/null";
    181183die "Couldn't spawn ghostscript interpreter" if !defined $pid;
    182 print PS join("\n", @$PS), "\n";
     184foreach (@$PS) {
     185    print PS "$_\n";
     186}
    183187close PS;
    184188waitpid($pid, 0);
     
    243247# swap the order of the rows; OpenGL textures are bottom-up.
    244248open PPM, "$FONT.ppm" or die;
    245 seek PPM, -3*$TEXSIZ*$TEXSIZ, 2 or die;
    246 my @rows = ();
    247249my $pixel;
    248 for(my $r=0; $r<$TEXSIZ; $r++) {
    249     my @row = ();
    250     for(my $c=0; $c<$TEXSIZ; $c++) {
     250foreach my $r (1 .. $TEXSIZ) {
     251    seek PPM, -3*$r*$TEXSIZ, 2 or die;
     252    foreach (1 .. $TEXSIZ) {
    251253        read PPM, $pixel, 3 or die;
    252         push @row, substr($pixel, 0, 1);
     254        print TXF substr($pixel, 0, 1);
    253255    }
    254     push @rows, \@row;
    255256}
    256257close PPM;
    257 for(my $r=(@rows - 1); $r>=0; $r--) {
    258     print TXF join('', @{$rows[$r]});
    259 }
    260258close TXF;
    261259
     
    299297        my $m = $metrics{$c};
    300298        next if !defined $m;
    301 
    302         my $id = sprintf "%2.2x", $CHARS{$c};
    303299
    304300        # No space?
     
    317313
    318314        push @PS, "$vx $vy moveto";
    319         push @PS, "<$id> show";
     315        push @PS, "/$c glyphshow";
    320316
    321317        # Next box...
Note: See TracChangeset for help on using the changeset viewer.