mirror of https://github.com/Chlumsky/msdfgen.git
Use `units_per_EM` property in font to scale font data.
This scales so that units_per_EM=2048 is the baseline and other values are scaled to this size.
This commit is contained in:
parent
fdc26858d0
commit
ed587a1454
|
|
@ -68,7 +68,7 @@ void destroyFont(FontHandle *font) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getFontScale(double &output, FontHandle *font) {
|
bool getFontScale(double &output, FontHandle *font) {
|
||||||
output = font->face->units_per_EM/64.;
|
output = font->face->units_per_EM;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,10 +98,16 @@ bool loadGlyph(Shape &output, FontHandle *font, int unicode, double *advance) {
|
||||||
FT_Error error = FT_Load_Char(font->face, unicode, FT_LOAD_NO_SCALE);
|
FT_Error error = FT_Load_Char(font->face, unicode, FT_LOAD_NO_SCALE);
|
||||||
if (error)
|
if (error)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
double unitsPerEm;
|
||||||
|
double unitScale;
|
||||||
|
getFontScale(unitsPerEm, font);
|
||||||
|
unitScale = 2048.0 / unitsPerEm;
|
||||||
|
|
||||||
output.contours.clear();
|
output.contours.clear();
|
||||||
output.inverseYAxis = false;
|
output.inverseYAxis = false;
|
||||||
if (advance)
|
if (advance)
|
||||||
*advance = font->face->glyph->advance.x/64.;
|
*advance = unitScale * font->face->glyph->advance.x/64.;
|
||||||
|
|
||||||
int last = -1;
|
int last = -1;
|
||||||
// For each contour
|
// For each contour
|
||||||
|
|
@ -123,7 +129,7 @@ bool loadGlyph(Shape &output, FontHandle *font, int unicode, double *advance) {
|
||||||
round++;
|
round++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2 point(font->face->glyph->outline.points[index].x/64., font->face->glyph->outline.points[index].y/64.);
|
Point2 point(unitScale*font->face->glyph->outline.points[index].x/64., unitScale*font->face->glyph->outline.points[index].y/64.);
|
||||||
PointType pointType = font->face->glyph->outline.tags[index]&1 ? PATH_POINT : font->face->glyph->outline.tags[index]&2 ? CUBIC_POINT : QUADRATIC_POINT;
|
PointType pointType = font->face->glyph->outline.tags[index]&1 ? PATH_POINT : font->face->glyph->outline.tags[index]&2 ? CUBIC_POINT : QUADRATIC_POINT;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue