Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkCharToGlyphCache.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkCharToGlyphCache_DEFINED
9#define SkCharToGlyphCache_DEFINED
10
14
15#include <cstdint>
16
18public:
21
22 // return number of unichars cached
23 int count() const {
24 return fK32.size();
25 }
26
27 void reset(); // forget all cache entries (to save memory)
28
29 /**
30 * Given a unichar, return its glyphID (if the return value is positive), else return
31 * ~index of where to insert the computed glyphID.
32 *
33 * int result = cache.charToGlyph(unichar);
34 * if (result >= 0) {
35 * glyphID = result;
36 * } else {
37 * glyphID = compute_glyph_using_typeface(unichar);
38 * cache.insertCharAndGlyph(~result, unichar, glyphID);
39 * }
40 */
41 int findGlyphIndex(SkUnichar c) const;
42
43 /**
44 * Insert a new char/glyph pair into the cache at the specified index.
45 * See charToGlyph() for how to compute the bit-not of the index.
46 */
47 void insertCharAndGlyph(int index, SkUnichar, SkGlyphID);
48
49 // helper to pre-seed an entry in the cache
50 void addCharAndGlyph(SkUnichar unichar, SkGlyphID glyph) {
51 int index = this->findGlyphIndex(unichar);
52 if (index >= 0) {
53 SkASSERT(SkToU16(index) == glyph);
54 } else {
55 this->insertCharAndGlyph(~index, unichar, glyph);
56 }
57 }
58
59private:
62 double fDenom;
63};
64
65#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr uint16_t SkToU16(S x)
Definition SkTo.h:24
int32_t SkUnichar
Definition SkTypes.h:175
uint16_t SkGlyphID
Definition SkTypes.h:179
int findGlyphIndex(SkUnichar c) const
void insertCharAndGlyph(int index, SkUnichar, SkGlyphID)
void addCharAndGlyph(SkUnichar unichar, SkGlyphID glyph)
int size() const
Definition SkTDArray.h:138