| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
=pod |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
bookshelf-listallfonts - list all fonts known to LuaTeX with "interesting" features |
| 8 |
|
| 9 |
=head1 SYNOPSIS |
| 10 |
|
| 11 |
bookshelf-listallfonts [-d] [-f FEATURES_FILE] [-x EXCLUDED_PATTERNS_FILE] |
| 12 |
|
| 13 |
bookshelf-listallfonts -h |
| 14 |
|
| 15 |
bookshelf-listallfonts -v |
| 16 |
|
| 17 |
bookshelf-listallfonts -m |
| 18 |
|
| 19 |
=head1 DESCRIPTION |
| 20 |
|
| 21 |
List all fonts known to LuaTeX adding "interesting" features to the |
| 22 |
listing. |
| 23 |
|
| 24 |
The script queries luaotfload databases and outputs the list of fonts |
| 25 |
and features as a tab-separated stream with two field: font |
| 26 |
name+feature name, and LuaTeX loading command. This form is suitable |
| 27 |
for L<mkfontsel.pl(1)> command from the I<bookshelf> package. |
| 28 |
|
| 29 |
We always include default features, C<+clig;+liga;+tlig>. |
| 30 |
|
| 31 |
It is recommended to issue |
| 32 |
|
| 33 |
luaotfload-tool --update --force |
| 34 |
|
| 35 |
before running the script. |
| 36 |
|
| 37 |
=head1 OPTIONS |
| 38 |
|
| 39 |
=over 4 |
| 40 |
|
| 41 |
=item B<-d> |
| 42 |
|
| 43 |
Print debug information on the standard output. |
| 44 |
|
| 45 |
=item B<-f> I<FEATURES_FILE> |
| 46 |
|
| 47 |
Use patterns in the I<FEATURES> file instead of the default ones. |
| 48 |
|
| 49 |
=item B<-x> I<EXCLUDED_PATTERNS_FILE> |
| 50 |
|
| 51 |
Exclude patterns (font paths and features or combinations) listed |
| 52 |
in I<EXCLUDED_PATTERNS_FILE>. |
| 53 |
|
| 54 |
=item B<-v> |
| 55 |
|
| 56 |
Print version information |
| 57 |
|
| 58 |
=item B<-h> |
| 59 |
|
| 60 |
Print usage information |
| 61 |
|
| 62 |
=item B<-m> |
| 63 |
|
| 64 |
Print manual page |
| 65 |
|
| 66 |
=back |
| 67 |
|
| 68 |
=head1 AUTHOR |
| 69 |
|
| 70 |
Boris Veytsman, 2024 |
| 71 |
|
| 72 |
=head1 LICENSE |
| 73 |
|
| 74 |
LPPL 1.3c |
| 75 |
|
| 76 |
=cut |
| 77 |
|
| 78 |
use strict; |
| 79 |
use Getopt::Long; |
| 80 |
use Pod::Usage; |
| 81 |
use open qw( :std :encoding(UTF-8) ); |
| 82 |
my $VERSION = "1.0"; |
| 83 |
my $featuresFile =""; |
| 84 |
my $excludedPatternsFile = ""; |
| 85 |
my $DEBUG=0; |
| 86 |
my $help=0; |
| 87 |
my $man=0; |
| 88 |
my $vrs=0; |
| 89 |
|
| 90 |
GetOptions( |
| 91 |
"debug" => \$DEBUG, |
| 92 |
"features|f=s" => \$featuresFile, |
| 93 |
"excluded|x=s" => \$excludedPatternsFile, |
| 94 |
"help|?" => \$help, |
| 95 |
"man" => \$man, |
| 96 |
"version" => \$vrs |
| 97 |
) or pod2usage(2); |
| 98 |
|
| 99 |
pod2usage(1) if $help; |
| 100 |
pod2usage(-exitval => 0, -verbose=>2) if $man; |
| 101 |
die ("$0, version $VERSION, License: LPPL 1.3c\n") if $vrs; |
| 102 |
|
| 103 |
|
| 104 |
my @features; |
| 105 |
if ($featuresFile) { |
| 106 |
open(FEATURES, $featuresFile) or die ("Cannot open file $featuresFile\n"); |
| 107 |
while (<FEATURES>) { |
| 108 |
chomp; |
| 109 |
if (length($_)) { |
| 110 |
push @features, $_; |
| 111 |
} |
| 112 |
} |
| 113 |
close FEATURES; |
| 114 |
} else { |
| 115 |
@features = qw( |
| 116 |
^hist$ |
| 117 |
^onum$ |
| 118 |
^pcap$ |
| 119 |
^smcp$ |
| 120 |
^ss |
| 121 |
^swsh$ |
| 122 |
^titl$ |
| 123 |
^unic$ |
| 124 |
); |
| 125 |
} |
| 126 |
|
| 127 |
my @excluded; |
| 128 |
if ($excludedPatternsFile) { |
| 129 |
open(PATTERNS, $excludedPatternsFile) or die ("Cannot open file $excludedPatternsFile\n"); |
| 130 |
while (<PATTERNS>) { |
| 131 |
chomp; |
| 132 |
if (length($_)) { |
| 133 |
push @excluded, $_; |
| 134 |
} |
| 135 |
} |
| 136 |
close PATTERNS; |
| 137 |
} else { |
| 138 |
@excluded = qw( |
| 139 |
Alegreya.*\+ss02 |
| 140 |
Spectral.*\+ss04 |
| 141 |
Hans_Holbein |
| 142 |
Megazoid-Shade |
| 143 |
HEJI2Text |
| 144 |
NotoColorEmoji |
| 145 |
GimletXRay-VF |
| 146 |
MegabaseCore |
| 147 |
PappardelleV2 |
| 148 |
countriesofeurope |
| 149 |
drmdoz |
| 150 |
drmsy |
| 151 |
drmtc |
| 152 |
drmfigs |
| 153 |
drmgrk |
| 154 |
smf |
| 155 |
SimpleIcons |
| 156 |
Skak |
| 157 |
FontAwesome |
| 158 |
InputCipher |
| 159 |
FdSymbol |
| 160 |
greciliae |
| 161 |
blex\.ttf |
| 162 |
blsy\.ttf |
| 163 |
rblmi\.ttf |
| 164 |
emo-lingchi |
| 165 |
MnSymbol |
| 166 |
MdSymbol |
| 167 |
dantelogo |
| 168 |
emmentaler |
| 169 |
marvosym |
| 170 |
Asap-Symbol |
| 171 |
metsymb |
| 172 |
AlgolRevived |
| 173 |
P22FraJenPeo.otf |
| 174 |
LTCFlueronsGranjon |
| 175 |
LTCArchiveOrn |
| 176 |
SVRsymbols |
| 177 |
LTCHalloweenOrnaments |
| 178 |
BradleyInitialsDJRLayers-Frame |
| 179 |
P22CezanSwa |
| 180 |
P22GaugnXtr |
| 181 |
P22CezanSkt |
| 182 |
P22CezanLig |
| 183 |
P22DeaPro.*\+ss07 |
| 184 |
BradleyInitialsDJRLayers-Background |
| 185 |
Junicode.*\+ss12 |
| 186 |
Junicode.*\+ss13 |
| 187 |
Junicode.*\+ss14 |
| 188 |
QTDingBits |
| 189 |
Math-Companion |
| 190 |
Script-Companion |
| 191 |
TwemojiMozilla |
| 192 |
NAMU-Tryzub |
| 193 |
\/Fonts\/Supplemental\/ |
| 194 |
NotoSansMyanmar\.ttc |
| 195 |
); |
| 196 |
} |
| 197 |
|
| 198 |
my $standardFeatures="+clig;+liga;+tlig"; |
| 199 |
|
| 200 |
open(FONTS, |
| 201 |
'luaotfload-tool --list="plainname" --fields="fullpath,format,subfont"|') |
| 202 |
or die ("Cannot run luaotfload-tool\n"); |
| 203 |
while (<FONTS>) { |
| 204 |
chomp; |
| 205 |
if (/^\s*$/) { |
| 206 |
next; |
| 207 |
} |
| 208 |
my ($plainname, $fullpath, $format, $subfont) = split /\t/; |
| 209 |
if ($DEBUG) { |
| 210 |
print STDERR "Font: $plainname\n"; |
| 211 |
} |
| 212 |
my $goodFont=1; |
| 213 |
foreach my $excl (@excluded) { |
| 214 |
if ($fullpath =~ m/$excl/) { |
| 215 |
$goodFont=0; |
| 216 |
if ($DEBUG) { |
| 217 |
print STDERR " Font $plainname is excluded by pattern $excl\n"; |
| 218 |
} |
| 219 |
last; |
| 220 |
} |
| 221 |
} |
| 222 |
if (!$goodFont) { |
| 223 |
next; |
| 224 |
} |
| 225 |
my $loadcommand = "[".$fullpath."]"; |
| 226 |
if ($format eq 'ttc') { |
| 227 |
$loadcommand .= "(".($subfont-1).")"; |
| 228 |
} |
| 229 |
$loadcommand .= ":$standardFeatures"; |
| 230 |
print "$plainname\t$loadcommand\n"; |
| 231 |
if ($format eq 'ttc') { |
| 232 |
next; # WE do not extract features for TTC fonts |
| 233 |
} |
| 234 |
|
| 235 |
open (FEATURES, "otfinfo -f '$fullpath' |"); |
| 236 |
while (<FEATURES>) { |
| 237 |
chomp; |
| 238 |
my ($feature, $featurename) = split /\t/; |
| 239 |
my $loadcommand1 = $loadcommand . ";+$feature"; |
| 240 |
my $goodFeature=0; |
| 241 |
foreach my $pattern (@features) { |
| 242 |
if ($feature =~ m/$pattern/) { |
| 243 |
$goodFeature=1; |
| 244 |
last; |
| 245 |
} |
| 246 |
} |
| 247 |
if (!$goodFeature) { |
| 248 |
next; |
| 249 |
} |
| 250 |
|
| 251 |
foreach my $excl (@excluded) { |
| 252 |
if ($loadcommand1 =~ m/$excl/) { |
| 253 |
$goodFeature=0; |
| 254 |
if ($DEBUG) { |
| 255 |
print STDERR |
| 256 |
" Feature $featurename is excluded by pattern $excl\n"; |
| 257 |
} |
| 258 |
last; |
| 259 |
} |
| 260 |
|
| 261 |
} |
| 262 |
if ($goodFeature) { |
| 263 |
print "$plainname; $featurename\t$loadcommand1\n"; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
close FEATURES; |
| 268 |
|
| 269 |
} |
| 270 |
close FONTS; |
| 271 |
|