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