OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include <hb.h> | 39 #include <hb.h> |
40 #include <memory> | 40 #include <memory> |
41 #include <unicode/uscript.h> | 41 #include <unicode/uscript.h> |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 class Font; | 45 class Font; |
46 class SimpleFontData; | 46 class SimpleFontData; |
47 class HarfBuzzShaper; | 47 class HarfBuzzShaper; |
48 | 48 |
49 // Shaping text runs is split into several stages: Run segmentation, shaping the | |
50 // initial segment, identify shaped and non-shaped sequences of the shaping | |
51 // result, and processing sub-runs by trying to shape them with a fallback font | |
52 // until the last resort font is reached. | |
53 // | |
54 // If caps formatting is requested, an additional lowercase/uppercase | |
55 // segmentation stage is required. In this stage, OpenType features in the font | |
56 // are matched against the requested formatting and formatting is synthesized as | |
57 // required by the CSS Level 3 Fonts Module. | |
58 // | |
59 // Going through one example - for simplicity without caps formatting - to | |
60 // illustrate the process: The following is a run of vertical text to be | |
61 // shaped. After run segmentation in RunSegmenter it is split into 4 | |
62 // segments. The segments indicated by the segementation results showing the | |
63 // script, orientation information and small caps handling of the individual | |
64 // segment. The Japanese text at the beginning has script "Hiragana", does not | |
65 // need rotation when laid out vertically and does not need uppercasing when | |
66 // small caps is requested. | |
67 // | |
68 // 0 い | |
69 // 1 ろ | |
70 // 2 は USCRIPT_HIRAGANA, | |
71 // OrientationIterator::OrientationKeep, | |
72 // SmallCapsIterator::SmallCapsSameCase | |
73 // | |
74 // 3 a | |
75 // 4 ̄ (Combining Macron) | |
76 // 5 a | |
77 // 6 A USCRIPT_LATIN, | |
78 // OrientationIterator::OrientationRotateSideways, | |
79 // SmallCapsIterator::SmallCapsUppercaseNeeded | |
80 // | |
81 // 7 い | |
82 // 8 ろ | |
83 // 9 は USCRIPT_HIRAGANA, | |
84 // OrientationIterator::OrientationKeep, | |
85 // SmallCapsIterator::SmallCapsSameCase | |
86 // | |
87 // | |
88 // Let's assume the CSS for this text run is as follows: | |
89 // font-family: "Heiti SC", Tinos, sans-serif; | |
90 // where Tinos is a web font, defined as a composite font, with two sub ranges, | |
91 // one for Latin U+00-U+FF and one unrestricted unicode-range. | |
92 // | |
93 // FontFallbackIterator provides the shaper with Heiti SC, then Tinos of the | |
94 // restricted unicode-range, then the unrestricted full unicode-range Tinos, | |
95 // then a system sans-serif. | |
96 // | |
97 // The initial segment 0-2 to the shaper, together with the segmentation | |
98 // properties and the initial Heiti SC font. Characters 0-2 are shaped | |
99 // successfully with Heiti SC. The next segment, 3-5 is passed to the shaper. | |
100 // The shaper attempts to shape it with Heiti SC, which fails for the Combining | |
101 // Macron. So the shaping result for this segment would look similar to this. | |
102 // | |
103 // Glyphpos: 0 1 2 3 | |
104 // Cluster: 0 0 2 3 | |
105 // Glyph: a x a A (where x is .notdef) | |
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 | |
114 // is requested from the FontFallbackIterator. In this case, Tinos (for the | |
115 // range U+00-U+FF) comes back. Shaping using this font, assuming it is | |
116 // subsetted, fails again since there is no combining mark available. This | |
117 // triggers requesting yet another font. This time, the Tinos font for the full | |
118 // range. With this, shaping succeeds with the following HarfBuzz result: | |
119 // | |
120 // Glyphpos 0 1 2 3 | |
121 // Cluster: 0 0 2 3 | |
122 // Glyph: a ̄ a A (with glyph coordinates placing the ̄ above the first a) | |
123 // | |
124 // Now this sub run is successfully processed and can be appended to | |
125 // ShapeResult. A new ShapeResult::RunInfo is created. The logic in | |
126 // insertRunIntoShapeResult then takes care of merging the shape result into | |
127 // the right position the vector of RunInfos in ShapeResult. | |
128 // | |
129 // Shaping then continues analogously for the remaining Hiragana Japanese | |
130 // sub-run, and the result is inserted into ShapeResult as well. | |
131 class PLATFORM_EXPORT HarfBuzzShaper final { | 49 class PLATFORM_EXPORT HarfBuzzShaper final { |
132 public: | 50 public: |
133 HarfBuzzShaper(const UChar*, unsigned length, TextDirection); | 51 HarfBuzzShaper(const UChar*, unsigned length, TextDirection); |
134 PassRefPtr<ShapeResult> shapeResult(const Font*) const; | 52 PassRefPtr<ShapeResult> shapeResult(const Font*) const; |
135 ~HarfBuzzShaper() {} | 53 ~HarfBuzzShaper() {} |
136 | 54 |
137 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange }; | 55 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange }; |
138 | 56 |
139 struct HolesQueueItem { | 57 struct HolesQueueItem { |
140 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 58 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
(...skipping 25 matching lines...) Expand all Loading... |
166 hb_buffer_t*); | 84 hb_buffer_t*); |
167 | 85 |
168 const UChar* m_normalizedBuffer; | 86 const UChar* m_normalizedBuffer; |
169 unsigned m_normalizedBufferLength; | 87 unsigned m_normalizedBufferLength; |
170 TextDirection m_textDirection; | 88 TextDirection m_textDirection; |
171 }; | 89 }; |
172 | 90 |
173 } // namespace blink | 91 } // namespace blink |
174 | 92 |
175 #endif // HarfBuzzShaper_h | 93 #endif // HarfBuzzShaper_h |
OLD | NEW |