FontCollection.h revision 9cc9bbe1461f359f0b27c5e7645c17dda001ab1d
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 <ft2build.h> 23#include FT_FREETYPE_H 24#include FT_TRUETYPE_TABLES_H 25 26#include "SparseBitSet.h" 27#include "FontFamily.h" 28 29namespace android { 30 31class FontCollection { 32public: 33 explicit FontCollection(const std::vector<FontFamily*>& typefaces); 34 35 ~FontCollection(); 36 37 const FontFamily* getFamilyForChar(uint32_t ch) const; 38 class Run { 39 public: 40 // Do copy constructor, assignment, destructor so it can be used in vectors 41 Run() : font(NULL) { } 42 Run(const Run& other): font(other.font), start(other.start), end(other.end) { 43 if (font) FT_Reference_Face(font); 44 } 45 Run& operator=(const Run& other) { 46 if (other.font) FT_Reference_Face(other.font); 47 if (font) FT_Done_Face(font); 48 font = other.font; 49 start = other.start; 50 end = other.end; 51 return *this; 52 } 53 ~Run() { if (font) FT_Done_Face(font); } 54 55 FT_Face font; 56 int start; 57 int end; 58 }; 59 void itemize(const uint16_t *string, size_t string_length, FontStyle style, 60 std::vector<Run>* result) const; 61 private: 62 static const int kLogCharsPerPage = 8; 63 static const int kPageMask = (1 << kLogCharsPerPage) - 1; 64 65 struct FontInstance { 66 SparseBitSet* mCoverage; 67 FontFamily* mFamily; 68 }; 69 70 struct Range { 71 size_t start; 72 size_t end; 73 }; 74 75 // Highest UTF-32 code point that can be mapped 76 uint32_t mMaxChar; 77 78 // This vector has ownership of the bitsets and typeface objects. 79 std::vector<FontInstance> mInstances; 80 81 // This vector contains pointers into mInstances 82 std::vector<const FontInstance*> mInstanceVec; 83 84 // These are offsets into mInstanceVec, one range per page 85 std::vector<Range> mRanges; 86}; 87 88} // namespace android 89 90#endif // MINIKIN_FONT_COLLECTION_H 91