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_FREETYPE_H 18 #define MINIKIN_FONT_FREETYPE_H 19 20 #include <ft2build.h> 21 #include FT_FREETYPE_H 22 #include FT_TRUETYPE_TABLES_H 23 24 #include <minikin/MinikinFont.h> 25 26 // An abstraction for platform fonts, allowing Minikin to be used with 27 // multiple actual implementations of fonts. 28 29 namespace android { 30 31 struct GlyphBitmap { 32 uint8_t *buffer; 33 int width; 34 int height; 35 int left; 36 int top; 37 }; 38 39 class MinikinFontFreeType : public MinikinFont { 40 public: 41 explicit MinikinFontFreeType(FT_Face typeface); 42 43 ~MinikinFontFreeType(); 44 45 bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; 46 47 float GetHorizontalAdvance(uint32_t glyph_id, 48 const MinikinPaint &paint) const; 49 50 void GetBounds(MinikinRect* bounds, uint32_t glyph_id, 51 const MinikinPaint& paint) const; 52 53 // If buf is NULL, just update size 54 bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); 55 56 int32_t GetUniqueId() const; 57 58 // Not a virtual method, as the protocol to access rendered 59 // glyph bitmaps is probably different depending on the 60 // backend. 61 bool Render(uint32_t glyph_id, 62 const MinikinPaint &paint, GlyphBitmap *result); 63 64 MinikinFontFreeType* GetFreeType(); 65 66 private: 67 FT_Face mTypeface; 68 int32_t mUniqueId; 69 static int32_t sIdCounter; 70 }; 71 72 } // namespace android 73 74 #endif // MINIKIN_FONT_FREETYPE_H 75