Merge pull request #6 from ucpu/master

load shape directly from FT glyph slot
This commit is contained in:
Chris Kohnert 2018-02-28 09:18:33 -08:00 committed by GitHub
commit bf9e5671ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -7,7 +7,7 @@
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#ifdef _WIN32
#if defined(_WIN32) && !defined(MSDFGEN_NO_PRAGMA_LIB)
#pragma comment(lib, "freetype.lib")
#endif
@ -129,10 +129,17 @@ bool loadGlyph(Shape &output, FontHandle *font, int unicode, double *advance) {
FT_Error error = FT_Load_Char(font->face, unicode, FT_LOAD_NO_SCALE);
if (error)
return false;
return loadGlyphSlot(output, font->face->glyph, advance);
}
bool loadGlyphSlot(Shape &output, FT_GlyphSlot glyph, double *advance) {
if (!glyph)
return false;
output.contours.clear();
output.inverseYAxis = false;
if (advance)
*advance = font->face->glyph->advance.x/64.;
*advance = glyph->advance.x/64.;
FtContext context = { };
context.shape = &output;
@ -143,7 +150,7 @@ bool loadGlyph(Shape &output, FontHandle *font, int unicode, double *advance) {
ftFunctions.cubic_to = &ftCubicTo;
ftFunctions.shift = 0;
ftFunctions.delta = 0;
error = FT_Outline_Decompose(&font->face->glyph->outline, &ftFunctions, &context);
FT_Error error = FT_Outline_Decompose(&glyph->outline, &ftFunctions, &context);
if (error)
return false;
return true;

View File

@ -4,6 +4,8 @@
#include <cstdlib>
#include "../core/Shape.h"
typedef struct FT_GlyphSlotRec_ *FT_GlyphSlot;
namespace msdfgen {
class FreetypeHandle;
@ -23,6 +25,8 @@ bool getFontScale(double &output, FontHandle *font);
bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font);
/// Loads the shape prototype of a glyph from font file
bool loadGlyph(Shape &output, FontHandle *font, int unicode, double *advance = NULL);
/// Loads the shape prototype of a glyph directly from FT glyph slot
bool loadGlyphSlot(Shape &output, FT_GlyphSlot glyph, double *advance = NULL);
/// Returns the kerning distance adjustment between two specific glyphs.
bool getKerning(double &output, FontHandle *font, int unicode1, int unicode2);