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

  1. TrueType Technical Talk #2: Linear vs. Non-Linear Scaling
  2.  
  3.  
  4.  
  5.  
  6. George Moore
  7. April 20th, 1992
  8.  
  9.  
  10.  
  11.  
  12.  
  13. Copyright 1992 Microsoft Corporation.  Permission is given to freely 
  14. redistribute for private non-profit use provided this notice remains 
  15. with the document.
  16. -----------------
  17.  
  18.  
  19.  
  20. The quality and legibility of the fonts that appear on your computer
  21. screen is also important to millions of other users worldwide.  One 
  22. of the great typographic strengths of TrueType that cannot be matched 
  23. by other font scaling solutions is its ability to perform what is 
  24. known as non-linear scaling.  This feature results in higher quality 
  25. text which is more legible on low resolution devices like computer 
  26. screens and 300 dpi laserprinters.  Non-linear scaling is not some 
  27. vague promise of something that you could do with TrueType -- it
  28. is implemented today in the fonts we ship with Windows 3.1.  To 
  29. understand why this feature is important, we have to look at one of 
  30. the more fundemental problems that occur in digital typography.  
  31.  
  32. If you will recall from the TrueType Talk #1, all digital typographic
  33. systems store extremely high resolution outlines in the font itself,
  34. which are then scaled to the proper size for the target device.  These 
  35. outlines are then "hinted" to remove poor fitting of the outline to the 
  36. pixel grid on the screen or printer.  One of the problems that I really
  37. didn't discuss in the first talk is round-off error during the scaling 
  38. process itself.  This is a big problem.
  39.  
  40. Let's say you have a lower-case letter "m" outline that you are 
  41. attempting to make legible at a small size on a 96dpi (VGA resolution) PC 
  42. screen.  The outline itself was originally stored as a series of quadratic 
  43. B-splines in the high-resolution Cartesian em square space of the font 
  44. file.  In the following crude illustration, the `*' are used to denote 
  45. on-curve control points in the original theoretical outline.  The numbers 
  46. beside the `*' are the coordinates of the individual control points in the 
  47. high-resolution space:
  48.  
  49.     *--------* (42,200)
  50.     |(6,200) |                                                   (246,187)
  51.     |        *-------------------------------------------------------*
  52.     |       (42,187)                                                 |
  53.     |                        (108,151)                  (210,151)    |
  54.     |        *------------------*        *------------------*        |
  55.     |        |(42,151)          |        |(144,151)         |        |
  56.     |        |                  |        |                  |        |
  57.     |        |                  |        |                  |        |
  58.     |        |                  |        |                  |        |
  59.     |        |                  |        |                  |        |
  60.     |        |                  |        |                  |        |
  61.     |        |                  |        |                  |        |
  62.     |        |                  |        |                  |        |
  63.     |        |                  |        |                  |        |
  64.     |        |                  |        |                  |        |
  65.     |        |                  |        |                  |        |
  66.     |(6,0)   |                  |(108,0) |                  |(210,0) |
  67. +   *--------*                  *--------*                  *--------*   +
  68. ^          (42,0)                      (144,0)                   (246,0) ^
  69. |                                                                        |
  70. (0,0)                                                                 (252,0)
  71.  
  72. The `+' denote the starting and stopping points for the character itself,
  73. which includes the glyph shape plus the space around it.  The gap from 
  74. coordinate location (0,0) to (6,0) is known as the left side-bearing.  
  75. Likewise, the gap from (246,0) to (252,0) is called the right side-bearing.
  76. These gaps are what keeps the character from running into the other 
  77. characters on the line of text.  In this case both side-bearings are 
  78. defined as 6 units in the em square space.  As you can also see, the 
  79. entire character occupies 252 units in the horizontal direction (known 
  80. as the advance width) and 200 units in the vertical direction.  Finally, 
  81. each vertical stem is exactly 36 units wide (because 42 - 6 = 36 and 
  82. 144 - 108 = 36) with a gap of exactly 66 units of space between each 
  83. vertical stem (because 108 - 42 = 66 and 210 - 144 = 66).
  84.  
  85. Now, given that, let's assume we have a scaling factor of 10 to 1,
  86. meaning we have to scale the outline down for a particular point size
  87. that is exactly one-tenth the size of the original outline.  Therefore,
  88. the advance width becomes 25.2 rather than 252.  Likewise, the width of
  89. each stem becomes 3.6 rather than 36 and the gap between the stems
  90. becomes 6.6 rather than 66.  This looks like it's an easy problem to
  91. solve since you just divide all of the numbers by 10.  But there's a
  92. danger in that.  Since no physical display device (either screen or
  93. printer) can display anything less than a pixel, you have to round all
  94. of the values to the nearest whole number.  A pixel, by definition, is 
  95. the smallest element that is used to display information.  It's like a 
  96. binary bit -- it's either on or it's off.  So the 3.6 pixel widths of 
  97. the stems become 4 pixels wide and the 6.6 pixel widths of the gaps 
  98. become 7 pixels wide.  Likewise, each side bearing of .6 pixels rounds
  99. up to 1 pixel:
  100.  
  101.     |        |                  |        |                  |        |
  102.     |        |                  |        |                  |        |
  103.     |        |                  |        |                  |        |
  104.     |        |                  |        |                  |        |
  105. +<1>*--------*  < 7 pixels >    *--------*   < 7 pixels >   *--------*<1>+
  106.     <4 pixels>                  <4 pixels>                  <4 pixels>
  107.  
  108. So now we've got a real problem.  If you add up the high resolution
  109. widths for each feature in this letter (6 + 36 + 66 + 36 + 66 + 36 + 6),
  110. the correct width of the character is 252 units across, which rounds
  111. to 25 pixels after you apply the 10:1 scaling factor.  The character 
  112. WANTS to be 25 pixels wide, however, the character NEEDS to be 28 
  113. pixels wide because if you add up the individual rounded values 
  114. (1 + 4 + 7 + 4 + 7 + 4 + 1) you get 28.  The character grew by 12% 
  115. because of round-off errors.
  116.  
  117. The 25 pixel answer is the linearly scaled value for that character,
  118. whereas the 28 pixel answer is its non-linearly scaled value.
  119. The non-linearly scaled value is also sometimes called its "hinted" 
  120. width since the hints are used to specifically make the character
  121. wider at certain sizes.  If you assume simple linear scaling, you have 
  122. to somehow fit 28 pixels into a space reserved for 25 pixels.
  123.  
  124. So what do you do with those extra 3 pixels?  You could remove one 
  125. each from the width of each stem, making each vertical stem only 3 pixels 
  126. wide (instead of 4 like it should be).  But then your letter "m" will not 
  127. match the other letters in the same font at the same size (because the "i",
  128. "t", "j" and others will still be 4 pixels wide since they don't have this 
  129. rounding problem).  You could remove one pixel each from the gap between 
  130. each stem, making each gap only 6 pixels wide, but what do you do with the 
  131. third pixel?  You can't remove 1 from just one of the vertical stems since 
  132. then they wouldn't match.  You can't remove it from one of the sidebearings 
  133. because then the character would collide with the next one in the line.
  134. In short, you are stuck with a weird-looking asymmetrical character if you 
  135. try to base all of your calculations on the original width as stored in the 
  136. high-resolution em square space of the font.
  137.  
  138. But the problem is even worse than what I just described.  At very 
  139. small point sizes on low resolution displays you sometimes don't have 
  140. enough pixels to represent the character with any fidelity.  Because 
  141. of cumulative round-off error in the scaling process, you might need 7 
  142. pixels to represent the letter "m" that has a linearly scaled width of 
  143. only 6 pixels.  What do you do?  You have the choice of the following 
  144. shapes:
  145.  
  146.     +- - - - - -+
  147.     |           |
  148.     |  @ @ @ @ @|    <-- in this example, there is a one pixel space
  149.     |  @   @   @|        for the left side bearing, but no right side
  150.     |  @   @   @|        bearing at all, meaning the letter would run
  151.     |  @   @   @|        into the next one to the right of it.
  152.     |  @   @   @|
  153.     +- - - - - -+
  154.  
  155.     +- - - - - -+
  156.     |           |
  157.     |  @ @ @ @  |    <-- You could fix that problem by deleting one
  158.     |  @   @ @  |        pixel from the center of the "m", but now it
  159.     |  @   @ @  |        is no longer recognizable as an "m".  You are
  160.     |  @   @ @  |        trading legibility for correct spacing in this
  161.     |  @   @ @  |        case.
  162.     +- - - - - -+
  163.  
  164. And these examples are only using sans-serif faces.  Imagine trying to 
  165. squeeze serifs in there also!  But this problem is not limited to 
  166. only computer screens.  In reality, any font that you are trying to 
  167. represent below approximately 60 ppem can have this problem with 
  168. certain characters.  And if you do the math (from the ppem formula 
  169. supplied in Talk #1), you will realize that 60 ppem corresponds to 
  170. around 14 point at 300 dpi.  This means it is impossible to produce 
  171. high-quality text at 14 point and below at 300 dpi if you base all of 
  172. your calculations on simple linear scaling.  
  173.  
  174. You'll notice that if you take this exact same letter "m" and try to 
  175. render it on a reasonably high resolution device, this rounding problem 
  176. goes away.  If you have at least 252 pixels across for the example given 
  177. above, there is absolutely no problem since the character will scale 
  178. linearly.  Now you've got two different devices (the screen and the 
  179. printer), each with the exact same character at the exact same point 
  180. size, and each reporting different widths.  Both widths are right, but 
  181. both are also wrong.
  182.  
  183.  
  184.  
  185. Existing Digitial Typography Systems
  186. ====================================
  187.  
  188. Under existing systems, such as the Intellifont format from AGFA (found
  189. in the HP LaserJet III printer and others) and the Type-1 format from 
  190. Adobe (found in PostScript printers), this problem of having two "correct"
  191. answers for the width of each character is an incredibly hard engineering
  192. problem to solve.  In fact, it's an impossible problem to solve.  Remember,
  193. both of these systems were designed for printers first.  It took several 
  194. years before Adobe Type Manager was made available for Windows and the
  195. Macintosh.  Because the font rasterizers were originally designed to 
  196. exist only within the printer, there was no way to communicate the width 
  197. of each character back to the application in the host computer.  If you 
  198. do the typographically correct thing and allow non-linear scaling, the 
  199. width of each character will depend upon both the point size you are 
  200. trying to render *and* the resolution of your target device.  The ideal 
  201. width (i.e., the non-linearly scaled value) of a particular character at 
  202. 5 point may be one value, but an entirely different value at 6 point, yet 
  203. another at 7 point, etc.  And none of these may match the easily 
  204. calculated linearly scaled values.  If you allow non-linear scaling, you 
  205. cannot successfully predict exactly what the widths of the characters 
  206. will be until you actually try to render each character by applying the 
  207. hints.
  208.  
  209. Applications that are running on the host computer system connected to 
  210. these stand-alone printers will be attempting to figure out line breaks 
  211. and page breaks based upon the widths of those characters.  The only way 
  212. for the application to calculate these various widths is to assume that 
  213. all characters at all point sizes will scale linearly.  By allowing
  214. only linear scaling, the application on the host only needs a list of 
  215. the high-resolution widths for each character.  It can then do the 
  216. simple integer math itself to figure out how wide a character will be 
  217. at a certain size without having to communicate with the printer.
  218.  
  219. However, later it was decided to port these font scaling solutions to
  220. Windows or the Macintosh.  Now the primary output device for these
  221. versions of the rasterizer would be a low resolution computer monitor
  222. running at 96 dpi (a VGA resolution screen).  Now a large percentage of 
  223. the time the text would be below 60 ppem (45 point @ 96 dpi), so if you 
  224. assume linear scaling, these characters would have to be wedged into a 
  225. space smaller than they should normally fit.  If those font scaling 
  226. programs allowed non-linear scaling for the screen they would break all 
  227. existing applications and the millions of fonts which had been already 
  228. distributed.  The end result was that screen quality had to suffer 
  229. because printed output (combined with backwards compatibility) is more 
  230. important.
  231.  
  232.  
  233. TrueType and Non-Linearity
  234. ==========================
  235.  
  236. This problem does not occur with TrueType because it was designed from 
  237. the very beginning to reside within the operating system of the host 
  238. computer, not the printer.  This way it could produce high quality text
  239. for both devices, without having either device suffer because of the 
  240. limitations of the other.
  241.  
  242. Most major applications care about providing WYSIWYG linebreaks and
  243. pagebreaks between the screen and the printer.  When these applications 
  244. (such as PageMaker, Ami Pro, Word for Windows, WordPerfect for Windows, 
  245. etc.) first start running, one of the first things they do is ask the 
  246. operating system to provide a list of the widths of each character at 
  247. the point size you are using.  By building this list, the application 
  248. can figure out how wide each word will be, and therefore, how wide each 
  249. line will be.  In Windows 3.0 with the old-style bitmapped screen fonts,
  250. it was easy enough to calculate these line endings since the width
  251. information for each character was simply stored in the font itself and 
  252. no calculations were really necessary.  But with non-linear outline 
  253. scaling fonts, it becomes a more complex problem.
  254.  
  255. The only way to figure out how wide each character will be after the
  256. pixel rounding occurs is to execute the hints for each character (since
  257. you have no idea what kind of things the hints will do to the outline).
  258. But even on a reasonably fast 386-based machine, the execution of all 
  259. the hints for all of the characters in the font could take around one 
  260. full second.  This is an unacceptable delay for most people who are 
  261. used to dealing with non-GUI applications.  For this reason, contained 
  262. within each TrueType font is a table called the 'hdmx' (Horizontal Device 
  263. Metrics) which contains precomputed widths for each character at some of 
  264. the more popular sizes.  In the Microsoft distributed fonts for Windows 
  265. 3.1, we store these precomputed values from 9 to 24 ppem and then for 15 
  266. other popular larger sizes.  This way when the application tells Windows 
  267. "give me the widths of each character at 13 ppem", Windows just pulls 
  268. these precomputed values out of the hdmx table as necessary.  The hdmx 
  269. table in each font isn't that large, and so the trade-off between disk 
  270. space and execution speed is very good.  The hdmx table is built by the 
  271. font vendor when they compile the TrueType font for distribution.
  272.  
  273. The addition of the hdmx table solves one problem, but it creates a new
  274. smaller one.  The font vendor is only going to include a limited number
  275. of ppem values in the 'hdmx' for some of the more popular sizes, but it's 
  276. entirely possible that the font will scale non-linearly past the top of
  277. the range of hdmx values.  However, at a certain point the font will 
  278. scale linearly because you will have enough pixels to faithfully 
  279. reproduce the shape of the characters.  When the font reaches linearity,
  280. the width calculations become easy.  So you have this "grey area" between 
  281. the top of the hdmx table range and the bottom of the linear range.  It 
  282. would be unacceptable to take the time hit to execute the hints simply 
  283. to find out the advance width for the sizes that aren't covered in the 
  284. hdmx table.  If an application asks for the widths of the characters at 
  285. 75 ppem, they may be scaling linearly at that point, but the only way to 
  286. be sure is to execute the hints.  For this reason, we have defined another 
  287. table in the font file called the 'LTSH' (Linear Threshold).  The LTSH 
  288. table defines the point at which it is reasonable to assume linearly 
  289. scaled advance widths on a character-by-character basis.  Between the 
  290. hdmx and the LTSH tables, the fonts appear on the screen quite fast and 
  291. with good typographic quality.
  292.  
  293.  
  294. Existing Applications and Non-Linearity
  295. =======================================
  296.  
  297. How do Windows or Macintosh applications cope with non-linearly scaling
  298. fonts?  How do they handle the scaled width of the "W" being different
  299. on the screen than on the printer?  As it turns out, this is not a big
  300. problem.  In Windows 3.0, applications had to go to great lengths to 
  301. make the widths of the old-style screen bitmap fonts match the widths 
  302. of the printer fonts.  Applications would aways calculate the widths 
  303. for the printer and then try to make the screen display match.  This 
  304. was not as easy as it sounds since you had vastly different widths, 
  305. not to mention character shapes, between the two devices.  For example,
  306. if the user selected the "Avant Garde Gothic" printer font, Windows
  307. might select the "Helv" screen font as the closest match -- even though
  308. they share little in common.  The applications used a number of tricks
  309. to accomplish this alignment feat.  The most common algorithm used was
  310. to simply add or delete extra pixels between words so that the spacing
  311. of the characters within the words looked right, but the spacing between
  312. the words was off just a little.  This way the line breaks would appear
  313. correct.
  314.  
  315. When using TrueType fonts on the screen and printer, Windows can now do
  316. a much better job of matching the shapes of the characters.  So the
  317. applications continue to do exactly the same thing as in the past,
  318. except now there is a much more typographically correct font available
  319. for the screen.  The extra one or two pixels taken up by the "W" will
  320. simply be absorbed in the inter-word spacing.  However, if the 
  321. typographer hinting the font made all, or most, of the characters take 
  322. up extra space on the line, the words might start to run together since
  323. there are only a finite number of pixels between each word.  For this 
  324. reason, when Monotype produced our base 13 Windows TrueType fonts, they 
  325. did a little research into history.
  326.  
  327. Monotype has been in business since 1897 and has almost 100 years
  328. experience in designing and selling type -- real type, the kind made of
  329. lead.  Since Monotype had to make separate pieces of lead for each letter
  330. of the alphabet, they have made precise charts that give the distribution
  331. patterns of each letter of the alphabet.  The letter A, for example, is
  332. used far more often than the letter X, so they would naturally make more
  333. A's for any given font.  As it turns out, about 70% of all documents are
  334. made from just 13 characters: a, c, d, e, h, i, l, n, o, r, s, t, and u.
  335. Anyone who has watched "Wheel of Fortune" can verify this.  So when
  336. Monotype hinted our base Windows fonts, they were very careful to make 
  337. sure that those 13 characters do not exceed the linearly scaled advance
  338. width.  This makes it much easier for applications to produce correctly
  339. justified text.  Happily, the characters that are most likely to exceed 
  340. their linear values (such as m and w) are not in the above list.  This 
  341. 70% figure is holds up across all Western and Eastern European languages.
  342. In reality, the distribution pattern for the uppercase letters is
  343. slightly different than the lowercase letters, but we decided to use
  344. the same rules for both so that lines in all uppercase will not break
  345. differently than the same lines in lowercase.
  346.  
  347.  
  348. The End Result
  349. ==============
  350.  
  351. So what does this all mean for the end user?  All of this technology is
  352. used for one reason only: producing the highest quality text given the
  353. physical restrictions of the output device.  Take, for example, the
  354. Arial Bold "w" in TrueType format.  Since the "w" tends to have more 
  355. round-off errors that other letters, Monotype allowed its hinted advance 
  356. width to exceed the linear width on several occasions:
  357.  
  358.   Pixels   PointSize   Linear Width  Hinted Width
  359.   Per Em   (at 96dpi)  (in pixels)   (in pixels)   Difference
  360.   -------  ----------  ------------  ------------  ----------
  361.     11         8           8.6           10             1
  362.     12         9           9.3           10             1
  363.     13        10          10.1           11             1
  364.     14        11          11.4           11             0
  365.   * 15         (not used)
  366.     16        12          12.4           13             1
  367.     17        13          13.5           14             0
  368.     18        14          14.0           15             1
  369.  
  370.   * If you do the math from Tech Talk #1, you will notice that both
  371.     14 and 15 ppem round to 11 point at 96 dpi.  Since you can only
  372.     have one point size for any given ppem value, the 15 ppem number
  373.     is not used and hence, not shown on this chart.
  374.  
  375. As you can see, for 8, 9, 10, 12 and 14 point at VGA resolution,
  376. Monotype allowed the Arial Bold "w" to be slightly wider than it should 
  377. be for legibility purposes.  
  378.  
  379. If you have a copy of the tool called "Zoom-In" from the Windows Software
  380. Development Kit, you can enlarge areas of the screen to see what pixel 
  381. patterns are formed by the various letters in a particular font.  For 
  382. an example of the asymmetries caused by forcing a character to be
  383. linearly scaled, I have reproduced the pixel patterns formed by the
  384. letter "M" by Helvetica (with ATM for Windows v2.0) and Arial (with 
  385. TrueType) at the exact same point size on the same screen:
  386.  
  387.    ATM: Helvetica @ 13 pixels/em         TrueType: Arial @ 13 pixels/em
  388.         (or 10 point on VGA):                 (or 10 point on VGA):
  389.  
  390.           @             @                      @               @
  391.           @ @         @ @                      @ @           @ @
  392.           @   @     @   @                      @ @           @ @
  393.           @   @     @   @                      @   @       @   @
  394.           @   @     @   @                      @   @       @   @ 
  395.           @   @     @   @                      @     @   @     @
  396.           @   @     @   @                      @     @   @     @
  397.           @     @   @   @                      @     @   @     @
  398.           @     @ @     @                      @       @       @
  399.           @     @       @                      @       @       @
  400.  
  401. As you can see, by forcing the letter to be only 8 pixels wide (in the
  402. case of ATM), the "M" looks a little strange.  By deciding to allow the
  403. character to be 9 pixels wide (in the case of TrueType), you regain the
  404. symmetry that makes for a reasonable looking character.  If you wish to
  405. see this for yourself, make sure you turn off "Bitmap Substitution"
  406. in ATM under Windows or else you'll get the old-style "Helv" bitmap.
  407.  
  408. In comparing many letters (and the spacing) at different point sizes,
  409. you'll notice that the base Monotype TrueType fonts produce more
  410. legible, easy to read characters than ATM.  Even if you leave "Bitmap
  411. Substitution" on under ATM, it doesn't help for those fonts which no
  412. bitmaps are available.  Windows does not distribute the bold or italic 
  413. bitmap versions of "Helv" or "Tms Rmn", nor does bitmap substitution
  414. help in the case of fonts beyond the base 13.
  415.  
  416. The TrueType format has the capability to produce the best looking 
  417. digital fonts in the world at any resolution.  Monotype has shown that 
  418. this can happen with the Windows 3.1 base fonts.  The big caveat is that 
  419. the results from other third-party vendors will depend entirely upon the 
  420. hinting algorithm they choose to implement.  There will be bad-looking 
  421. TrueType fonts, created by people who don't know any better, just like 
  422. there are bad-looking Type-1 fonts created by people who don't know any
  423. better.  The big difference, however, is the fact that it is at least 
  424. possible to create scaling fonts in TrueType which are very close to 
  425. hand-tuned bitmaps.
  426. ----------------------------------------------------------------------
  427.