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