1// LAF FreeType Wrapper
2// Copyright (c) 2020 Igara Studio S.A.
3// Copyright (c) 2016-2017 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#include "ft/lib.h"
9
10#include "base/log.h"
11#include "ft/stream.h"
12
13#include <iostream>
14
15namespace ft {
16
17Lib::Lib()
18 : m_ft(nullptr)
19{
20 FT_Init_FreeType(&m_ft);
21}
22
23Lib::~Lib()
24{
25 if (m_ft)
26 FT_Done_FreeType(m_ft);
27}
28
29FT_Face Lib::open(const std::string& filename)
30{
31 FT_Stream stream = ft::open_stream(filename);
32 FT_Open_Args args;
33 memset(&args, 0, sizeof(args));
34 args.flags = FT_OPEN_STREAM;
35 args.stream = stream;
36
37 LOG(VERBOSE, "FT: Loading font '%s'\n", filename.c_str());
38
39 FT_Face face = nullptr;
40 FT_Error err = FT_Open_Face(m_ft, &args, 0, &face);
41 if (!err)
42 FT_Select_Charmap(face, FT_ENCODING_UNICODE);
43 return face;
44}
45
46} // namespace ft
47