• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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_TEST_FREE_TYPE_MINIKIN_FONT_FOR_TEST_H
18 #define MINIKIN_TEST_FREE_TYPE_MINIKIN_FONT_FOR_TEST_H
19 
20 #include <ft2build.h>
21 
22 #include <string>
23 
24 #include "minikin/Buffer.h"
25 #include "minikin/Font.h"
26 #include "minikin/MinikinFont.h"
27 #include "minikin/MinikinFontFactory.h"
28 #include FT_FREETYPE_H
29 
30 #include "minikin/Macros.h"
31 
32 namespace minikin {
33 
34 class FreeTypeMinikinFontForTest : public MinikinFont {
35 public:
36     FreeTypeMinikinFontForTest(const std::string& font_path, int index);
FreeTypeMinikinFontForTest(const std::string & font_path)37     FreeTypeMinikinFontForTest(const std::string& font_path)
38             : FreeTypeMinikinFontForTest(font_path, 0) {}
39     virtual ~FreeTypeMinikinFontForTest();
40 
41     // MinikinFont overrides.
42     float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint& paint,
43                                const FontFakery& fakery) const override;
44     void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint,
45                    const FontFakery& fakery) const override;
46     void GetFontExtent(MinikinExtent* extent, const MinikinPaint& paint,
47                        const FontFakery& fakery) const override;
48 
GetFontPath()49     const std::string& GetFontPath() const override { return mFontPath; }
GetFontData()50     const void* GetFontData() const { return mFontData; }
GetFontSize()51     size_t GetFontSize() const { return mFontSize; }
GetFontIndex()52     int GetFontIndex() const { return mFontIndex; }
GetAxes()53     const std::vector<minikin::FontVariation>& GetAxes() const { return mAxes; }
54 
55 private:
56     const std::string mFontPath;
57     const int mFontIndex;
58     void* mFontData;
59     size_t mFontSize;
60     std::vector<minikin::FontVariation> mAxes;
61 
62     FT_Library mFtLibrary;
63     FT_Face mFtFace;
64 
65     MINIKIN_PREVENT_COPY_AND_ASSIGN(FreeTypeMinikinFontForTest);
66 };
67 
68 class FreeTypeMinikinFontForTestFactory : MinikinFontFactory {
69 private:
70     FreeTypeMinikinFontForTestFactory();
71 
72 public:
73     static void init();
74 
75     void write(BufferWriter* writer, const MinikinFont* typeface) const override;
76 
77     std::shared_ptr<MinikinFont> create(BufferReader reader) const override;
78 
79     void skip(BufferReader* reader) const override;
80 };
81 
82 }  // namespace minikin
83 
84 #endif  // MINIKIN_TEST_FREE_TYPE_MINIKIN_FONT_FOR_TEST_H
85