OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "platform/fonts/CharacterRange.h" | 28 #include "platform/fonts/CharacterRange.h" |
29 #include "platform/fonts/SimpleFontData.h" | 29 #include "platform/fonts/SimpleFontData.h" |
30 #include "platform/fonts/shaping/CachingWordShapeIterator.h" | 30 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
31 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 31 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
32 #include "platform/fonts/shaping/ShapeCache.h" | 32 #include "platform/fonts/shaping/ShapeCache.h" |
33 #include "platform/fonts/shaping/ShapeResultBuffer.h" | 33 #include "platform/fonts/shaping/ShapeResultBuffer.h" |
34 #include "wtf/text/CharacterNames.h" | 34 #include "wtf/text/CharacterNames.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 float CachingWordShaper::width(const Font* font, | 38 ShapeCache* CachingWordShaper::shapeCache() const { |
39 const TextRun& run, | 39 return m_font.m_fontFallbackList->shapeCache(m_font.m_fontDescription); |
| 40 } |
| 41 |
| 42 float CachingWordShaper::width(const TextRun& run, |
40 HashSet<const SimpleFontData*>* fallbackFonts, | 43 HashSet<const SimpleFontData*>* fallbackFonts, |
41 FloatRect* glyphBounds) { | 44 FloatRect* glyphBounds) { |
42 float width = 0; | 45 float width = 0; |
43 RefPtr<const ShapeResult> wordResult; | 46 RefPtr<const ShapeResult> wordResult; |
44 CachingWordShapeIterator iterator(m_shapeCache, run, font); | 47 CachingWordShapeIterator iterator(shapeCache(), run, &m_font); |
45 while (iterator.next(&wordResult)) { | 48 while (iterator.next(&wordResult)) { |
46 if (wordResult) { | 49 if (wordResult) { |
47 if (glyphBounds) { | 50 if (glyphBounds) { |
48 FloatRect adjustedBounds = wordResult->bounds(); | 51 FloatRect adjustedBounds = wordResult->bounds(); |
49 // Translate glyph bounds to the current glyph position which | 52 // Translate glyph bounds to the current glyph position which |
50 // is the total width before this glyph. | 53 // is the total width before this glyph. |
51 adjustedBounds.setX(adjustedBounds.x() + width); | 54 adjustedBounds.setX(adjustedBounds.x() + width); |
52 glyphBounds->unite(adjustedBounds); | 55 glyphBounds->unite(adjustedBounds); |
53 } | 56 } |
54 width += wordResult->width(); | 57 width += wordResult->width(); |
55 if (fallbackFonts) | 58 if (fallbackFonts) |
56 wordResult->fallbackFonts(fallbackFonts); | 59 wordResult->fallbackFonts(fallbackFonts); |
57 } | 60 } |
58 } | 61 } |
59 | 62 |
60 return width; | 63 return width; |
61 } | 64 } |
62 | 65 |
63 static inline float shapeResultsForRun( | 66 static inline float shapeResultsForRun( |
64 ShapeCache* shapeCache, | 67 ShapeCache* shapeCache, |
65 const Font* font, | 68 const Font* font, |
66 const TextRun& run, | 69 const TextRun& run, |
67 HashSet<const SimpleFontData*>* fallbackFonts, | |
68 ShapeResultBuffer* resultsBuffer) { | 70 ShapeResultBuffer* resultsBuffer) { |
69 CachingWordShapeIterator iterator(shapeCache, run, font); | 71 CachingWordShapeIterator iterator(shapeCache, run, font); |
70 RefPtr<const ShapeResult> wordResult; | 72 RefPtr<const ShapeResult> wordResult; |
71 float totalWidth = 0; | 73 float totalWidth = 0; |
72 while (iterator.next(&wordResult)) { | 74 while (iterator.next(&wordResult)) { |
73 if (wordResult) { | 75 if (wordResult) { |
74 totalWidth += wordResult->width(); | 76 totalWidth += wordResult->width(); |
75 if (fallbackFonts) | |
76 wordResult->fallbackFonts(fallbackFonts); | |
77 resultsBuffer->appendResult(std::move(wordResult)); | 77 resultsBuffer->appendResult(std::move(wordResult)); |
78 } | 78 } |
79 } | 79 } |
80 return totalWidth; | 80 return totalWidth; |
81 } | 81 } |
82 | 82 |
83 int CachingWordShaper::offsetForPosition(const Font* font, | 83 int CachingWordShaper::offsetForPosition(const TextRun& run, |
84 const TextRun& run, | |
85 float targetX, | 84 float targetX, |
86 bool includePartialGlyphs) { | 85 bool includePartialGlyphs) { |
87 ShapeResultBuffer buffer; | 86 ShapeResultBuffer buffer; |
88 shapeResultsForRun(m_shapeCache, font, run, nullptr, &buffer); | 87 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
89 | 88 |
90 return buffer.offsetForPosition(run, targetX, includePartialGlyphs); | 89 return buffer.offsetForPosition(run, targetX, includePartialGlyphs); |
91 } | 90 } |
92 | 91 |
93 float CachingWordShaper::fillGlyphBuffer( | 92 float CachingWordShaper::fillGlyphBuffer( |
94 const Font* font, | |
95 const TextRun& run, | 93 const TextRun& run, |
96 HashSet<const SimpleFontData*>* fallbackFonts, | |
97 GlyphBuffer* glyphBuffer, | 94 GlyphBuffer* glyphBuffer, |
98 unsigned from, | 95 unsigned from, |
99 unsigned to) { | 96 unsigned to) { |
100 ShapeResultBuffer buffer; | 97 ShapeResultBuffer buffer; |
101 shapeResultsForRun(m_shapeCache, font, run, fallbackFonts, &buffer); | 98 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
102 | 99 |
103 return buffer.fillGlyphBuffer(glyphBuffer, run, from, to); | 100 return buffer.fillGlyphBuffer(glyphBuffer, run, from, to); |
104 } | 101 } |
105 | 102 |
106 float CachingWordShaper::fillGlyphBufferForTextEmphasis( | 103 float CachingWordShaper::fillGlyphBufferForTextEmphasis( |
107 const Font* font, | |
108 const TextRun& run, | 104 const TextRun& run, |
109 const GlyphData* emphasisData, | 105 const GlyphData* emphasisData, |
110 GlyphBuffer* glyphBuffer, | 106 GlyphBuffer* glyphBuffer, |
111 unsigned from, | 107 unsigned from, |
112 unsigned to) { | 108 unsigned to) { |
113 ShapeResultBuffer buffer; | 109 ShapeResultBuffer buffer; |
114 shapeResultsForRun(m_shapeCache, font, run, nullptr, &buffer); | 110 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
115 | 111 |
116 return buffer.fillGlyphBufferForTextEmphasis(glyphBuffer, run, emphasisData, | 112 return buffer.fillGlyphBufferForTextEmphasis(glyphBuffer, run, emphasisData, |
117 from, to); | 113 from, to); |
118 } | 114 } |
119 | 115 |
120 CharacterRange CachingWordShaper::getCharacterRange(const Font* font, | 116 CharacterRange CachingWordShaper::getCharacterRange(const TextRun& run, |
121 const TextRun& run, | |
122 unsigned from, | 117 unsigned from, |
123 unsigned to) { | 118 unsigned to) { |
124 ShapeResultBuffer buffer; | 119 ShapeResultBuffer buffer; |
125 float totalWidth = | 120 float totalWidth = |
126 shapeResultsForRun(m_shapeCache, font, run, nullptr, &buffer); | 121 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
127 | 122 |
128 return buffer.getCharacterRange(run.direction(), totalWidth, from, to); | 123 return buffer.getCharacterRange(run.direction(), totalWidth, from, to); |
129 } | 124 } |
130 | 125 |
131 Vector<CharacterRange> CachingWordShaper::individualCharacterRanges( | 126 Vector<CharacterRange> CachingWordShaper::individualCharacterRanges( |
132 const Font* font, | |
133 const TextRun& run) { | 127 const TextRun& run) { |
134 ShapeResultBuffer buffer; | 128 ShapeResultBuffer buffer; |
135 float totalWidth = | 129 float totalWidth = |
136 shapeResultsForRun(m_shapeCache, font, run, nullptr, &buffer); | 130 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
137 | 131 |
138 auto ranges = buffer.individualCharacterRanges(run.direction(), totalWidth); | 132 auto ranges = buffer.individualCharacterRanges(run.direction(), totalWidth); |
139 // The shaper can fail to return glyph metrics for all characters (see | 133 // The shaper can fail to return glyph metrics for all characters (see |
140 // crbug.com/613915 and crbug.com/615661) so add empty ranges to ensure all | 134 // crbug.com/613915 and crbug.com/615661) so add empty ranges to ensure all |
141 // characters have an associated range. | 135 // characters have an associated range. |
142 while (ranges.size() < static_cast<unsigned>(run.length())) | 136 while (ranges.size() < static_cast<unsigned>(run.length())) |
143 ranges.push_back(CharacterRange(0, 0)); | 137 ranges.push_back(CharacterRange(0, 0)); |
144 return ranges; | 138 return ranges; |
145 } | 139 } |
146 | 140 |
| 141 Vector<ShapeResultBuffer::RunFontData> CachingWordShaper::runFontData( |
| 142 const TextRun& run) const { |
| 143 ShapeResultBuffer buffer; |
| 144 shapeResultsForRun(shapeCache(), &m_font, run, &buffer); |
| 145 |
| 146 return buffer.runFontData(); |
| 147 } |
| 148 |
147 }; // namespace blink | 149 }; // namespace blink |
OLD | NEW |