home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s076 / 2.img / TXT / TT1.TXT < prev    next >
Encoding:
Text File  |  1992-04-21  |  31.0 KB  |  590 lines

  1. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2.  
  3.  
  4.  
  5.  
  6.  
  7. TrueType Technical Talk #1:
  8. An Introduction to Digital Typography using TrueType
  9.  
  10.  
  11.  
  12.  
  13.  
  14. George Moore,
  15. November 5th 1991
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. Copyright 1991 Microsoft Corporation.  Permission is given to 
  23. redistribute freely for private non-profit use, provided this 
  24. notice remains with the document.
  25. -----------------
  26.  
  27.  
  28.  
  29. In most digital type systems, whether implemented on a computer or 
  30. in a printer, there are just a few basic steps that the system 
  31. goes through in order to display characters on the target device.
  32. The essential steps are:
  33.  
  34.     1. Load the font outline and feed it to the rasterizer.
  35.     2. Scale the outline to the correct size.
  36.     3. Fill the outline with pixels, creating a raster bitmap
  37.     4. Transfer the raster bitmap to the display device.
  38.  
  39. Expanding upon this list gives us a more detailed look at how TrueType
  40. works.  I'll list the steps in order, and then talk at length about 
  41. each one:
  42.  
  43.     1. Load the font and feed it to the rasterizer.
  44.     2. Scale the outline to the correct point size for the correct 
  45.        resolution of the device.
  46.     3. Apply the hints to the outline, distorting the contours to
  47.        build what is known as a hinted, or gridfitted outline.
  48.     4. Fill the gridfitted outline with pixels, creating a raster bitmap.
  49.     5. Scan for dropouts (optional).
  50.     6. Cache the raster bitmap.
  51.     7. Transfer the raster bitmap to the appropriate display device.
  52.  
  53.  
  54. Step #1: Loading the font
  55. =========================
  56. In a printer, the loading of a font is usually accomplished by the 
  57. printer's BIOS when it has to locate the font in ROM, or as a 
  58. downloaded version of the font stored in local printer RAM.  In a 
  59. computer, this is normally accomplished by the operating system when 
  60. it has to locate the font file on disk.  In Windows 3.1 in particular,
  61. TrueType fonts are stored as .TTF files in the system directory of 
  62. your Windows directory.  These .TTF files are what is known in the 
  63. Macintosh world as the raw `sfnt' resources.  All TrueType fonts on 
  64. the PC are stored and used in Motorola format using big-Endian byte 
  65. ordering.  All Intel and other little-Endian implementations of the 
  66. TrueType rasterizer perform the byte swapping on the fly in order to 
  67. maintain binary compatibility with the Macintosh.  TrueType fonts can 
  68. be installed in the system by the user running the Control Panel, or 
  69. via an application using the new CreateScalableFontResource() in
  70. conjunction with the AddFontResource() APIs.
  71.  
  72. When the user selects a TrueType font from a menu, Windows will go
  73. out to the disk, locate the particular .TTF file and present it to the 
  74. TrueType rasterizer that is a part of GDI (the Graphical Device 
  75. Interface in Windows).  I will cover the font mapping, selection and 
  76. other Windows internals in a future posting since it is beyond the 
  77. scope of this document.
  78.  
  79.  
  80. Step #2: Scaling the outline to the correct point size
  81. ======================================================
  82. I need to give a little background and break this one large complex 
  83. step into smaller steps so that it can be better understood:
  84.  
  85. Outlines
  86. --------
  87. In a TrueType font, character shapes are described by their outlines.
  88. A glyph outline consists of a series of connected contours and lines,
  89. which are defined by a series of points that describe second order 
  90. (quadratic) B-splines.  The TrueType B-spline format uses two types 
  91. of points to define curves, those that are ON the curve and those that 
  92. are OFF the curve.  Any combination of off and on curve points is 
  93. acceptable when defining a curve.  Straight lines are defined by their
  94. endpoints.
  95.  
  96. Generally, most professional font foundries like Monotype store their
  97. digitized outlines in their internal libraries in a format known as 
  98. Ikarus.  Ikarus was developed by a company called URW in Germany and has 
  99. become the standard international interchange format for unhinted digital 
  100. fonts.  Monotype uses a tool called SplineLab from Projective Solutions 
  101. to convert the Ikarus data to a raw, unhinted, skeletal TrueType file.
  102. Shrinkwrapped commercial end-user tools like Font Studio 2.0 from LetraSet 
  103. and Fontographer 3.5 from Altsys usually allow you to convert and 
  104. manipulate TrueType outlines from a number of different formats.
  105.  
  106. FUnits and the em square
  107. ------------------------
  108. In a TrueType font file, the on and off curve point locations are 
  109. described in font units, or FUnits.  An FUnit is the smallest measurable
  110. unit in the em square, which is an imaginary Cartesian coordinate square 
  111. in some arbitrary high resolution space that is used to size and align 
  112. glyphs.  The granularity of the em square is determined by the number 
  113. of FUnits per em, or more simply "units per em".  The greater the 
  114. number of units per em, the greater the precision available in 
  115. addressing locations within the em square.  And no, the em is not
  116. short for "Auntie Em" of The Wizard of Oz, but instead is a historic
  117. measurement in typography that refers to the space which will 
  118. completely contain the capital letter "M" of any given font design.  
  119. While this need not be strictly true in the world of digitized fonts,
  120. it is still a reasonable rule of thumb.  Although all Apple and 
  121. Microsoft distributed TrueType fonts are built with an em square of 
  122. 2048, the TrueType rasterizer actually allows you to build any 
  123. particular font with any arbitrary em square size up to 32767 (from 
  124. coordinate locations -16384,-16384 to +16383,+16383).  Outline scaling 
  125. will be fastest if the units per em is chosen to be a power of 2.
  126.  
  127. Scaling a glyph
  128. ---------------
  129. The first step in this process is the conversion of FUnits to device 
  130. space, which will be dependent upon the physical resolution of the 
  131. target output device.
  132.  
  133. The Cartesian coordinate values in the em square can be converted to
  134. values in the pixel coordinate system by the following formula:
  135.  
  136.    (FUnit value) * (point size of the letter) * (resolution)
  137.   -----------------------------------------------------------
  138.              (72 points per inch) * (units per em)
  139.  
  140. So, for example, let's say that you wanted to calculate the advance
  141. width for the letter "p" in a particular font (the advance width is
  142. how wide the character will be, including the space before and after 
  143. the letter).  This particular character will be at 18 point on a VGA 
  144. resolution screen (96 dpi).  The advance width of the letter that is 
  145. defined in the device independent space is 1250 FUnits, and the units 
  146. per em is defined for this font as 2048:
  147.  
  148.          1250 * 18 * 96
  149.         ---------------- = 14.65 pixels wide
  150.             72 * 2048
  151.  
  152. At 300 dpi, the same letter will be the same physical size, but because 
  153. the pixels are smaller it will take 45.78 pixels to represent the same
  154. character.  At 1200 dpi it would take 183.11 pixels.  The computed
  155. x-resolution size is used for metrics like the widths of characters,
  156. while the y-resolution is used for ascender, descender and linegap
  157. values.
  158.  
  159. In reality, scaling is actually performed by using the above formula
  160. in conjunction with a standard 2x2 transformation matrix.  The 
  161. transformation can be computed as:
  162.  
  163.       Sx(Cos theta)      -Sy(Sin theta)
  164.       Sx(Sin theta)       Sy(Cos theta)
  165.  
  166. "Sx" is the scale factor formula from above with the "resolution" value
  167. set to the x-resolution of the target device.  "Sy" is the y-resolution, 
  168. and "theta" is the rotation angle in counter-clockwise degrees from the
  169. vertical.  This formula handles all rotations, shearing, and stretching
  170. of the outlines.  Applications under Windows 3.1 can directly
  171. manipulate this transformation matrix with the GetGlyphOutline() API.
  172.  
  173. An em square size of 2048 may not sound particularly high, but it 
  174. provides an effective resolution much higher than the actual resolution 
  175. of the high-end 2500 dpi phototypesetters that are on the market today.
  176. If you do the math, you will realize that a motion of 5.89 FUnits in 
  177. the em square space actually corresponds to motion of just 1 pixel at 
  178. 2500 dpi at 10 point.  Which means that if you were using 10 point text 
  179. with an em square of 2048, your phototypesetter would need to have an
  180. actual resolution of around 15000 dpi (or 225 million dots per square 
  181. inch) before the granularity of the em square outline would start to 
  182. have an effect on the number of pixels turned on or off on the actual 
  183. physical outline.  15000 dpi phototypesetters are not likely to come 
  184. on the market in the next couple of years.
  185.  
  186. When you display type on a particular physical device at a specific
  187. point size, you gain an effective resolution measured in pixels per em
  188. (ppem).  The formula for calculating pixels per em is:
  189.  
  190.                                  dots per inch
  191.         ppem = point size * -----------------------
  192.                              72 points to an inch
  193.  
  194. It is important to realize that the raster bitmap patterns formed 
  195. for a glyph at any particular resolution will be the same regardless 
  196. of how big those pixels are (assuming there is no optical scaling going
  197. on, which I'll discuss later).  This seems like an obvious thing to say,
  198. but it's something that a lot of people don't realize until you stop
  199. to think about it.  This is why the ppem value is important.  Let's 
  200. say that you are looking at a 30 point glyph on a 96dpi screen.  The 
  201. ppem value for that glyph will be 30*96/72 or 40 ppem.  The 40 ppem
  202. bitmap pattern of the character at 30 points on a 96dpi device will be 
  203. *exactly the same* as the 10 point version of the same character on a 
  204. 300 dpi device.  This is because 9.6*300/72 equals 40 ppem, and 9.6
  205. point rounds to 10 point (if that particular font tells the rasterizer 
  206. to round values to the nearest pixel, that is.  Otherwise it would be 
  207. 9 point).  The pixels may be smaller, but they form the same raster 
  208. pattern.  
  209.  
  210. This fact is important in both hinting of glyphs and caching of
  211. bitmaps, both of which are covered later.  The important point to
  212. remember in Step #2 is the fact that scaling an outline involves
  213. converting the high resolution device independent outline into an
  214. outline targeted for a particular display device.
  215.  
  216.  
  217. Step #3: Applying the hints
  218. ===========================
  219. In an imperfect world like the one we live in, there is always theory
  220. and reality, and reality very rarely lives up to the theories.  The 
  221. theory in this case is the device independent outlines that are stored 
  222. in a TrueType font; the reality is that most low resolution devices
  223. cannot do them justice.  Compromises always occur, usually in the 
  224. form of poor fitting of the outline to the pixels on the output device.
  225. This is where hinting comes in.  Hints are used to produce legible 
  226. characters from the high resolution outlines on low resolution physical 
  227. devices below 800 dpi (depending upon the size of the character).  To
  228. see why this happens, examine the following drawing of a capital letter 
  229. sans serif "H" outline (I couldn't figure out how to draw nice serifs 
  230. using just ASCII characters).  The dots represent the centers of the 
  231. pixels which form the grid of the output device:
  232. .   .   .   .   .   .   .   .   .   .   .   .   .
  233.        +-----+                   +-----+         
  234. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  235.        |     |                   |     |         
  236. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  237.        |     |                   |     |         
  238. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  239.        |     +-------------------+     |         
  240. .   .  |.   .   .   .   .   .   .   .  |.   .   .
  241.        |     +-------------------+     |         
  242. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  243.        |     |                   |     |         
  244. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  245.        |     |                   |     |         
  246. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  247.        |     |                   |     |         
  248. .   .  |.   .|  .   .   .   .   .|  .  |.   .   .
  249.        +-----+                   +-----+         
  250. .   .   .   .   .   .   .   .   .   .   .   .   .
  251. Most every outline scaling system will use a simple method to
  252. determine which pixels to turn on or off: if the center of the pixel 
  253. falls inside the outline, turn it on, otherwise turn it off.  You will 
  254. notice that the left vertical stem of the "H" encompasses the centers 
  255. of a two pixel column, meaning it will be two pixels wide.  However, 
  256. the right vertical stem only incorporates one pixel center column, 
  257. meaning the left stem will be twice as wide as the right stem, EVEN 
  258. THOUGH BOTH STEMS ARE EXACTLY THE SAME WIDTH IN THE ORIGINAL OUTLINE
  259. (you can count the widths yourself to verify).  You may not actually 
  260. notice details like that when you are reading the text on the screen,
  261. instead you'll just think to yourself: "Hey, that's a pretty ugly font."
  262. The human eye is very good at picking out subtle abnormalities
  263. like that.
  264.  
  265. Hints are used to distort an outline in a systematic fashion so as to 
  266. produce legible text.  In this case, the typographer might tell the 
  267. hinting mechanism to move the two stems slightly closer together:
  268. .   .   .   .   .   .   .   .   .   .   .   .   .
  269.          +-----+                 +-----+         
  270. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  271.          |     |                 |     |         
  272. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  273.          |     |                 |     |         
  274. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  275.          |     +-----------------+     |         
  276. .   .   .|  .   .   .   .   .   .   .  |.   .   .
  277.          |     +-----------------+     |         
  278. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  279.          |     |                 |     |         
  280. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  281.          |     |                 |     |         
  282. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  283.          |     |                 |     |         
  284. .   .   .|  .  |.   .   .   .   .|  .  |.   .   .
  285.          +-----+                 +-----+         
  286. .   .   .   .   .   .   .   .   .   .   .   .   .
  287. This way both vertical stems and the horizontal stroke will all be
  288. exactly one pixel wide.  The higher the resolution of the device, the 
  289. less you need hints because you have more pixels to play with.  If you 
  290. assume the above example was on a 96 dpi screen, at 300 dpi you would 
  291. have a little more than 3 times the grid density, and so an off-by-one 
  292. pixel error at 300 dpi would only be 1/3 the size of the same off-by-one 
  293. pixel at 96 dpi.  However, even at 300 dpi, hints are very important
  294. until you start to reach 100 ppem.
  295.  
  296. The distortion of the outlines by the hints is accomplished in the
  297. TrueType rasterizer by the execution of a rich set of instructions
  298. which allow designers to specify how character features should be 
  299. rendered.  These instructions form an assembly language for font
  300. hinting.  Within the TrueType rasterizer is a software-based interpreter,
  301. much like the hardware-based CPU in a computer.  The interpreter 
  302. processes a stream of ordered binary instructions which take their 
  303. arguments from the interpreter stack and place the results back on 
  304. that stack.  All opcodes are 1 byte in size, but the data can be 
  305. either a single or double byte (word) depending upon the instruction.
  306.  
  307. A small example of some TrueType code follows.  This example is a 
  308. subsection of the hints used for the letter "B" in Times New Roman:
  309.  
  310.     SVTCA[X]
  311.     SRP1[], 44
  312.     SRP2[], 4
  313.     SLOOP[], 3
  314.     IP[], 51, 36, 0
  315.     CALL[], 16, 31, 27, 22, 33, 35     /* Backward Serif 22->21->16 */
  316.     CALL[], 15, 31, 27, 9, 33, 34      /* Forward Serif 9->10->15 */
  317.     IUP[X]
  318.     IUP[Y]
  319.     RS[], 8
  320.     JROF[], #LRnd0, *
  321.     SRP0[], 0
  322.     ALIGNRP[], 1
  323.  
  324. The TrueType instruction set is fully programmable, with loops,
  325. conditionals, branching, math operations, etc.  As you can see from
  326. the example, in this particular case Monotype has defined a subroutine
  327. which contains all of the hints necessary to manipulate the serifs of
  328. Times New Roman (the "CALL[]" statements).  Besides the good programming 
  329. practice of saving code space, this also means that you will be 
  330. guaranteed that all of the serifs in a particular font will be rendered 
  331. identically at any given point size, thus preserving beauty and harmony 
  332. within a typeface.  Since most of the complex problems associated with 
  333. the execution of the hints can be resolved at compile-time, this allows 
  334. the small, fast, dumb rasterizer to execute the code very quickly at 
  335. run-time.
  336.  
  337. The executable portion of the TrueType code is broken into three main 
  338. sections (ranked from least to most specific):
  339.     
  340.     1. The code that is executed when the font is first loaded,
  341.        called the font program.  This is stored in the 'fpgm'
  342.        table in the font file.  In the Monotype-produced fonts 
  343.        for Windows 3.1, the fpgm is generally used for subroutine 
  344.        definitions.
  345.     2. The code that is executed any time there is a point size
  346.        change, transformation change, device resolution change, or 
  347.        spot size change.  This is called the control value program 
  348.        and is stored in the 'prep' table.
  349.     3. The code that is attached to individual glyphs which is 
  350.        stored in the 'glyf' table.
  351.  
  352. This offers great flexibility in scope of certain operations which can
  353. be triggered by specific events within the rasterizer.  The code to
  354. manipulate the font-wide serif subroutines would probably go in the
  355. font program ('fpgm') and actually be called in the individual glyph 
  356. program.  However, the code which makes sure the center of the "e" 
  357. doesn't close up at small point sizes would only go in the glyph 
  358. program.  Since the code can be localized to specific events, another 
  359. interesting thing that can be done is use similar subroutines stored 
  360. in the font program for all members of a typeface family (light, regular,
  361. demibold, bold, heavy, black, etc.) which would maintain similar visual 
  362. consistency across the entire family.
  363.  
  364. The control value program mentioned in section #2 above is run to set 
  365. up values in the control value table (known as the CVT) which allows 
  366. for common control values to be applied across all of the glyphs in a 
  367. font.  For example, you might want all of the glyphs in a font to jump 
  368. from a stem width of two pixels at 17 point to three pixels at 18
  369. point, again for visual consistency.  This can be easily accomplished 
  370. by plugging the right values into the CVT in conjunction with the Move
  371. Indirect Relative Point (MIRP) opcode.  The CVT is also useful for 
  372. passing information between the various elements in a special kind of 
  373. glyph, known as a composite glyph, which can be built up from several 
  374. different elements within a font.  A good example of composite glyphs 
  375. are the accented characters located above ANSI 0x7F, such as "A acute".
  376. In the case of "A acute", you can simply take the glyph of the "A" and 
  377. merge it with the "acute" accent to form a completely new glyph that is 
  378. actually comprised of two different elements.  This saves both code space 
  379. and hinting time.  Composite glyphs can also be used in conjunction with
  380. any transformation to save a lot of space within a font.  For example,
  381. if the font design allowed it, you could create the comma, open single 
  382. quote, close single quote, open double quote, close double quote and
  383. baseline double quotes all by various transformations of a single font 
  384. element which need only be hinted once.
  385.  
  386. If you change the size of the character, the resolution of the device,
  387. or the transformation of the outline (by rotation, skewing, etc.), you
  388. have to re-execute the hints for that specific raster bitmap pattern.
  389. In the Microsoft and Apple distributed TrueType system fonts, hints are 
  390. turned off during any non-standard outline transformation.  Only for
  391. rotations of orthogonal angles (90, 180 and 270 degrees) are hints
  392. used since the alignment of the outline to the grid will be the same
  393. in those cases.  There *are* hinting algorithms which could be executed
  394. in TrueType which are rotation invariant, however we do not make use 
  395. of them.  Most other digital font formats do not provide hints under 
  396. rotation either (however, some versions of the Intellifont rasterizer 
  397. leave hints on under rotation so that they can use the "black distance"
  398. information to embolden the font if a bold version is not available).
  399. It is easy to turn off the execution of hints under rotation with 
  400. the INSTRCTRL[] opcode.
  401.  
  402. Writing raw TrueType instructions can be a very time consuming and
  403. error-prone chore, just like writing in any form of assembly language.
  404. It is also not a good idea to make typographers, who are artists, learn 
  405. a computer science approach to doing their job.  This is where the 
  406. availability of good tools comes in.  There can be many approaches to 
  407. hinting fonts, but the method that Monotype has been using for our base 
  408. Windows fonts has been with the use of a high-end tool called "TypeMan" 
  409. from a company named Type Solutions.  TypeMan will first make a 
  410. best-guess for the hinting of the font by running its own autohinter on 
  411. the glyphs first.  It then allows you to tweak the generated code it 
  412. produced in a high-level language format which will then be compiled 
  413. down into raw TrueType instructions.  Like any good compiler, it checks 
  414. syntax, resolves "linking" problems in addition to doing quite a few 
  415. other housekeeping duties within the fonts.  Type Solutions can be 
  416. reached at (603) 382-6400 for information about this and other tools.
  417.  
  418. Using TypeMan is one approach to generating TrueType fonts.  Another
  419. is conversion of existing fonts to TrueType format.  The TrueType 
  420. instruction set is a superset of all known hinting methods, so 
  421. it is theoretically possible to convert any other hints to TrueType 
  422. hints.  In fact, it's more than a theory -- this is exactly how 
  423. several font foundries are producing their initial set of TrueType 
  424. fonts.  They simply take their existing hinted fonts and recompile
  425. them in TrueType format.  This allows a very large library of fonts 
  426. to be created rather quickly.  And since the hints are being 
  427. transferred directly, there is no degradation of the quality of the 
  428. resulting bitmaps.
  429.  
  430. Other companies, like Bitstream and AGFA/Compugraphic, will take their 
  431. existing fonts, convert their own hints to TrueType hints, and then go 
  432. back and do extra work on the font.  They have developed a production 
  433. environment that allows them to take their existing library of outline 
  434. fonts and add the appropriate hinting and font file structure needed 
  435. to support new font technologies.
  436.  
  437. TrueType is the only digital type system available on the PC or the
  438. Macintosh which provides this arbitrary, user-defined, flexible, 
  439. algorithmic approach as a hinting mechanism.  This works well for 
  440. many different languages, since the hinting algorithms you would use 
  441. for Latin fonts will be different than for Kanji, Chinese, Korean, 
  442. Arabic, Hebrew, Devanagari, Telugu, Kannada, Sinhalese, Bengali, 
  443. Gurmukhi, etc.
  444.  
  445.  
  446. Step #4: Fill the outline, creating a raster bitmap
  447. ===================================================
  448. In order to first fill an outline with pixels efficiently, it is 
  449. desirable to decompose the curves into scanlines so as to create an 
  450. edge list (some people call it an edge table).  This list contains all 
  451. of the edges of the contours sorted by their smaller y-coordinates so 
  452. that the filling algorithm does not have to calculate intersections 
  453. with the outlines at every single pixel location.  More information 
  454. on this process can generally be found in any introductory computer 
  455. graphics textbook and it is not worth going into detail here.
  456.  
  457. This is a very quick step since all of the hard work has already been 
  458. done.  The outline has already been distorted to correspond to the 
  459. size of the pixels (step #3), and the system already knows where the 
  460. edges of the outlines with respect to the grid are located (step #4a).
  461. All the filling algorithm has to do at this point is decide if the 
  462. center of each pixel is enclosed within the outline.  If it is, you 
  463. simply turn that pixel on, otherwise leave it off.
  464.  
  465.  
  466. Step #5: Scan for dropouts
  467. ==========================
  468. "Tune in, turn on, and drop-out" was the motto for millions of
  469. people during the 1960's, although it could very well be applied to 
  470. portions of digital typography today.  Tuning the outline for the 
  471. grid, turning pixels on and checking for dropouts are three of 
  472. the major components of any font scaling system.
  473.  
  474. A pixel dropout occurs whenever there is a connected region of a 
  475. glyph interior that contains two black pixels that cannot be connected 
  476. by a straight line that only passes through those black pixels.  In the 
  477. following close-up example you can see that the outline for the center-
  478. bar of the letter "H" happens to go between two rows of pixels:
  479. .     .    |.     . |   .     .     .     .   | .     .|    .     .
  480.            |        |                         |        |
  481.            |        |                         |        |
  482.            |        |                         |        |
  483. .     .    |.     . |   .     .     .     .   | .     .|    .     .
  484.            |        +-------------------------+        |
  485.            |                                           |
  486.            |        +-------------------------+        |
  487. .     .    |.     . |   .     .     .     .   | .     .|    .     .
  488.            |        |                         |        |
  489.            |        |                         |        |
  490.            |        |                         |        |
  491. .     .    |.     . |   .     .     .     .   | .     .|    .     .
  492. This is one example of a dropout (although this one could be corrected
  493. with some appropriate hints).  Another more difficult one to fix (and
  494. more difficult to illustrate in ASCII) could happen on a thin curve that 
  495. just happened to pass between two pixel centers.
  496.  
  497. It is possible to test for potential dropouts by looking at an
  498. imaginary line segment connecting two adjacent pixel centers.  If this
  499. line segment is intersected by both a on-Transition contour and an
  500. off-Transition contour, a potential dropout condition exists.  The
  501. potential dropout only becomes an actual dropout if the two contour
  502. lines continue on in both directions to cut other line segments
  503. between adjacent pixel centers.  If the two contours join together
  504. immediately after crossing a scan line (forming a stub), a dropout
  505. does not occur, although a stem of the glyph may become shorter than
  506. desired.
  507.  
  508. Depending upon the glyph shapes, dropout control can be a time-expensive
  509. operation.  For this reason it is an optional step that can be turned 
  510. on or off by the TrueType SCANCTRL[] opcode.  It is worth noting that
  511. you can turn SCANCTRL[] on or off on a per character basis depending
  512. upon the size of the glyph (its ppem value).  For example, a character
  513. like the letter "I" will generally not have dropouts even at low ppem 
  514. values, so you can speed up its rasterization by turning SCANCTRL[] off.
  515. However, the character "@" is very difficult to image because of all 
  516. the delicate curves involved, so you might want to leave SCANCTRL[] on 
  517. for even large sizes (in some of the fonts that we ship in Windows 3.1,
  518. SCANCTRL[] for the "@" symbol is left on up to 60 ppem).  It is up to 
  519. the individual font vendor to weigh the tradeoffs involved with dropout 
  520. control.  For example, a vendor selling barcode fonts probably wouldn't
  521. need it at all.
  522.  
  523.  
  524. Step #6: Cache the raster bitmap
  525. ================================
  526. Steps #6 and #7 are not so much a part of the rasterizer, but more
  527. a part of the environment that the rasterizer is implemented in.
  528.  
  529. For most Latin fonts of only a couple hundred characters each, a cache 
  530. of any reasonable size makes the speed of the rasterizer almost 
  531. meaningless.  This is because the rasterizer only runs once, the 
  532. first time you select a font or a new point size, and from then on 
  533. the bitmaps are transferred out of the cache to the screen or page 
  534. buffer.  If you are editing a document with a particular font, chances 
  535. are that 99.9% of the time the font is used on the screen it is being 
  536. transferred from the cache.
  537.  
  538. In Windows 3.1, all TrueType bitmaps at all ppem values are cached
  539. automatically in the kernel's private memory arena.  And since the 
  540. Windows kernel will make use of all unused memory in the system as its 
  541. cache, this means you could have a font cache of several megabytes.  If 
  542. you are running in protect mode on the 80386, Windows will also page 
  543. bitmap caches to the swap file when physical memory is filled.  This 
  544. means you could have, for example, 32 megabytes of virtual font cache 
  545. on an 8 megabyte machine.  With the advent of the new virtual disk 
  546. driver in Windows 3.1 running in protect mode (called "fastdisk"), it 
  547. is faster to load cached bitmaps from disk than to re-render the 
  548. character from scratch.  The kernel uses an LRU system to discard old 
  549. data when memory fills up, or when an application asks for extra 
  550. memory in low memory conditions.  But generally speaking, not much 
  551. is ever flushed from the cache since most swap partitions are so large 
  552. in relation to the data that is being cached.  This is in stark 
  553. contrast to third-party font scaling solutions which use a smaller 
  554. fixed cache which cannot be dynamically allocated to other programs.
  555. These take memory away from applications in low memory conditions and 
  556. do not make the best use of free memory when it is available.
  557.  
  558. The caching keys used by GDI in the selection of the pre-rendered 
  559. raster bitmaps are specific to the transformations applied to the glyph 
  560. and to the effects of optical scaling (which is a venerable typographic 
  561. concept which allows for changes in the shapes of the glyphs depending 
  562. upon not only the ppem value, but also the pointsize).
  563.  
  564.  
  565. Step #7: Transfer the raster bitmap from the cache to the display
  566. =================================================================
  567. This step is also implementation specific.  Most printers have a
  568. dedicated blitting chip which can quickly blast bitmaps from the local
  569. printer cache to the page buffer.
  570.  
  571. Under Windows 3.1, it really depends upon what kind of hardware you
  572. have in your machine as to how this step is accomplished.  If you have
  573. a video card which contains a hardware blitter (which is generally a
  574. swell thing to have under Windows anyway), the font bitmaps can be
  575. quickly moved from the cache via a direct DMA transfer.  If you have a
  576. normal video subsystem in your PC, Windows will handle the transfer of
  577. the bitmap via software, which is still reasonably quick.
  578.  
  579. Of probable equal importance to the transfer of the bitmaps to the 
  580. screen is the communication of the metrics information in the font to 
  581. the applications in the system.  The new TrueType APIs will return 
  582. many useful values, such as left and right sidebearing values for
  583. individual characters, x-height of the font, em square size, subscript
  584. and superscript size values, underline position, strikeout position,
  585. typographic ascent, typographic descent, typographic linegap, the 
  586. italic angle of the font (useful for making an insertion cursor match 
  587. the angle of the font), and many other interesting things.
  588. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  589.  
  590.