| 1 |
#!/usr/bin/perl |
| 2 |
# SPDX-License-Identifier: Artistic-1.0-Perl |
| 3 |
# Copyright (C) 2011 Simon Cozens |
| 4 |
use Encode qw/encode/; |
| 5 |
$SIG{__WARN__} = sub { |
| 6 |
CORE::dump if $_[0] =~ /uninitialized value in subroutine entry/; |
| 7 |
warn @_; |
| 8 |
}; |
| 9 |
|
| 10 |
use strict; |
| 11 |
#use warnings; |
| 12 |
use Text::Gr2; |
| 13 |
use Getopt::Long; |
| 14 |
my %opts; |
| 15 |
my $mask = 0x80 | 0x02; |
| 16 |
|
| 17 |
GetOptions(\%opts, "trace=s", "mask=i","cache","dpi=i","point=i"); |
| 18 |
|
| 19 |
my ($fontfile, $text) = @ARGV; |
| 20 |
die "No font file given!\n" unless $fontfile; |
| 21 |
die "Font file not readable!\n" unless -r $fontfile; |
| 22 |
|
| 23 |
if ($opts{trace}) { |
| 24 |
$mask = $opts{mask} if defined $opts{mask}; |
| 25 |
open my $t, ">", $opts{trace} or die "Can't write on trace file!\n"; |
| 26 |
Text::Gr2->start_logging($t, $mask); |
| 27 |
} |
| 28 |
|
| 29 |
my $face = Text::Gr2::Face->open($fontfile, |
| 30 |
$opts{cache} ? (cache_size => 1000, dumb_rendering => 1) : (), |
| 31 |
preload_glyphs => 1); |
| 32 |
die "Invalid font, failed to read or parse tables\n" unless $face; |
| 33 |
|
| 34 |
if (!$text) { |
| 35 |
print_features($face); |
| 36 |
exit; |
| 37 |
} |
| 38 |
|
| 39 |
my $point = $opts{point} // 12; |
| 40 |
my $dpi = $opts{dpi} // 72; |
| 41 |
my $sized_font = $face->make_font($dpi/72*$point); |
| 42 |
|
| 43 |
my $seg = $sized_font->segment($face, $text); |
| 44 |
print "pos gid attach\t x\t y\tins bw\t chars\t\tUnicode\n"; |
| 45 |
my $p = 0; |
| 46 |
my %map; |
| 47 |
my @slots = $seg->slots; |
| 48 |
for (@slots) { $map{0+$_} = $p++ } |
| 49 |
$p = 0; |
| 50 |
for my $slot ($seg->slots) { |
| 51 |
printf("%02d %4d %3d\@%d,%d\t%6.1f\t%6.1f\t%2d%4d\t%3d %3d\t", |
| 52 |
$p++, $slot->gid, $map{$slot->attached_to} || -1, |
| 53 |
$slot->attr($seg, 3,0), |
| 54 |
$slot->attr($seg, 4,0), |
| 55 |
$slot->origin_X, |
| 56 |
$slot->origin_Y, |
| 57 |
$slot->can_insert_before, |
| 58 |
$seg->cinfo($slot->original)->break_weight,$slot->before, $slot->after, |
| 59 |
); |
| 60 |
print "\n"; |
| 61 |
} |
| 62 |
|
| 63 |
print "\nChar\tUnicode\n"; |
| 64 |
$p = 0; |
| 65 |
my @cinfos = $seg->cinfos; |
| 66 |
for (@cinfos) { |
| 67 |
printf "%d\t%04X\n", $p++,$_->unicode_char(); |
| 68 |
} |
| 69 |
sub print_features { |
| 70 |
my $face = shift; |
| 71 |
print $face->n_fref." features\n"; |
| 72 |
for my $f ($face->features) { |
| 73 |
my $label = $f->label(0x0409, 1); |
| 74 |
my $fuid = $f->id; |
| 75 |
print $f->_id." ".$fuid." ".$label."\n"; |
| 76 |
for ($f->values) { |
| 77 |
my $label = $f->value_label($_,0x0409, 1); |
| 78 |
print "\t$_\t$label\n"; |
| 79 |
} |
| 80 |
print "\n"; |
| 81 |
} |
| 82 |
print "Feature languages: ",join "\t", $face->languages; |
| 83 |
print "\n"; |
| 84 |
} |
| 85 |
END { Text::Gr2->stop_logging; } |