MinikinFont.h revision 448b0fd720d7ba902b9be224a287d08abe3ebea8
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_H 18#define MINIKIN_FONT_H 19 20#include <minikin/MinikinRefCounted.h> 21 22// An abstraction for platform fonts, allowing Minikin to be used with 23// multiple actual implementations of fonts. 24 25namespace android { 26 27class MinikinFont; 28 29// Possibly move into own .h file? 30// Note: if you add a field here, also update LayoutCacheKey 31struct MinikinPaint { 32 MinikinFont *font; 33 float size; 34 float scaleX; 35 float skewX; 36 int32_t paintFlags; 37}; 38 39struct MinikinRect { 40 float mLeft, mTop, mRight, mBottom; 41 bool isEmpty() const { 42 return mLeft == mRight || mTop == mBottom; 43 } 44 void set(const MinikinRect& r) { 45 mLeft = r.mLeft; 46 mTop = r.mTop; 47 mRight = r.mRight; 48 mBottom = r.mBottom; 49 } 50 void offset(float dx, float dy) { 51 mLeft += dx; 52 mTop += dy; 53 mRight += dx; 54 mBottom += dy; 55 } 56 void setEmpty() { 57 mLeft = mTop = mRight = mBottom = 0; 58 } 59 void join(const MinikinRect& r); 60}; 61 62class MinikinFontFreeType; 63 64class MinikinFont : public MinikinRefCounted { 65public: 66 virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; 67 68 virtual float GetHorizontalAdvance(uint32_t glyph_id, 69 const MinikinPaint &paint) const = 0; 70 71 virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, 72 const MinikinPaint &paint) const = 0; 73 74 // If buf is NULL, just update size 75 virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0; 76 77 virtual int32_t GetUniqueId() const = 0; 78 79 static uint32_t MakeTag(char c1, char c2, char c3, char c4) { 80 return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | 81 ((uint32_t)c3 << 8) | (uint32_t)c4; 82 } 83}; 84 85} // namespace android 86 87#endif // MINIKIN_FONT_H 88