|
7 | 7 | #include <cstdio>
|
8 | 8 | #include <iterator>
|
9 | 9 | #include <set>
|
10 |
| -#include <sstream> |
11 | 10 | #include <stdexcept>
|
12 | 11 | #include <string>
|
13 | 12 | #include <vector>
|
@@ -207,32 +206,44 @@ FT2Font::get_path(std::vector<double> &vertices, std::vector<unsigned char> &cod
|
207 | 206 | codes.push_back(CLOSEPOLY);
|
208 | 207 | }
|
209 | 208 |
|
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, |
213 | 210 | FT2Font::WarnFunc warn, bool warn_if_used)
|
214 | 211 | : ft_glyph_warn(warn), warn_if_used(warn_if_used), image({1, 1}), face(nullptr),
|
215 | 212 | hinting_factor(hinting_factor_),
|
216 | 213 | // set default kerning factor to 0, i.e., no kerning manipulation
|
217 | 214 | kerning_factor(0)
|
218 | 215 | {
|
219 | 216 | clear();
|
| 217 | + // Set fallbacks |
| 218 | + std::copy(fallback_list.begin(), fallback_list.end(), std::back_inserter(fallbacks)); |
| 219 | +} |
| 220 | + |
| 221 | +FT2Font::~FT2Font() |
| 222 | +{ |
| 223 | + close(); |
| 224 | +} |
| 225 | + |
| 226 | +void FT2Font::open(FT_Open_Args &open_args) |
| 227 | +{ |
220 | 228 | FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
|
221 | 229 | if (open_args.stream != nullptr) {
|
222 | 230 | face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
|
223 | 231 | }
|
224 |
| - // Set fallbacks |
225 |
| - std::copy(fallback_list.begin(), fallback_list.end(), std::back_inserter(fallbacks)); |
226 | 232 | }
|
227 | 233 |
|
228 |
| -FT2Font::~FT2Font() |
| 234 | +void FT2Font::close() |
229 | 235 | {
|
| 236 | + // This should be idempotent, in case a user manually calls close before the |
| 237 | + // destructor does. |
| 238 | + |
230 | 239 | for (auto & glyph : glyphs) {
|
231 | 240 | FT_Done_Glyph(glyph);
|
232 | 241 | }
|
| 242 | + glyphs.clear(); |
233 | 243 |
|
234 | 244 | if (face) {
|
235 | 245 | FT_Done_Face(face);
|
| 246 | + face = nullptr; |
236 | 247 | }
|
237 | 248 | }
|
238 | 249 |
|
|
0 commit comments