1 /*
2  * Copyright (C) 2013 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 #ifndef MINIKIN_FONT_FAMILY_H
18 #define MINIKIN_FONT_FAMILY_H
19 
20 #include <memory>
21 #include <string>
22 #include <unordered_set>
23 #include <vector>
24 
25 #include "minikin/FamilyVariant.h"
26 #include "minikin/Font.h"
27 #include "minikin/FontStyle.h"
28 #include "minikin/HbUtils.h"
29 #include "minikin/Macros.h"
30 #include "minikin/SparseBitSet.h"
31 
32 namespace minikin {
33 
34 class FontFamily {
35 public:
36     explicit FontFamily(std::vector<Font>&& fonts);
37     FontFamily(FamilyVariant variant, std::vector<Font>&& fonts);
38     FontFamily(uint32_t localeListId, FamilyVariant variant, std::vector<Font>&& fonts,
39                bool isCustomFallback);
40 
41     FakedFont getClosestMatch(FontStyle style) const;
42 
localeListId()43     uint32_t localeListId() const { return mLocaleListId; }
variant()44     FamilyVariant variant() const { return mVariant; }
45 
46     // API's for enumerating the fonts in a family. These don't guarantee any particular order
getNumFonts()47     size_t getNumFonts() const { return mFonts.size(); }
getFont(size_t index)48     const Font* getFont(size_t index) const { return &mFonts[index]; }
getStyle(size_t index)49     FontStyle getStyle(size_t index) const { return mFonts[index].style(); }
isColorEmojiFamily()50     bool isColorEmojiFamily() const { return mIsColorEmoji; }
supportedAxes()51     const std::unordered_set<AxisTag>& supportedAxes() const { return mSupportedAxes; }
isCustomFallback()52     bool isCustomFallback() const { return mIsCustomFallback; }
53 
54     // Get Unicode coverage.
getCoverage()55     const SparseBitSet& getCoverage() const { return mCoverage; }
56 
57     // Returns true if the font has a glyph for the code point and variation selector pair.
58     // Caller should acquire a lock before calling the method.
59     bool hasGlyph(uint32_t codepoint, uint32_t variationSelector) const;
60 
61     // Returns true if this font family has a variaion sequence table (cmap format 14 subtable).
hasVSTable()62     bool hasVSTable() const { return !mCmapFmt14Coverage.empty(); }
63 
64     // Creates new FontFamily based on this family while applying font variations. Returns nullptr
65     // if none of variations apply to this family.
66     std::shared_ptr<FontFamily> createFamilyWithVariation(
67             const std::vector<FontVariation>& variations) const;
68 
69 private:
70     void computeCoverage();
71 
72     uint32_t mLocaleListId;
73     FamilyVariant mVariant;
74     std::vector<Font> mFonts;
75     std::unordered_set<AxisTag> mSupportedAxes;
76     bool mIsColorEmoji;
77     bool mIsCustomFallback;
78 
79     SparseBitSet mCoverage;
80     std::vector<std::unique_ptr<SparseBitSet>> mCmapFmt14Coverage;
81 
82     MINIKIN_PREVENT_COPY_AND_ASSIGN(FontFamily);
83 };
84 
85 }  // namespace minikin
86 
87 #endif  // MINIKIN_FONT_FAMILY_H
88