<<

52 MAPS 31 Adam T. Lindsay

OpenType in ConTEXt Multi--dimensional support and advanced font features

Keywords ConTeXt OpenType Abstract This is a summary of issues encountered and solutions implemented in order to support some advanced OpenType features in ConTEXt. This article describes an accompanying set of support files that address installation (using TEXFONT), accommodating extended opticals families, and some “pro” font features. The extended character set afforded by pro fonts enables support for comprehensive and old--style figures. Although the typescripts and commands are described together, certain features (like variant encodings for TEXFONTand optical typescripts) can be used independently of the other features described.

Introduction This article, originally produced as a ConTEXt “My Way” article, introduces some issues in installing, using, and integrating OpenType fonts in ConTEXt. OpenType has been discussed elsewhere in detail, but it should suffice to say that it is a modern melding of POSTSCRIPT and TrueType, enabling advanced features and Unicode support. Roman and With some of the most complex OpenType fonts, one also sees integration with C multiple design sizes. This is not necessarily unique to OpenType fonts, but is a co-- ItalicC and occurring feature seen with “premium”--quality fonts. Some of the advanced typo- Bold and graphical features seen in such fonts are integrated for small caps (across C every font variant), old style and tabulation figures, and greek glyphs, all within BoldIC the same font. This article introduces some strategies for taking advantage of small Figure 1 Small caps in caps and old style figures, and for rudimentary math fonts for fonts that include several variants greek language support. It should be noted that this package owes its existence to Adobe’s “Type Classics for Learning,”1 an education--only package of very high quality OpenType fonts, for 99 USD. Many thanks to Bruce D’Arcus for pointing out the existence of this package, and his enthusiasm and cunning for encouraging me to do something with it. He also pointed me to the work of Achim Blumensath, whose efforts in the LATEX domain sparked my ideas about font installation. Otared Kavian provided an extended mathematics example used in earlier drafts. George Williams and Eddie Kohler provided the actual font wizardry. Obvious thanks to Hans Hagen and Don Knuth for providing such a rich foundation for this modest addition to the TEX and ConTEXt canon. The working assumption throughout this article is that users use ConTEXt with PDFTEX, which can handle the converted forms of each of these fonts. The support files (typescripts and sample encodings) are available at the author’s web site.2 OpenType in ConTEXt NAJAAR 2004 53

Font installation using FontForge The first issue to deal with is getting the fonts to be installed into the TeX tree. Early on, I decided that I should try to use TEXFONT, because it was clearly a ConTEXt-- friendly tool, it had excellent globbing support (e.g., for converting and installing an entire directory of fonts at once), and, frankly, because I was slightly more familiar with it than other tools. It was pointed out that FontForge3, by George Williams, was a powerful, freely--available, open--source, cross--platform tool that handled OpenType fonts as well as any other. This first font installation method therefore depends on a working installation of FontForge. I extended TEXFONT to include an optional pre-processing step that converts an OpenType font to a .pfb and .afm pair. From there, TEXFONT could work its usual magic. The first option of interest to someone installing OpenType fonts is –preproc. This command--line switch triggers a run of FontForge for each otf found in the current directory. For example, if you wanted to install the Cronos Pro OpenType fonts, go into the directory containing the fonts, and issue the command: texfont --makepath --install --enco=texnansi --preproc --vend=adobe --coll=CronosPro If you prefer to work with batch files in TEXFONT, the following line should be a good place to start: --=? --ve=adobe --co=CronosPro --so=auto --pre In order to support at least some of the many extended characters in a “Pro” font, an- other command--line option was added to TEXFONT, –variant=blah (abbreviated as –va=), which allows one .enc file to masquerade as another. For example, if I am working with the texnansi encoding, I can create a variant encoding that substi- tutes small caps for the lowercase letters. I name that encoding texnansiSC.enc, put it in a place where it can be found (like fonts/enc/dvips/context under TDS 1.1), and run: texfont --en=texnansi --va=SC --pre --ve=adobe --co=CronosPro The –variant option appends the variant’s name (SC, here) to the end of the name of the encoding (texnansi), and looks for that particular .enc file on the path. One variant, texnansiOSFSC.enc, is included in the support files as a starter. It was the only variant I personally needed for initial support of my own fonts, but you’re welcome to create (and share!) your own. It is worth noting that there is nothing about the –variant option that is intrinsic to OpenType fonts. If you are working with any sort of font with extended glyphs (such as Caps), you can create a font that accesses those extended glyphs (while masquerading as a known encoding) by using this method. Font installation using LCDF Typetools For those who don’t have the patience to hand--assemble custom encoding variants, a more palatable option will be to use the LCDF Typetools4 from Eddie Kohler. These tools have advanced, specialised features with respect to OpenType. The otftotfm tool is very capable of installing fonts by itself, but integration with TEXFONT gives further automation (globbing again) and better integration with ConTEXt. In order to use the LCDF Typetools within TEXFONT, you should add the command-- line option –lcdf. This option alone will install the raw .otf files, which PDFTEX, as of this writing, can use and embed into PDF files, but cannot subset. A more likely option for most users will be to combine –lcdf with –preproc, which converts the .otf files into normal Type1 .pfb files, a more commonly usable format for modern TEX systems. 54 MAPS 31 Adam T. Lindsay

Eddie’s tools’ real strength lies in the ability to activate OpenType features and use all the glyphs in the font to their full potential. These features include non-- standard ligatures, contextual swashes, small caps, number cases and spacing, and historical alternates. The tools accomplish this by creating a custom encoding and by embedding information in the .tfm files it creates.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 € ⁄ ˙ ˝ ˛ fl ff fi ffi ffl 000 00 001 01 002 02 003 03 004 04 005 05 006 06 007 07 010 08 011 09 012 0a 013 0b 014 0c 015 0d 016 0e 017 0f 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ı  ` ´ ˇ ˘ ¯ ˚ ¸ ß æ œ ø Æ Œ Ø 020 10 021 11 022 12 023 13 024 14 025 15 026 16 027 17 030 18 031 19 032 1a 033 1b 034 1c 035 1d 036 1e 037 1f 32 33 34 35 36 37 38 39 40 41 42 43 44 hyph 45 46 47 ! " # $ % & ’ ( ) * + , - . / 040 20 041 21 042 22 043 23 044 24 045 25 046 26 047 27 050 28 051 29 052 2a 053 2b 054 2c 055 2d 056 2e 057 2f 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 060 30 061 31 062 32 063 33 064 34 065 35 066 36 067 37 070 38 071 39 072 3a 073 3b 074 3c 075 3d 076 3e 077 3f 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 @ A B C D E F G H I J K L M N O 100 40 101 41 102 42 103 43 104 44 105 45 106 46 107 47 110 48 111 49 112 4a 113 4b 114 4c 115 4d 116 4e 117 4f 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 P Q R S T U V W X Y Z [ \ ] ˆ _ 120 50 121 51 122 52 123 53 124 54 125 55 126 56 127 57 130 58 131 59 132 5a 133 5b 134 5c 135 5d 136 5e 137 5f 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 ‘ a b c d e f g h i j k l m n o 140 60 141 61 142 62 143 63 144 64 145 65 146 66 147 67 150 68 151 69 152 6a 153 6b 154 6c 155 6d 156 6e 157 6f 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 p q r s t u v w x y z { | } ˜ ¨ 160 70 161 71 162 72 163 73 164 74 165 75 166 76 167 77 170 78 171 79 172 7a 173 7b 174 7c 175 7d 176 7e 177 7f 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 Ł ' ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ^ − 200 80 201 81 202 82 203 83 204 84 205 85 206 86 207 87 210 88 211 89 212 8a 213 8b 214 8c 215 8d 216 8e 217 8f 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 ł ‘ ’ “ ” • – — ˜ ™ š › œ ž ~ Ÿ 220 90 221 91 222 92 223 93 224 94 225 95 226 96 227 97 230 98 231 99 232 9a 233 9b 234 9c 235 9d 236 9e 237 9f 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ 240 a0 241 a1 242 a2 243 a3 244 a4 245 a5 246 a6 247 a7 250 a8 251 a9 252 aa 253 ab 254 ac 255 ad 256 ae 257 af 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ 260 b0 261 b1 262 b2 263 b3 264 b4 265 b5 266 b6 267 b7 270 b8 271 b9 272 ba 273 bb 274 bc 275 bd 276 be 277 bf 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï 300 c0 301 c1 302 c2 303 c3 304 c4 305 c5 306 c6 307 c7 310 c8 311 c9 312 ca 313 cb 314 cc 315 cd 316 ce 317 cf 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß 320 d0 321 d1 322 d2 323 d3 324 d4 325 d5 326 d6 327 d7 330 d8 331 d9 332 da 333 db 334 dc 335 dd 336 de 337 df 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 à á â ã ä å æ ç è é ê ë ì í î ï 340 e0 341 e1 342 e2 343 e3 344 e4 345 e5 346 e6 347 e7 350 e8 351 e9 352 ea 353 eb 354 ec 355 ed 356 ee 357 ef 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ 360 f0 361 f1 362 f2 363 f3 364 f4 365 f5 366 f6 367 f7 370 f8 371 f9 372 fa 373 fb 374 fc 375 fd 376 fe 377 ff name: texnansi-WarnockPro-Regular at 12.0pt encoding: default mapping: default handling: default Figure 2 WarnockPro-Regular in the normal tex’n’ansi encoding ATEXFONT user needs to be aware of two main things when using TEXFONT with LCDF Typetools. The –variant command--line option is re-interpreted as a means to pass four--letter OpenType features. For example, the command--line option of –va=liga,kern,onum,pnum passes the options of ligatures, , old--style nu- merals, and proportionally--spaced numerals to the LCDF Typetools. The resultant .tfm files will be named: baseencoding-LIGA-KERN-ONUM-PNUM-fontname.tfm, OpenType in ConTEXt NAJAAR 2004 55

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    ⁄ ˙ ˝ ˛ fl ff fi ffi ffl 000 00 001 01 002 02 003 03 004 04 005 05 006 06 007 07 010 08 011 09 012 0a 013 0b 014 0c 015 0d 016 0e 017 0f 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ı  ` ´ ˇ ˘ ¯ ˚ ¸ ß æ œ ø Æ Œ Ø 020 10 021 11 022 12 023 13 024 14 025 15 026 16 027 17 030 18 031 19 032 1a 033 1b 034 1c 035 1d 036 1e 037 1f 32 33 34 35 36 37 38 39 40 41 42 43 44 hyph 45 46 47 ! "    & ’ ( ) * + , - . / 040 20 041 21 042 22 043 23 044 24 045 25 046 26 047 27 050 28 051 29 052 2a 053 2b 054 2c 055 2d 056 2e 057 2f 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63           : ; < = > ? 060 30 061 31 062 32 063 33 064 34 065 35 066 36 067 37 070 38 071 39 072 3a 073 3b 074 3c 075 3d 076 3e 077 3f 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 @ A B C D E F G H I J K L M N O 100 40 101 41 102 42 103 43 104 44 105 45 106 46 107 47 110 48 111 49 112 4a 113 4b 114 4c 115 4d 116 4e 117 4f 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 P Q R S T U V W X Y Z [ \ ] ˆ _ 120 50 121 51 122 52 123 53 124 54 125 55 126 56 127 57 130 58 131 59 132 5a 133 5b 134 5c 135 5d 136 5e 137 5f 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 ‘ a b c d e f g h i j k l m n o 140 60 141 61 142 62 143 63 144 64 145 65 146 66 147 67 150 68 151 69 152 6a 153 6b 154 6c 155 6d 156 6e 157 6f 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 p q r s t u v w x y z { | } ˜ ¨ 160 70 161 71 162 72 163 73 164 74 165 75 166 76 167 77 170 78 171 79 172 7a 173 7b 174 7c 175 7d 176 7e 177 7f 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 Ł ' ‚  „ … † ‡ ˆ  Š ‹ Œ Ž ^ − 200 80 201 81 202 82 203 83 204 84 205 85 206 86 207 87 210 88 211 89 212 8a 213 8b 214 8c 215 8d 216 8e 217 8f 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 ł ‘ ’ “ ” • – — ˜ ™ š › œ ž ~ Ÿ 220 90 221 91 222 92 223 93 224 94 225 95 226 96 227 97 230 98 231 99 232 9a 233 9b 234 9c 235 9d 236 9e 237 9f 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 ¡   ¤  ¦ § ¨ © ª « ¬ ­ ® ¯ 240 a0 241 a1 242 a2 243 a3 244 a4 245 a5 246 a6 247 a7 250 a8 251 a9 252 aa 253 ab 254 ac 255 ad 256 ae 257 af 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ 260 b0 261 b1 262 b2 263 b3 264 b4 265 b5 266 b6 267 b7 270 b8 271 b9 272 ba 273 bb 274 bc 275 bd 276 be 277 bf 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï 300 c0 301 c1 302 c2 303 c3 304 c4 305 c5 306 c6 307 c7 310 c8 311 c9 312 ca 313 cb 314 cc 315 cd 316 ce 317 cf 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß 320 d0 321 d1 322 d2 323 d3 324 d4 325 d5 326 d6 327 d7 330 d8 331 d9 332 da 333 db 334 dc 335 dd 336 de 337 df 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 à á â ã ä å æ ç è é ê ë ì í î ï 340 e0 341 e1 342 e2 343 e3 344 e4 345 e5 346 e6 347 e7 350 e8 351 e9 352 ea 353 eb 354 ec 355 ed 356 ee 357 ef 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ 360 f0 361 f1 362 f2 363 f3 364 f4 365 f5 366 f6 367 f7 370 f8 371 f9 372 fa 373 fb 374 fc 375 fd 376 fe 377 ff name: texnansi-LIGA-KERN-SALT-ONUM-WarnockPro-Regular at 12.0pt encoding: default mapping: default handling: default Figure 3 WarnockPro-Regular in the tex’n’ansi encoding, modified with the LIGAture, KERNing, Stylistic ALTernates, and Oldstyle NUMerals features. Note that not only are ligatures inserted into blank slots in the encoding, but the numerals and some letters (like the ‘k’, ‘v’, and ‘y’) are substituted with alternate forms. and the produced .map file will be named: baseencoding-LIGA-KERN-ONUM-PNUM- vendor-collection.map. The second thing to be aware of is TEX’s limit of 256 glyphs in any font encoding. Many features (including ligatures and especially contextual swashes) require open slots in the base encoding. Although LCDF Typetools is clever in deciding which glyphs should be discarded from an over--full encoding, a user should keep this limitation in mind. 56 MAPS 31 Adam T. Lindsay

Opticals

Most fonts that TEX users are familiar with include only two design axes, namely weight (e.g., light, regular, or bold) and shape (e.g., italic, slanted, or roman)5. Back in the days of metal type, each size of a given font had different design charac- teristics, because the eye is sensitive to different features at different scales. “Opti- cal” fonts essentially add another design axis. This design axis was well--developed in the days of multiple master fonts, but since that technology appears to be dying, premium fonts are now being issued at discrete points along that axis. The font package that was used in the development of these macros and typescripts typical- ly included four optical font sizes for each font: caption, regular, sub--head, and display. Their differences are shown in figure 4. Ag Ag Ag Ag caption display subhead regular Figure 4 The four design sizes of Warnock Pro Opticals, shown at the same size At small design sizes (caption), there is typically lower contrast, a heavier stroke, a slightly larger x-height, and generally courser features. At large design sizes (dis- play), strokes, tapers, serifs, and other details are much more refined. This package supports these various design sizes with a series of extensive type- scripts. It’s essentially a brute--force method that defines font synonyms for each design size for each variant. That is, support for opticals is achieved by using a type- script that has small, regular, large, and extra--large fonts named for each of roman, italic, bold, and bold italic font variants, and adapting the \tfa–\tfd switching for each body font size. For example, there are font synonyms declared for each of the following: - Caption, Serif, SerifSubhead, SerifDisplay, SerifItalicCaption, SerifItalic, SerifItalic- Subhead, SerifItalicDisplay, and so on... . Each of these symbolic names is tied to font commands through the definition of a very large “Opticals” typescript, which generically associates a type variation and a type size with a design size. An extract follows: \starttypescript [serif] [Opticals] [size] \definebodyfont [12pt,11pt][rm] [tf=Serif sa 1, tfa=SerifSubhead sa \magfactor1, tfb=SerifSubhead sa \magfactor2, tfc=SerifSubhead sa \magfactor3, tfd=SerifDisplay sa \magfactor4, it=SerifItalic sa 1, ita=SerifItalicSubhead sa \magfactor1, itb=SerifItalicSubhead sa \magfactor2, itc=SerifItalicSubhead sa \magfactor3, itd=SerifItalicDisplay sa \magfactor4, ...] \stoptypescript OpenType in ConTEXt NAJAAR 2004 57

As the bodyfont size changes (12pt,11pt, above), the relationships between the opticals change. This is handled in a huge typescript. In order to use this typescript yourself, you should define each of the SerifCaption ... SerifItalicDisplay synonyms in your own typescript, and include that with the Opticals typescript. For example, I defined the various opticals for the Warnock font in a typescript called WarnockProSiz. I first created a typescript that associated the optical sizes with the actual font names as installed by TEXFONT: \starttypescript [serif] [WarnockProSiz] [texnansi] \definefontsynonym[SerifCaption][texnansi-WarnockPro-Capt] [encoding=texnansi,handling=pure] \definefontsynonym[SerifText][texnansi-WarnockPro-Regular] [encoding=texnansi,handling=pure] \definefontsynonym[SerifSubhead][texnansi-WarnockPro-Subh] [encoding=texnansi,handling=pure] \definefontsynonym[SerifDisplay][texnansi-WarnockPro-Disp] [encoding=texnansi,handling=pure] ... \stoptypescript I then created a Warnock to tie my size synonyms with the Opticals type- script: \starttypescript[Warn] \definetypeface[war][rm][serif][WarnockProSiz][Opticals][encoding=texnansi] \definetypeface[war][rc][romancaps][WarnockProSiz][Opticals][encoding=texnansi] \stoptypescript If SerifDisplay you can SerifSubhead read all of this SerifSubhead without squinting at all, SerifSubhead you have better eyesight than Serif

I do. In fact, these fonts can get quite Serif

small without losing all that much legibility! SerifCaption Figure 5 The \tfd... \tfxx series with a base size of 12pt. Small Caps Current support for small caps, both inside and outside TEX, is generally very primi- tive. Most fonts – if they do offer it – only offer small caps support as a variation on the plain, roman font, and not for any italic/slanted fonts or bold fonts. This means that the small caps shape is of limited use with non--normal font alternatives (what ConTEXt calls \it and \bf). With a full complement of small caps shapes for each font alternative, small caps can be used more extensively. The approach chosen for this package was to create another serif font style to exist inside the serif family, alongside the familiar roman (rm) style. The new font family, roman caps (rc) defines parallel font alternatives, using small caps variants. This means more work in terms of defining font synonyms, but it enables the small caps shape as a full design axis. The definitions begin as follows: 58 MAPS 31 Adam T. Lindsay

\definebodyfont [12pt,11pt][rc] [tf=SerifCaps sa 1, tfa=SerifCapsSubhead sa \magfactor1, ...] ... and proceeds as the other definitions, above. There are sans serif equivalents defined, as well. The sans small caps family (cs, caps sans) is treated the same way. If you have installed a small caps type variant for a sans serif font, you should define and use this parallel family. In order to use these font families, you may call them directly with macros like  {\rc\bf this}. This is inconvenient, and requires you to recall the font alter- Figure 6 \rc\bf this native as well as the roman caps font style. To alleviate the inconvenience, the support files for this article define a new font command, which switches from the normal style to the caps style while keeping the current alternative. The command is \SmCap, and it is used grouped, like other font commands. The following text in the margin is achieved with the code: text   text rm it {\it text {\SmCap text \ text} text \fontstyle\ \fontalternative} text   text rm bf {\bf text {\SmCap text \em text} text \fontstyle\ \fontalternative}       {\rc text {\SmCap text \em text} text \fontstyle\ \fontalternative} There is an identical command \OldStyle, which assumes that there are old style figures defined in the small caps family. It works in the same way as the above: 0123456789  {\tf 0123456789 \OldStyle 0123456789}\crlf {\bi 0123456789 \OldStyle 0123456789}\crlf 0123456789  {\itx 0123456789 \OldStyle 0123456789}\crlf 0123456789 

Known issues The sheer number of fonts defined means that these typescripts are extremely mem- ory--intensive. A modern computer should not struggle, as long as the font memory allocated to ConTEXt is sufficient. The default compound that is used in composed words is a hybrid char- well--hung acter that doesn’t work well in some pro fonts, including Warnock. I think it is best to replace the default compound character with a stretched hyphen with the hang-dog command: Figure 7 ConTEXt’s de- \def\compoundhyphen{\scale[sx=1.5]{-} fault compound hyphen vs. a stretched hyphen. Math support is preliminary and still considered a work--in--progress, but it certainly seems possible to fashion a math font from sufficiently complete (e.g., containing Greek language support) fonts. Footnotes

1. see http://www.adobe.com/education/ed_products/typeclassics.html 2. see http://homepage.mac.com/atl/tex/ 3. née PfaEdit, see http://fontforge.sourceforge.net/ 4. Available from http://www.lcdf.org/type/ 5. Yes, it’s true that the ubiquitous ComputerModern has many design sizes.

Adam T. Lindsay Lancaster University UK [email protected]