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_MINIKIN_FONT_H 18 #define MINIKIN_MINIKIN_FONT_H 19 20 #include <cstdint> 21 #include <memory> 22 #include <vector> 23 24 #include "minikin/FontVariation.h" 25 26 namespace minikin { 27 28 class FontFakery; 29 struct MinikinExtent; 30 struct MinikinPaint; 31 struct MinikinRect; 32 33 // An abstraction for platform fonts, allowing Minikin to be used with 34 // multiple actual implementations of fonts. 35 class MinikinFont { 36 public: MinikinFont(int32_t uniqueId)37 explicit MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} 38 ~MinikinFont()39 virtual ~MinikinFont() {} 40 41 virtual float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint& paint, 42 const FontFakery& fakery) const = 0; GetHorizontalAdvances(uint16_t * glyph_ids,uint32_t count,const MinikinPaint & paint,const FontFakery & fakery,float * outAdvances)43 virtual void GetHorizontalAdvances(uint16_t* glyph_ids, uint32_t count, 44 const MinikinPaint& paint, const FontFakery& fakery, 45 float* outAdvances) const { 46 for (uint32_t i = 0; i < count; ++i) { 47 outAdvances[i] = GetHorizontalAdvance(glyph_ids[i], paint, fakery); 48 } 49 } 50 51 virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint, 52 const FontFakery& fakery) const = 0; 53 54 virtual void GetFontExtent(MinikinExtent* extent, const MinikinPaint& paint, 55 const FontFakery& fakery) const = 0; 56 57 // Override if font can provide access to raw data GetFontData()58 virtual const void* GetFontData() const { return nullptr; } 59 60 // Override if font can provide access to raw data GetFontSize()61 virtual size_t GetFontSize() const { return 0; } 62 63 // Override if font can provide access to raw data. 64 // Returns index within OpenType collection GetFontIndex()65 virtual int GetFontIndex() const { return 0; } 66 67 virtual const std::vector<minikin::FontVariation>& GetAxes() const = 0; 68 createFontWithVariation(const std::vector<FontVariation> &)69 virtual std::shared_ptr<MinikinFont> createFontWithVariation( 70 const std::vector<FontVariation>&) const { 71 return nullptr; 72 } 73 MakeTag(char c1,char c2,char c3,char c4)74 static uint32_t MakeTag(char c1, char c2, char c3, char c4) { 75 return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; 76 } 77 GetUniqueId()78 int32_t GetUniqueId() const { return mUniqueId; } 79 80 private: 81 const int32_t mUniqueId; 82 }; 83 84 } // namespace minikin 85 86 #endif // MINIKIN_MINIKIN_FONT_H 87