FontCollection.h 2.8 KB
Newer Older
R
Raph Levien 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MINIKIN_FONT_COLLECTION_H
#define MINIKIN_FONT_COLLECTION_H

#include <vector>

R
Raph Levien 已提交
22
#include <minikin/MinikinRefCounted.h>
R
Raph Levien 已提交
23 24
#include <minikin/MinikinFont.h>
#include <minikin/FontFamily.h>
R
Raph Levien 已提交
25 26 27

namespace android {

R
Raph Levien 已提交
28
class FontCollection : public MinikinRefCounted {
R
Raph Levien 已提交
29 30 31 32 33
public:
    explicit FontCollection(const std::vector<FontFamily*>& typefaces);

    ~FontCollection();

R
Raph Levien 已提交
34 35
    struct Run {
        FakedFont fakedFont;
R
Raph Levien 已提交
36 37 38
        int start;
        int end;
    };
39

R
Raph Levien 已提交
40 41
    void itemize(const uint16_t *string, size_t string_length, FontStyle style,
            std::vector<Run>* result) const;
42

43 44 45 46 47
    // Returns true if there is a glyph for the code point and variation selector pair.
    // Returns false if no fonts have a glyph for the code point and variation
    // selector pair, or invalid variation selector is passed.
    bool hasVariationSelector(uint32_t baseCodepoint, uint32_t variationSelector) const;

48 49
    // Get the base font for the given style, useful for font-wide metrics.
    MinikinFont* baseFont(FontStyle style);
R
Raph Levien 已提交
50 51 52

    // Get base font with fakery information (fake bold could affect metrics)
    FakedFont baseFontFaked(FontStyle style);
53

54
    uint32_t getId() const;
55 56 57 58

    // Calls each managed font family's FontFamily::purgeHbFontCache method.
    // Caller should acquire a lock before calling the method.
    void purgeFontFamilyHbFontCache() const;
59
private:
R
Raph Levien 已提交
60 61 62 63 64 65 66 67
    static const int kLogCharsPerPage = 8;
    static const int kPageMask = (1 << kLogCharsPerPage) - 1;

    struct Range {
        size_t start;
        size_t end;
    };

S
Seigo Nonaka 已提交
68
    FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const;
69

70 71 72 73 74 75
    // static for allocating unique id's
    static uint32_t sNextId;

    // unique id for this font collection (suitable for cache key)
    uint32_t mId;

R
Raph Levien 已提交
76 77 78 79
    // Highest UTF-32 code point that can be mapped
    uint32_t mMaxChar;

    // This vector has ownership of the bitsets and typeface objects.
80
    std::vector<FontFamily*> mFamilies;
R
Raph Levien 已提交
81 82

    // This vector contains pointers into mInstances
83
    std::vector<FontFamily*> mFamilyVec;
R
Raph Levien 已提交
84 85 86 87 88 89 90 91

    // These are offsets into mInstanceVec, one range per page
    std::vector<Range> mRanges;
};

}  // namespace android

#endif  // MINIKIN_FONT_COLLECTION_H