summaryrefslogtreecommitdiff
path: root/doc/ttfmetrics.ph
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-04-10 06:35:29 -0700
committerH. Peter Anvin <hpa@zytor.com>2017-04-10 06:35:29 -0700
commit70b070f952be06f373f0554afa1c73b4bd3ef898 (patch)
treeae07ebe9b5816a2b29222d966a536d5e19a597f0 /doc/ttfmetrics.ph
parent92ae33b1b34af0d7df0d6bf2a52635ca393831a7 (diff)
downloadnasm-70b070f952be06f373f0554afa1c73b4bd3ef898.tar.gz
doc: improve the look of the documentation with better fonts
Use the Adobe Source Sans/Code Pro fonts by default. They are Open Source fonts by Adobe. However, since these fonts are quite large, let them be an external dependency and do our best to try to find them with whatever mechanism is available on the system for finding standard fonts. Also have a list of substitution fonts if necessary. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'doc/ttfmetrics.ph')
-rw-r--r--doc/ttfmetrics.ph67
1 files changed, 67 insertions, 0 deletions
diff --git a/doc/ttfmetrics.ph b/doc/ttfmetrics.ph
new file mode 100644
index 00000000..493ac853
--- /dev/null
+++ b/doc/ttfmetrics.ph
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use Font::TTF::Font;
+use Font::TTF::Head;
+use Font::TTF::Hmtx;
+use Font::TTF::Cmap;
+use Font::TTF::Maxp;
+use Font::TTF::PSNames;
+use Font::TTF::Post;
+
+use strict;
+
+sub parse_ttf_file($) {
+ my($filename) = @_;
+
+ my $fontdata = {
+ widths => {},
+ kern => {}
+ };
+
+ my $f = Font::TTF::Font->open($filename);
+
+ return undef if (!defined($f));
+
+ $fontdata->{file} = $filename;
+ $fontdata->{type} = defined($f->{' CFF'}) ? 'otf' : 'ttf';
+
+ $f->{head}->read();
+ #printf "unitsPerEm: %d\n", $f->{head}{unitsPerEm};
+ #printf "xMin yMin xMax yMax: %d %d %d %d\n",
+ #$f->{head}{xMin},
+ #$f->{head}{yMin},
+ #$f->{head}{xMin},
+ #$f->{head}{yMax};
+ #$f->{maxp}->read();
+ my $glyphs = $f->{maxp}{numGlyphs};
+ #printf "Total glyphs: %d\n", $glyphs;
+ $f->{cmap}->read();
+ $f->{hmtx}->read();
+ $f->{name}->read();
+ $fontdata->{name} = $f->{name}->find_name(6); # PostScript name
+ $f->{post}->read();
+ my $psglyphs = 0;
+ my $psmap = $f->{post}->{VAL};
+ $psmap = [] if (!defined($psmap));
+ #printf "Glyphs with PostScript names: %d\n", scalar(@$psmap);
+
+ # Can be done as an array of arrays in case of multiple unicodes to
+ # one glyph...
+ my @unimap = $f->{cmap}->reverse();
+
+ for (my $i = 0; $i < $glyphs; $i++) {
+ my $width = $f->{hmtx}->{advance}[$i];
+ my $psname = $psmap->[$i];
+ if (!defined($psname)) {
+ $psname = Font::TTF::PSNames::lookup($unimap[$i]);
+ }
+ next if (!defined($psname) || ($psname eq '.notdef'));
+ $fontdata->{widths}{$psname} = $f->{hmtx}->{advance}[$i];
+ }
+
+ $f->release;
+
+ return $fontdata;
+}
+
+1;