MinikinFontFreeType.h revision aaa4e3470270496e6eb80704eadecb2cb7c56bf0
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 29namespace android { 30 31struct GlyphBitmap { 32 uint8_t *buffer; 33 int width; 34 int height; 35 int left; 36 int top; 37}; 38 39class MinikinFontFreeType : public MinikinFont { 40public: 41 explicit MinikinFontFreeType(FT_Face typeface); 42 43 ~MinikinFontFreeType(); 44 45 float GetHorizontalAdvance(uint32_t glyph_id, 46 const MinikinPaint &paint) const; 47 48 void GetBounds(MinikinRect* bounds, uint32_t glyph_id, 49 const MinikinPaint& paint) const; 50 51 const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); 52 53 // TODO: provide access to raw data, as an optimization. 54 55 int32_t GetUniqueId() const; 56 57 // Not a virtual method, as the protocol to access rendered 58 // glyph bitmaps is probably different depending on the 59 // backend. 60 bool Render(uint32_t glyph_id, 61 const MinikinPaint &paint, GlyphBitmap *result); 62 63 MinikinFontFreeType* GetFreeType(); 64 65private: 66 FT_Face mTypeface; 67 int32_t mUniqueId; 68 static int32_t sIdCounter; 69}; 70 71} // namespace android 72 73#endif // MINIKIN_FONT_FREETYPE_H 74