@@ -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+
119137FontHandle * 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
206207bool loadGlyph (Shape &output, FontHandle *font, unicode_t unicode, double *advance) {
0 commit comments