Skip to content

Commit fe89bea

Browse files
committed
Split font opening out of FT2Font constructor
This makes it easier to do later refactors.
1 parent 5fc9559 commit fe89bea

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/ft2font.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <cstdio>
88
#include <iterator>
99
#include <set>
10-
#include <sstream>
1110
#include <stdexcept>
1211
#include <string>
1312
#include <vector>
@@ -207,20 +206,14 @@ FT2Font::get_path(std::vector<double> &vertices, std::vector<unsigned char> &cod
207206
codes.push_back(CLOSEPOLY);
208207
}
209208

210-
FT2Font::FT2Font(FT_Open_Args &open_args,
211-
long hinting_factor_,
212-
std::vector<FT2Font *> &fallback_list,
209+
FT2Font::FT2Font(long hinting_factor_, std::vector<FT2Font *> &fallback_list,
213210
FT2Font::WarnFunc warn, bool warn_if_used)
214211
: ft_glyph_warn(warn), warn_if_used(warn_if_used), image({1, 1}), face(nullptr),
215212
hinting_factor(hinting_factor_),
216213
// set default kerning factor to 0, i.e., no kerning manipulation
217214
kerning_factor(0)
218215
{
219216
clear();
220-
FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
221-
if (open_args.stream != nullptr) {
222-
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
223-
}
224217
// Set fallbacks
225218
std::copy(fallback_list.begin(), fallback_list.end(), std::back_inserter(fallbacks));
226219
}
@@ -236,6 +229,14 @@ FT2Font::~FT2Font()
236229
}
237230
}
238231

232+
void FT2Font::open(FT_Open_Args &open_args)
233+
{
234+
FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
235+
if (open_args.stream != nullptr) {
236+
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
237+
}
238+
}
239+
239240
void FT2Font::clear()
240241
{
241242
pen.x = pen.y = 0;

src/ft2font.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class FT2Font
9999
typedef void (*WarnFunc)(FT_ULong charcode, std::set<FT_String*> family_names);
100100

101101
public:
102-
FT2Font(FT_Open_Args &open_args, long hinting_factor,
103-
std::vector<FT2Font *> &fallback_list,
102+
FT2Font(long hinting_factor, std::vector<FT2Font *> &fallback_list,
104103
WarnFunc warn, bool warn_if_used);
105104
virtual ~FT2Font();
105+
void open(FT_Open_Args &open_args);
106106
void clear();
107107
void set_size(double ptsize, double dpi);
108108
void set_charmap(int i);

src/ft2font_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,10 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
497497
self->stream.close = nullptr;
498498
}
499499

500-
self->x = new FT2Font(open_args, hinting_factor, fallback_fonts, ft_glyph_warn,
500+
self->x = new FT2Font(hinting_factor, fallback_fonts, ft_glyph_warn,
501501
warn_if_used);
502-
503502
self->x->set_kerning_factor(kerning_factor);
503+
self->x->open(open_args);
504504

505505
return self;
506506
}

0 commit comments

Comments
 (0)