summaryrefslogtreecommitdiff
path: root/doc/genps.pl
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/genps.pl
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/genps.pl')
-rwxr-xr-xdoc/genps.pl75
1 files changed, 57 insertions, 18 deletions
diff --git a/doc/genps.pl b/doc/genps.pl
index 18918f93..3cacdb9a 100755
--- a/doc/genps.pl
+++ b/doc/genps.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
## --------------------------------------------------------------------------
-##
-## Copyright 1996-2016 The NASM Authors - All Rights Reserved
+##
+## Copyright 1996-2017 The NASM Authors - All Rights Reserved
## See the file AUTHORS included with the NASM distribution for
## the specific copyright holders.
##
@@ -15,7 +15,7 @@
## copyright notice, this list of conditions and the following
## disclaimer in the documentation and/or other materials provided
## with the distribution.
-##
+##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -36,8 +36,11 @@
# Format the documentation as PostScript
#
+use File::Spec;
+
require 'psfonts.ph'; # The fonts we want to use
require 'pswidth.ph'; # PostScript string width
+require 'findfont.ph'; # Find fonts in the system
#
# PostScript configurables; these values are also available to the
@@ -46,13 +49,13 @@ require 'pswidth.ph'; # PostScript string width
%psconf = (
pagewidth => 595, # Page width in PostScript points
pageheight => 792, # Page height in PostScript points
- lmarg => 100, # Left margin in PostScript points
- rmarg => 50, # Right margin in PostScript points
- topmarg => 100, # Top margin in PostScript points
- botmarg => 100, # Bottom margin in PostScript points
- plmarg => 50, # Page number position relative to left margin
+ lmarg => 72*1.25, # Left margin in PostScript points
+ rmarg => 72, # Right margin in PostScript points
+ topmarg => 72, # Top margin in PostScript points
+ botmarg => 72, # Bottom margin in PostScript points
+ plmarg => 72*0.25, # Page number position relative to left margin
prmarg => 0, # Page number position relative to right margin
- pymarg => 50, # Page number position relative to bot margin
+ pymarg => 24, # Page number position relative to bot margin
startcopyright => 75, # How much above the bottom margin is the
# copyright notice stuff
bulladj => 12, # How much to indent a bullet paragraph
@@ -102,6 +105,8 @@ while ( $arg = shift(@ARGV) ) {
$psconf{$parm} = shift(@ARGV);
} elsif ( $parm =~ /^(title|subtitle|year|author|license)$/ ) {
$metadata{$parm} = shift(@ARGV);
+ } elsif ( $parm =~ /^fontsdir$/ ) {
+ $fontsdir = shift(@ARGV);
} elsif ( $parm eq 'headps' ) {
$headps = shift(@ARGV);
} else {
@@ -127,6 +132,29 @@ $tocskip = 6; # Space between TOC entries
'code' => $paraskip, 'toc0' => $tocskip,
'toc1' => $tocskip, 'toc2' => $tocskip);
+# Read the font metrics files, and update @AllFonts
+# Get the list of fonts used
+%ps_all_fonts = ();
+%ps_font_subst = ();
+foreach my $fset ( @AllFonts ) {
+ foreach my $font ( @{$fset->{fonts}} ) {
+ my $fdata;
+ my @flist = @{$font->[1]};
+ my $fname;
+ while (defined($fname = shift(@flist))) {
+ $fdata = findfont($fname);
+ last if (defined($fdata));
+ }
+ if (!defined($fdata)) {
+ die "$infile: no font found of: ".
+ join(', ', @{$font->[1]}), "\n".
+ "Install one of these fonts or update psfonts.ph\n";
+ }
+ $ps_all_fonts{$fname} = $fdata;
+ $font->[1] = $fdata;
+ }
+}
+
# Custom encoding vector. This is basically the same as
# ISOLatin1Encoding (a level 2 feature, so we dont want to use it),
# but with the "naked" accents at \200-\237 moved to the \000-\037
@@ -955,13 +983,13 @@ ps_break_pages($startofindex, $nlines);
#
push(@bookmarks, ['index', 0, 'Index']);
-# Get the list of fonts used
-%ps_all_fonts = ();
-foreach $fset ( @AllFonts ) {
- foreach $font ( @{$fset->{fonts}} ) {
- $ps_all_fonts{$font->[1]->{name}}++;
- }
+@all_fonts_lst = sort(keys(%ps_all_fonts));
+$all_fonts_str = join(' ', @all_fonts_lst);
+@need_fonts_lst = ();
+foreach my $f (@all_fonts_lst) {
+ push(@need_fonts_lst, $f); # unless (defined($ps_all_fonts{$f}->{file}));
}
+$need_fonts_str = join(' ', @need_fonts_lst);
# Emit the PostScript DSC header
print "%!PS-Adobe-3.0\n";
@@ -969,8 +997,8 @@ print "%%Pages: $curpage\n";
print "%%BoundingBox: 0 0 ", $psconf{pagewidth}, ' ', $psconf{pageheight}, "\n";
print "%%Creator: (NASM psflow.pl)\n";
print "%%DocumentData: Clean7Bit\n";
-print "%%DocumentFonts: ", join(' ', keys(%ps_all_fonts)), "\n";
-print "%%DocumentNeededFonts: ", join(' ', keys(%ps_all_fonts)), "\n";
+print "%%DocumentFonts: $all_fonts_str\n";
+print "%%DocumentNeededFonts: $need_fonts_str\n";
print "%%Orientation: Portrait\n";
print "%%PageOrder: Ascend\n";
print "%%EndComments\n";
@@ -984,6 +1012,17 @@ foreach $c ( keys(%psbool) ) {
print "/$c ", ($psbool{$c}?'true':'false'), " def\n";
}
+# Embed font data, if applicable
+#foreach my $f (@all_fonts_lst) {
+# my $fontfile = $all_ps_fonts{$f}->{file};
+# if (defined($fontfile)) {
+# if (open(my $fh, '<', $fontfile)) {
+# print vector <$fh>;
+# close($fh);
+# }
+# }
+#}
+
# Emit custom encoding vector
$zstr = '/NASMEncoding [ ';
foreach $c ( @NASMEncoding ) {
@@ -1008,7 +1047,7 @@ print " definefont pop\n";
print "} def\n";
# Emit fontset definitions
-foreach $font ( keys(%ps_all_fonts) ) {
+foreach $font ( sort(keys(%ps_all_fonts)) ) {
print '/',$font,'-NASM /',$font," nasmenc\n";
}