| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Vpl2ovp: a program to generate accented virtual fonts for Omega |
| 4 |
# Copyright (C) 2008 John D. Smith |
| 5 |
|
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
|
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 |
|
| 20 |
$version = 0.25; |
| 21 |
#------------------------------------------------------------------------# |
| 22 |
$description = |
| 23 |
"Syntax: vpl2ovp -d definition-file [-s shrink-factor] |
| 24 |
[-c candrabindu-adjustment] [-b] vpl-file |
| 25 |
|
| 26 |
Vpl2ovp creates new Omega virtual fonts based on existing TeX |
| 27 |
fonts or virtual fonts (\"input fonts\"). A successful run will |
| 28 |
read a pl (Property List) or vpl (Virtual Property List) file |
| 29 |
and a definition file, and will generate a new ovp (Omega |
| 30 |
Virtual Property List) file on standard output. The input font |
| 31 |
is assumed to adhere to the standard TeX encoding for text |
| 32 |
fonts unless it was created with either of the programs afm2pl |
| 33 |
or afm2tfm, in which case it is assumed to conform to |
| 34 |
(respectively) the Adobe Standard Encoding or the encoding |
| 35 |
specified in the file dvips.enc. In either case, the name of |
| 36 |
the input font is assumed to be the name of the input file |
| 37 |
without its .vpl or .pl extension: it must conform to normal |
| 38 |
TeX conventions for naming fonts, as vpl2ovp attempts to draw |
| 39 |
conclusions from it about the kind of font it is dealing with. |
| 40 |
|
| 41 |
A typical complete sequence of commands to create a new virtual |
| 42 |
font might therefore be |
| 43 |
tftopl cmr10.tfm cmr10.pl |
| 44 |
vpl2ovp -d Unicode1.def cmr10.pl >cmr10-uni1.ovp |
| 45 |
ovp2ovf cmr10-uni1.ovp cmr10-uni1.ovf cmr10-uni1.ofm |
| 46 |
for a Computer Modern font, or |
| 47 |
afm2pl Times-Roman.afm rptmr.pl |
| 48 |
pltotf rptmr.pl rptmr.tfm |
| 49 |
vpl2ovp -d Unicode1.def rptmr.pl >ptmr-uni1.ovp |
| 50 |
ovp2ovf ptmr-uni1.ovp ptmr-uni1.ovf ptmr-uni1.ofm |
| 51 |
for a PostScript font. |
| 52 |
|
| 53 |
Another approach for a PostScript font is to use afm2tfm: |
| 54 |
afm2tfm Times-Roman.afm -t dvips.enc -v ptmr rptmr |
| 55 |
vpl2ovp -d Unicode1.def ptmr.vpl >ptmr-uni1.ovp |
| 56 |
ovp2ovf ptmr-uni1.ovp ptmr-uni1.ovf ptmr-uni1.ofm |
| 57 |
-- but this is now deprecated, as afm2tfm generates incorrect |
| 58 |
values for the heights of some characters, and this can lead to |
| 59 |
bad accent placing. |
| 60 |
|
| 61 |
In order to keep the whole of the character range \"F0-\"FF free for |
| 62 |
the requirements of the encoding specified in the definition file, |
| 63 |
certain modifications are made to input fonts following the dvips.enc |
| 64 |
encoding to bring them into greater conformity with the TeX norm. In |
| 65 |
particular, the characters dotaccent and hungarumlaut are placed in |
| 66 |
the positions assigned by TeX (\"5F, \"7D), not those enforced by |
| 67 |
dvips.enc (\"C7, \"CD). The f-ligatures, double quotes and dashes are |
| 68 |
also moved from the upper half of the original 8-bit character set to |
| 69 |
their normal TeX positions. As a result, the following characters are |
| 70 |
not found in the lower half of the character set: quotesingle, |
| 71 |
quotedbl, backslash, underscore, braceleft, bar, braceright. These |
| 72 |
characters can, however, be assigned positions in the output font if |
| 73 |
they are needed. (Indeed, they could all be explicitly restored to |
| 74 |
their dvips.enc positions if this were desired.) |
| 75 |
|
| 76 |
Options: |
| 77 |
|
| 78 |
-d should refer to a font definition file. This file (which could |
| 79 |
usefully be named, e.g., \"Unicode1.def\") should consist of |
| 80 |
lines of character definitions, in the form |
| 81 |
\"number\" \"character\" |
| 82 |
or |
| 83 |
\"number\" \"character\" \"accent\" |
| 84 |
Here \"number\" represents the character's position in the new |
| 85 |
encoding and may be expressed in decimal, octal or hex; |
| 86 |
\"character\" names the character (e.g. \"comma\", \"eight\", |
| 87 |
\"A\") or consists of the word \".notdef\" (indicating that |
| 88 |
the specified number's \"slot\" in the new encoding is to be |
| 89 |
empty); and \"accent\" optionally names an accent to be placed |
| 90 |
on the character. In addition to the standard accents available |
| 91 |
in PostScript fonts, \"underbar\" and \"underdot\" are also |
| 92 |
available, as are \"under\" versions of all the normal |
| 93 |
superscript accents (\"underdieresis\", \"underring\", etc.). |
| 94 |
The Indian accent \"candrabindu\" may also be specified: it |
| 95 |
is formed by overprinting a breve with a dotaccent. Finally, |
| 96 |
\"overdot\" may be used as a synonym for \"dotaccent\". |
| 97 |
|
| 98 |
Note that all accents used in defining accented characters must |
| 99 |
themselves be defined in the .def file. Those which exist in the |
| 100 |
source font should simply be referenced by name in their |
| 101 |
appropriate Unicode position (e.g. \"0x0304 macron\"); those |
| 102 |
which do not should be defined as the character \"space\" |
| 103 |
followed by the name of the accent (e.g. \"0x0310 space |
| 104 |
candrabindu\"). |
| 105 |
|
| 106 |
If the character named in the \"accent\" position is not in fact |
| 107 |
a valid accent character, the program interprets the definition |
| 108 |
as a request for a digraph formed from the \"character\" and the |
| 109 |
\"accent\". A digraph consisting of, say, \"k\" and \"h\" will be |
| 110 |
indistinguishable from the letters \"k\" and \"h\" printed |
| 111 |
consecutively, but the digraph \"kh\" can itself receive accents |
| 112 |
like any other character: see next paragraph. |
| 113 |
|
| 114 |
A new character (such as \"amacron\" or \"kh\") may be freely |
| 115 |
used in the \"character\" position of a further definition (such |
| 116 |
as \"amacron breve\" or \"kh underbar\"). There is no constraint |
| 117 |
on the ordering of definitions within a definition file. The |
| 118 |
definition of \"a macron\" does not have to precede that of |
| 119 |
\"amacron breve\": requests for \"impossible\" characters are |
| 120 |
deferred until their constituents have had a chance to come into |
| 121 |
being. |
| 122 |
|
| 123 |
\"Slots\" for which no new definition is given retain the |
| 124 |
definition they have in the input font. |
| 125 |
|
| 126 |
The definition file may also contain blank lines and comments |
| 127 |
(introduced by \"\#\"). |
| 128 |
|
| 129 |
-s may optionally give the factor, expressed as a per-thousand |
| 130 |
value, by which normally superscript accents (such as dieresis, |
| 131 |
ring) should be shrunk when they are used as subscript accents |
| 132 |
(such as underdieresis, underring). Values of around 800 may be |
| 133 |
found useful. |
| 134 |
|
| 135 |
-c may optionally give two comma-separated numerical values to |
| 136 |
adjust the x and y coordinates of the dotaccent placed within a |
| 137 |
breve to form the candrabindu accent. A coordinate scheme using |
| 138 |
\"DESIGNUNITS R 1000\" is assumed. |
| 139 |
|
| 140 |
-b may optionally be specified to block the use of predefined |
| 141 |
accented characters, forcing vpl2ovp to define its own |
| 142 |
versions. This may be useful to secure a consistent appearance |
| 143 |
in cases where a font designer does not share vpl2ovp's views |
| 144 |
on where accents should be placed. |
| 145 |
|
| 146 |
-h prints this help. |
| 147 |
"; |
| 148 |
#------------------------------------------------------------------------# |
| 149 |
|
| 150 |
######################## |
| 151 |
# Packages and constants |
| 152 |
######################## |
| 153 |
# |
| 154 |
use File::Basename; |
| 155 |
use Getopt::Std; |
| 156 |
$cmdline = basename($0) . " " . join " ", @ARGV; |
| 157 |
getopts('d:s:c:bh'); |
| 158 |
if ($opt_h or !$opt_d or $#ARGV != 0) { |
| 159 |
print STDERR $description; |
| 160 |
exit 1; |
| 161 |
} |
| 162 |
|
| 163 |
$filename = $ARGV[0]; |
| 164 |
$dummycodepoint = 0xF8FF; |
| 165 |
($fontname = $filename) =~ s/\..*$//; |
| 166 |
($encname = basename($opt_d)) =~ s/\..*$//; |
| 167 |
$vtitle = "(VTITLE Font $fontname modified for $encname encoding by vpl2ovp"; |
| 168 |
$vtitle .= " v. $version" if $version; |
| 169 |
$vtitle .= ")\n(COMMENT Command line: $cmdline)"; |
| 170 |
$vtitle .= "\n(OFMLEVEL H 0)"; |
| 171 |
|
| 172 |
# |
| 173 |
# Flags for bold and small caps. These are probably a bit iffy, but |
| 174 |
# there's not much that can be done about it. |
| 175 |
# |
| 176 |
if ($fontname =~ /(^p.*b[oi]?[c]?$|^[^p].*bx[a-z]*[0-9]+$)/) { $bold = 1 } |
| 177 |
if ($fontname =~ /(^p.*c$|^[^p].*csc[a-z]*[0-9]+$)/) { $scaps = 1 } |
| 178 |
if ($opt_s) { $shrink = $opt_s / 1000 } else { $shrink = 1 } |
| 179 |
|
| 180 |
# |
| 181 |
# Array to convert from number to vpl representation |
| 182 |
# |
| 183 |
foreach $i (0 .. 0xFFFF) { |
| 184 |
$nv[$i] = (chr($i) =~ /[0-9A-Za-z]/ ? "C " . chr $i : sprintf("H %04lX", $i)); |
| 185 |
} |
| 186 |
|
| 187 |
# |
| 188 |
# Now the encoding vectors. |
| 189 |
# |
| 190 |
@TeXenc = ( |
| 191 |
"Gamma", "Delta", "Theta", "Lambda", |
| 192 |
"Xi", "Pi", "Sigma", "Upsilon", |
| 193 |
"Phi", "Psi", "Omega", "ff", |
| 194 |
"fi", "fl", "ffi", "ffl", |
| 195 |
"dotlessi", "dotlessj", "grave", "acute", |
| 196 |
"caron", "breve", "macron", "ring", |
| 197 |
"cedilla", "germandbls", "ae", "oe", |
| 198 |
"oslash", "AE", "OE", "Oslash", |
| 199 |
"space", "exclam", "quotedblright", "numbersign", |
| 200 |
"dollar", "percent", "ampersand", "quoteright", |
| 201 |
"parenleft", "parenright", "asterisk", "plus", |
| 202 |
"comma", "hyphen", "period", "slash", |
| 203 |
"zero", "one", "two", "three", |
| 204 |
"four", "five", "six", "seven", |
| 205 |
"eight", "nine", "colon", "semicolon", |
| 206 |
"exclamdown", "equal", "questiondown", "question", |
| 207 |
"at", "A", "B", "C", |
| 208 |
"D", "E", "F", "G", |
| 209 |
"H", "I", "J", "K", |
| 210 |
"L", "M", "N", "O", |
| 211 |
"P", "Q", "R", "S", |
| 212 |
"T", "U", "V", "W", |
| 213 |
"X", "Y", "Z", "bracketleft", |
| 214 |
"quotedblleft", "bracketright", "circumflex", "dotaccent", |
| 215 |
"quoteleft", "a", "b", "c", |
| 216 |
"d", "e", "f", "g", |
| 217 |
"h", "i", "j", "k", |
| 218 |
"l", "m", "n", "o", |
| 219 |
"p", "q", "r", "s", |
| 220 |
"t", "u", "v", "w", |
| 221 |
"x", "y", "z", "endash", |
| 222 |
"emdash", "hungarumlaut", "tilde", "dieresis" |
| 223 |
); |
| 224 |
|
| 225 |
@dvipsenc = ( |
| 226 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 227 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 228 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 229 |
".notdef", "quotesingle", "exclamdown", "questiondown", |
| 230 |
"dotlessi", "dotlessj", "grave", "acute", |
| 231 |
"caron", "breve", "macron", "ring", |
| 232 |
"cedilla", "germandbls", "ae", "oe", |
| 233 |
"oslash", "AE", "OE", "Oslash", |
| 234 |
"space", "exclam", "quotedbl", "numbersign", |
| 235 |
"dollar", "percent", "ampersand", "quoteright", |
| 236 |
"parenleft", "parenright", "asterisk", "plus", |
| 237 |
"comma", "hyphen", "period", "slash", |
| 238 |
"zero", "one", "two", "three", |
| 239 |
"four", "five", "six", "seven", |
| 240 |
"eight", "nine", "colon", "semicolon", |
| 241 |
"less", "equal", "greater", "question", |
| 242 |
"at", "A", "B", "C", |
| 243 |
"D", "E", "F", "G", |
| 244 |
"H", "I", "J", "K", |
| 245 |
"L", "M", "N", "O", |
| 246 |
"P", "Q", "R", "S", |
| 247 |
"T", "U", "V", "W", |
| 248 |
"X", "Y", "Z", "bracketleft", |
| 249 |
"backslash", "bracketright", "circumflex", "underscore", |
| 250 |
"quoteleft", "a", "b", "c", |
| 251 |
"d", "e", "f", "g", |
| 252 |
"h", "i", "j", "k", |
| 253 |
"l", "m", "n", "o", |
| 254 |
"p", "q", "r", "s", |
| 255 |
"t", "u", "v", "w", |
| 256 |
"x", "y", "z", "braceleft", |
| 257 |
"bar", "braceright", "tilde", "dieresis", |
| 258 |
"asciicircum", "asciitilde", "Ccedilla", "Iacute", |
| 259 |
"Icircumflex", "atilde", "edieresis", "egrave", |
| 260 |
"scaron", "zcaron", "Eth", "ff", |
| 261 |
"ffi", "ffl", ".notdef", ".notdef", |
| 262 |
".notdef", ".notdef", "Scaron", ".notdef", |
| 263 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 264 |
"Ydieresis", ".notdef", "Zcaron", ".notdef", |
| 265 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 266 |
".notdef", ".notdef", "cent", "sterling", |
| 267 |
"fraction", "yen", "florin", "section", |
| 268 |
"currency", "copyright", "quotedblleft", "guillemotleft", |
| 269 |
"guilsinglleft", "guilsinglright", "fi", "fl", |
| 270 |
"degree", "endash", "dagger", "daggerdbl", |
| 271 |
"periodcentered", ".notdef", "paragraph", "bullet", |
| 272 |
"quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", |
| 273 |
"ellipsis", "perthousand", ".notdef", ".notdef", |
| 274 |
"Agrave", "Aacute", "Acircumflex", "Atilde", |
| 275 |
"Adieresis", "Aring", ".notdef", "dotaccent", |
| 276 |
"Egrave", "Eacute", "Ecircumflex", "Edieresis", |
| 277 |
"Igrave", "hungarumlaut", "ogonek", "Idieresis", |
| 278 |
"emdash", "Ntilde", "Ograve", "Oacute", |
| 279 |
"Ocircumflex", "Otilde", "Odieresis", ".notdef", |
| 280 |
".notdef", "Ugrave", "Uacute", "Ucircumflex", |
| 281 |
"Udieresis", "Yacute", "Thorn", ".notdef", |
| 282 |
"agrave", "aacute", "acircumflex", "ordfeminine", |
| 283 |
"adieresis", "aring", ".notdef", "ccedilla", |
| 284 |
"Lslash", "eacute", "ecircumflex", "ordmasculine", |
| 285 |
"igrave", "iacute", "icircumflex", "idieresis", |
| 286 |
".notdef", "ntilde", "ograve", "oacute", |
| 287 |
"ocircumflex", "otilde", "odieresis", ".notdef", |
| 288 |
"lslash", "ugrave", "uacute", "ucircumflex", |
| 289 |
"udieresis", "yacute", "thorn", "ydieresis" |
| 290 |
); |
| 291 |
|
| 292 |
@adobeenc=( |
| 293 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 294 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 295 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 296 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 297 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 298 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 299 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 300 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 301 |
"space", "exclam", "quotedbl", "numbersign", |
| 302 |
"dollar", "percent", "ampersand", "quoteright", |
| 303 |
"parenleft", "parenright", "asterisk", "plus", |
| 304 |
"comma", "hyphen", "period", "slash", |
| 305 |
"zero", "one", "two", "three", |
| 306 |
"four", "five", "six", "seven", |
| 307 |
"eight", "nine", "colon", "semicolon", |
| 308 |
"less", "equal", "greater", "question", |
| 309 |
"at", "A", "B", "C", |
| 310 |
"D", "E", "F", "G", |
| 311 |
"H", "I", "J", "K", |
| 312 |
"L", "M", "N", "O", |
| 313 |
"P", "Q", "R", "S", |
| 314 |
"T", "U", "V", "W", |
| 315 |
"X", "Y", "Z", "bracketleft", |
| 316 |
"backslash", "bracketright", "asciicircum", "underscore", |
| 317 |
"quoteleft", "a", "b", "c", |
| 318 |
"d", "e", "f", "g", |
| 319 |
"h", "i", "j", "k", |
| 320 |
"l", "m", "n", "o", |
| 321 |
"p", "q", "r", "s", |
| 322 |
"t", "u", "v", "w", |
| 323 |
"x", "y", "z", "braceleft", |
| 324 |
"bar", "braceright", "asciitilde", ".notdef", |
| 325 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 326 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 327 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 328 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 329 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 330 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 331 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 332 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 333 |
".notdef", "exclamdown", "cent", "sterling", |
| 334 |
"fraction", "yen", "florin", "section", |
| 335 |
"currency", "quotesingle", "quotedblleft", "guillemotleft", |
| 336 |
"guilsinglleft", "guilsinglright", "fi", "fl", |
| 337 |
".notdef", "endash", "dagger", "daggerdbl", |
| 338 |
"periodcentered", ".notdef", "paragraph", "bullet", |
| 339 |
"quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", |
| 340 |
"ellipsis", "perthousand", ".notdef", "questiondown", |
| 341 |
".notdef", "grave", "acute", "circumflex", |
| 342 |
"tilde", "macron", "breve", "dotaccent", |
| 343 |
"dieresis", ".notdef", "ring", "cedilla", |
| 344 |
".notdef", "hungarumlaut", "ogonek", "caron", |
| 345 |
"emdash", ".notdef", ".notdef", ".notdef", |
| 346 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 347 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 348 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 349 |
".notdef", "AE", ".notdef", "ordfeminine", |
| 350 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 351 |
"Lslash", "Oslash", "OE", "ordmasculine", |
| 352 |
".notdef", ".notdef", ".notdef", ".notdef", |
| 353 |
".notdef", "ae", ".notdef", ".notdef", |
| 354 |
".notdef", "dotlessi", ".notdef", ".notdef", |
| 355 |
"lslash", "oslash", "oe", "germandbls", |
| 356 |
".notdef", ".notdef", ".notdef", ".notdef" |
| 357 |
); |
| 358 |
|
| 359 |
############### |
| 360 |
# Read DEF file |
| 361 |
############### |
| 362 |
# |
| 363 |
open DEF, $opt_d or die "Cannot open $opt_d: $!\n"; |
| 364 |
while (<DEF>) { |
| 365 |
next if (/^\s*$/ || /^\#/); |
| 366 |
s/\s*(\#.*)?$//; |
| 367 |
push @deflines, $_; |
| 368 |
} |
| 369 |
close DEF; |
| 370 |
|
| 371 |
############### |
| 372 |
# Read VPL file |
| 373 |
############### |
| 374 |
# |
| 375 |
# File header |
| 376 |
# |
| 377 |
$vplhead = <> or exit 1; |
| 378 |
unless ($vplhead =~ /^\((VTITLE|FAMILY) /) { |
| 379 |
die "$filename is not a vpl file: giving up\n" |
| 380 |
} |
| 381 |
do { |
| 382 |
$_ = <>; |
| 383 |
$vplhead .= $_; |
| 384 |
} until ($_ =~ /^\(LIGTABLE$/ or eof); |
| 385 |
if (eof) { |
| 386 |
die "$filename does not seem to be a text font (no LIGTABLE): giving up\n"; |
| 387 |
} |
| 388 |
if ($vplhead =~ s/\A\(VTITLE(.*)$/$vtitle\n(COMMENT Old vtitle:$1/m) { |
| 389 |
$vplhead =~ s/\n\(COMMENT Please edit that VTITLE .*\)$//m; |
| 390 |
@enc = @dvipsenc; |
| 391 |
$dvips = 1; |
| 392 |
} |
| 393 |
elsif ($vplhead =~ /\A\(FAMILY.*\)\n\(CODINGSCHEME ADOBESTANDARDENCODING\)$/m) { |
| 394 |
$vplhead =~ s/\A/$vtitle\n/m; |
| 395 |
@enc = @adobeenc; |
| 396 |
$dvips = 0; |
| 397 |
} |
| 398 |
else { |
| 399 |
$vplhead =~ s/\A/$vtitle\n/m; |
| 400 |
@enc = @TeXenc; |
| 401 |
$dvips = 0; |
| 402 |
} |
| 403 |
if ($vplhead =~ /^\(CODINGSCHEME TEX MATH SYMBOLS/m) { |
| 404 |
die "$filename is a TeX math font: giving up\n"; |
| 405 |
} |
| 406 |
unless ($vplhead =~ s/^(\(CODINGSCHEME .*\+\s?)(\S+)\)$/$1$encname)/m) { |
| 407 |
$vplhead =~ s/^(\(CODINGSCHEME .*)\)$/$1 + $encname)/m; |
| 408 |
} |
| 409 |
if ($vplhead =~ s/^\(DESIGNUNITS R (.+)\)\n//m) { $scale = $1 } |
| 410 |
else { $scale = 1 } |
| 411 |
$vplhead =~ s/^\(COMMENT.*DESIGNSIZE.*\)\n//gm; |
| 412 |
$vplhead =~ s/^\(BOUNDARYCHAR.*\)\n//gm; |
| 413 |
if ($vplhead =~ /^ \(SLANT R (.+)\)/m) { $slant = $1 } |
| 414 |
if ($vplhead =~ /^ \(XHEIGHT [DR] (.+)\)/m) { $xheight = $1 } |
| 415 |
unless ($vplhead =~ /^\(MAPFONT /m) { |
| 416 |
if ($vplhead =~ /^\(DESIGNSIZE R (.*)\)$/m) { $dsize = $1 *$scale } |
| 417 |
$mapfont = "\n(MAPFONT D 0\n (FONTNAME $fontname)\n (FONTDSIZE R $dsize)\n )"; |
| 418 |
$vplhead =~ s/\n\(LIGTABLE\Z/$mapfont$&/m; |
| 419 |
} |
| 420 |
$vplhead =~ s/^(\(FONTDIMEN)/(SEVENBITSAFEFLAG FALSE)\n$1/m; |
| 421 |
if ($opt_s) { |
| 422 |
$vplhead =~ s[^(\(MAPFONT D )0(.*?)( \))] |
| 423 |
[$&\n${1}1$2 (FONTAT R ${ \($shrink * $scale) })\n$3]ms; |
| 424 |
} |
| 425 |
@vplhead = split /^/, $vplhead; |
| 426 |
foreach (@vplhead) { |
| 427 |
s[(?<!(IGNSIZE|MAPFONT)) [RD] (-?)([0-9.]+)\)] |
| 428 |
[" R " . $2 . $3/$scale . ")"]ge |
| 429 |
} |
| 430 |
|
| 431 |
# |
| 432 |
# Ligatures and kerns |
| 433 |
# |
| 434 |
do { |
| 435 |
$_ = <>; |
| 436 |
s/ \(comment .*$//i; |
| 437 |
s/^( \((?:LABEL|KRN) )O ([0-7]+)(.*)$/$1 . sprintf("H %04lX", oct $2) . $3/e; |
| 438 |
if (/ \(LIG /) { |
| 439 |
s/O ([0-7]+)/sprintf("H %04lX", oct $1)/ge; |
| 440 |
} |
| 441 |
$ligs .= $_; |
| 442 |
} until $_ =~ /^ \)/; |
| 443 |
# |
| 444 |
# Now build a hash to convert from vpl representation to char name |
| 445 |
# and use it to make ligtable readable |
| 446 |
# |
| 447 |
foreach $i (0 .. 255) { $vc{$nv[$i]} = $enc[$i] } |
| 448 |
$ligs =~ s/^( \((?:LABEL|KRN) )(\S+ \S+)(.*\))$/$1$vc{$2}$3/gm; |
| 449 |
$ligs =~ s/^( \(LIG )(\S+ \S+) (\S+ \S+)\)$/$1$vc{$2} $vc{$3})/gm; |
| 450 |
# |
| 451 |
# Character definitions: store "encoded" defs in @chars, store *all* |
| 452 |
# defs in %allchars |
| 453 |
# |
| 454 |
$_ = <>; |
| 455 |
do { |
| 456 |
if (/^\(CHARACTER/) { |
| 457 |
$character = $_; |
| 458 |
do { |
| 459 |
$_ = <>; |
| 460 |
$character .= $_; |
| 461 |
} until $_ =~ /^ \)/; |
| 462 |
storeinfo($character); |
| 463 |
$_ = <>; |
| 464 |
} |
| 465 |
} until eof; |
| 466 |
foreach $i (0 .. $#chars) { |
| 467 |
if ($chars[$i] and $enc[$i] ne ".notdef") { |
| 468 |
$allchars{$enc[$i]} = $chars[$i]; |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
################## |
| 473 |
# Set up constants |
| 474 |
################## |
| 475 |
|
| 476 |
$subacc = "(cedilla|ogonek|commaaccent)"; |
| 477 |
$supacc = "(grave|acute|circumflex|tilde|macron|breve|dotaccent|overdot|dieresis|ring|hungarumlaut|caron|candrabindu)"; |
| 478 |
$underacc = "(underdot|under$supacc)"; |
| 479 |
$accents = "($subacc|$supacc|$underacc|underbar)"; |
| 480 |
$underadp = 0.230; # depth of "under" accs |
| 481 |
$underddp = 0.213; # depth of underdot |
| 482 |
if ($bold) { $thk = 0.072 } else { $thk = 0.052 } # thickness and |
| 483 |
$underbdp = 0.082 + $thk; # depth of underbar |
| 484 |
$capheight = $allchars{"X"}{ht}; |
| 485 |
$accheight = $allchars{"macron"}{ht}; |
| 486 |
$accdepth = $accheight - $thk * $scale; # probable approx. "depth" of macron |
| 487 |
$v1 = $accheight - $xheight; # vertical offset for double accents |
| 488 |
$v2 = $capheight - $xheight; # vertical offset for accented caps etc |
| 489 |
if ($scaps) { # accented small caps |
| 490 |
$scoffset = $allchars{"x"}{ht} - $xheight; |
| 491 |
$v1 += $scoffset; |
| 492 |
} |
| 493 |
if ($opt_c) { # candrabindu |
| 494 |
($cbx, $cby) = $opt_c =~ /^(.*),(.*)$/; |
| 495 |
$cbx += ($allchars{"breve"}{wd} - $allchars{"dotaccent"}{wd}) / 2; |
| 496 |
$cbx /= 1000; |
| 497 |
$cby /= 1000; |
| 498 |
} |
| 499 |
|
| 500 |
###################### |
| 501 |
# Build the characters |
| 502 |
###################### |
| 503 |
# |
| 504 |
# First normalise dvips.enc encoding quirks |
| 505 |
# |
| 506 |
if ($dvips) { |
| 507 |
chmove("fi", 014); |
| 508 |
chmove("fl", 015); |
| 509 |
chmove("quotedblright", 042); |
| 510 |
chmove("quotedblleft", 0134); |
| 511 |
chmove("dotaccent", 0137); |
| 512 |
chmove("endash", 0173); |
| 513 |
chmove("emdash", 0174); |
| 514 |
chmove("hungarumlaut", 0175); |
| 515 |
} |
| 516 |
# |
| 517 |
# Now build a list of definitions supplied by user |
| 518 |
# |
| 519 |
for (@deflines) { |
| 520 |
if (/^\s*(\d+|0[0-7]+|0x[0-9a-fA-F]+)\s+([a-zA-Z]+?|\.notdef)(?:\s+([a-zA-Z]+))?$/) { |
| 521 |
($num, $char, $acc) = ($1, $2, $3); |
| 522 |
$num = oct $num if $num =~ /^0/; |
| 523 |
if ($num > 0xFFFF) { die "Bad definition (number out of range): $_\n" } |
| 524 |
$def = {}; |
| 525 |
$def->{qdef} = $_; |
| 526 |
$def->{num} = $num; |
| 527 |
$def->{char} = $char; |
| 528 |
$def->{acc} = $acc; |
| 529 |
if ($char eq "space") { $def->{nchar} = $acc } |
| 530 |
else { $def->{nchar} = $char . $acc } |
| 531 |
push @nchars, $def->{nchar}; |
| 532 |
push @defs, $def; |
| 533 |
} |
| 534 |
else { die "Bad definition: $_\n" } |
| 535 |
} |
| 536 |
# |
| 537 |
# Work through the list |
| 538 |
# |
| 539 |
while (@defs) { |
| 540 |
$def = shift @defs; |
| 541 |
$qdef = $def->{qdef}; |
| 542 |
$num = $def->{num}; |
| 543 |
$char = $def->{char}; |
| 544 |
$acc = $def->{acc}; |
| 545 |
$nchar = $def->{nchar}; |
| 546 |
# |
| 547 |
# If we can't handle $char/$acc yet, but believe we will be able |
| 548 |
# to later, send the definition to the back of the queue. In case |
| 549 |
# it later turns out we were wrong, allow only five loops before |
| 550 |
# giving up. |
| 551 |
# |
| 552 |
if (!$allchars{$char} and $char ne ".notdef") { |
| 553 |
if (grep /^$char$/, @nchars) { |
| 554 |
unless (++$def->{requeue} > 5) { |
| 555 |
push @defs, $def; |
| 556 |
next; |
| 557 |
} |
| 558 |
} |
| 559 |
else { die "Bad definition (no such character): $qdef\n" } |
| 560 |
} |
| 561 |
if ($acc and !$allchars{$acc} and $acc !~ /^$accents$/) { |
| 562 |
if (grep /^$acc$/, @nchars) { |
| 563 |
unless (++$def->{requeue} > 5) { |
| 564 |
push @defs, $def; |
| 565 |
next; |
| 566 |
} |
| 567 |
} |
| 568 |
else { die "Bad definition (no such accent): $qdef\n" } |
| 569 |
} |
| 570 |
# |
| 571 |
# Remove any existing claims on $num |
| 572 |
# |
| 573 |
@{ $allchars{$chars[$num]{id}}{num} } = grep !/$num/, |
| 574 |
@{ $allchars{$chars[$num]{id}}{num} }; |
| 575 |
# |
| 576 |
# First deal with .notdef |
| 577 |
# |
| 578 |
if ($nchar eq ".notdef") { |
| 579 |
undef $chars[$num]; |
| 580 |
} |
| 581 |
# |
| 582 |
# Next look among existing chars (unless blocked by -b) |
| 583 |
# |
| 584 |
elsif (!($acc and $opt_b) and $allchars{$nchar}) { |
| 585 |
push( @{ $allchars{$nchar}{num} }, $num); |
| 586 |
$chars[$num] = $allchars{$nchar}; |
| 587 |
} |
| 588 |
# |
| 589 |
# If it can't be built from sub-elements, issue a warning and move on |
| 590 |
# |
| 591 |
elsif (!$acc) { |
| 592 |
warn "No such character - ignoring definition: $qdef\n"; |
| 593 |
undef $chars[$num]; |
| 594 |
} |
| 595 |
# |
| 596 |
# Now build the char |
| 597 |
# |
| 598 |
else { |
| 599 |
# |
| 600 |
# First get rid of predefined/duplicated ligtable statements |
| 601 |
# and character definitions; also synonyms |
| 602 |
# |
| 603 |
$ligs =~ s/\n \((LABEL|KRN|LIG) ($nchar .*|.*$nchar)\)$//gm; |
| 604 |
$allchars{$nchar} = (); |
| 605 |
if ($acc eq "overdot") { |
| 606 |
$nchar2 = $char . "dotaccent"; |
| 607 |
$ligs =~ s/\n \((LABEL|KRN|LIG) ($nchar2 .*|.*$nchar2)\)$//gm; |
| 608 |
delete $allchars{$nchar2}; |
| 609 |
} |
| 610 |
# |
| 611 |
# Store the info that will be needed to have the character |
| 612 |
# linked into the LIGTABLE |
| 613 |
# |
| 614 |
push @newligs, "$char: (LIG $acc $nchar)"; |
| 615 |
# |
| 616 |
# Go! |
| 617 |
# |
| 618 |
if ($acc =~ /^$subacc$/) { |
| 619 |
subacc($num, $char, $acc, $nchar); |
| 620 |
fixkerns($char, $acc); |
| 621 |
} |
| 622 |
elsif ($acc =~ /^$supacc$/) { |
| 623 |
supacc($num, $char, $acc, $nchar); |
| 624 |
fixkerns($char, $acc); |
| 625 |
} |
| 626 |
elsif ($acc =~ /^$underacc$/) { |
| 627 |
underacc($num, $char, $acc, $nchar); |
| 628 |
fixkerns($char, $acc); |
| 629 |
} |
| 630 |
elsif ($acc =~ /^underbar$/) { |
| 631 |
underb($num, $char, $nchar); |
| 632 |
fixkerns($char, $acc); |
| 633 |
} |
| 634 |
else { |
| 635 |
digraph($num, $char, $acc, $nchar); |
| 636 |
fixkerns($char, $acc); |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
################### |
| 642 |
# Sort out ligtable |
| 643 |
################### |
| 644 |
# |
| 645 |
# Pull in the newly created ligatures |
| 646 |
# |
| 647 |
foreach $newlig (@newligs) { |
| 648 |
$newlig =~ s/^(.+)://; |
| 649 |
$newelm1 = $1; |
| 650 |
unless ($ligs =~ s/(^ \(LABEL $newelm1\)\n)/$1$newlig\n/m) { |
| 651 |
$ligs =~ s[^( \)\n)] |
| 652 |
[ \(LABEL $newelm1\)\n$newlig\n \(STOP\)\n$1]m |
| 653 |
} |
| 654 |
} |
| 655 |
# |
| 656 |
# Convert to vpl representation, eliminating statements invoking |
| 657 |
# "unencoded" characters |
| 658 |
# |
| 659 |
@liglist = split /\n/, $ligs; |
| 660 |
$ligs = ""; |
| 661 |
foreach (@liglist) { |
| 662 |
if (/^( \(LIG \S+ )(\S+)\)$/) { |
| 663 |
if ($n = ${ $allchars{$2}{num} }[0]) { |
| 664 |
s/^( \(LIG \S+ )(\S+)\)$/$1$nv[$n])/; |
| 665 |
} |
| 666 |
else { next } |
| 667 |
} |
| 668 |
if (/^( \((?:LABEL|LIG|KRN) )([^ )]+)(.*)$/) { |
| 669 |
($one, $two, $three) = ($1, $2, $3); |
| 670 |
foreach $n (@{ $allchars{$two}{num} }) { |
| 671 |
$ligs .= "$one$nv[$n]$three\n"; |
| 672 |
} |
| 673 |
} |
| 674 |
else { $ligs .= "$_\n" } |
| 675 |
} |
| 676 |
# |
| 677 |
# Eliminate sequences orphaned by elimination of a LABEL |
| 678 |
# |
| 679 |
@liglist = split / \(STOP\)\n/, $ligs; |
| 680 |
$ligs = ""; |
| 681 |
foreach (@liglist) { |
| 682 |
if (/^ \(LABEL /m) { $ligs .= "$_ (STOP)\n" } |
| 683 |
elsif (/^ \)$/m) { $ligs .= $_ } |
| 684 |
} |
| 685 |
# |
| 686 |
# Eliminate empty statements |
| 687 |
# |
| 688 |
$ligs =~ s/(^ \(LABEL .*\)\n)+ \(STOP\)\n//gm; |
| 689 |
@ligs = split /^/, $ligs; |
| 690 |
foreach (@ligs) { |
| 691 |
s/ [RD] (-?)([0-9.]+)\)/" R " . $1 . $2\/$scale . ")"/ge |
| 692 |
} |
| 693 |
|
| 694 |
#################### |
| 695 |
# Output the results |
| 696 |
#################### |
| 697 |
# |
| 698 |
print @vplhead, @ligs; |
| 699 |
foreach $i (0 .. 0xFFFF) { if (defined $chars[$i]{id}) { printchar($i) } } |
| 700 |
|
| 701 |
##################### |
| 702 |
# End of main program |
| 703 |
##################### |
| 704 |
|
| 705 |
sub storeinfo { |
| 706 |
# |
| 707 |
# Extract info from a character definition and store it in @chars |
| 708 |
# |
| 709 |
my $char = shift; |
| 710 |
my $num; |
| 711 |
if ($char =~ /\A\(CHARACTER O ([0-7]+)/m) { $num = oct $1 } |
| 712 |
elsif ($char =~ /\A\(CHARACTER C (.)/m) { $num = ord $1 } |
| 713 |
$chars[$num]{id} = $enc[$num]; |
| 714 |
push( @{ $chars[$num]{num} }, $num); |
| 715 |
if ($char =~ /^ \(CHARWD R (.*?)\)$/m) { $chars[$num]{wd} = $1 } |
| 716 |
if ($char =~ /^ \(CHARHT R (.*?)\)$/m) { $chars[$num]{ht} = $1 } |
| 717 |
if ($char =~ /^ \(CHARDP R (.*?)\)$/m) { $chars[$num]{dp} = $1 } |
| 718 |
if ($char =~ /^ \(CHARIC R (.*?)\)$/m) { $chars[$num]{ic} = $1 } |
| 719 |
if ($char =~ /^ \(MAP\n((.|\n)*)^ \)/m) { $chars[$num]{map} = $1 } |
| 720 |
else { $chars[$num]{map} = " (SETCHAR $nv[$num])\n" } |
| 721 |
$chars[$num]{map} =~ s[(\(SETCHAR )O ([0-7]+)\)] |
| 722 |
[$1 . sprintf("H %04lX", oct $2) . ")"]gme |
| 723 |
} |
| 724 |
|
| 725 |
sub printchar { |
| 726 |
# |
| 727 |
# Extract info from @chars and build it into a character definition |
| 728 |
# |
| 729 |
my $num = shift; |
| 730 |
my @ch; |
| 731 |
push @ch, "(CHARACTER "; |
| 732 |
if (chr($num) =~ /[0-9A-Za-z]/) { push @ch, "C " . chr($num) } |
| 733 |
else { |
| 734 |
push @ch, sprintf("H %04lX", $num); |
| 735 |
push @ch, " (COMMENT " . $chars[$num]{id} . ")"; |
| 736 |
} |
| 737 |
push @ch, "\n"; |
| 738 |
push @ch, " (CHARWD R " . $chars[$num]{wd} . ")\n" |
| 739 |
if defined $chars[$num]{wd}; |
| 740 |
push @ch, " (CHARHT R " . $chars[$num]{ht} . ")\n" |
| 741 |
if defined $chars[$num]{ht}; |
| 742 |
push @ch, " (CHARDP R " . $chars[$num]{dp} . ")\n" if $chars[$num]{dp}; |
| 743 |
push @ch, " (CHARIC R " . $chars[$num]{ic} . ")\n" if $chars[$num]{ic}; |
| 744 |
push @ch, " (MAP\n"; |
| 745 |
push @ch, $chars[$num]{map}; |
| 746 |
push @ch, " )\n"; |
| 747 |
push @ch, " )\n"; |
| 748 |
foreach (@ch) { |
| 749 |
s/(?<!SELECTFONT) [RD] (-?)([0-9.]+)\)/" R " . $1 . $2\/$scale . ")"/ge |
| 750 |
} |
| 751 |
print @ch |
| 752 |
} |
| 753 |
|
| 754 |
sub chmove { |
| 755 |
# |
| 756 |
# Move a character |
| 757 |
# |
| 758 |
my ($char, $num) = @_; |
| 759 |
my $i; |
| 760 |
foreach $i (@{ $allchars{$char}{num} }) { undef $chars[$i] } |
| 761 |
@{ $allchars{$char}{num} } = (); |
| 762 |
@{ $allchars{$chars[$num]{id}}{num} } = grep !/$num/, |
| 763 |
@{ $allchars{$chars[$num]{id}}{num} }; |
| 764 |
push( @{ $allchars{$char}{num} }, $num); |
| 765 |
$chars[$num] = $allchars{$char}; |
| 766 |
} |
| 767 |
|
| 768 |
sub max { |
| 769 |
# |
| 770 |
# Return greater of two values |
| 771 |
# |
| 772 |
my ($a, $b) = @_; |
| 773 |
return $a > $b ? $a : $b; |
| 774 |
} |
| 775 |
|
| 776 |
sub subacc { |
| 777 |
# |
| 778 |
# Subscript accents |
| 779 |
# |
| 780 |
my ($num, $char, $acc, $id) = @_; |
| 781 |
my ($h, $s1, $s2, $s3); |
| 782 |
$allchars{$id}{wd} = $allchars{$char}{wd}; |
| 783 |
$allchars{$id}{ht} = $allchars{$char}{ht}; |
| 784 |
$allchars{$id}{dp} = $allchars{$acc}{dp}; |
| 785 |
$allchars{$id}{ic} = $allchars{$char}{ic}; |
| 786 |
$allchars{$id}{id} = $id; |
| 787 |
push( @{ $allchars{$id}{num} }, $num); |
| 788 |
$s1 = $allchars{$char}{map}; |
| 789 |
$s1 =~ s/\A (.*)\n\Z/(PUSH) $1 (POP)/s; |
| 790 |
$h = sprintf("%.3f", ($allchars{$char}{wd} - $allchars{$acc}{wd}) / 2); |
| 791 |
if ($h > 0) { $s2 = " (MOVERIGHT R $h) " } |
| 792 |
elsif ($h < 0) { |
| 793 |
$h = -$h; |
| 794 |
$s2 = " (MOVELEFT R $h) "; |
| 795 |
} |
| 796 |
else { $s2 = " " } |
| 797 |
$s3 = $allchars{$acc}{map}; |
| 798 |
$s3 =~ s/\A.*(\(SETCHAR . .+?\)).*\Z/$1/s; |
| 799 |
$allchars{$id}{map} = " $s1\n$s2$s3\n"; |
| 800 |
$chars[$num] = $allchars{$id}; |
| 801 |
} |
| 802 |
|
| 803 |
sub supacc { |
| 804 |
# |
| 805 |
# Superscript accents |
| 806 |
# |
| 807 |
my ($num, $char, $acc, $id) = @_; |
| 808 |
my ($cb, $h, $hadj, $tallchar, $ic, $s1, $s2, $s3); |
| 809 |
if ($char eq "i" and $allchars{"dotlessi"}) { $char = "dotlessi" } |
| 810 |
if ($char eq "j" and $allchars{"dotlessj"}) { $char = "dotlessj" } |
| 811 |
if ($acc eq "overdot") { $acc = "dotaccent" } |
| 812 |
if ($acc eq "candrabindu") { |
| 813 |
$acc = "breve"; |
| 814 |
($cb = $allchars{"dotaccent"}{map}) =~ s/\A.*(\(SETCHAR . .+?\)).*\Z/$1/s; |
| 815 |
} |
| 816 |
$allchars{$id}{wd} = $allchars{$char}{wd}; |
| 817 |
$allchars{$id}{ht} = $allchars{$acc}{ht}; |
| 818 |
$allchars{$id}{dp} = $allchars{$char}{dp}; |
| 819 |
$allchars{$id}{id} = $id; |
| 820 |
push( @{ $allchars{$id}{num} }, $num); |
| 821 |
$s1 = $allchars{$char}{map}; |
| 822 |
$s1 =~ s/\A (.*)\n\Z/(PUSH) $1 (POP)/s; |
| 823 |
if ($scaps and $char =~ /^[a-z]/) { # accented small caps |
| 824 |
$tallchar = 1; |
| 825 |
if ($char =~ /$supacc$/ |
| 826 |
and $char !~ /under$supacc$/) { # double accs |
| 827 |
$s2 = " (MOVEUP R $v1)"; |
| 828 |
$allchars{$id}{ht} += $v1; |
| 829 |
$hadj = sprintf("%.3f", $v1 * $slant); |
| 830 |
$ic = $allchars{$char}{ic}; |
| 831 |
} |
| 832 |
else { # single accs |
| 833 |
$s2 = " (MOVEUP R $scoffset)"; |
| 834 |
$allchars{$id}{ht} += $scoffset; |
| 835 |
$hadj = sprintf("%.3f", $scoffset * $slant); |
| 836 |
$ic = $allchars{$acc}{ic} + $hadj; |
| 837 |
} |
| 838 |
} |
| 839 |
elsif ($allchars{$char}{ht} >= ($accheight + $v2)) { # double accs |
| 840 |
$tallchar = 1; # on caps etc. |
| 841 |
$s2 = " (MOVEUP R ${ \($v1 + $v2) })"; |
| 842 |
$allchars{$id}{ht} += ($v1 + $v2); |
| 843 |
$hadj = sprintf("%.3f", ($v1 + $v2) * $slant); |
| 844 |
$ic = $allchars{$char}{ic}; |
| 845 |
} |
| 846 |
elsif ($allchars{$char}{ht} > 1.15 * $xheight) { |
| 847 |
$tallchar = 1; |
| 848 |
if ($char =~ /$supacc$/ |
| 849 |
and $char !~ /under$supacc$/) { # double accs |
| 850 |
$s2 = " (MOVEUP R $v1)"; |
| 851 |
$allchars{$id}{ht} += $v1; |
| 852 |
$hadj = sprintf("%.3f", $v1 * $slant); |
| 853 |
$ic = $allchars{$char}{ic}; |
| 854 |
} |
| 855 |
else { # caps etc. |
| 856 |
$s2 = " (MOVEUP R $v2)"; |
| 857 |
$allchars{$id}{ht} += $v2; |
| 858 |
$hadj = sprintf("%.3f", $v2 * $slant); |
| 859 |
$ic = $allchars{$char}{ic}; |
| 860 |
} |
| 861 |
} |
| 862 |
else { # single accs |
| 863 |
$s2 = " "; |
| 864 |
$ic = $allchars{$acc}{ic}; |
| 865 |
} |
| 866 |
$h = sprintf("%.3f", ($allchars{$char}{wd} - $allchars{$acc}{wd}) / 2); |
| 867 |
unless ($tallchar) { $ic -= $h } |
| 868 |
$allchars{$id}{ic} = $ic unless $ic < 0; |
| 869 |
$h += $hadj; |
| 870 |
if ($h > 0) { $s2 .= " (MOVERIGHT R $h) " } |
| 871 |
elsif ($h < 0) { |
| 872 |
$h = -$h; |
| 873 |
$s2 .= " (MOVELEFT R $h) "; |
| 874 |
} |
| 875 |
else { $s2 .= " " } |
| 876 |
$s3 = $allchars{$acc}{map}; |
| 877 |
$s3 =~ s/\A.*(\(SETCHAR . .+?\)).*\Z/$1/s; |
| 878 |
if ($cb) { # candrabindu |
| 879 |
$cb = $s2 . $cb; |
| 880 |
if ($cbx) { |
| 881 |
unless (($cb =~ s/(MOVERIGHT R )([0-9.]+)/$1 . ($2 + $cbx * $scale)/e) |
| 882 |
or ($cb =~ s/(MOVELEFT R )([0-9.]+)/$1 . ($2 - $cbx * $scale)/e)) { |
| 883 |
$cb =~ s/^( +)/"$1(MOVERIGHT R " . ($cbx * $scale) . ") "/e; |
| 884 |
} |
| 885 |
} |
| 886 |
if ($cby) { |
| 887 |
unless ($cb =~ s/(MOVEUP R )([0-9.]+)/$1 . ($2 + $cby * $scale)/e) { |
| 888 |
$cb =~ s/^( +)/"$1(MOVEUP R " . ($cby * $scale) . ") "/e; |
| 889 |
} |
| 890 |
} |
| 891 |
$cb .= "\n"; |
| 892 |
$s1 = "(PUSH) " . $s1; |
| 893 |
$s3 .= " (POP)"; |
| 894 |
} |
| 895 |
$allchars{$id}{map} = " $s1\n$s2$s3\n$cb"; |
| 896 |
$chars[$num] = $allchars{$id}; |
| 897 |
} |
| 898 |
|
| 899 |
sub underacc { |
| 900 |
# |
| 901 |
# Dropped accents |
| 902 |
# |
| 903 |
my ($num, $char, $acc, $id) = @_; |
| 904 |
my ($h, $v, $s1, $s2, $s3); |
| 905 |
$acc =~ s/^under//; |
| 906 |
if ($acc eq "dot") { $acc = "period" } |
| 907 |
if ($acc eq "candrabindu") { die "Bad definition (no such accent): $qdef\n" } |
| 908 |
$allchars{$id}{wd} = $allchars{$char}{wd}; |
| 909 |
$allchars{$id}{ht} = $allchars{$char}{ht}; |
| 910 |
$allchars{$id}{ic} = $allchars{$char}{ic}; |
| 911 |
$allchars{$id}{id} = $id; |
| 912 |
push( @{ $allchars{$id}{num} }, $num); |
| 913 |
if ($acc =~ /^$supacc$/) { |
| 914 |
$v = $allchars{$id}{dp} = $underadp * $scale * $shrink; |
| 915 |
$v += ($accdepth * $shrink); |
| 916 |
} |
| 917 |
else { |
| 918 |
$v = $allchars{$id}{dp} = $underddp * $scale + $allchars{$acc}{dp}; |
| 919 |
} |
| 920 |
$s1 = $allchars{$char}{map}; |
| 921 |
$s1 =~ s/\A (.*)\n\Z/(PUSH) $1 (POP)/s; |
| 922 |
if ($acc =~ /^$supacc$/) { |
| 923 |
$h = ($allchars{$char}{wd} - ($allchars{$acc}{wd} * $shrink)) / 2 - $v * $slant; |
| 924 |
if ($opt_s) { $s2 = " (SELECTFONT D 1)\n" } |
| 925 |
} |
| 926 |
else { |
| 927 |
$h = ($allchars{$char}{wd} - $allchars{$acc}{wd}) / 2 - $v * $slant; |
| 928 |
} |
| 929 |
$h = sprintf("%.3f", $h); |
| 930 |
if ($h > 0) { |
| 931 |
$s2 .= " (MOVEDOWN R $v) (MOVERIGHT R $h) "; |
| 932 |
} |
| 933 |
elsif ($h < 0) { |
| 934 |
$h = -$h; |
| 935 |
$s2 .= " (MOVEDOWN R $v) (MOVELEFT R $h) "; |
| 936 |
} |
| 937 |
else { $s2 = " (MOVEDOWN R $v) " } |
| 938 |
$s3 = $allchars{$acc}{map}; |
| 939 |
$s3 =~ s/\A.*(\(SETCHAR . .+?\)).*\Z/$1/s; |
| 940 |
if ($opt_s and $acc =~ /^$supacc$/) { $s3 .= "\n (SELECTFONT D 0)" } |
| 941 |
$allchars{$id}{map} = " $s1\n$s2$s3\n"; |
| 942 |
$chars[$num] = $allchars{$id}; |
| 943 |
} |
| 944 |
|
| 945 |
sub underb { |
| 946 |
# |
| 947 |
# Underbar |
| 948 |
# |
| 949 |
my ($num, $char, $id) = @_; |
| 950 |
my ($h, $w, $dp, $s1, $s2, $s3); |
| 951 |
$allchars{$id}{wd} = $allchars{$char}{wd}; |
| 952 |
$allchars{$id}{ht} = $allchars{$char}{ht}; |
| 953 |
$allchars{$id}{dp} = $dp = $underbdp * $scale; |
| 954 |
$allchars{$id}{ic} = $allchars{$char}{ic}; |
| 955 |
$allchars{$id}{id} = $id; |
| 956 |
push( @{ $allchars{$id}{num} }, $num); |
| 957 |
$s1 = $allchars{$char}{map}; |
| 958 |
$s1 =~ s/\A (.*)\n\Z/(PUSH) $1 (POP)/s; |
| 959 |
$h = sprintf("%.3f", ($allchars{$id}{wd} / 10 - $dp * $slant)); |
| 960 |
$w = sprintf("%.3f", ($allchars{$id}{wd} * 8 / 10)); |
| 961 |
if ($h > 0) { |
| 962 |
$s2 = " (MOVEDOWN R $dp) (MOVERIGHT R $h) "; |
| 963 |
} |
| 964 |
elsif ($h < 0) { |
| 965 |
$h = -$h; |
| 966 |
$s2 = " (MOVEDOWN R $dp) (MOVELEFT R $h) "; |
| 967 |
} |
| 968 |
else { $s2 .= " (MOVEDOWN R $dp) " } |
| 969 |
$s3 = "(SETRULE R ${ \($thk) } R $w)"; |
| 970 |
$allchars{$id}{map} = " $s1\n$s2$s3\n"; |
| 971 |
$chars[$num] = $allchars{$id}; |
| 972 |
# |
| 973 |
# If the character to be underscored is a digraph, fix up the LIGTABLE |
| 974 |
# |
| 975 |
if (grep /^$char$/, @digraphs) { |
| 976 |
pop @newligs; |
| 977 |
dummychar(0x035F, "uni035F") unless defined $allchars{uni035F}; |
| 978 |
$char =~ /^(.)(.)$/; |
| 979 |
($one, $two) = ($1, $2); |
| 980 |
$one_ = $one . "_uni035F"; |
| 981 |
dummychar($dummycodepoint--, $one_) unless defined $allchars{$one_}; |
| 982 |
push @newligs, "$one: (LIG uni035F $one_)" |
| 983 |
unless (grep /^$one: \(LIG uni035F $one_\)$/, @newligs); |
| 984 |
push @newligs, "$one_: (LIG $two $id)"; |
| 985 |
} |
| 986 |
} |
| 987 |
|
| 988 |
sub digraph { |
| 989 |
# |
| 990 |
# Make a new character consisting of two existing characters |
| 991 |
# |
| 992 |
my ($num, $char, $acc, $id) = @_; |
| 993 |
my ($one, $two, $kern, $s1, $s2, $charZWJ); |
| 994 |
# |
| 995 |
# Remove the ligature info -- we don't want every occurrence of |
| 996 |
# e.g."kh" to be converted into a digraph. |
| 997 |
# |
| 998 |
pop @newligs; |
| 999 |
# |
| 1000 |
# List all digraphs for future reference |
| 1001 |
# |
| 1002 |
push @digraphs, $id; |
| 1003 |
if ($ligs =~ /^ \(LABEL $char\)\n(.*?)\n \(KRN $acc R (-?[0-9.]+)\)\n/ms) { |
| 1004 |
($one, $two) = ($1, $2); |
| 1005 |
} |
| 1006 |
$kern = $two if $one !~ /^ \(STOP\)$/m; |
| 1007 |
$allchars{$id}{wd} = $allchars{$char}{wd} + $allchars{$acc}{wd}; |
| 1008 |
$allchars{$id}{wd} += $kern; |
| 1009 |
$allchars{$id}{ht} = max($allchars{$char}{ht}, $allchars{$acc}{ht}); |
| 1010 |
$allchars{$id}{dp} = max($allchars{$char}{dp}, $allchars{$acc}{dp}); |
| 1011 |
$allchars{$id}{ic} = $allchars{$acc}{ic}; |
| 1012 |
$allchars{$id}{id} = $id; |
| 1013 |
push( @{ $allchars{$id}{num} }, $num); |
| 1014 |
$s1 = $allchars{$char}{map}; |
| 1015 |
chomp ($s2 = $allchars{$acc}{map}); |
| 1016 |
$s1 =~ s/(\(SETCHAR .*?\))/$1\n$s2/; |
| 1017 |
if ($kern) { |
| 1018 |
if ($kern < 0) { |
| 1019 |
$kern = -$kern; |
| 1020 |
$s1 =~ s/(\(SETCHAR .*?\))/$1 (MOVELEFT R $kern)/; |
| 1021 |
} |
| 1022 |
else { $s1 =~ s/(\(SETCHAR .*?\))/$1 (MOVERIGHT R $kern)/ } |
| 1023 |
} |
| 1024 |
$allchars{$id}{map} = $s1; |
| 1025 |
$chars[$num] = $allchars{$id}; |
| 1026 |
} |
| 1027 |
|
| 1028 |
sub dummychar { |
| 1029 |
# |
| 1030 |
# Make a new dummy character |
| 1031 |
# |
| 1032 |
my ($num, $id) = @_; |
| 1033 |
$allchars{$id}{wd} = 0; |
| 1034 |
$allchars{$id}{ht} = 0; |
| 1035 |
$allchars{$id}{dp} = 0; |
| 1036 |
$allchars{$id}{ic} = 0; |
| 1037 |
$allchars{$id}{id} = $id; |
| 1038 |
push( @{ $allchars{$id}{num} }, $num); |
| 1039 |
$allchars{$id}{map} = " (SETCHAR H 0020)\n"; |
| 1040 |
$chars[$num] = $allchars{$id}; |
| 1041 |
} |
| 1042 |
|
| 1043 |
sub fixkerns { |
| 1044 |
# |
| 1045 |
# Generalise the kerning info contained in the vpl file by applying |
| 1046 |
# it to new accented chars. Do not kern lower-case chars bearing |
| 1047 |
# superscript accents with capitals, quotes or a preceding "f". |
| 1048 |
# |
| 1049 |
my ($char, $acc) = @_; |
| 1050 |
my ($olabel, $nlabel, @liglist, $lchar, $rchar); |
| 1051 |
return if $char eq "space"; |
| 1052 |
if ($acc =~ /^$accents$/) { $lchar = $rchar = $char } |
| 1053 |
else { |
| 1054 |
$lchar = $char; |
| 1055 |
$rchar = $acc; |
| 1056 |
} |
| 1057 |
unless ($char =~ /^[a-z]/ and $acc =~ /^$supacc$/) { |
| 1058 |
$ligs =~ s[(\n \(LABEL )$rchar\)(?!\n \(LIG.*$)] |
| 1059 |
[$&$1$char$acc)]gm |
| 1060 |
unless $ligs =~ /\n \(LABEL $char$acc\)$/m; |
| 1061 |
$ligs =~ s[(\n \(LABEL )$rchar\)(\n \(LIG.*$)+(?!\n \(STOP\))] |
| 1062 |
[$&$1$char$acc)]gm |
| 1063 |
unless $ligs =~ /\n \(LABEL $char$acc\)$/m; |
| 1064 |
$ligs =~ s[(\n \(KRN )$lchar( .*)$] |
| 1065 |
[$&$1$char$acc$2]gm; |
| 1066 |
} |
| 1067 |
else { |
| 1068 |
if ($ligs =~ /\n \(LABEL $char\).*?\(STOP\)/s) { |
| 1069 |
$nlabel = $olabel = $&; |
| 1070 |
$nlabel =~ s/(\n \(LABEL $char)\)/$1$acc)/ |
| 1071 |
unless $ligs =~ /\n \(LABEL $char$acc\)/m; |
| 1072 |
$nlabel =~ s/\n \(LIG .*\)$//gm; |
| 1073 |
$nlabel =~ s/\n \(LABEL (?!$char$acc).*\)$//gm; |
| 1074 |
$nlabel =~ s/\n \(KRN ([A-Z]|quote).*\)$//gm; |
| 1075 |
$ligs =~ s/(\n \(LABEL )$char\).*?\(STOP\)/$olabel$nlabel/s; |
| 1076 |
} |
| 1077 |
@liglist = split /\n \(STOP\)/, $ligs; |
| 1078 |
foreach (@liglist) { |
| 1079 |
unless (/\n \(LABEL ([A-Zf]|quote).*\)$/m) { |
| 1080 |
s/(\n \(KRN $char)( .*\))$/$&$1$acc$2/gm; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
$ligs = join("\n (STOP)", @liglist); |
| 1084 |
} |
| 1085 |
} |