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 <string>
21 
22 #include "minikin/Buffer.h"
23 #include "minikin/Font.h"
24 #include "minikin/MinikinFont.h"
25 
26 #include <ft2build.h>
27 #include FT_FREETYPE_H
28 
29 #include "minikin/Macros.h"
30 
31 namespace minikin {
32 
33 class FreeTypeMinikinFontForTest : public MinikinFont {
34 public:
35     FreeTypeMinikinFontForTest(const std::string& font_path, int index);
FreeTypeMinikinFontForTest(const std::string & font_path)36     FreeTypeMinikinFontForTest(const std::string& font_path)
37             : FreeTypeMinikinFontForTest(font_path, 0) {}
38     virtual ~FreeTypeMinikinFontForTest();
39 
40     // MinikinFont overrides.
41     float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint& paint,
42                                const FontFakery& fakery) const override;
43     void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint,
44                    const FontFakery& fakery) const override;
45     void GetFontExtent(MinikinExtent* extent, const MinikinPaint& paint,
46                        const FontFakery& fakery) const override;
47 
GetFontPath()48     const std::string& GetFontPath() const override { return mFontPath; }
GetFontData()49     const void* GetFontData() const { return mFontData; }
GetFontSize()50     size_t GetFontSize() const { return mFontSize; }
GetFontIndex()51     int GetFontIndex() const { return mFontIndex; }
GetAxes()52     const std::vector<minikin::FontVariation>& GetAxes() const { return mAxes; }
53 
54 private:
55     const std::string mFontPath;
56     const int mFontIndex;
57     void* mFontData;
58     size_t mFontSize;
59     std::vector<minikin::FontVariation> mAxes;
60 
61     FT_Library mFtLibrary;
62     FT_Face mFtFace;
63 
64     MINIKIN_PREVENT_COPY_AND_ASSIGN(FreeTypeMinikinFontForTest);
65 };
66 
67 void writeFreeTypeMinikinFontForTest(BufferWriter* writer, const MinikinFont* typeface);
68 
69 Font::TypefaceLoader* readFreeTypeMinikinFontForTest(BufferReader* reader);
70 
71 }  // namespace minikin
72 
73 #endif  // MINIKIN_TEST_FREE_TYPE_MINIKIN_FONT_FOR_TEST_H
74