FontCollection.h revision 0f2a025d135f9ca52cc3cf917fffc29d6c126094
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_COLLECTION_H
18#define MINIKIN_FONT_COLLECTION_H
19
20#include <vector>
21
22#include <minikin/MinikinRefCounted.h>
23#include <minikin/MinikinFont.h>
24#include <minikin/FontFamily.h>
25
26namespace android {
27
28class FontCollection : public MinikinRefCounted {
29public:
30    explicit FontCollection(const std::vector<FontFamily*>& typefaces);
31
32    ~FontCollection();
33
34    struct Run {
35        FakedFont fakedFont;
36        int start;
37        int end;
38    };
39
40    void itemize(const uint16_t *string, size_t string_length, FontStyle style,
41            std::vector<Run>* result) const;
42
43    // Get the base font for the given style, useful for font-wide metrics.
44    MinikinFont* baseFont(FontStyle style);
45
46    // Get base font with fakery information (fake bold could affect metrics)
47    FakedFont baseFontFaked(FontStyle style);
48
49    uint32_t getId() const;
50
51    // Calls each managed font family's FontFamily::purgeHbFontCache method.
52    // Caller should acquire a lock before calling the method.
53    void purgeFontFamilyHbFontCache() const;
54private:
55    static const int kLogCharsPerPage = 8;
56    static const int kPageMask = (1 << kLogCharsPerPage) - 1;
57
58    struct Range {
59        size_t start;
60        size_t end;
61    };
62
63    FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const;
64
65    // static for allocating unique id's
66    static uint32_t sNextId;
67
68    // unique id for this font collection (suitable for cache key)
69    uint32_t mId;
70
71    // Highest UTF-32 code point that can be mapped
72    uint32_t mMaxChar;
73
74    // This vector has ownership of the bitsets and typeface objects.
75    std::vector<FontFamily*> mFamilies;
76
77    // This vector contains pointers into mInstances
78    std::vector<FontFamily*> mFamilyVec;
79
80    // These are offsets into mInstanceVec, one range per page
81    std::vector<Range> mRanges;
82};
83
84}  // namespace android
85
86#endif  // MINIKIN_FONT_COLLECTION_H
87