• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, int sourceId, 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 
GetFontPath()52     const std::string& GetFontPath() const override { return mFilePath; }
53 
54     SkTypeface* GetSkTypeface() const;
55     sk_sp<SkTypeface> RefSkTypeface() const;
56 
57     // Access to underlying raw font bytes
58     const void* GetFontData() const;
59     size_t GetFontSize() const;
60     int GetFontIndex() const;
getFilePath()61     const std::string& getFilePath() const { return mFilePath; }
62     const std::vector<minikin::FontVariation>& GetAxes() const;
63     std::shared_ptr<minikin::MinikinFont> createFontWithVariation(
64             const std::vector<minikin::FontVariation>&) const;
GetSourceId()65     int GetSourceId() const override { return mSourceId; }
66 
67     static uint32_t packFontFlags(const SkFont&);
68     static void unpackFontFlags(SkFont*, uint32_t fontFlags);
69 
70     // set typeface and fake bold/italic parameters
71     static void populateSkFont(SkFont*, const minikin::MinikinFont* font,
72                                minikin::FontFakery fakery);
73 
74 private:
75     sk_sp<SkTypeface> mTypeface;
76 
77     int mSourceId;
78     // A raw pointer to the font data - it should be owned by some other object with
79     // lifetime at least as long as this object.
80     const void* mFontData;
81     size_t mFontSize;
82     int mTtcIndex;
83     std::vector<minikin::FontVariation> mAxes;
84     std::string mFilePath;
85 };
86 
87 }  // namespace android
88 
89 #endif  // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
90