diff options
Diffstat (limited to 'include/minikin')
-rw-r--r-- | include/minikin/CssParse.h | 23 | ||||
-rw-r--r-- | include/minikin/FontCollection.h | 3 | ||||
-rw-r--r-- | include/minikin/FontFamily.h | 61 |
3 files changed, 77 insertions, 10 deletions
diff --git a/include/minikin/CssParse.h b/include/minikin/CssParse.h index 2dceb4a..519056d 100644 --- a/include/minikin/CssParse.h +++ b/include/minikin/CssParse.h @@ -25,26 +25,31 @@ namespace android { enum CssTag { unknown, fontSize, - fontWeight, fontStyle, - minikinHinting, + fontWeight, + cssLang, minikinBidi, + minikinHinting, + minikinVariant, }; const std::string cssTagNames[] = { "unknown", "font-size", - "font-weight", "font-style", - "-minikin-hinting", + "font-weight", + "lang", "-minikin-bidi", + "-minikin-hinting", + "-minikin-variant", }; class CssValue { public: enum Type { UNKNOWN, - FLOAT + FLOAT, + STRING }; enum Units { SCALAR, @@ -58,14 +63,20 @@ public: Type getType() const { return mType; } double getFloatValue() const { return floatValue; } int getIntValue() const { return floatValue; } + std::string getStringValue() const { return stringValue; } std::string toString(CssTag tag) const; void setFloatValue(double v) { mType = FLOAT; floatValue = v; } + void setStringValue(const std::string& v) { + mType = STRING; + stringValue = v; + } private: Type mType; double floatValue; + std::string stringValue; Units mUnits; }; @@ -85,4 +96,4 @@ private: } // namespace android -#endif // MINIKIN_CSS_PARSE_H
\ No newline at end of file +#endif // MINIKIN_CSS_PARSE_H diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h index c6c2ed0..a350237 100644 --- a/include/minikin/FontCollection.h +++ b/include/minikin/FontCollection.h @@ -32,7 +32,8 @@ public: ~FontCollection(); - const FontFamily* getFamilyForChar(uint32_t ch) const; + const FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; + class Run { public: // Do copy constructor, assignment, destructor so it can be used in vectors diff --git a/include/minikin/FontFamily.h b/include/minikin/FontFamily.h index a4fe9cb..6bdf5d6 100644 --- a/include/minikin/FontFamily.h +++ b/include/minikin/FontFamily.h @@ -25,6 +25,36 @@ namespace android { +class MinikinFont; + +// FontLanguage is a compact representation of a bcp-47 language tag. It +// does not capture all possible information, only what directly affects +// font rendering. +class FontLanguage { + friend class FontStyle; +public: + FontLanguage() : mBits(0) { } + + // Parse from string + FontLanguage(const char* buf, size_t size); + + bool operator==(const FontLanguage other) const { return mBits == other.mBits; } + + // 0 = no match, 1 = language matches, 2 = language and script match + int match(const FontLanguage other) const; + +private: + explicit FontLanguage(uint32_t bits) : mBits(bits) { } + + uint32_t bits() const { return mBits; } + + static const uint32_t kBaseLangMask = 0xffff; + static const uint32_t kScriptMask = (1 << 18) - (1 << 16); + static const uint32_t kHansFlag = 1 << 16; + static const uint32_t kHantFlag = 1 << 17; + uint32_t mBits; +}; + // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into a single 32-bit word // so it can be efficiently copied, embedded in other objects, etc. @@ -33,24 +63,44 @@ 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); + } 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); } + bool operator==(const FontStyle other) const { return bits == other.bits; } - // TODO: language, variant hash_t hash() const { return bits; } private: - static const int kWeightMask = 0xf; - static const int kItalicMask = 16; + 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; uint32_t bits; }; +enum FontVariant { + VARIANT_DEFAULT = 0, + VARIANT_COMPACT = 1, + VARIANT_ELEGANT = 2, +}; + inline hash_t hash_type(const FontStyle &style) { return style.hash(); } class FontFamily : public MinikinRefCounted { public: + FontFamily() { } + + FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant) { + } + ~FontFamily(); // Add font to family, extracting style information from the font @@ -59,6 +109,9 @@ public: void addFont(MinikinFont* typeface, FontStyle style); MinikinFont* getClosestMatch(FontStyle style) const; + FontLanguage lang() const { return mLang; } + int variant() const { return mVariant; } + // API's for enumerating the fonts in a family. These don't guarantee any particular order size_t getNumFonts() const; MinikinFont* getFont(size_t index) const; @@ -73,6 +126,8 @@ private: MinikinFont* typeface; FontStyle style; }; + FontLanguage mLang; + int mVariant; std::vector<Font> mFonts; }; |