mirror of https://github.com/Chlumsky/msdfgen.git
Added readFreetypeOutline to font import
This commit is contained in:
parent
7ff249bcd4
commit
eeec8f222d
|
|
@ -116,6 +116,24 @@ FontHandle * adoptFreetypeFont(FT_Face ftFace) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline) {
|
||||||
|
output.contours.clear();
|
||||||
|
output.inverseYAxis = false;
|
||||||
|
FtContext context = { };
|
||||||
|
context.shape = &output;
|
||||||
|
FT_Outline_Funcs ftFunctions;
|
||||||
|
ftFunctions.move_to = &ftMoveTo;
|
||||||
|
ftFunctions.line_to = &ftLineTo;
|
||||||
|
ftFunctions.conic_to = &ftConicTo;
|
||||||
|
ftFunctions.cubic_to = &ftCubicTo;
|
||||||
|
ftFunctions.shift = 0;
|
||||||
|
ftFunctions.delta = 0;
|
||||||
|
FT_Error error = FT_Outline_Decompose(outline, &ftFunctions, &context);
|
||||||
|
if (!output.contours.empty() && output.contours.back().edges.empty())
|
||||||
|
output.contours.pop_back();
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
|
FontHandle * loadFont(FreetypeHandle *library, const char *filename) {
|
||||||
if (!library)
|
if (!library)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -181,26 +199,9 @@ bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *a
|
||||||
FT_Error error = FT_Load_Glyph(font->face, glyphIndex.getIndex(), FT_LOAD_NO_SCALE);
|
FT_Error error = FT_Load_Glyph(font->face, glyphIndex.getIndex(), FT_LOAD_NO_SCALE);
|
||||||
if (error)
|
if (error)
|
||||||
return false;
|
return false;
|
||||||
output.contours.clear();
|
|
||||||
output.inverseYAxis = false;
|
|
||||||
if (advance)
|
if (advance)
|
||||||
*advance = F26DOT6_TO_DOUBLE(font->face->glyph->advance.x);
|
*advance = F26DOT6_TO_DOUBLE(font->face->glyph->advance.x);
|
||||||
|
return !readFreetypeOutline(output, &font->face->glyph->outline);
|
||||||
FtContext context = { };
|
|
||||||
context.shape = &output;
|
|
||||||
FT_Outline_Funcs ftFunctions;
|
|
||||||
ftFunctions.move_to = &ftMoveTo;
|
|
||||||
ftFunctions.line_to = &ftLineTo;
|
|
||||||
ftFunctions.conic_to = &ftConicTo;
|
|
||||||
ftFunctions.cubic_to = &ftCubicTo;
|
|
||||||
ftFunctions.shift = 0;
|
|
||||||
ftFunctions.delta = 0;
|
|
||||||
error = FT_Outline_Decompose(&font->face->glyph->outline, &ftFunctions, &context);
|
|
||||||
if (error)
|
|
||||||
return false;
|
|
||||||
if (!output.contours.empty() && output.contours.back().edges.empty())
|
|
||||||
output.contours.pop_back();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance) {
|
bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *advance) {
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,13 @@ FreetypeHandle * initializeFreetype();
|
||||||
/// Deinitializes the FreeType library.
|
/// Deinitializes the FreeType library.
|
||||||
void deinitializeFreetype(FreetypeHandle *library);
|
void deinitializeFreetype(FreetypeHandle *library);
|
||||||
|
|
||||||
#ifdef FT_FREETYPE_H
|
#ifdef FT_LOAD_DEFAULT // FreeType included
|
||||||
/// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
|
/// Creates a FontHandle from FT_Face that was loaded by the user. destroyFont must still be called but will not affect the FT_Face.
|
||||||
FontHandle * adoptFreetypeFont(FT_Face ftFace);
|
FontHandle * adoptFreetypeFont(FT_Face ftFace);
|
||||||
|
/// Converts the geometry of FreeType's FT_Outline to a Shape object.
|
||||||
|
FT_Error readFreetypeOutline(Shape &output, FT_Outline *outline);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Loads a font file and returns its handle.
|
/// Loads a font file and returns its handle.
|
||||||
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
FontHandle * loadFont(FreetypeHandle *library, const char *filename);
|
||||||
/// Loads a font from binary data and returns its handle.
|
/// Loads a font from binary data and returns its handle.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue