diff options
author | Seigo Nonaka <nona@google.com> | 2015-12-02 11:07:29 +0900 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2015-12-08 18:49:18 -0800 |
commit | 6d9dcd2cf3d3ed26a886e02d94c907311e7b1f83 (patch) | |
tree | 505e6e82cb643297696b74126341827f7dcaa18c /include | |
parent | a47969c90ac9ef5d2c7c439030d3cfcabbecc539 (diff) | |
download | android_frameworks_minikin-6d9dcd2cf3d3ed26a886e02d94c907311e7b1f83.tar.gz android_frameworks_minikin-6d9dcd2cf3d3ed26a886e02d94c907311e7b1f83.tar.bz2 android_frameworks_minikin-6d9dcd2cf3d3ed26a886e02d94c907311e7b1f83.zip |
Introduce FontLanguageListCache.
FontLanguageListCache is an intentionally leaky singleton and its
internal cache won't be purged.
BUG: 25122318
Change-Id: I272097e979fe44b83fd86822235350e12eda8f51
Diffstat (limited to 'include')
-rw-r--r-- | include/minikin/FontCollection.h | 2 | ||||
-rw-r--r-- | include/minikin/FontFamily.h | 37 |
2 files changed, 23 insertions, 16 deletions
diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h index 09c9356..cd14261 100644 --- a/include/minikin/FontCollection.h +++ b/include/minikin/FontCollection.h @@ -65,7 +65,7 @@ private: size_t end; }; - FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const; + FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; // static for allocating unique id's static uint32_t sNextId; diff --git a/include/minikin/FontFamily.h b/include/minikin/FontFamily.h index 776bcc4..539a06c 100644 --- a/include/minikin/FontFamily.h +++ b/include/minikin/FontFamily.h @@ -87,35 +87,42 @@ private: }; // FontStyle represents all style information needed to select an actual font -// from a collection. The implementation is packed into a single 32-bit word +// from a collection. The implementation is packed into two 32-bit words // so it can be efficiently copied, embedded in other objects, etc. class FontStyle { public: - FontStyle(int weight = 4, bool italic = false) { - bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); - } - FontStyle(FontLanguage lang, int variant = 0, int weight = 4, bool italic = false) { - bits = (weight & kWeightMask) | (italic ? kItalicMask : 0) - | (variant << kVariantShift) | (lang.bits() << kLangShift); - } - FontStyle(FontLanguages langs, int variant = 0, int weight = 4, bool italic = false) : - // TODO: Use all the languages in langs - FontStyle(langs[0], variant, weight, italic) { } + FontStyle() : FontStyle(0 /* variant */, 4 /* weight */, false /* italic */) {} + FontStyle(int weight, bool italic) : FontStyle(0 /* variant */, weight, italic) {} + FontStyle(uint32_t langListId) + : FontStyle(langListId, 0 /* variant */, 4 /* weight */, false /* italic */) {} + + FontStyle(int variant, int weight, bool italic); + FontStyle(uint32_t langListId, int variant, int weight, bool italic); + int getWeight() const { return bits & kWeightMask; } bool getItalic() const { return (bits & kItalicMask) != 0; } int getVariant() const { return (bits >> kVariantShift) & kVariantMask; } - FontLanguage getLanguage() const { return FontLanguage(bits >> kLangShift); } + uint32_t getLanguageListId() const { return mLanguageListId; } - bool operator==(const FontStyle other) const { return bits == other.bits; } + bool operator==(const FontStyle other) const { + return bits == other.bits && mLanguageListId == other.mLanguageListId; + } + + hash_t hash() const; - hash_t hash() const { return bits; } + // Looks up a language list from an internal cache and returns its ID. + // If the passed language list is not in the cache, registers it and returns newly assigned ID. + static uint32_t registerLanguageList(const std::string& languages); private: static const uint32_t kWeightMask = (1 << 4) - 1; static const uint32_t kItalicMask = 1 << 4; static const int kVariantShift = 5; static const uint32_t kVariantMask = (1 << 2) - 1; - static const int kLangShift = 7; + + static uint32_t pack(int variant, int weight, bool italic); + uint32_t bits; + uint32_t mLanguageListId; }; enum FontVariant { |