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 26 namespace android { 27 28 class FontCollection : public MinikinRefCounted { 29 public: 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 private: 51 static const int kLogCharsPerPage = 8; 52 static const int kPageMask = (1 << kLogCharsPerPage) - 1; 53 54 struct Range { 55 size_t start; 56 size_t end; 57 }; 58 59 FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; 60 61 // static for allocating unique id's 62 static uint32_t sNextId; 63 64 // unique id for this font collection (suitable for cache key) 65 uint32_t mId; 66 67 // Highest UTF-32 code point that can be mapped 68 uint32_t mMaxChar; 69 70 // This vector has ownership of the bitsets and typeface objects. 71 std::vector<FontFamily*> mFamilies; 72 73 // This vector contains pointers into mInstances 74 std::vector<FontFamily*> mFamilyVec; 75 76 // These are offsets into mInstanceVec, one range per page 77 std::vector<Range> mRanges; 78 }; 79 80 } // namespace android 81 82 #endif // MINIKIN_FONT_COLLECTION_H 83