• 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 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()37     MinikinFont() {}
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     // Returns the font path or an empty string.
58     virtual const std::string& GetFontPath() const = 0;
59 
60     // Override if font can provide access to raw data
GetFontData()61     virtual const void* GetFontData() const { return nullptr; }
62 
63     // Override if font can provide access to raw data
GetFontSize()64     virtual size_t GetFontSize() const { return 0; }
65 
66     // Override if font can provide access to raw data.
67     // Returns index within OpenType collection
GetFontIndex()68     virtual int GetFontIndex() const { return 0; }
69 
GetSourceId()70     virtual int GetSourceId() const { return 0; }
71 
72     virtual const std::vector<minikin::FontVariation>& GetAxes() const = 0;
73 
createFontWithVariation(const std::vector<FontVariation> &)74     virtual std::shared_ptr<MinikinFont> createFontWithVariation(
75             const std::vector<FontVariation>&) const {
76         return nullptr;
77     }
78 
MakeTag(char c1,char c2,char c3,char c4)79     static uint32_t MakeTag(char c1, char c2, char c3, char c4) {
80         return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4;
81     }
82 };
83 
84 }  // namespace minikin
85 
86 #endif  // MINIKIN_MINIKIN_FONT_H
87