FontCollection.h revision 80d113bcd4bbc395218503354af1a5a6dba59b4b
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 // Returns true if there is a glyph for the code point and variation selector pair. 44 // Returns false if no fonts have a glyph for the code point and variation 45 // selector pair, or invalid variation selector is passed. 46 bool hasVariationSelector(uint32_t baseCodepoint, uint32_t variationSelector) const; 47 48 // Get the base font for the given style, useful for font-wide metrics. 49 MinikinFont* baseFont(FontStyle style); 50 51 // Get base font with fakery information (fake bold could affect metrics) 52 FakedFont baseFontFaked(FontStyle style); 53 54 uint32_t getId() const; 55 56 // Calls each managed font family's FontFamily::purgeHbFontCache method. 57 // Caller should acquire a lock before calling the method. 58 void purgeFontFamilyHbFontCache() const; 59private: 60 static const int kLogCharsPerPage = 8; 61 static const int kPageMask = (1 << kLogCharsPerPage) - 1; 62 63 struct Range { 64 size_t start; 65 size_t end; 66 }; 67 68 FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const; 69 70 // static for allocating unique id's 71 static uint32_t sNextId; 72 73 // unique id for this font collection (suitable for cache key) 74 uint32_t mId; 75 76 // Highest UTF-32 code point that can be mapped 77 uint32_t mMaxChar; 78 79 // This vector has ownership of the bitsets and typeface objects. 80 std::vector<FontFamily*> mFamilies; 81 82 // This vector contains pointers into mInstances 83 std::vector<FontFamily*> mFamilyVec; 84 85 // These are offsets into mInstanceVec, one range per page 86 std::vector<Range> mRanges; 87}; 88 89} // namespace android 90 91#endif // MINIKIN_FONT_COLLECTION_H 92