Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/README.md

Issue 2601953002: Start documentation of text stack in platform/fonts (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Blink's Text Stack #
2
3 This README serves as an documentation entry point of Blink's text stack.
4
5 This README can be viewed in formatted form [here](https://chromium.googlesource .com/chromium/src/+/master/third_party/WebKit/Source/platform/fonts/README.md).
6
7 ## Overview ##
8
9 Blink's text stack covers those functional parts of the layout engine that
10 process CSS-styled HTML text. From source document to visual output this rougly
11 comprises the following stages:
12
13 * [Processing CSS style information into a font definition](#Mapping-CSS-Style-t o-Font-Objects)
14 * [Using this font definition for matching against available web and system font s](#Font-Matching)
15 * [Segmenting text into portions suitable for shaping](#Run-Segmentation)
16 * [Looking up elements from the previously shaped entries in the word cache](#Wo rd-Cache)
17 * [Using the matched font for shaping and mapping from characters to glyphs](#Te xt-Shaping)
18 * [Font fallback](#Font-Fallback)
19
20 ## Mapping CSS Style to Font Objects ##
21
22 TODO(drott): Describe steps from `ComputedStyle`, `FontBuilder` to
23 `FontDescription` and `Font` objects.
24
25 ## Font Matching ##
26
27 TODO(drott): Describe font matching against system fonts in platform specific
28 implementations as well as matching against web fonts in `FontStyleMatcher`.
29
30 ## Word Cache ##
31
32 TODO(drott,eae): Describe at which level the word cache hooks in, how the cache
33 keys are calculated and its approach of word and CJK segmentation.
34
35 ## Run Segmentation ##
36
37 TODO(drott): Describe purpose and run segmentation approach of `RunSegmenter`.
38
39 ## Text Shaping ##
40
41 The low level shaping implementation is
42 in
43 [shaping/HarfBuzzShaper.h](https://cs.chromium.org/chromium/src/third_party/WebK it/Source/platform/fonts/shaping/HarfBuzzShaper.h) and
44 [shaping/HarfBuzzShaper.cpp](https://cs.chromium.org/chromium/src/third_party/We bKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp)
45
46 Shaping text runs is split into several
47 stages: [Run segmentation](#Run-Segmentation), shaping the initial segment,
48 identify shaped and non-shaped sequences of the shaping result, and processing
49 sub-runs by trying to shape them with a fallback font until the last resort font
50 is reached.
51
52 If caps formatting is requested, an additional lowercase/uppercase
53 segmentation stage is required. In this stage, OpenType features in the font
54 are matched against the requested formatting and formatting is synthesized as
55 required by the CSS Level 3 Fonts Module.
56
57 Below we will go through one example - for simplicity without caps formatting -
58 to illustrate the process: The following is a run of vertical text to be
59 shaped. After run segmentation in `RunSegmenter` it is split into 4 segments. Th e
60 segments indicated by the segementation results showing the script, orientation
61 information and small caps handling of the individual segment. The Japanese text
62 at the beginning has script "Hiragana", does not need rotation when laid out
63 vertically and does not need uppercasing when small caps is requested.
64
65 ```
66 0 い
67 1 ろ
68 2 は USCRIPT_HIRAGANA,
69 OrientationIterator::OrientationKeep,
70 SmallCapsIterator::SmallCapsSameCase
71
72 3 a
73 4 ̄ (Combining Macron)
74 5 a
75 6 A USCRIPT_LATIN,
76 OrientationIterator::OrientationRotateSideways,
77 SmallCapsIterator::SmallCapsUppercaseNeeded
78
79 7 い
80 8 ろ
81 9 は USCRIPT_HIRAGANA,
82 OrientationIterator::OrientationKeep,
83 SmallCapsIterator::SmallCapsSameCase
84 ```
85
86 Let's assume the CSS for this text run is as follows:
87 `font-family: "Heiti SC", Tinos, sans-serif;`
88 where Tinos is a web font, defined as a composite font, with two sub ranges,
89 one for Latin `U+00-U+FF` and one unrestricted unicode-range.
90
91 `FontFallbackIterator` provides the shaper with Heiti SC, then Tinos of the
92 restricted unicode-range, then the unrestricted full unicode-range Tinos,
93 then a system sans-serif.
94
95 The initial segment 0-2 to the shaper, together with the segmentation
96 properties and the initial Heiti SC font. Characters 0-2 are shaped
97 successfully with Heiti SC. The next segment, 3-5 is passed to the shaper.
98 The shaper attempts to shape it with Heiti SC, which fails for the Combining
99 Macron. So the shaping result for this segment would look similar to this.
100
101 ```
102 Glyphpos: 0 1 2 3
103 Cluster: 0 0 2 3
104 Glyph: a x a A (where x is .notdef)
105 ```
106
107 Now in the `extractShapeResults()` step we notice that there is more work to
108 do, since Heiti SC does not have a glyph for the Combining Macron combined
109 with an a. So, this cluster together with a Todo item for switching to the
110 next font is put into `HolesQueue`.
111
112 After shaping the initial segment, the remaining items in the `HolesQueue` are
113 processed, picking them from the head of the queue. So, first, the next font is
114 requested from the `FontFallbackIterator`. In this case, Tinos (for the range
115 `U+00-U+FF`) comes back. Shaping using this font, assuming it is subsetted,
116 fails again since there is no combining mark available. This triggers requesting
117 yet another font. This time, the Tinos font for the full range. With this,
118 shaping succeeds with the following HarfBuzz result:
119
120 ```
121 Glyphpos 0 1 2 3
122 Cluster: 0 0 2 3
123 Glyph: a ◌̄ a A (with glyph coordinates placing the ◌̄ above the first a)
124 ```
125
126 Now this sub run is successfully processed and can be appended to
127 `ShapeResult`. A new `ShapeResult::RunInfo` is created. The logic in
128 `ShapeResult::insertRun` then takes care of merging the shape result into the
129 right position the vector of `RunInfo`s in `ShapeResult`.
130
131 Shaping then continues analogously for the remaining Hiragana Japanese sub-run,
132 and the result is inserted into `ShapeResult` as well.
133
134 ## Font Fallback ##
135
136 TODO(drott): Describe when font fallback is invoked, and how
137 `FontFallbackIterator` cycles through fallback fonts during shaping.
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698