From 361d9b8a7c6826272184a88007b0c5b7a26c1cb7 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Thu, 9 Nov 2000 22:15:34 +0000 Subject: [PATCH] Revised. --- docs/glyphs/glyphs-4.html | 373 ++++++++++--------- docs/glyphs/glyphs-5.html | 733 ++++++++++++++++++++++++-------------- 2 files changed, 684 insertions(+), 422 deletions(-) diff --git a/docs/glyphs/glyphs-4.html b/docs/glyphs/glyphs-4.html index 4f07878ff..0bcc02cc1 100644 --- a/docs/glyphs/glyphs-4.html +++ b/docs/glyphs/glyphs-4.html @@ -1,12 +1,13 @@ - + - - - - FreeType Glyph Conventions + + + FreeType Glyph Conventions - -
-

-FreeType Glyph Conventions

- -
-

-version 2.1

+

+ FreeType Glyph Conventions +

-
-

-Copyright 1998-2000 David Turner (david@freetype.org)
-Copyright 2000 The FreeType Development Team (devel@freetype.org)

- -
- -
- - - -
-Previous - -Contents - -Next -
- -
-

-IV. Kerning +

+ Version 2.1

-
- -

The term 'kerning' refers to specific information used to adjust -the relative positions of coincident glyphs in a string of text. This section -describes several types of kerning information, as well as the way to process -them when performing text layout. -

- -

-1. Kerning pairs -

- -

Kerning consists in modifying the spacing between two successive -glyphs according to their outlines. For example, a "T" and a "y" can be -easily moved closer, as the top of the "y" fits nicely under the "T"'s -upper right bar. -

- -

When laying out text with only their standard widths, some consecutive -glyphs sometimes seem a bit too close or too distant. For example, the -space between the 'A' and the 'V' in the following word seems a little -wider than needed. -

-

-

Compare this to the same word, when the distance between these two letters -has been slightly reduced : -

-

- -

As you can see, this adjustment can make a great difference. Some font -faces thus include a table containing kerning distances for a set of given -glyph pairs, used during text layout. Note that : -
  -

-
    -
  • -The pairs are ordered, i.e. the space for pair (A,V) isn't necessarily -the space for pair (V,A). They also index glyphs, and not characters.
  • -
- -
    -
  • -Kerning distances can be expressed in horizontal or vertical directions, -depending on layout and/or script. For example, some horizontal layouts -like arabic can make use of vertical kerning adjustments between successive -glyphs. A vertical script can have vertical kerning distances.
  • -
- -
    -
  • -Kerning distances are expressed in grid units. They are usually oriented -in the X axis, which means that a negative value indicates that two glyphs -must be set closer in a horizontal layout.
  • -
-
-
- -

-2. Applying kerning

- -
Applying kerning when rendering text is a rather easy process. -It merely consists in adding the scaled kern distance to the pen position -before writing each next glyph. However, the typographically correct renderer -must take a few more details in consideration. -

The "sliding dot" problem is a good example : many font faces include -a kerning distance between capital letters like "T" or "F" and a following -dot ("."), in order to slide the latter glyph just right to their main -leg. I.e. -

-

+

+ Copyright 1998-2000 David Turner (david@freetype.org)
+ Copyright 2000 The FreeType Development Team (devel@freetype.org) +

-

However, this sometimes requires additional adjustments between the -dot and the letter following it, depending on the shapes of the enclosing -letters. When applying "standard" kerning adjustments, the previous sentence -would become :

-

- -

Which clearly is too contracted. The solution here, as exhibited in -the first example is to only slide the dots when possible. Of course, this -requires a certain knowledge of the text's meaning. The above adjustments -would not necessarily be welcomed if we were rendering the final dot of -a given paragraph. -

This is only one example, and there are many others showing that a real -typographer is needed to layout text properly. If not available, some kind -of user interaction or tagging of the text could be used to specify some -adjustments, but in all cases, this requires some support in applications -and text libraries. -

For more mundane and common uses, however, we can have a very simple -algorithm, which  avoids the sliding dot problem, and others, though -not producing optimal results. It can be seen as : -
  -

-
    -
  1. -place the first glyph on the baseline
  2. - -
  3. -save the location of the pen position/origin in pen1
  4. - -
  5. -adjust the pen position with the kerning distance between the first and -second glyph
  6. - -
  7. -place the second glyph and compute the next pen position/origin in pen2.
  8. - -
  9. -use pen1 as the next pen position if it is beyond pen2, use pen2 otherwise.
  10. -
-
-
- - -
- - - -
-Previous - -Contents - -Next -
- -
+ + +
+ +
+ + + + + + +
+ Previous + + Contents + + Next +
+
+ +


+ + + +
+

+ IV. Kerning +

+
+ +

The term kerning refers to specific information used to + adjust the relative positions of coincident glyphs in a string of text. + This section describes several types of kerning information, as well as + the way to process them when performing text layout.

+ + + +

+ 1. Kerning pairs +

+ +

Kerning consists in modifying the spacing between two successive + glyphs according to their outlines. For example, a "T" and a "y" can be + easily moved closer, as the top of the "y" fits nicely under the upper + right bar of the "T".

+ +

When laying out text with only their standard widths, some + consecutive glyphs seem a bit too close or too distant. For example, + the space between the "A" and the "V" in the following word seems a + little wider than needed.

+ +

+ the word 'bravo' unkerned +

+ +

Compare this to the same word, where the distance between these two + letters has been slightly reduced:

+ +

+ the word 'bravo' with kerning +

+ +

As you can see, this adjustment can make a great difference. Some + font faces thus include a table containing kerning distances for a set + of given glyph pairs for text layout.

+ +
    +
  • +

    The pairs are ordered, i.e., the space for pair (A,V) isn't + necessarily the space for pair (V,A). They also index glyphs, and + not characters.

    +
  • +
  • +

    Kerning distances can be expressed in horizontal or vertical + directions, depending on layout and/or script. For example, some + horizontal layouts like Arabic can make use of vertical kerning + adjustments between successive glyphs. A vertical script can have + vertical kerning distances.

    +
  • +
  • +

    Kerning distances are expressed in grid units. They are usually + oriented in the X axis, which means that a negative + value indicates that two glyphs must be set closer in a horizontal + layout.

    +
  • +
+ + +
+

+ 2. Applying kerning +

+ +

Applying kerning when rendering text is a rather easy process. It + merely consists in adding the scaled kern distance to the pen position + before writing each next glyph. However, the typographically correct + renderer must take a few more details in consideration.

+ +

The "sliding dot" problem is a good example: Many font faces include + a kerning distance between capital letters like "T" or "F" and a + following dot ("."), in order to slide the latter glyph just right to + their main leg:

+ +

+ example for sliding dots +

+ +

This sometimes requires additional adjustments between the dot and + the letter following it, depending on the shapes of the enclosing + letters. When applying "standard" kerning adjustments, the previous + sentence would become:

+ +

+ example for too much kerning +

+ +

This is clearly too contracted. The solution here, as exhibited in + the first example, is to only slide the dots when possible. Of course, + this requires a certain knowledge of the text's meaning. The above + adjustments would not necessarily be welcome if we were rendering the + final dot of a given paragraph.This is only one example, and there are many others showing that a + real typographer is needed to layout text properly. If not available, + some kind of user interaction or tagging of the text could be used to + specify some adjustments, but in all cases, this requires some support + in applications and text libraries.

+ +

For more mundane and common uses, however, we can have a very simple + algorithm, which avoids the sliding dot problem, and others, though not + producing optimal results. It can be seen as

+ +
    +
  1. + Place the first glyph on the baseline. +
  2. +
  3. + Save the location of the pen position/origin in pen1. +
  4. +
  5. + Adjust the pen position with the kerning distance between the first + and second glyph. +
  6. +
  7. + Place the second glyph and compute the next pen position/origin in + pen2. +
  8. +
  9. + Use pen1 as the next pen position if it is beyond + pen2, use pen2 otherwise. +
  10. +
+ + +


+ +
+ + + + + + +
+ Previous + + Contents + + Next +
+
+ +
+ diff --git a/docs/glyphs/glyphs-5.html b/docs/glyphs/glyphs-5.html index deac4ead5..11acbc7bf 100644 --- a/docs/glyphs/glyphs-5.html +++ b/docs/glyphs/glyphs-5.html @@ -1,12 +1,13 @@ - + - - - - FreeType Glyph Conventions + + + FreeType Glyph Conventions - -

-FreeType Glyph Conventions -

- -

-version 2.1 -

- -

-Copyright 1998-2000 David Turner (david@freetype.org)
-Copyright 2000 The FreeType Development Team (devel@freetype.org) -

- -
- -
- - - -
-Previous - -Contents - -Next -
- -

-V. Text processing -

- -

This section demonstrates how to use the concepts previously -defined to render text, whatever the layout you use. -

- - -

-1. Writing simple text strings : -

- -

In this first example, we'll generate a simple string of Roman -text, i.e. with a horizontal left-to-right layout. Using exclusively pixel -metrics, the process looks like : -

1) convert the character string into a series of glyph -indexes. -
2) place the pen to the cursor position. -
3) get or load the glyph image. -
4) translate the glyph so that its 'origin' matches the pen position -
5) render the glyph to the target device -
6) increment the pen position by the glyph's advance width in pixels -
7) start over at step 3 for each of the remaining glyphs -
8) when all glyphs are done, set the text cursor to the new pen -position
-Note that kerning isn't part of this algorithm.
- -

-2. Sub-pixel positioning :

- -
It is somewhat useful to use sub-pixel positioning when rendering -text. This is crucial, for example, to provide semi-WYSIWYG text layouts. -Text rendering is very similar to the algorithm described in sub-section -1, with the following few differences : -
    -
  • -The pen position is expressed in fractional pixels.
  • - -
  • -Because translating a hinted outline by a non-integer distance will ruin -its grid-fitting, the position of the glyph origin must be rounded before -rendering the character image.
  • - -
  • -The advance width is expressed in fractional pixels, and isn't necessarily -an integer.
  • -
- -


Which finally looks like : -

1. convert the character string into a series of glyph -indexes. -
2. place the pen to the cursor position. This can be a non-integer -point. -
3. get or load the glyph image. -
4. translate the glyph so that its 'origin' matches the rounded -pen position. -
5. render the glyph to the target device -
6. increment the pen position by the glyph's advance width in fractional -pixels. -
7. start over at step 3 for each of the remaining glyphs -
8. when all glyphs are done, set the text cursor to the new pen -position
-Note that with fractional pixel positioning, the space between two given -letters isn't fixed, but determined by the accumulation of previous rounding -errors in glyph positioning.
- -

-3.  Simple kerning :

- -
Adding kerning to the basic text rendering algorithm is easy -: when a kerning pair is found, simply add the scaled kerning distance -to the pen position before step 4. Of course, the distance should be rounded -in the case of algorithm 1, though it doesn't need to for algorithm 2. -This gives us : -

Algorithm 1 with kerning: -

3) get or load the glyph image. -
4) Add the rounded scaled kerning distance, if any, to the pen -position -
5) translate the glyph so that its 'origin' matches the pen position -
6) render the glyph to the target device -
7) increment the pen position by the glyph's advance width in pixels -
8) start over at step 3 for each of the remaining glyphs
- -


Algorithm 2 with kerning: -

3) get or load the glyph image. -
4) Add the scaled unrounded kerning distance, if any, to the pen -position. -
5) translate the glyph so that its 'origin' matches the rounded -pen position. -
6) render the glyph to the target device -
7) increment the pen position by the glyph's advance width in fractional -pixels. -
8) start over at step 3 for each of the remaining glyphs
-Of course, the algorithm described in section IV can also be applied to -prevent the sliding dot problem if one wants to..
- -

-4. Right-To-Left Layout :

- -
The process of laying out arabic or hebrew text is extremely -similar. The only difference is that the pen position must be decremented -before the glyph rendering (remember : the advance width is always positive, -even for arabic glyphs). Thus, algorithm 1 becomes : -

Right-to-left Algorithm 1: -

3) get or load the glyph image. -
4) Decrement the pen position by the glyph's advance width in pixels -
5) translate the glyph so that its 'origin' matches the pen position -
6) render the glyph to the target device -
7) start over at step 3 for each of the remaining glyphs
- -


The changes to Algorithm 2, as well as the inclusion of kerning -are left as an exercise to the reader. -
  -
 

- -

-5. Vertical layouts :

- -
Laying out vertical text uses exactly the same processes, with -the following significant differences : -
  -
-
  • -The baseline is vertical, and the vertical metrics must be used instead -of the horizontal one.
  • - -
  • -The left bearing is usually negative, but this doesn't change the fact -that the glyph origin must be located on the baseline.
  • - -
  • -The advance height is always positive, so the pen position must be decremented -if one wants to write top to bottom (assuming the Y axis is oriented upwards).
  • -
    -Through the following algorithm : -
    1) convert the character string into a series of glyph -indexes. -
    2) place the pen to the cursor position. -
    3) get or load the glyph image. -
    4) translate the glyph so that its 'origin' matches the pen position -
    5) render the glyph to the target device -
    6) decrement the vertical pen position by the glyph's advance height -in pixels -
    7) start over at step 3 for each of the remaining glyphs -
    8) when all glyphs are done, set the text cursor to the new pen -position
    -
    - -

    -6. WYSIWYG text layouts :

    - -
    As you probably know, the acronym WYSIWYG stands for 'What -You See Is What You Get'. Basically, this means that the output of -a document on the screen should match "perfectly" its printed version. -A true wysiwyg system requires two things : -

    device-independent text layout -

    Which means that the document's formatting is the same on the -screen than on any printed output, including line breaks, justification, -ligatures, fonts, position of inline images, etc..
    - -


    matching display and print character sizes -

    Which means that the displayed size of a given character should -match its dimensions when printed. For example, a text string which is -exactly 1 inch tall when printed should also appear 1 inch tall on the -screen (when using a scale of 100%).
    - -


    It is clear that matching sizes cannot be possible if the computer -has no knowledge of the physical resolutions of the display device(s) it -is using. And of course, this is the most common case ! That's not too -unfortunate, however  because most users really don't care about this -feature. Legibility is much more important. -

    When the Mac appeared, Apple decided to choose a resolution of 72 dpi -to describe the Macintosh screen to the font sub-system (whatever the monitor -used). This choice was most probably driven by the fact that, at this resolution, -1 point = 1 pixel. However; it neglected one crucial fact : as most users -tend to choose a document character size between 10 and 14 points, the -resultant displayed text was rather small and not too legible without scaling. -Microsoft engineers took notice of this problem and chose a resolution -of 96 dpi on Windows, which resulted in slightly larger, and more legible, -displayed characters (for the same printed text size). -

    These distinct resolutions explain some differences when displaying -text at the same character size on a Mac and a Windows machine. Moreover, -it is not unusual to find some TrueType fonts with enhanced hinting (tech -note: through delta-hinting) for the sizes of 10, 12, 14 and 16 points -at 96 dpi. -
      -

    As for device-independent text, it is a notion that is, unfortunately, -often abused. For example, many word processors, including MS Word, do -not really use device-independent glyph positioning algorithms when laying -out text. Rather, they use the target printer's resolution to compute hinted -glyph metrics for the layout. Though it guarantees that the printed version -is always the "nicest" it can be, especially for very low resolution printers -(like dot-matrix), it has a very sad effect : changing the printer can -have dramatic effects on the whole document layout, especially if -it makes strong use of justification, uses few page breaks, etc.. -

    Because the glyph metrics vary slightly when the resolution changes -(due to hinting), line breaks can change enormously, when these differences -accumulate over long runs of text. Try for example printing a very long -document (with no page breaks) on a 300 dpi ink-jet printer, then the same -one on a 3000 dpi laser printer : you'll be extremely lucky if your final -page count didn't change between the prints ! Of course, we can still call -this WYSIWYG, as long as the printer resolution is fixed !! -

    Some applications, like Adobe Acrobat, which targeted device-independent -placement from the start, do not suffer from this problem. There are two -ways to achieve this : either use the scaled and unhinted glyph metrics -when laying out text both in the rendering and printing processes, or simply -use wathever metrics you want and store them with the text in order to -get sure they're printed the same on all devices (the latter being probably -the best solution, as it also enables font substitution without breaking -text layouts). -

    Just like matching sizes, device-independent placement isn't necessarily -a feature that most users want. However, it is pretty clear that for any -kind of professional document processing work, it is a requirement.

    - - -
    - - - -
    -Previous - -Contents - -Next -
    - -
    +

    + FreeType Glyph Conventions +

    + +

    + Version 2.1 +

    + +

    + Copyright 1998-2000 David Turner (david@freetype.org)
    + Copyright 2000 The FreeType Development Team (devel@freetype.org) +

    + +
    + + +
    + +
    + + + + + + +
    + Previous + + Contents + + Next +
    +
    + +


    + + + +
    +

    + V. Text processing +

    +
    + +

    This section demonstrates how to use the concepts previously defined + to render text, whatever the layout you use.

    + + + +

    + 1. Writing simple text strings +

    + +

    In this first example, we will generate a simple string of Roman + text, i.e. with a horizontal left-to-right layout. Using exclusively + pixel metrics, the process looks like: + + +

      +
    1. + Convert the character string into a series of glyph + indices. +
    2. +
    3. + Place the pen to the cursor position. +
    4. +
    5. + Get or load the glyph image. +
    6. +
    7. + Translate the glyph so that its 'origin' matches the pen position. +
    8. +
    9. + Render the glyph to the target device. +
    10. +
    11. + Increment the pen position by the glyph's advance width in pixels. +
    12. +
    13. + Start over at step 3 for each of the remaining glyphs. +
    14. +
    15. + When all glyphs are done, set the text cursor to the new pen + position. +
    16. +
    + + +

    Note that kerning isn't part of this algorithm.

    + + +
    +

    + 2. Sub-pixel positioning +

    + +

    It is somewhat useful to use sub-pixel positioning when rendering + text. This is crucial, for example, to provide semi-WYSIWYG text + layouts. Text rendering is very similar to the algorithm described in + subsection 1, with the following few differences:

    + +
    +