• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "Minikin"
18 
19 #include "minikin/LayoutCore.h"
20 
21 #include <hb-icu.h>
22 #include <hb-ot.h>
23 #include <log/log.h>
24 #include <unicode/ubidi.h>
25 #include <unicode/utf16.h>
26 #include <utils/LruCache.h>
27 
28 #include <cmath>
29 #include <iostream>
30 #include <mutex>
31 #include <string>
32 #include <vector>
33 
34 #include "BidiUtils.h"
35 #include "FontFeatureUtils.h"
36 #include "LayoutUtils.h"
37 #include "LocaleListCache.h"
38 #include "MinikinInternal.h"
39 #include "minikin/Emoji.h"
40 #include "minikin/HbUtils.h"
41 #include "minikin/LayoutCache.h"
42 #include "minikin/LayoutPieces.h"
43 #include "minikin/Macros.h"
44 
45 namespace minikin {
46 
47 namespace {
48 
49 struct SkiaArguments {
50     const MinikinFont* font;
51     const MinikinPaint* paint;
52     FontFakery fakery;
53 };
54 
55 // Returns true if the character needs to be excluded for the line spacing.
isLineSpaceExcludeChar(uint16_t c)56 inline bool isLineSpaceExcludeChar(uint16_t c) {
57     return c == CHAR_LINE_FEED || c == CHAR_CARRIAGE_RETURN;
58 }
59 
harfbuzzGetGlyphHorizontalAdvance(hb_font_t *,void * fontData,hb_codepoint_t glyph,void *)60 static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* /* hbFont */, void* fontData,
61                                                        hb_codepoint_t glyph, void* /* userData */) {
62     SkiaArguments* args = reinterpret_cast<SkiaArguments*>(fontData);
63     float advance = args->font->GetHorizontalAdvance(glyph, *args->paint, args->fakery);
64     return 256 * advance + 0.5;
65 }
66 
harfbuzzGetGlyphHorizontalAdvances(hb_font_t *,void * fontData,unsigned int count,const hb_codepoint_t * first_glyph,unsigned glyph_stride,hb_position_t * first_advance,unsigned advance_stride,void *)67 static void harfbuzzGetGlyphHorizontalAdvances(hb_font_t* /* hbFont */, void* fontData,
68                                                unsigned int count,
69                                                const hb_codepoint_t* first_glyph,
70                                                unsigned glyph_stride, hb_position_t* first_advance,
71                                                unsigned advance_stride, void* /* userData */) {
72     SkiaArguments* args = reinterpret_cast<SkiaArguments*>(fontData);
73     std::vector<uint16_t> glyphVec(count);
74     std::vector<float> advVec(count);
75 
76     const hb_codepoint_t* glyph = first_glyph;
77     for (uint32_t i = 0; i < count; ++i) {
78         glyphVec[i] = *glyph;
79         glyph = reinterpret_cast<const hb_codepoint_t*>(reinterpret_cast<const uint8_t*>(glyph) +
80                                                         glyph_stride);
81     }
82 
83     args->font->GetHorizontalAdvances(glyphVec.data(), count, *args->paint, args->fakery,
84                                       advVec.data());
85 
86     hb_position_t* advances = first_advance;
87     for (uint32_t i = 0; i < count; ++i) {
88         *advances = HBFloatToFixed(advVec[i]);
89         advances = reinterpret_cast<hb_position_t*>(reinterpret_cast<uint8_t*>(advances) +
90                                                     advance_stride);
91     }
92 }
93 
harfbuzzGetGlyphHorizontalOrigin(hb_font_t *,void *,hb_codepoint_t,hb_position_t *,hb_position_t *,void *)94 static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* /* fontData */,
95                                                   hb_codepoint_t /* glyph */,
96                                                   hb_position_t* /* x */, hb_position_t* /* y */,
97                                                   void* /* userData */) {
98     // Just return true, following the way that Harfbuzz-FreeType implementation does.
99     return true;
100 }
101 
getFontFuncs()102 hb_font_funcs_t* getFontFuncs() {
103     static hb_font_funcs_t* fontFuncs = nullptr;
104     static std::once_flag once;
105     std::call_once(once, [&]() {
106         fontFuncs = hb_font_funcs_create();
107         // Override the h_advance function since we can't use HarfBuzz's implemenation. It may
108         // return the wrong value if the font uses hinting aggressively.
109         hb_font_funcs_set_glyph_h_advance_func(fontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0);
110         hb_font_funcs_set_glyph_h_advances_func(fontFuncs, harfbuzzGetGlyphHorizontalAdvances, 0,
111                                                 0);
112         hb_font_funcs_set_glyph_h_origin_func(fontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0);
113         hb_font_funcs_make_immutable(fontFuncs);
114     });
115     return fontFuncs;
116 }
117 
getFontFuncsForEmoji()118 hb_font_funcs_t* getFontFuncsForEmoji() {
119     static hb_font_funcs_t* fontFuncs = nullptr;
120     static std::once_flag once;
121     std::call_once(once, [&]() {
122         fontFuncs = hb_font_funcs_create();
123         // Don't override the h_advance function since we use HarfBuzz's implementation for emoji
124         // for performance reasons.
125         // Note that it is technically possible for a TrueType font to have outline and embedded
126         // bitmap at the same time. We ignore modified advances of hinted outline glyphs in that
127         // case.
128         hb_font_funcs_set_glyph_h_origin_func(fontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0);
129         hb_font_funcs_make_immutable(fontFuncs);
130     });
131     return fontFuncs;
132 }
133 
isColorBitmapFont(const HbFontUniquePtr & font)134 static bool isColorBitmapFont(const HbFontUniquePtr& font) {
135     HbBlob cbdt(font, HB_TAG('C', 'B', 'D', 'T'));
136     return cbdt;
137 }
138 
decodeUtf16(const uint16_t * chars,size_t len,ssize_t * iter)139 static hb_codepoint_t decodeUtf16(const uint16_t* chars, size_t len, ssize_t* iter) {
140     UChar32 result;
141     U16_NEXT(chars, *iter, (ssize_t)len, result);
142     if (U_IS_SURROGATE(result)) {  // isolated surrogate
143         result = 0xFFFDu;          // U+FFFD REPLACEMENT CHARACTER
144     }
145     return (hb_codepoint_t)result;
146 }
147 
getScriptRun(const uint16_t * chars,size_t len,ssize_t * iter)148 static hb_script_t getScriptRun(const uint16_t* chars, size_t len, ssize_t* iter) {
149     if (size_t(*iter) == len) {
150         return HB_SCRIPT_UNKNOWN;
151     }
152     uint32_t cp = decodeUtf16(chars, len, iter);
153     hb_unicode_funcs_t* unicode_func = hb_unicode_funcs_get_default();
154     hb_script_t current_script = hb_unicode_script(unicode_func, cp);
155     for (;;) {
156         if (size_t(*iter) == len) break;
157         const ssize_t prev_iter = *iter;
158         cp = decodeUtf16(chars, len, iter);
159         const hb_script_t script = hb_unicode_script(unicode_func, cp);
160         if (script != current_script) {
161             if (current_script == HB_SCRIPT_INHERITED || current_script == HB_SCRIPT_COMMON) {
162                 current_script = script;
163             } else if (script == HB_SCRIPT_INHERITED || script == HB_SCRIPT_COMMON) {
164                 continue;
165             } else {
166                 *iter = prev_iter;
167                 break;
168             }
169         }
170     }
171     if (current_script == HB_SCRIPT_INHERITED) {
172         current_script = HB_SCRIPT_COMMON;
173     }
174 
175     return current_script;
176 }
177 
178 /**
179  * Disable certain scripts (mostly those with cursive connection) from having letterspacing
180  * applied. See https://github.com/behdad/harfbuzz/issues/64 for more details.
181  */
isScriptOkForLetterspacing(hb_script_t script)182 static bool isScriptOkForLetterspacing(hb_script_t script) {
183     return !(script == HB_SCRIPT_ARABIC || script == HB_SCRIPT_NKO ||
184              script == HB_SCRIPT_PSALTER_PAHLAVI || script == HB_SCRIPT_MANDAIC ||
185              script == HB_SCRIPT_MONGOLIAN || script == HB_SCRIPT_PHAGS_PA ||
186              script == HB_SCRIPT_DEVANAGARI || script == HB_SCRIPT_BENGALI ||
187              script == HB_SCRIPT_GURMUKHI || script == HB_SCRIPT_MODI ||
188              script == HB_SCRIPT_SHARADA || script == HB_SCRIPT_SYLOTI_NAGRI ||
189              script == HB_SCRIPT_TIRHUTA || script == HB_SCRIPT_OGHAM);
190 }
191 
determineHyphenChar(hb_codepoint_t preferredHyphen,hb_font_t * font)192 static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) {
193     hb_codepoint_t glyph;
194     if (preferredHyphen == 0x058A    /* ARMENIAN_HYPHEN */
195         || preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */
196         || preferredHyphen == 0x1400 /* CANADIAN SYLLABIC HYPHEN */) {
197         if (hb_font_get_nominal_glyph(font, preferredHyphen, &glyph)) {
198             return preferredHyphen;
199         } else {
200             // The original hyphen requested was not supported. Let's try and see if the
201             // Unicode hyphen is supported.
202             preferredHyphen = CHAR_HYPHEN;
203         }
204     }
205     if (preferredHyphen == CHAR_HYPHEN) { /* HYPHEN */
206         // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for the preferred hyphen.
207         // Note that we intentionally don't do anything special if the font doesn't have a
208         // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something missing.
209         if (!hb_font_get_nominal_glyph(font, preferredHyphen, &glyph)) {
210             return 0x002D;  // HYPHEN-MINUS
211         }
212     }
213     return preferredHyphen;
214 }
215 
216 template <typename HyphenEdit>
addHyphenToHbBuffer(const HbBufferUniquePtr & buffer,const HbFontUniquePtr & font,HyphenEdit hyphen,uint32_t cluster)217 static inline void addHyphenToHbBuffer(const HbBufferUniquePtr& buffer, const HbFontUniquePtr& font,
218                                        HyphenEdit hyphen, uint32_t cluster) {
219     auto [chars, size] = getHyphenString(hyphen);
220     for (size_t i = 0; i < size; i++) {
221         hb_buffer_add(buffer.get(), determineHyphenChar(chars[i], font.get()), cluster);
222     }
223 }
224 
225 // Returns the cluster value assigned to the first codepoint added to the buffer, which can be used
226 // to translate cluster values returned by HarfBuzz to input indices.
addToHbBuffer(const HbBufferUniquePtr & buffer,const uint16_t * buf,size_t start,size_t count,size_t bufSize,ssize_t scriptRunStart,ssize_t scriptRunEnd,StartHyphenEdit inStartHyphen,EndHyphenEdit inEndHyphen,const HbFontUniquePtr & hbFont)227 static inline uint32_t addToHbBuffer(const HbBufferUniquePtr& buffer, const uint16_t* buf,
228                                      size_t start, size_t count, size_t bufSize,
229                                      ssize_t scriptRunStart, ssize_t scriptRunEnd,
230                                      StartHyphenEdit inStartHyphen, EndHyphenEdit inEndHyphen,
231                                      const HbFontUniquePtr& hbFont) {
232     // Only hyphenate the very first script run for starting hyphens.
233     const StartHyphenEdit startHyphen =
234             (scriptRunStart == 0) ? inStartHyphen : StartHyphenEdit::NO_EDIT;
235     // Only hyphenate the very last script run for ending hyphens.
236     const EndHyphenEdit endHyphen =
237             (static_cast<size_t>(scriptRunEnd) == count) ? inEndHyphen : EndHyphenEdit::NO_EDIT;
238 
239     // In the following code, we drop the pre-context and/or post-context if there is a
240     // hyphen edit at that end. This is not absolutely necessary, since HarfBuzz uses
241     // contexts only for joining scripts at the moment, e.g. to determine if the first or
242     // last letter of a text range to shape should take a joining form based on an
243     // adjacent letter or joiner (that comes from the context).
244     //
245     // TODO: Revisit this for:
246     // 1. Desperate breaks for joining scripts like Arabic (where it may be better to keep
247     //    the context);
248     // 2. Special features like start-of-word font features (not implemented in HarfBuzz
249     //    yet).
250 
251     // We don't have any start-of-line replacement edit yet, so we don't need to check for
252     // those.
253     if (isInsertion(startHyphen)) {
254         // A cluster value of zero guarantees that the inserted hyphen will be in the same
255         // cluster with the next codepoint, since there is no pre-context.
256         addHyphenToHbBuffer(buffer, hbFont, startHyphen, 0 /* cluster */);
257     }
258 
259     const uint16_t* hbText;
260     int hbTextLength;
261     unsigned int hbItemOffset;
262     unsigned int hbItemLength = scriptRunEnd - scriptRunStart;  // This is >= 1.
263 
264     const bool hasEndInsertion = isInsertion(endHyphen);
265     const bool hasEndReplacement = isReplacement(endHyphen);
266     if (hasEndReplacement) {
267         // Skip the last code unit while copying the buffer for HarfBuzz if it's a replacement. We
268         // don't need to worry about non-BMP characters yet since replacements are only done for
269         // code units at the moment.
270         hbItemLength -= 1;
271     }
272 
273     if (startHyphen == StartHyphenEdit::NO_EDIT) {
274         // No edit at the beginning. Use the whole pre-context.
275         hbText = buf;
276         hbItemOffset = start + scriptRunStart;
277     } else {
278         // There's an edit at the beginning. Drop the pre-context and start the buffer at where we
279         // want to start shaping.
280         hbText = buf + start + scriptRunStart;
281         hbItemOffset = 0;
282     }
283 
284     if (endHyphen == EndHyphenEdit::NO_EDIT) {
285         // No edit at the end, use the whole post-context.
286         hbTextLength = (buf + bufSize) - hbText;
287     } else {
288         // There is an edit at the end. Drop the post-context.
289         hbTextLength = hbItemOffset + hbItemLength;
290     }
291 
292     hb_buffer_add_utf16(buffer.get(), hbText, hbTextLength, hbItemOffset, hbItemLength);
293 
294     unsigned int numCodepoints;
295     hb_glyph_info_t* cpInfo = hb_buffer_get_glyph_infos(buffer.get(), &numCodepoints);
296 
297     // Add the hyphen at the end, if there's any.
298     if (hasEndInsertion || hasEndReplacement) {
299         // When a hyphen is inserted, by assigning the added hyphen and the last
300         // codepoint added to the HarfBuzz buffer to the same cluster, we can make sure
301         // that they always remain in the same cluster, even if the last codepoint gets
302         // merged into another cluster (for example when it's a combining mark).
303         //
304         // When a replacement happens instead, we want it to get the cluster value of
305         // the character it's replacing, which is one "codepoint length" larger than
306         // the last cluster. But since the character replaced is always just one
307         // code unit, we can just add 1.
308         uint32_t hyphenCluster;
309         if (numCodepoints == 0) {
310             // Nothing was added to the HarfBuzz buffer. This can only happen if
311             // we have a replacement that is replacing a one-code unit script run.
312             hyphenCluster = 0;
313         } else {
314             hyphenCluster = cpInfo[numCodepoints - 1].cluster + (uint32_t)hasEndReplacement;
315         }
316         addHyphenToHbBuffer(buffer, hbFont, endHyphen, hyphenCluster);
317         // Since we have just added to the buffer, cpInfo no longer necessarily points to
318         // the right place. Refresh it.
319         cpInfo = hb_buffer_get_glyph_infos(buffer.get(), nullptr /* we don't need the size */);
320     }
321     return cpInfo[0].cluster;
322 }
323 
324 }  // namespace
325 
LayoutPiece(const U16StringPiece & textBuf,const Range & range,bool isRtl,const MinikinPaint & paint,StartHyphenEdit startHyphen,EndHyphenEdit endHyphen)326 LayoutPiece::LayoutPiece(const U16StringPiece& textBuf, const Range& range, bool isRtl,
327                          const MinikinPaint& paint, StartHyphenEdit startHyphen,
328                          EndHyphenEdit endHyphen) {
329     const uint16_t* buf = textBuf.data();
330     const size_t start = range.getStart();
331     const size_t count = range.getLength();
332     const size_t bufSize = textBuf.size();
333 
334     mAdvances.resize(count, 0);  // Need zero filling.
335 
336     // Usually the number of glyphs are less than number of code units.
337     mFontIndices.reserve(count);
338     mGlyphIds.reserve(count);
339     mPoints.reserve(count);
340 
341     HbBufferUniquePtr buffer(hb_buffer_create());
342     U16StringPiece substr = textBuf.substr(range);
343     std::vector<FontCollection::Run> items =
344             paint.font->itemize(substr, paint.fontStyle, paint.localeListId, paint.familyVariant);
345 
346     std::vector<hb_feature_t> features = cleanAndAddDefaultFontFeatures(paint);
347 
348     std::vector<HbFontUniquePtr> hbFonts;
349     double size = paint.size;
350     double scaleX = paint.scaleX;
351 
352     std::unordered_map<const Font*, uint32_t> fontMap;
353 
354     float x = 0;
355     float y = 0;
356     for (int run_ix = isRtl ? items.size() - 1 : 0;
357          isRtl ? run_ix >= 0 : run_ix < static_cast<int>(items.size());
358          isRtl ? --run_ix : ++run_ix) {
359         FontCollection::Run& run = items[run_ix];
360         FakedFont fakedFont = paint.font->getBestFont(substr, run, paint.fontStyle);
361         auto it = fontMap.find(fakedFont.font.get());
362         uint8_t font_ix;
363         if (it == fontMap.end()) {
364             // First time to see this font.
365             font_ix = mFonts.size();
366             mFonts.push_back(fakedFont);
367             fontMap.insert(std::make_pair(fakedFont.font.get(), font_ix));
368 
369             // We override some functions which are not thread safe.
370             HbFontUniquePtr font(hb_font_create_sub_font(fakedFont.font->baseFont().get()));
371             hb_font_set_funcs(
372                     font.get(), isColorBitmapFont(font) ? getFontFuncsForEmoji() : getFontFuncs(),
373                     new SkiaArguments({fakedFont.font->typeface().get(), &paint, fakedFont.fakery}),
374                     [](void* data) { delete reinterpret_cast<SkiaArguments*>(data); });
375             hbFonts.push_back(std::move(font));
376         } else {
377             font_ix = it->second;
378         }
379         const HbFontUniquePtr& hbFont = hbFonts[font_ix];
380 
381         bool needExtent = false;
382         for (int i = run.start; i < run.end; ++i) {
383             if (!isLineSpaceExcludeChar(buf[i])) {
384                 needExtent = true;
385                 break;
386             }
387         }
388         if (needExtent) {
389             MinikinExtent verticalExtent;
390             fakedFont.font->typeface()->GetFontExtent(&verticalExtent, paint, fakedFont.fakery);
391             mExtent.extendBy(verticalExtent);
392         }
393 
394         hb_font_set_ppem(hbFont.get(), size * scaleX, size);
395         hb_font_set_scale(hbFont.get(), HBFloatToFixed(size * scaleX), HBFloatToFixed(size));
396 
397         // TODO: if there are multiple scripts within a font in an RTL run,
398         // we need to reorder those runs. This is unlikely with our current
399         // font stack, but should be done for correctness.
400 
401         // Note: scriptRunStart and scriptRunEnd, as well as run.start and run.end, run between 0
402         // and count.
403         ssize_t scriptRunEnd;
404         for (ssize_t scriptRunStart = run.start; scriptRunStart < run.end;
405              scriptRunStart = scriptRunEnd) {
406             scriptRunEnd = scriptRunStart;
407             hb_script_t script = getScriptRun(buf + start, run.end, &scriptRunEnd /* iterator */);
408             // After the last line, scriptRunEnd is guaranteed to have increased, since the only
409             // time getScriptRun does not increase its iterator is when it has already reached the
410             // end of the buffer. But that can't happen, since if we have already reached the end
411             // of the buffer, we should have had (scriptRunEnd == run.end), which means
412             // (scriptRunStart == run.end) which is impossible due to the exit condition of the for
413             // loop. So we can be sure that scriptRunEnd > scriptRunStart.
414 
415             double letterSpace = 0.0;
416             double letterSpaceHalf = 0.0;
417 
418             if (paint.letterSpacing != 0.0 && isScriptOkForLetterspacing(script)) {
419                 letterSpace = paint.letterSpacing * size * scaleX;
420                 letterSpaceHalf = letterSpace * 0.5;
421             }
422 
423             hb_buffer_clear_contents(buffer.get());
424             hb_buffer_set_script(buffer.get(), script);
425             hb_buffer_set_direction(buffer.get(), isRtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
426             const LocaleList& localeList = LocaleListCache::getById(paint.localeListId);
427             if (localeList.size() != 0) {
428                 hb_language_t hbLanguage = localeList.getHbLanguage(0);
429                 for (size_t i = 0; i < localeList.size(); ++i) {
430                     if (localeList[i].supportsScript(hb_script_to_iso15924_tag(script))) {
431                         hbLanguage = localeList.getHbLanguage(i);
432                         break;
433                     }
434                 }
435                 hb_buffer_set_language(buffer.get(), hbLanguage);
436             }
437 
438             const uint32_t clusterStart =
439                     addToHbBuffer(buffer, buf, start, count, bufSize, scriptRunStart, scriptRunEnd,
440                                   startHyphen, endHyphen, hbFont);
441 
442             hb_shape(hbFont.get(), buffer.get(), features.empty() ? NULL : &features[0],
443                      features.size());
444             unsigned int numGlyphs;
445             hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer.get(), &numGlyphs);
446             hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer.get(), NULL);
447 
448             // At this point in the code, the cluster values in the info buffer correspond to the
449             // input characters with some shift. The cluster value clusterStart corresponds to the
450             // first character passed to HarfBuzz, which is at buf[start + scriptRunStart] whose
451             // advance needs to be saved into mAdvances[scriptRunStart]. So cluster values need to
452             // be reduced by (clusterStart - scriptRunStart) to get converted to indices of
453             // mAdvances.
454             const ssize_t clusterOffset = clusterStart - scriptRunStart;
455 
456             if (numGlyphs) {
457                 mAdvances[info[0].cluster - clusterOffset] += letterSpaceHalf;
458                 x += letterSpaceHalf;
459             }
460             for (unsigned int i = 0; i < numGlyphs; i++) {
461                 const size_t clusterBaseIndex = info[i].cluster - clusterOffset;
462                 if (i > 0 && info[i - 1].cluster != info[i].cluster) {
463                     mAdvances[info[i - 1].cluster - clusterOffset] += letterSpaceHalf;
464                     mAdvances[clusterBaseIndex] += letterSpaceHalf;
465                     x += letterSpace;
466                 }
467 
468                 hb_codepoint_t glyph_ix = info[i].codepoint;
469                 float xoff = HBFixedToFloat(positions[i].x_offset);
470                 float yoff = -HBFixedToFloat(positions[i].y_offset);
471                 xoff += yoff * paint.skewX;
472                 mFontIndices.push_back(font_ix);
473                 mGlyphIds.push_back(glyph_ix);
474                 mPoints.emplace_back(x + xoff, y + yoff);
475                 float xAdvance = HBFixedToFloat(positions[i].x_advance);
476 
477                 if (clusterBaseIndex < count) {
478                     mAdvances[clusterBaseIndex] += xAdvance;
479                 } else {
480                     ALOGE("cluster %zu (start %zu) out of bounds of count %zu", clusterBaseIndex,
481                           start, count);
482                 }
483                 x += xAdvance;
484             }
485             if (numGlyphs) {
486                 mAdvances[info[numGlyphs - 1].cluster - clusterOffset] += letterSpaceHalf;
487                 x += letterSpaceHalf;
488             }
489         }
490     }
491     mFontIndices.shrink_to_fit();
492     mGlyphIds.shrink_to_fit();
493     mPoints.shrink_to_fit();
494     mAdvance = x;
495 }
496 
497 }  // namespace minikin
498