{"id":2693,"date":"2013-03-30T15:03:03","date_gmt":"2013-03-30T15:03:03","guid":{"rendered":"http:\/\/www.readytext.co.uk\/?p=2693"},"modified":"2014-02-08T13:07:37","modified_gmt":"2014-02-08T13:07:37","slug":"type-42-postscript-fonts-with-dvips-freetype-lcdf-typetools-and-re-encoding","status":"publish","type":"post","link":"https:\/\/www.readytext.co.uk\/?p=2693","title":{"rendered":"Type 42 PostScript fonts with DVIPS: FreeType, LCDF Typetools and re-encoding"},"content":{"rendered":"<h1>Summary<\/h1>\n<p>This is a lengthy post which covers numerous topics on using fonts with TeX and DVIPS. It was fun to write and program but it certainly absorbed many hours of my evenings and weekends. In some areas I&#8217;ve had to omit some finer details because it would make the article way too long and I&#8217;d probably run out of steam and never finish it: think of it as a &#8220;getting started&#8221; tutorial. I hope it is useful and interesting. Now to get on with some of those household tasks I&#8217;ve put off whilst writing this &ndash; and thanks to my partner, Alison Tovey, who has waited patiently (well, almost :-)) whilst I was glued to WordPress!<\/p>\n<h1>Introduction<\/h1>\n<p>Modern TeX(-based) engines, such as XeTeX and LuaTeX, provide direct access to using OpenType fonts, albeit using different philosophies\/methods. This post looks at just one way to use TrueType-flavoured OpenType fonts with the traditional TeX&ndash;DVIPS&ndash;PostScript&ndash;PDF workflow which is usually associated with the 8-bit world of Type 1 PostScript fonts. The idea is that we&#8217;ll convert TrueType-flavoured OpenType fonts to Type 42 PostScript fonts and include the Type 42 font data into DVIPS&#8217;s PostScript output stream using the <code>DVIPS -h filename<\/code> mechanism. In addition, we&#8217;ll look at using font encoding and the creation of TeX Font Metrics to enable access to the rich set of glyphs in a modern TrueType-flavour OpenType font.<\/p>\n<p>Many Truetype-flavoured OpenType fonts (and thus the resulting Type 42 PostScript font) contain hundreds, if not <em>thousands<\/em>, of glyphs &ndash; making the 8-bit world of the traditional PostScript Encoding Vector little more than a tiny window into the rich array of available glyphs. By re-encoding the base Type 42 font we can generate a range of 256-character fonts for TeX and DVIPS to exploit the full range of glyphs in the original TrueType font &ndash; such as a true small caps font if the TrueType font has them.<\/p>\n<p>We will also need to create the TeX Font Metrics (TFMs) so that TeX can access the metric data describing our fonts &ndash; the width, height, depth plus any kerning and linatures we care to add. Of course, the virtual font mechanism is also a valid approach &ndash; see <a href=\"http:\/\/tug.org\/TUGboat\/tb11-1\/tb27knut.pdf\">Virtual Fonts: More Fun for Grand Wizards<\/a> for more details. Much of what we&#8217;re doing here uses a number of freely available software tools to extract key data from the actual OpenType font files for onward processing into a form suitable for TeX.<\/p>\n<h2>Context of these experiments<\/h2>\n<p>Over the past few weeks I&#8217;ve spent some evenings and weekends building TeX and friends from WEB source code, using Microsoft&#8217;s Visual Studio. At the moment, this all resides in a large Visual Studio project containing all the various applications and is a little &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/W._Heath_Robinson\">Heath Robinson<\/a>&#8221; at the moment, although it does work. Within each of my builds of TeX and friends I&#8217;ve replaced the venerable Kpathsea path\/file-searching library with my one of own creation &ndash; which does a direct search using recursive directory traversal. I&#8217;m also toying with using database-lookup approach, hence the appearance of SQLite in the list of C libries within the screenshot.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/readytext.co.uk\/files\/web2c.png\" width=\"100%\"\/><\/p>\n<p>Turning to Eddie Kohler&#8217;s marvellous <a href=\"http:\/\/www.lcdf.org\/type\/\">LCDF Typetools collection<\/a>, I used MinGW\/MSYS to build this. LCDF Typetools contains some incredibly useful tools for working with fonts via TeX\/DVIPS &ndash; including <code>ttftotype42<\/code> which can generate a <a href=\"http:\/\/wwwimages.adobe.com\/www.adobe.com\/content\/dam\/Adobe\/en\/devnet\/font\/pdfs\/5012.Type42_Spec.pdf\">Type 42 PostScript font<\/a> from TrueType-flavoured OpenType fonts. You can think of a Type 42 font as a PostScript &#8220;wrapper&#8221; around the native TrueType font data, allowing you to insert TrueType fonts into PostScript code.<\/p>\n<h1>Characters, glyphs, glyph names, encodings and glyph IDs<\/h1>\n<p>Firstly, we need to review several interrelated topics: characters, glyphs, glyph names, encodings and glyph IDs (contained in OpenType fonts). Let&#8217;s begin by thinking about characters. A <em>character<\/em> can be considered as the fundamental building block of a language: it is, if you  like, an &#8220;atomic unit of communication&#8221; (spoken or not) which has a defined role and purpose: the character&#8217;s <em>meaning<\/em> (semantics). Most characters usually need some form visual representation; however, that visual representation may not be fixed: most characters of a human spoken\/written language can be represented in different forms. For example, the character &#8216;capital H&#8217; (H) can take on different visual appearances depending on the font you use to display it. Fonts come in different designs and each design of our &#8216;capital H&#8217; is called a <em>glyph<\/em>: a specific visual design which is particular to the font used to represent the &#8216;capital H&#8217;. Each character that a font is capable of displaying will have a glyph designed to to represent it &ndash; not only that but you may have a fancy font that contains multiple representations for a particular character: small caps, italic, bold and so forth. Each of these variants uses a different glyph to represent the same character: they still represent the same fundamental &#8220;unit of meaning&#8221; (a character) just using different visual forms of expression (glyphs).<\/p>\n<p>If we look around us we see, of course, that there are hundreds of languages in our world and if we break these languages down into their core units of expression\/meaning we soon find that many thousands of characters are needed to &#8220;define&#8221; or encompass these languages. So, how do we go about listing these characters and, more to the point, communicating in these languages through e-mails, text files, printed documents and so forth? As humans we refer to characters by a name (e.g., &#8216;capital H&#8217;) but computers, obviously, deal with numbers. To communicate our characters by computer we need a way to allocate an agreed set of numbers to those characters so that we can store or transmit them electronically. And that&#8217;s called the <em>encoding<\/em>. An encoding is simply an agreed set of numbers assigned to an agreed set of characters &ndash; so that we can store those numbers and know that our software will eventually display the correct glyphs to provide visual expression of our characters. To communicate using numbers to represent characters both sides have to agree on the encoding (mapping of numbers to characters) being used. If I save my text file (a bunch of numbers) and you open it up then your software must interpret those numbers in the same way I did when I wrote the text. Clearly, it&#8217;s essential for encoding standards to exist and perhaps the most well known is, of course, the Unicode standard which allocates a unique number to well over 100,000 characters (at present), with new characters being added from time-to-time as the Uniciode standard is updated.<\/p>\n<p>Let&#8217;s take closer at fonts. We&#8217;ve seen that the job of a font is to provide the glyphs which represent a certain set of characters. Naturally, any particular font will only contain glyphs to represent a small subset of the world&#8217;s characters: there are just too many for any single font to contain them all. We&#8217;ve also said that some fonts may contain multiple glyphs to represent the same character. Considering OpenType fonts for the moment, within each font the individual glyphs (designs representing a specific chartacter) are each given a <em>name<\/em> and a numeric identifier, called  the <em>glyph identifier<\/em> (also called the index or glyph ID). Each glyph is thus described by a (name, glyph ID) pair. It&#8217;s really important to realise that the glyph ID has <em><strong>nothing<\/strong> to do with encoding of characters<\/em>: it is just an internal bookkeeping number used within the font and assigned to each glyph by the font&#8217;s creator. The numeric IDs assigned to a particular glyph are not defined by a global standard. Furthermore, the names given to glyphs also show a great deal of variation too, although there are some attempts at standardizing them: see the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Adobe_Glyph_List\">Adobe Glyph List<\/a> which aims to provide a standard naming convention.<\/p>\n<p>Let&#8217;s recap. We&#8217;ve seen that the fundamental &#8220;unit of communication&#8221; is the character and that characters are <em>encoded<\/em> by assigning each one to a number. We&#8217;ve also seen that fonts contain the designs, called <em>glyphs<\/em>, which represent the characters supported by the font. Internally, each (OpenType) font assigns every glyph an <em>identifier<\/em> (glyph ID) and a <em>glyph name<\/em> which may, or may not, be &#8220;standard&#8221;.<\/p>\n<p>So, the next question we need to think about is: given a text file containing characters represented (stored) according to a specific encoding (a set of numbers), how does any font actually know how to map from a certain character in the text file to the correct glyph to represent it? After all, the encoding in the text file is usually based on a standard but the data in our font, glyph IDs and glyph names, are not standard? Well, not surprisingly there is indeed some extra bit of data inside the font which provides the glue and this is called the <em>Encoding Vector<\/em> (in older PostScript fonts) or character map (CMAP) table within the modern world of Unicode and OpenType fonts. The job of the Encoding Vector (or character map (CMAP)) is to provide the link between the standard world of encoded characters to the (relatively) non-standard inner font world of glyph IDs and glyph names.<\/p>\n<p><h1>A sneak peek at GentiumPlus-R: 5586 glyphs in a single font<\/h1>\n<p>For the remainder of this post I&#8217;ll use the free <a href=\"http:\/\/scripts.sil.org\/cms\/scripts\/page.php?item_id=Gentium_download#801ab246\">Gentium OpenType font<\/a> (GentiumPlus-R) as an example because I do not want to  inadvertantly infringe any commercial licence conditions in the work below. To help solidify the ideas described above I generated a table of all the glyphs (plus glyph ID and glyph name) contained within the GentiumPlus-R TrueType-flavour OpenType font.<\/p>\n<h2>GentiumPlus-R glyph chart<\/h2>\n<blockquote><p><strong>Technical details:<\/strong> To generate these glyph tables I wrote a command-line utility (in C) which used the FreeType library to extract the low-level data from inside the OpenType font. This data was written out as a PostScript program which loops over all the glyphs: drawing each glyph together with its glyph ID and name. This PostScript program was combined with the GentiumPlus (TrueType) font after converting it to a Type 42 PostScript font using <code>ttftotype42<\/code> compiled from the source code distributed as part of the wonderful <a href=\"http:\/\/www.lcdf.org\/type\/\">LCDF Typetools collection<\/a>.\n<\/p><\/blockquote>\n<p><a href=\"http:\/\/readytext.co.uk\/files\/gentium.pdf\">Download PDF<\/a><\/p>\n<p><iframe src=\"https:\/\/docs.google.com\/gview?url=http:\/\/readytext.co.uk\/files\/gentium.pdf&#038;embedded=true\" style=\"width:100%; height:600px;\" frameborder=\"0\"><\/iframe><\/p>\n<h1>PostScript Encoding Vectors<\/h1>\n<p>Let&#8217;s recap on our objectives. We&#8217;ve explored the idea of glyphs, characters and encodings and seen that OpenType fonts can contain many thousands of glyphs to display thousands of characters. However, OpenType fonts can&#8217;t easily be used within the <em>traditional <\/em> TeX&ndash;DVIPS&ndash;PostScriptS&ndash;PDF workflow: most traditional TeX workflows use 8-bit characters and Type 1 PostScript fonts. As yet, we&#8217;ve still not explained exctly how a character code is &#8220;mapped&#8221; to a specific glyph in a font. So, it&#8217;s time to look at this, focussing on Type 1 and Type 42 PostScript fonts, ignoring OpenType fonts. The &#8220;magic glue&#8221; we need to explore is the so-called <em>Encoding Vector<\/em> present in Type 1 and Type 42 fonts. The job of the Encoding Vector is to map from character codes in the input to glyphs contained in the font. Let&#8217;s look at an example to make this clearer. I&#8217;ll assume that you have access to the <code>ttftotype42<\/code> utility from the <a href=\"http:\/\/www.lcdf.org\/type\/\">LCDF Typetools collection<\/a>. If you don&#8217;t have it, or can&#8217;t compile it, contact me and I&#8217;ll e-mail my compiled version to you.<\/p>\n<h2>Using <code>ttftotype42<\/code><\/h2>\n<p>If you run <code>ttftotype42<\/code> on a TrueType-flavour OpenType font it will generate a fairly large plain text file which you can inspect with any text editor, so let&#8217;s do that. In these examples I&#8217;ll use the free <a href=\"http:\/\/scripts.sil.org\/cms\/scripts\/page.php?item_id=Gentium_download#801ab246\">Gentium OpenType font<\/a>.<\/p>\n<p>If you download GentiumPlus and place the GentiumPlus-R.ttf file in the same directory as <code>ttftotype42<\/code> and run<\/p>\n<p><code>ttftotype42 GentiumPlus-R.ttf GentiumPlus.t42<\/code><\/p>\n<p>you should generate a file <code>GentiumPlus.t42<\/code> which is a little over 2MB in size &ndash;  remember, the GentiumPlus font contains over 5,500 glyphs! Loosely speaking you can think of the Type 42 font generated by <code>ttftotype42<\/code> as being made up from the following sections:<\/p>\n<ul>\n<li>PostScript header<\/li>\n<li>Encoding Vector<\/li>\n<li>\/sfnts glyph data array<\/li>\n<li>\/CharStrings dictionary<\/li>\n<li>PostScript trailer<\/li>\n<\/ul>\n<blockquote><p><strong>Download <code>GentiumPlus.t42<\/code><\/strong>: I uploaded the Type 42 font file <code>GentiumPlus.t42<\/code> created by <code>ttftotype42<\/code> onto this site: you can <a href=\"https:\/\/www.readytext.co.uk\/files\/GentiumPlus.zip\">download it here<\/a>. <\/p>\n<\/blockquote>\n<p>Here&#8217;s an extract from the Type 42 font version of GentiumPlus-R.ttf with vast amouts of data snipped out for brevity:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n%!PS-TrueTypeFont-65536-98828-1\r\n%%VMusage: 0 0\r\n11 dict begin\r\n\/FontName \/GentiumPlus def\r\n\/FontType 42 def\r\n\/FontMatrix &#x5B;1 0 0 1 0 0] def\r\n\/FontBBox &#x5B;-0.676758 -0.463867 1.49951 1.26953] readonly def\r\n\/PaintType 0 def\r\n\/XUID &#x5B;42 16#30C4BB 16#E5CA1A 16#75CC0A 16#BE5D07 16#47E1FB 16#4C] def\r\n\/FontInfo 10 dict dup begin\r\n\/version (Version 1.510) readonly def\r\n\/Notice (Gentium is a trademark of SIL International.) readonly def\r\n\/Copyright (Copyright \\(c\\) 2003-2012, SIL International \\(http:\/\/scripts.sil.org\/\\)) readonly def\r\n\/FullName (Gentium Plus) readonly def\r\n\/FamilyName (Gentium Plus) readonly def\r\n\/Weight (Regular) readonly def\r\n\/isFixedPitch false def\r\n\/ItalicAngle 0 def\r\n\/UnderlinePosition -0.146484 def\r\n\/UnderlineThickness 0.0488281 def\r\nend readonly def\r\n\/Encoding 256 array\r\n0 1 255{1 index exch\/.notdef put}for\r\ndup 13 \/nonmarkingreturn put\r\ndup 32 \/space put\r\ndup 33 \/exclam put\r\ndup 34 \/quotedbl put\r\ndup 35 \/numbersign put\r\ndup 36 \/dollar put\r\ndup 37 \/percent put\r\ndup 38 \/ampersand put\r\n...\r\n...\r\n-- snipped lots of lines of the encoding vector --\r\n...\r\n...\r\ndup 254 \/thorn put\r\ndup 255 \/ydieresis put\r\nreadonly def\r\n\/sfnts&#x5B;\r\n&lt;00010000.......\r\n...\r\n...\r\n-- snipped vast amounts of glyph data --\r\n...\r\n...\r\n] def\r\n\/CharStrings 5586 dict dup begin\r\n\/.notdef 0 def\r\n\/.null 1 def\r\n\/nonmarkingreturn 2 def\r\n\/space 3 def\r\n\/exclam 4 def\r\n\/quotedbl 5 def\r\n\/numbersign 6 def\r\n...\r\n...\r\n-- snipped vast amounts of CharStrings data --\r\n...\r\n...\r\nend readonly def\r\nFontName currentdict end definefont pop\r\n<\/pre>\n<p>The section of interest here is the Encoding Vector which is reproduced in full:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/Encoding 256 array\r\n0 1 255{1 index exch\/.notdef put}for\r\ndup 13 \/nonmarkingreturn put\r\ndup 32 \/space put\r\ndup 33 \/exclam put\r\ndup 34 \/quotedbl put\r\ndup 35 \/numbersign put\r\ndup 36 \/dollar put\r\ndup 37 \/percent put\r\ndup 38 \/ampersand put\r\ndup 39 \/quotesingle put\r\ndup 40 \/parenleft put\r\ndup 41 \/parenright put\r\ndup 42 \/asterisk put\r\ndup 43 \/plus put\r\ndup 44 \/comma put\r\ndup 45 \/hyphen put\r\ndup 46 \/period put\r\ndup 47 \/slash put\r\ndup 48 \/zero put\r\ndup 49 \/one put\r\ndup 50 \/two put\r\ndup 51 \/three put\r\ndup 52 \/four put\r\ndup 53 \/five put\r\ndup 54 \/six put\r\ndup 55 \/seven put\r\ndup 56 \/eight put\r\ndup 57 \/nine put\r\ndup 58 \/colon put\r\ndup 59 \/semicolon put\r\ndup 60 \/less put\r\ndup 61 \/equal put\r\ndup 62 \/greater put\r\ndup 63 \/question put\r\ndup 64 \/at put\r\ndup 65 \/A put\r\ndup 66 \/B put\r\ndup 67 \/C put\r\ndup 68 \/D put\r\ndup 69 \/E put\r\ndup 70 \/F put\r\ndup 71 \/G put\r\ndup 72 \/H put\r\ndup 73 \/I put\r\ndup 74 \/J put\r\ndup 75 \/K put\r\ndup 76 \/L put\r\ndup 77 \/M put\r\ndup 78 \/N put\r\ndup 79 \/O put\r\ndup 80 \/P put\r\ndup 81 \/Q put\r\ndup 82 \/R put\r\ndup 83 \/S put\r\ndup 84 \/T put\r\ndup 85 \/U put\r\ndup 86 \/V put\r\ndup 87 \/W put\r\ndup 88 \/X put\r\ndup 89 \/Y put\r\ndup 90 \/Z put\r\ndup 91 \/bracketleft put\r\ndup 92 \/backslash put\r\ndup 93 \/bracketright put\r\ndup 94 \/asciicircum put\r\ndup 95 \/underscore put\r\ndup 96 \/grave put\r\ndup 97 \/a put\r\ndup 98 \/b put\r\ndup 99 \/c put\r\ndup 100 \/d put\r\ndup 101 \/e put\r\ndup 102 \/f put\r\ndup 103 \/g put\r\ndup 104 \/h put\r\ndup 105 \/i put\r\ndup 106 \/j put\r\ndup 107 \/k put\r\ndup 108 \/l put\r\ndup 109 \/m put\r\ndup 110 \/n put\r\ndup 111 \/o put\r\ndup 112 \/p put\r\ndup 113 \/q put\r\ndup 114 \/r put\r\ndup 115 \/s put\r\ndup 116 \/t put\r\ndup 117 \/u put\r\ndup 118 \/v put\r\ndup 119 \/w put\r\ndup 120 \/x put\r\ndup 121 \/y put\r\ndup 122 \/z put\r\ndup 123 \/braceleft put\r\ndup 124 \/bar put\r\ndup 125 \/braceright put\r\ndup 126 \/asciitilde put\r\ndup 160 \/uni00A0 put\r\ndup 161 \/exclamdown put\r\ndup 162 \/cent put\r\ndup 163 \/sterling put\r\ndup 164 \/currency put\r\ndup 165 \/yen put\r\ndup 166 \/brokenbar put\r\ndup 167 \/section put\r\ndup 168 \/dieresis put\r\ndup 169 \/copyright put\r\ndup 170 \/ordfeminine put\r\ndup 171 \/guillemotleft put\r\ndup 172 \/logicalnot put\r\ndup 173 \/uni00AD put\r\ndup 174 \/registered put\r\ndup 175 \/macron put\r\ndup 176 \/degree put\r\ndup 177 \/plusminus put\r\ndup 178 \/twosuperior put\r\ndup 179 \/threesuperior put\r\ndup 180 \/acute put\r\ndup 181 \/mu put\r\ndup 182 \/paragraph put\r\ndup 183 \/periodcentered put\r\ndup 184 \/cedilla put\r\ndup 185 \/onesuperior put\r\ndup 186 \/ordmasculine put\r\ndup 187 \/guillemotright put\r\ndup 188 \/onequarter put\r\ndup 189 \/onehalf put\r\ndup 190 \/threequarters put\r\ndup 191 \/questiondown put\r\ndup 192 \/Agrave put\r\ndup 193 \/Aacute put\r\ndup 194 \/Acircumflex put\r\ndup 195 \/Atilde put\r\ndup 196 \/Adieresis put\r\ndup 197 \/Aring put\r\ndup 198 \/AE put\r\ndup 199 \/Ccedilla put\r\ndup 200 \/Egrave put\r\ndup 201 \/Eacute put\r\ndup 202 \/Ecircumflex put\r\ndup 203 \/Edieresis put\r\ndup 204 \/Igrave put\r\ndup 205 \/Iacute put\r\ndup 206 \/Icircumflex put\r\ndup 207 \/Idieresis put\r\ndup 208 \/Eth put\r\ndup 209 \/Ntilde put\r\ndup 210 \/Ograve put\r\ndup 211 \/Oacute put\r\ndup 212 \/Ocircumflex put\r\ndup 213 \/Otilde put\r\ndup 214 \/Odieresis put\r\ndup 215 \/multiply put\r\ndup 216 \/Oslash put\r\ndup 217 \/Ugrave put\r\ndup 218 \/Uacute put\r\ndup 219 \/Ucircumflex put\r\ndup 220 \/Udieresis put\r\ndup 221 \/Yacute put\r\ndup 222 \/Thorn put\r\ndup 223 \/germandbls put\r\ndup 224 \/agrave put\r\ndup 225 \/aacute put\r\ndup 226 \/acircumflex put\r\ndup 227 \/atilde put\r\ndup 228 \/adieresis put\r\ndup 229 \/aring put\r\ndup 230 \/ae put\r\ndup 231 \/ccedilla put\r\ndup 232 \/egrave put\r\ndup 233 \/eacute put\r\ndup 234 \/ecircumflex put\r\ndup 235 \/edieresis put\r\ndup 236 \/igrave put\r\ndup 237 \/iacute put\r\ndup 238 \/icircumflex put\r\ndup 239 \/idieresis put\r\ndup 240 \/eth put\r\ndup 241 \/ntilde put\r\ndup 242 \/ograve put\r\ndup 243 \/oacute put\r\ndup 244 \/ocircumflex put\r\ndup 245 \/otilde put\r\ndup 246 \/odieresis put\r\ndup 247 \/divide put\r\ndup 248 \/oslash put\r\ndup 249 \/ugrave put\r\ndup 250 \/uacute put\r\ndup 251 \/ucircumflex put\r\ndup 252 \/udieresis put\r\ndup 253 \/yacute put\r\ndup 254 \/thorn put\r\ndup 255 \/ydieresis put\r\nreadonly def\r\n<\/pre>\n<p>The Encoding Vector is an array indexed by a number which runs from 0 to 255 and the value stored at each index position is the <em>name<\/em> of a glyph contained in the font. You have probably guessed that the index (0 to 255) is the numeric value of an input character. So, via the Encoding Vector with 256 potential character values as input, we can reach up to 256 individual glyphs contained in the font. (Note: I&#8217;m ignoring the PostScript <code>glyphshow<\/code> operator which allows access to any glyph if you know its name). <\/p>\n<blockquote><p><strong>The full story (quoting from the <a href=\"http:\/\/www.adobe.com\/devnet\/font\/pdfs\/5012.Type42_Spec.pdf\">Type 42 font specification<\/a>)<\/strong> &#8220;The PostScript interpreter uses the \/Encoding array to look up the character name, which is then used to access the \/Charstrings entry with that name. The value of that entry is the glyph index, which is then used to retrieve the glyph description.&#8221;<\/p><\/blockquote>\n<p>However, there are 5586 glyphs in GentiumPlus so does this mean the remaining 5330 glyphs are wasted and unreachable? Of course that&#8217;s not true but we can only reach 256 glyphs via each individual Encoding Vector: the trick we need is <em>font re-encoding<\/em>. The Encoding Vector is not a fixed entity: you can amend it or replace it entirely with a new one to map character codes 0 to 255 to different glyphs within the font. I won&#8217;t give the full details here, although it&#8217;s quite simple to understand. What you do, in effect, is a bit of PostScript programming to &#8220;clone&#8221; some of the font data structures, give this &#8220;clone&#8221; a new PostScript font name and a new Encoding Vector which maps the 256 character codes to totally different glyphs. For some excellent tutorials on PostScript programming, including font re-encoding, I highly recommend reading the truly excellent <a href=\"http:\/\/www.acumentraining.com\/acumenjournal.html\">Acumen Training Journal<\/a> which is completely free. Specifically, <a href=\"http:\/\/www.acumentraining.com\/Acumen_Journal\/AcumenJournal_Nov2001.zip\">November 2001<\/a> and <a href=\"http:\/\/www.acumentraining.com\/Acumen_Journal\/AcumenJournal_Dec2001.zip\">December 2001<\/a> issues.<\/p>\n<p>If you want a simple example to explore the ideas behind Encoding Vectors you can download <a href=\"https:\/\/www.readytext.co.uk\/files\/encoding.zip\">this code example (with PDF)<\/a> to see the results of re-encoding Times-Roman.<\/p>\n<h1>Hooking this up to TeX and DVIPS<\/h1>\n<p>Having discussed fonts, encoding and glyphs at some length we now move to the next task: how do we use these ideas with TeX and DVIPS? Let&#8217;s start with TeX. Here, I&#8217;m referring to the <em>traditional<\/em> TeX workflows that use TeX Font Metric (TFM) files. So what is a TFM? To do its typesetting work TeX&#8217;s algorithms need only some basic information about the font you want to use: it needs the <em>metrics<\/em>. TeX does not care about the actual glyphs in your font or what they look like, it needs a set of data that describes how big each glyph is: to TeX your glyphs are boxes with a certain width, depth and height. That&#8217;s not the whole story, of course, because TeX also needs some additional data called <code>fontdimen<\/code>s which are a set of additional parameters that describe some overall characteristics of the font. For pure text fonts there are 7 of these <code>fontdimen<\/code>s, for math fonts there are 13 or 22 depending on the type\/role of the math font. These <code>fontdimen<\/code>s are, of course, built into the TFM file.<\/p>\n<h2>Looking inside TFMs<\/h2>\n<p>TFM files are a highly compact binary file format and quite unsuitable for viewing or editing. However, you can convert a TFM file to a readable\/editable text representation using a program called <code>tftopl<\/code>, which is part of most TeX distributions. The editable text version of a TFM is referred to as a <em>property list<\/em> file. At the start of a TFM file for a text font (e.g., <code>cmr10.tfm<\/code>) you should see the 7 <code>fontdimen<\/code>s displayed like this:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(FONTDIMEN\r\n   (SLANT R 0.0)\r\n   (SPACE R 0.333334)\r\n   (STRETCH R 0.166667)\r\n   (SHRINK R 0.111112)\r\n   (XHEIGHT R 0.430555)\r\n   (QUAD R 1.000003)\r\n   (EXTRASPACE R 0.111112)\r\n   )\r\n<\/pre>\n<p>If you run <code>tftopl<\/code> on <code>cmex10.tfm<\/code> (math font with extensible symbols) you see 13 <code>fontdimen<\/code>s displayed like this:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(FONTDIMEN\r\n   (SLANT R 0.0)\r\n   (SPACE R 0.0)\r\n   (STRETCH R 0.0)\r\n   (SHRINK R 0.0)\r\n   (XHEIGHT R 0.430556)\r\n   (QUAD R 1.0)\r\n   (EXTRASPACE R 0.0)\r\n   (DEFAULTRULETHICKNESS R 0.04)\r\n   (BIGOPSPACING1 R 0.111111)\r\n   (BIGOPSPACING2 R 0.166667)\r\n   (BIGOPSPACING3 R 0.2)\r\n   (BIGOPSPACING4 R 0.6)\r\n   (BIGOPSPACING5 R 0.1)\r\n   )\r\n<\/pre>\n<p>If you run <code>tftopl<\/code> on <code>cmsy10.tfm<\/code> (math symbol font) you see 22 <code>fontdimen<\/code>s displayed like this: <\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(FONTDIMEN\r\n   (SLANT R 0.25)\r\n   (SPACE R 0.0)\r\n   (STRETCH R 0.0)\r\n   (SHRINK R 0.0)\r\n   (XHEIGHT R 0.430555)\r\n   (QUAD R 1.000003)\r\n   (EXTRASPACE R 0.0)\r\n   (NUM1 R 0.676508)\r\n   (NUM2 R 0.393732)\r\n   (NUM3 R 0.443731)\r\n   (DENOM1 R 0.685951)\r\n   (DENOM2 R 0.344841)\r\n   (SUP1 R 0.412892)\r\n   (SUP2 R 0.362892)\r\n   (SUP3 R 0.288889)\r\n   (SUB1 R 0.15)\r\n   (SUB2 R 0.247217)\r\n   (SUPDROP R 0.386108)\r\n   (SUBDROP R 0.05)\r\n   (DELIM1 R 2.389999)\r\n   (DELIM2 R 1.01)\r\n   (AXISHEIGHT R 0.25)\r\n   )\r\n<\/pre>\n<p>The role of these <code>fontdimen<\/code>s within math fonts is extremely complex. If you want to read about this in depth you can find a list of excellent articles <a href=\"https:\/\/www.readytext.co.uk\/?p=2319\">in this post<\/a>. In addition to the glyph metrics (height, width, depth) and <code>fontdimen<\/code>s TFM files contain constructs for kerning and ligatures. There&#8217;s a lot of information already available on the inner details of TFMs so there&#8217;s no point repeating it here.<\/p>\n<p>The bulk of a TFM file is concerned with providing the height, width and depth of the characters encoded into the TFM. And that brings up a very important point: individual TFM files are tied to a particular encoding. For example, right at the start of a <code>cmr10.tfm<\/code> file you should see something like this:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(FAMILY CMR)\r\n(FACE O 352)\r\n(CODINGSCHEME TEX TEXT)\r\n(DESIGNSIZE R 10.0)\r\n(COMMENT DESIGNSIZE IS IN POINTS)\r\n(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)\r\n(CHECKSUM O 11374260171) \r\n<\/pre>\n<p>It contains the line <code>(CODINGSCHEME TEX TEXT)<\/code> telling you that the TFM is encoded using the TeX Text encoding scheme. Let&#8217;s examine this. Referring back to our discussion of PostScript Encoding Vectors, let&#8217;s take a look at the first few lines of the Encoding Vector sitting inside the Type 1 font file for cmr10 &ndash; i.e., <code>cmr10.pfb<\/code>. The first 10 positions are encoded like this:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\ndup 0 \/Gamma put\r\ndup 1 \/Delta put\r\ndup 2 \/Theta put\r\ndup 3 \/Lambda put\r\ndup 4 \/Xi put\r\ndup 5 \/Pi put\r\ndup 6 \/Sigma put\r\ndup 7 \/Upsilon put\r\ndup 8 \/Phi put\r\ndup 9 \/Psi put\r\ndup 10 \/Omega put\r\n<\/pre>\n<p>And this is the key point: the character encoding in your TFM file has to match the encoding of your PostScript font (or a re-encoded version of it). If we look at the metric data for the corresponding characters encoded in the <code>cmr10.tfm<\/code> file we find: <\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(CHARACTER O 0\r\n   (CHARWD R 0.625002)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 1\r\n   (CHARWD R 0.833336)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 2\r\n   (CHARWD R 0.777781)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 3\r\n   (CHARWD R 0.694446)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 4\r\n   (CHARWD R 0.666669)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 5\r\n   (CHARWD R 0.750002)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 6\r\n   (CHARWD R 0.722224)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 7\r\n   (CHARWD R 0.777781)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 10\r\n   (CHARWD R 0.722224)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 11\r\n   (CHARWD R 0.777781)\r\n   (CHARHT R 0.683332)\r\n   )\r\n(CHARACTER O 12\r\n   (CHARWD R 0.722224)\r\n   (CHARHT R 0.683332)\r\n   )\r\n<\/pre>\n<p>Statements such as <code>CHARACTER O 0<\/code> describe the metrics (just width and height in these examples) for the character with octal value 0, <code>CHARACTER O 12<\/code> describes character with octal value 12 (i.e., 10 in denary (base 10)). Note that the values are relative to the <code>(DESIGNSIZE R 10.0)<\/code> which means, for example, that <code>CHARACTER O 12<\/code> has a width of 0.722224 &times; 10 = 7.22224 points &ndash; because the DESIGNSIZE is 10 points. So, it is clearly vital that the encoding of your TFM matches the encoding of your PostScript font otherwise you&#8217;ll get the wrong glyphs on output and the wrong widths, heights and depths used by TeX&#8217;s typesetting calculations!<\/p>\n<h2>Using FreeType to generate raw metric data<\/h2>\n<p><a href=\"http:\/\/www.freetype.org\/\">FreeType<\/a> is a superb C library which provides a rich set of functions to access many internals of a font, together, of course, with functions to rasterize fonts for screen display. Just to note, FreeType does not provide an OpenType shaping engine, for that you&#8217;ll need to use the equally superb <a href=\"http:\/\/savannah.nongnu.org\/files\/?group=m17n\">libotf C library<\/a> (which also uses FreeType). However, I digress. Using FreeType you can create some extremely useful and simple utilities to extract a wide range of data from font files to generate raw data for creating the TFM files and Encoding Vectors you&#8217;ll need to hook-up a Type 42 font to DVIPS and TeX. Let&#8217;s look at this is a little detail. The task at hand is: given an OpenType (TrueType) font, how can do you obtain details of the glyphs it contains: the names and metrics (width, height, depth)?<\/p>\n<h3>FreeType&#8217;s view of glyph metrics<\/h3>\n<p>The FreeType API provides access to the glyph metrics shown in the <a href=\" http:\/\/www.freetype.org\/freetype2\/docs\/glyphs\/glyphs-3.html\">FreeType Glyph Conventions<\/a> documentation. You should read this together with the Adobe&#8217;s <a href=\"http:\/\/partners.adobe.com\/public\/developer\/en\/font\/T1_SPEC.PDF\">Type 1 Font Format Specification<\/a> (Chapter 3) to make sure you understand what is meant by a glyph&#8217;s width.<\/p>\n<h2>Simple examples of using the FreeType API<\/h2>\n<p>Here&#8217;s some ultra-basic examples, without any proper error checking etc, to show how you might use FreeType. You start by initializing the FreeType library (<code>FT_Init_FreeType(...)<\/code>), then create a new face object (<code>FT_New_Face(...)<\/code>) and use this to access the font and glyph details you need. The first example writes metric data to STDOUT, the second example processes the font data to create an Encoding Vectors and a skeleton <em>property list<\/em> file for creating a TFM. Note that is a &#8220;bare bones&#8221; TFM and does not generate any ligatures or kerning data. To generate a binary TFM from a property list file you need another utility called <code>pltotf<\/code> which is also part of most TeX distributions.<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;windows.h&gt;\r\n#include &lt;ft2build.h&gt;\r\n#include &lt;freetype\/t1tables.h&gt;\r\n#include &lt;freetype\/ftoutln.h&gt;\r\n#include &lt;freetype\/ftbbox.h&gt;\r\n#include FT_GLYPH_H\r\n#include FT_FREETYPE_H\r\n\r\nint main (int  ac,  char** av)\r\n{\r\n    FT_Library font_library;\r\n    FT_Face    font_face;\r\n    FT_BBox    bbox;\r\n\r\n    int  glyph_index; \r\n    int  glyph_count;\r\n    char char_name&#x5B;256];\r\n    const char* fontfilepath = &quot;PUT THE PATH TO YOUR FONT HERE&quot;;\r\n    char buf&#x5B;5];\r\n    int err=1;\r\n\r\n   if (FT_Init_FreeType( &amp;font_library ) )\r\n\t{\r\n\t\/\/ Failed to init library, \r\n\t} else\r\n\t{\r\n\t\tif ( FT_New_Face( font_library, fontfilepath, 0 , &amp;font_face ) )\r\n\t\t{\r\n\t\t\t\/\/ Managed to open library but failedto open the font\r\n\t\t\tFT_Done_FreeType(font_library);\r\n\t\t\treturn err;\r\n\t\t}\r\n\t\telse {\t\r\n\t\t\t\/\/ library and font opened OK\r\n\t\t\t\/\/ find out the number of glyphs and process each glyph\r\n\t\t\tglyph_count = font_face-&gt;num_glyphs;\r\n\t\t\tfor ( glyph_index = 0 ; glyph_index &lt; glyph_count; glyph_index++ )\r\n\t\t\t\t{\r\n                                \/\/ NOTE: FT_Get_Glyph_Name can FAIL for some TrueType-flavour\r\n                                \/\/ OpenType fonts so you *really* do need to check the value of err!!\r\n\t\t\t\terr = FT_Get_Glyph_Name(font_face, glyph_index, &amp;char_name&#x5B;0], 32 );\r\n\t\t\t\t_itoa(glyph_index, buf, 10);\r\n\t\t\t\t\/\/ load the glyph with no scaling etc to get raw data\r\n\t\t\t\tFT_Load_Glyph(font_face,  glyph_index,  FT_LOAD_NO_SCALE);\r\n\t\t\t\t\/\/ get the bounding box of the raw glyph data\r\n\t\t\t\tFT_Outline_Get_BBox(&amp;(font_face-&gt;glyph-&gt;outline), &amp;bbox);\r\n\t\t\t\tprintf( &quot;\/%s %ld def &quot;,   char_name, glyph_index);\r\n\t\t\t\tprintf(&quot;width=%ld &quot;, font_face-&gt;glyph-&gt;metrics.width);\r\n\t\t\t\tprintf(&quot;height=%ld &quot;, font_face-&gt;glyph-&gt;metrics.height); \r\n\t\t\t\tprintf(&quot;horiAdvance=%ld &quot;, font_face-&gt;glyph-&gt;metrics.horiAdvance);\r\n\t\t\t\tprintf(&quot;horiBearingX=%ld &quot;, font_face-&gt;glyph-&gt;metrics.horiBearingX); \r\n\t\t\t\tprintf(&quot;horiBearingY=%ld &quot;, font_face-&gt;glyph-&gt;metrics.horiBearingY); \r\n\t\t\t\tprintf(&quot;vertAdvance=%ld &quot;,  font_face-&gt;glyph-&gt;metrics.vertAdvance); \r\n\t\t\t\tprintf(&quot;vertBearingX=%ld &quot;, font_face-&gt;glyph-&gt;metrics.vertBearingX); \r\n\t\t\t\tprintf(&quot;vertBearingY=%ld &quot;, font_face-&gt;glyph-&gt;metrics.vertBearingY);\r\n\t\t\t\tprintf(&quot;xMax=%ld &quot;, bbox.xMax);\r\n\t\t\t\tprintf(&quot;yMax=%ld &quot;, bbox.yMax); \r\n\t\t\t\tprintf(&quot;yMin=%ld &quot;, bbox.yMin); \r\n\t\t\t\tprintf(&quot;xMin=%ld \\n&quot;, bbox.xMin); \r\n\t\t\t}\r\n\t\t}\r\n\t\tFT_Done_FreeType(font_library);\r\n\t}\r\n}\r\n<\/pre>\n<h3>Creating an Encoding Vector and property list file<\/h3>\n<p>The following simple-minded function shows how you might use FreeType to generate an Encoding Vector and property list file. Reflecting the unusual glyphs we&#8217;re using, the output files are called <code>weirdo.pl<\/code> and <code>weirdo.enc<\/code>.<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nvoid makeweirdo(FT_Face font_face, char *name, int len)\r\n{\r\nFILE * vec;\r\nFILE * plist;\r\nint i;\r\nFT_BBox bbox;\r\nint k=32; \/\/ only encode positions 32--255\r\n\r\nchar *fname=&quot;your_path_here\\\\weirdo.enc&quot;;\r\nchar *pname=&quot;your_path_here\\\\weirdo.weirdo.pl&quot;;\r\nchar * header= &quot;(COMMENT Created by Graham Douglas)\\r\\n\\\r\n(FAMILY WEIRDO)\\r\\n\\\r\n(CODINGSCHEME WEIRDO)\\r\\n\\\r\n(DESIGNSIZE R 10.0)\\r\\n\\\r\n(FONTDIMEN\\r\\n\\\r\n   (SLANT R 0.0)\\r\\n\\\r\n   (SPACE R 0.333334)\\r\\n\\\r\n   (STRETCH R 0.166667)\\r\\n\\\r\n   (SHRINK R 0.111112)\\r\\n\\\r\n   (XHEIGHT R 0.430555)\\r\\n\\\r\n   (QUAD R 1.000003)\\r\\n\\\r\n   (EXTRASPACE R 0.111112)\\r\\n\\\r\n   )\\r\\n&quot;;\r\n\tvec = fopen(fname, &quot;wb&quot;);\r\n\tplist = fopen(pname, &quot;wb&quot;);\r\n\r\n\tfprintf(vec,&quot;%s&quot;, &quot;\/veccy 256 array 0 1 255 {1 index exch \/.notdef put} for\\r\\n&quot;);\r\n\tfprintf(plist,&quot;%s&quot;, header);\r\n\r\n\t\/\/ Here we are looping over GentiumPlus glyph IDs whose value is 5000 to 5223\r\n\tfor (i=5000; i&lt;5224; i++)\r\n\t{\r\n\t\tFT_Get_Glyph_Name(font_face, i, name, len);\r\n\t\tFT_Load_Glyph(font_face,  i,  FT_LOAD_NO_SCALE);\r\n\t\tFT_Outline_Get_BBox(&amp;(font_face-&gt;glyph-&gt;outline), &amp;bbox);\r\n\t\tfprintf(plist,&quot;(CHARACTER O %o (COMMENT Glyph name is %s)\\r\\n&quot;, k, name);\r\n\t\tfprintf(plist,&quot;    (CHARWD R %.5f)\\r\\n&quot;, font_face-&gt;glyph-&gt;metrics.horiAdvance\/2048.0); \r\n\t\tfprintf(plist,&quot;    (CHARHT R %.5f)\\r\\n&quot;, bbox.yMax\/2048.0);\r\n                \/\/ FreeType's depth values are negative, TeX Font Metrics are not\r\n                \/\/ If bbox.yMin not negative then we don't output anything and TeX assumes zero depth\r\n\t\tif(bbox.yMin &lt; 0)\r\n\t\t{\r\n\t\t\tfprintf(plist,&quot;    (CHARDP R %.5f)\\r\\n&quot;, -1*bbox.yMin\/2048.0); \r\n\t\t}\r\n\t\tfprintf(plist, &quot;%s&quot;,&quot;    )\\r\\n&quot;); \r\n\t\t\r\n\tfprintf(vec, &quot;dup %ld \/%s put\\r\\n&quot;, k, name);\r\n\tk++;\r\n\t}\r\n\tfprintf(vec, &quot;%s&quot;, &quot; def\\r\\n&quot;);\r\n\tfclose(vec);\r\n\tfclose(plist);\r\n}\r\n<\/pre>\n<p>Here is a small extract from <code>weirdo.vec<\/code> and <code>weirdo.pl<\/code> &ndash; if you wish to explore the output you can download them (and <code>weirdo.tfm<\/code>) <a href=\"https:\/\/www.readytext.co.uk\/files\/weirdo.zip\">in this zip file<\/a>. (In the data below I followed the neat idea from LCDF Typetools and put the glyph name in as a comment).<\/p>\n<h4>weirdo.vec<\/h4>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/veccy\r\n256 array 0 1 255 {1 index exch \/.notdef put} for\r\ndup 32 \/uni1D9C.Dep50 put\r\ndup 33 \/uni1D9C.Dep41 put\r\ndup 34 \/uni023C.Dep51 put\r\ndup 35 \/uni023C.Dep50 put\r\n....\r\ndup 251 \/uni024C.Dep51 put\r\ndup 252 \/uni024C.Dep50 put\r\ndup 253 \/uni2C64.Dep51 put\r\ndup 254 \/uni2C64.Dep50 put\r\ndup 255 \/uni1DB3.Dep51 put\r\ndef\r\n<\/pre>\n<h4>weirdo.pl<\/h4>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n(COMMENT Created by Graham Douglas)\r\n(FAMILY WEIRDO)\r\n(CODINGSCHEME WEIRDO)\r\n(DESIGNSIZE R 10.0)\r\n(FONTDIMEN\r\n   (SLANT R 0.0)\r\n   (SPACE R 0.333334)\r\n   (STRETCH R 0.166667)\r\n   (SHRINK R 0.111112)\r\n   (XHEIGHT R 0.430555)\r\n   (QUAD R 1.000003)\r\n   (EXTRASPACE R 0.111112)\r\n   )\r\n(CHARACTER O 40 (COMMENT Glyph name is uni1D9C.Dep50)\r\n    (CHARWD R 0.30566)\r\n    (CHARHT R 0.59863)\r\n    )\r\n(CHARACTER O 41 (COMMENT Glyph name is uni1D9C.Dep41)\r\n    (CHARWD R 0.30566)\r\n    (CHARHT R 0.59863)\r\n    )\r\n(CHARACTER O 42 (COMMENT Glyph name is uni023C.Dep51)\r\n    (CHARWD R 0.43701)\r\n    (CHARHT R 0.55811)\r\n    (CHARDP R 0.09033)\r\n    )\r\n(CHARACTER O 43 (COMMENT Glyph name is uni023C.Dep50)\r\n    (CHARWD R 0.43701)\r\n    (CHARHT R 0.55811)\r\n    (CHARDP R 0.09033)\r\n    )\r\n(CHARACTER O 44 (COMMENT Glyph name is uni023C.Dep41)\r\n    (CHARWD R 0.43701)\r\n    (CHARHT R 0.55811)\r\n    (CHARDP R 0.09033)\r\n    )\r\n(CHARACTER O 45 (COMMENT Glyph name is uni1D9D.Dep51)\r\n    (CHARWD R 0.30566)\r\n    (CHARHT R 0.59863)\r\n    )\r\n(CHARACTER O 46 (COMMENT Glyph name is uni1D9D.Dep50)\r\n    (CHARWD R 0.30566)\r\n    (CHARHT R 0.59863)\r\n    )\r\n\r\n...\r\n...\r\n...\r\n\r\n(CHARACTER O 375 (COMMENT Glyph name is uni2C64.Dep51)\r\n    (CHARWD R 0.56104)\r\n    (CHARHT R 0.64453)\r\n    (CHARDP R 0.20020)\r\n    )\r\n(CHARACTER O 376 (COMMENT Glyph name is uni2C64.Dep50)\r\n    (CHARWD R 0.56104)\r\n    (CHARHT R 0.64453)\r\n    (CHARDP R 0.20020)\r\n    )\r\n(CHARACTER O 377 (COMMENT Glyph name is uni1DB3.Dep51)\r\n    (CHARWD R 0.27002)\r\n    (CHARHT R 0.59863)\r\n    )\r\n<\/pre>\n<p>To generate the binary TFM file <code>weirdo.tfm<\/code> from <code>weirdo.pl<\/code> run <code>pltotf<\/code>:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\npltotf weirdo.pl weirdo.tfm\r\nI had to round some heights by 0.0002451 units.\r\n<\/pre>\n<p>I got a warning from <code>pltotf<\/code>, but I don&#8217;t think it is too serious. To use the TFM you&#8217;ll need to put it in a suitable location within your TEXMF tree.<\/p>\n<h1>Hooking up to DVIPS<\/h1>\n<p>We&#8217;ve covered a huge range of topics so it is time to recap. So far, we&#8217;ve generated an Encoding Vector (<code>weirdo.vec<\/code>) based on the names of glyphs (in the Gentium-Plus font) whose glyph IDs span the range 5000&ndash;5523. Within our Encoding Vector we mapped those glyph names to the character codes 32&ndash;255. We have also created a property list file, based on the same encoding, which simply contains the width, height and depth of the Gentium-Plus glyphs in the range 5000&ndash;5523. Our next task is to pull together the following items and convince DVIPS to use them.<\/p>\n<ol>\n<li><strong>Re-encode <code>GentiumPlus.t42<\/code><\/strong>: We need to create a re-encoded font that uses our new Encoding Vector (<code>weirdo.vec<\/code>).<\/li>\n<li><strong>Update <code>config.ps<\/code><\/strong>: We need to tell DVIPS how to use our new font by creating a <code>.map<\/code> file and making sure DVIPS can find that map file.<\/li>\n<li><strong>Command-line switches<\/strong>: We&#8217;ll need to use some command-line switches to give DVIPS the info it needs to do its job.<\/li>\n<li><strong>Our Type 42 font<\/strong>: <code>GentiumPlus.t42<\/code>: We must tell DVIPS to embed that font into its PostScript output.<\/li>\n<\/ol>\n<p>Our goal is to tell TeX to load a font (TFM) called <code>weirdo<\/code> and for DVIPS to know how to use and find the <code>weirdo<\/code> font data to generate the correct PostScript code to render our glyphs. We&#8217;ll use our strange new <code>weirdo<\/code> font like this (in plain TeX):<\/p>\n<p><code>\\font\\weird=weirdo {\\weird HELLO}<\/code><\/p>\n<p>Note that the displayed output will <strong>not<\/strong> be the English word &#8220;HELLO&#8221; because we&#8217;ve chosen some rather strange glyphs from Gentium-Plus. The key observation is the input character codes are the ASCII values of the string <code>HELLO<\/code>; i.e. (in base 10):<\/p>\n<p><code><br \/>\nH = 72<br \/>\nE = 69<br \/>\nL = 76<br \/>\nL = 76<br \/>\nO = 79<br \/>\n<\/code>\t<\/p>\n<p>and our <code>weirdo.enc<\/code> Encoding Vector maps these character codes to the following glyphs:<\/p>\n<p><code><br \/>\n72 = uni1D94.Dep51<br \/>\n69 = uni1D9F.Dep51<br \/>\n76 = uni0511.Dep50<br \/>\n79 = uni0510.Dep51<br \/>\n<\/code><\/p>\n<p>So, we can expect some strange output in the final PostScript or PDF file!<\/p>\n<h2>How do we do the re-encoding?<\/h2>\n<p>The basic idea is that we tell DVIPS to embed the <code>GentiumPlus.t42<\/code> PostScript Type 42 font data into its PostScript output stream. We will then write some short PostScript headers that will do the re-encoding to generate our newly re-encoded font: which we&#8217;re calling <code>weirdo<\/code>. By using the DVIPS <code>-h<\/code> command-line switch we can get DVIPS to embed <code>GentiumPlus.t42<\/code> and the header PostScript file to perform the re-encoding. For example:<\/p>\n<p><code>DVIPS -h GentiumPlus.t42 -h weirdo.ps sometexfile.dvi<\/code><\/p>\n<p>The actual re-encoding, and &#8220;creation&#8221;, of our <code>weirdo<\/code> font will be taken care of by the file <code>weirdo.ps<\/code>, which will also need to contain the <code>weirdo.enc<\/code> data. If you wish, you can download <code><a href=\"https:\/\/www.readytext.co.uk\/files\/weirdo.ps\">weirdo.ps<\/a><\/code>. Here is the tiny fragment of PostScript required within <code>weirdo.ps<\/code> to &#8220;create&#8221; the weirdo font by re-encoding our Type 42 font whose PostScript name is GentiumPlus.<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/otfreencode\r\n{\r\n\tfindfont dup length dict copy\r\n\tdup 3 2 roll \/Encoding exch put\r\n\tdefinefont\r\n\tpop\r\n} bind def\r\n\r\n\/weirdo veccy \/GentiumPlus otfreencode\r\n<\/pre>\n<p>Note, of course, you could create a header PostScript file to generate multiple new fonts each with their own unique Encoding Vectors containing a range of glyphs from the Type 42 font.<\/p>\n<h2>Telling DVIPS how to use our new font<\/h2>\n<p>So far we&#8217;ve built the TFM file for TeX so now we need to tell DVIPS how to use it &ndash; so that it can process the <code>weirdo<\/code> font name as it parses the DVI file. DVIPS uses <code>.map<\/code> files to associate TFM file names with PostScript font names, together the actions DVIPS needs to take in order to process the font files and get the right PostScript font data into its output. These actions include processing\/parsing Type 1 font files (<code>.pfb<\/code>, <code>.pfa<\/code>) and re-encoding Type 1 fonts. For our <code>weirdo<\/code> font the <code>.map<\/code> file is very simple: all we need to do is create a file called <code>weirdo.map<\/code> with a single line:<\/p>\n<p><code>weirdo weirdo<\/code><\/p>\n<p>This super-simple <code>.map<\/code> file says that the TeX font name (TFM file) <code>weirdo<\/code> is mapped to a PostScript font called <code>weirdo<\/code> (as defined by the code in <code>weirdo.ps<\/code>). It also tells DVIPS that no other actions are needed because we&#8217;re not doing the re-encoding, here nor are we asking DVIPS to process a Type 1 font file (<code>.pfb<\/code>) file associated with <code>weirdo<\/code> &ndash; because there isn&#8217;t one! After you have created <code>weirdo.map<\/code> you&#8217;ll need to edit the DVIPS&#8217;s configuration file <code>config.ps<\/code> to tell DVIPS to use <code>weirdo.map<\/code>. Again, this is easy and all you need to do is add the following instruction to <code>config.ps<\/code>:<\/p>\n<p><code>p +weirdo.map<\/code><\/p>\n<h1>Does it work?<\/h1>\n<p>Well, I&#8217;d have wasted many hours if it didn&#8217;t :-). I used the following simple plain TeX example (test.tex) which I processed using my personal build of TeX for Windows (which does not use Kpathsea).<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\\hsize=300pt\r\n\\vsize=300pt\r\n\\font\\smallweird=weirdo at 12pt\r\nDear \\TeX\\ I would like to say HELLO in weirdo so {\\smallweird HELLO}. I would also like to see \r\na lot of strange glyphs so I'll input a text file containing  some of them: {\\smallweird \\input weirdchars }.\r\n\\bye\r\n<\/pre>\n<p><a href=\"http:\/\/readytext.co.uk\/files\/weirdchars.tex\">Download weirdchars.tex<\/a><\/p>\n<p>The resulting DVI file was processed to PostScript using a standard build of DVIPS with the following command line:<\/p>\n<p><code>DVIPS -h GentiumPlus.t42 -h weirdo.ps  test.dvi<\/code><\/p>\n<p>The resulting PostScript file is large because the <code>GentiumPlus.t42<\/code> file is over 2MB. However, the PDF file produced by Acrobat Distiller was about 35KB because the Type 42 font (<code>GentiumPlus.t42<\/code>) was subsetted.<\/p>\n<p><a href=\"http:\/\/readytext.co.uk\/files\/weirdotest.pdf\">Download PDF<\/a><\/p>\n<p><iframe src=\"https:\/\/docs.google.com\/gview?url=http:\/\/readytext.co.uk\/files\/weirdotest.pdf&#038;embedded=true\" style=\"width:100%; height:300px;\" frameborder=\"0\"><\/iframe><\/p>\n<h1>Concluding thoughts<\/h1>\n<p>&#8220;Alison, I&#8217;m ready to do the gardening. What?, it&#8217;s too late. That&#8217;s a shame.&#8221; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary This is a lengthy post which covers numerous topics on using fonts with TeX and DVIPS. It was fun to write and program but it certainly absorbed many hours of my evenings and weekends. In some areas I&#8217;ve had to omit some finer details because it would make the article way too long and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,23,29,14],"tags":[],"class_list":["post-2693","post","type-post","status-publish","format-standard","hentry","category-c-programming-miscellaneous","category-opentype","category-post-about-about-fonts-glyphs-and-characters","category-tex-general"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2693"}],"version-history":[{"count":125,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2693\/revisions"}],"predecessor-version":[{"id":3308,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2693\/revisions\/3308"}],"wp:attachment":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}