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 _ANDROID_GRAPHICS_MINIKIN_SKIA_H_ 18 #define _ANDROID_GRAPHICS_MINIKIN_SKIA_H_ 19 20 #include <SkRefCnt.h> 21 #include <cutils/compiler.h> 22 #include <minikin/MinikinFont.h> 23 #include <string> 24 #include <string_view> 25 26 class SkFont; 27 class SkTypeface; 28 29 namespace android { 30 31 class ANDROID_API MinikinFontSkia : public minikin::MinikinFont { 32 public: 33 MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize, 34 std::string_view filePath, int ttcIndex, 35 const std::vector<minikin::FontVariation>& axes); 36 37 float GetHorizontalAdvance(uint32_t glyph_id, const minikin::MinikinPaint& paint, 38 const minikin::FontFakery& fakery) const override; 39 40 void GetHorizontalAdvances(uint16_t* glyph_ids, uint32_t count, 41 const minikin::MinikinPaint& paint, 42 const minikin::FontFakery& fakery, 43 float* outAdvances) const override; 44 45 void GetBounds(minikin::MinikinRect* bounds, uint32_t glyph_id, 46 const minikin::MinikinPaint& paint, 47 const minikin::FontFakery& fakery) const override; 48 49 void GetFontExtent(minikin::MinikinExtent* extent, const minikin::MinikinPaint& paint, 50 const minikin::FontFakery& fakery) const override; 51 52 SkTypeface* GetSkTypeface() const; 53 sk_sp<SkTypeface> RefSkTypeface() const; 54 55 // Access to underlying raw font bytes 56 const void* GetFontData() const; 57 size_t GetFontSize() const; 58 int GetFontIndex() const; getFilePath()59 const std::string& getFilePath() const { return mFilePath; } 60 const std::vector<minikin::FontVariation>& GetAxes() const; 61 std::shared_ptr<minikin::MinikinFont> createFontWithVariation( 62 const std::vector<minikin::FontVariation>&) const; 63 64 static uint32_t packFontFlags(const SkFont&); 65 static void unpackFontFlags(SkFont*, uint32_t fontFlags); 66 67 // set typeface and fake bold/italic parameters 68 static void populateSkFont(SkFont*, const minikin::MinikinFont* font, 69 minikin::FontFakery fakery); 70 71 private: 72 sk_sp<SkTypeface> mTypeface; 73 74 // A raw pointer to the font data - it should be owned by some other object with 75 // lifetime at least as long as this object. 76 const void* mFontData; 77 size_t mFontSize; 78 int mTtcIndex; 79 std::vector<minikin::FontVariation> mAxes; 80 std::string mFilePath; 81 }; 82 83 } // namespace android 84 85 #endif // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_ 86