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