2 * Copyright 2019 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkCharToGlyphCache_DEFINED
9 #define SkCharToGlyphCache_DEFINED
11 #include "include/core/SkTypes.h"
12 #include "include/private/SkTDArray.h"
14 class SkCharToGlyphCache {
17 ~SkCharToGlyphCache();
19 // return number of unichars cached
24 void reset(); // forget all cache entries (to save memory)
27 * Given a unichar, return its glyphID (if the return value is positive), else return
28 * ~index of where to insert the computed glyphID.
30 * int result = cache.charToGlyph(unichar);
34 * glyphID = compute_glyph_using_typeface(unichar);
35 * cache.insertCharAndGlyph(~result, unichar, glyphID);
38 int findGlyphIndex(SkUnichar c) const;
41 * Insert a new char/glyph pair into the cache at the specified index.
42 * See charToGlyph() for how to compute the bit-not of the index.
44 void insertCharAndGlyph(int index, SkUnichar, SkGlyphID);
46 // helper to pre-seed an entry in the cache
47 void addCharAndGlyph(SkUnichar unichar, SkGlyphID glyph) {
48 int index = this->findGlyphIndex(unichar);
50 SkASSERT(SkToU16(index) == glyph);
52 this->insertCharAndGlyph(~index, unichar, glyph);
57 SkTDArray<int32_t> fK32;
58 SkTDArray<uint16_t> fV16;