Skip to content

Commit eeec8f2

Browse files
committed
Added readFreetypeOutline to font import
1 parent 7ff249b commit eeec8f2

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

ext/import-font.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ FontHandle * adoptFreetypeFont(FT_Face ftFace) {
116116
return handle;
117117
}
118118

119+
FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline) {
120+
output.contours.clear();
121+
output.inverseYAxis = false;
122+
FtContext context = { };
123+
context.shape = &output;
124+
FT_Outline_Funcs ftFunctions;
125+
ftFunctions.move_to = &ftMoveTo;
126+
ftFunctions.line_to = &ftLineTo;
127+
ftFunctions.conic_to = &ftConicTo;
128+
ftFunctions.cubic_to = &ftCubicTo;
129+
ftFunctions.shift = 0;
130+
ftFunctions.delta = 0;
131+
FT_Error error = FT_Outline_Decompose(outline, &ftFunctions, &context);
132+
if (!output.contours.empty() && output.contours.back().edges.empty())
133+
output.contours.pop_back();
134+
return error;
135+
}
136+
119137
FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
120138
if (!library)
121139
return NULL;
@@ -181,26 +199,9 @@ bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *a
181199
FT_Error error = FT_Load_Glyph(font->face, glyphIndex.getIndex(), FT_LOAD_NO_SCALE);
182200
if (error)
183201
return false;
184-
output.contours.clear();
185-
output.inverseYAxis = false;
186202
if (advance)
187203
*advance = F26DOT6_TO_DOUBLE(font->face->glyph->advance.x);
188-
189-
FtContext context = { };
190-
context.shape = &output;
191-
FT_Outline_Funcs ftFunctions;
192-
ftFunctions.move_to = &ftMoveTo;
193-
ftFunctions.line_to = &ftLineTo;
194-
ftFunctions.conic_to = &ftConicTo;
195-
ftFunctions.cubic_to = &ftCubicTo;
196-
ftFunctions.shift = 0;
197-
ftFunctions.delta = 0;
198-
error = FT_Outline_Decompose(&font->face->glyph->outline, &ftFunctions, &context);
199-
if (error)
200-
return false;
201-
if (!output.contours.empty() && output.contours.back().edges.empty())
202-
output.contours.pop_back();
203-
return true;
204+
return !readFreetypeOutline(output, &font->face->glyph->outline);
204205
}
205206

206207
bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance) {

ext/import-font.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ FreetypeHandle * initializeFreetype();
5252
/// Deinitializes the FreeType library.
5353
void deinitializeFreetype(FreetypeHandle *library);
5454

55-
#ifdef FT_FREETYPE_H
55+
#ifdef FT_LOAD_DEFAULT // FreeType included
5656
/// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
5757
FontHandle * adoptFreetypeFont(FT_Face ftFace);
58+
/// Converts the geometry of FreeType's FT_Outline to a Shape object.
59+
FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline);
5860
#endif
61+
5962
/// Loads a font file and returns its handle.
6063
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
6164
/// Loads a font from binary data and returns its handle.

0 commit comments

Comments
 (0)