Minor FontCoordinateScaling tweaks

This commit is contained in:
Chlumsky 2024-04-21 12:17:13 +02:00
parent bc9f02e156
commit c7a724c173
3 changed files with 21 additions and 21 deletions

View File

@ -103,12 +103,12 @@ static int ftCubicTo(const FT_Vector *control1, const FT_Vector *control2, const
static double getFontCoordinateScale(const FT_Face &face, FontCoordinateScaling coordinateScaling) { static double getFontCoordinateScale(const FT_Face &face, FontCoordinateScaling coordinateScaling) {
switch (coordinateScaling) { switch (coordinateScaling) {
case FontCoordinateScaling::LEGACY: case FONT_SCALING_NONE:
return MSDFGEN_LEGACY_FONT_COORDINATE_SCALE;
case FontCoordinateScaling::KEEP_INTEGERS:
return 1; return 1;
case FontCoordinateScaling::EM_NORMALIZED: case FONT_SCALING_EM_NORMALIZED:
return 1./(face->units_per_EM ? face->units_per_EM : 1); return 1./(face->units_per_EM ? face->units_per_EM : 1);
case FONT_SCALING_LEGACY:
return MSDFGEN_LEGACY_FONT_COORDINATE_SCALE;
} }
return 1; return 1;
} }
@ -243,11 +243,11 @@ bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, FontCoordinat
} }
bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *outAdvance) { bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *outAdvance) {
return loadGlyph(output, font, glyphIndex, FontCoordinateScaling::LEGACY, outAdvance); return loadGlyph(output, font, glyphIndex, FONT_SCALING_LEGACY, outAdvance);
} }
bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *outAdvance) { bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *outAdvance) {
return loadGlyph(output, font, unicode, FontCoordinateScaling::LEGACY, outAdvance); return loadGlyph(output, font, unicode, FONT_SCALING_LEGACY, outAdvance);
} }
bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1, FontCoordinateScaling coordinateScaling) { bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1, FontCoordinateScaling coordinateScaling) {

View File

@ -48,13 +48,13 @@ struct FontVariationAxis {
}; };
/// The scaling applied to font glyph coordinates when loading a glyph /// The scaling applied to font glyph coordinates when loading a glyph
enum class FontCoordinateScaling { enum FontCoordinateScaling {
/// The incorrect legacy version that was in effect before version 1.12, coordinate values are divided by 64
LEGACY,
/// The coordinates are kept as the integer values native to the font file /// The coordinates are kept as the integer values native to the font file
KEEP_INTEGERS, FONT_SCALING_NONE,
/// The coordinates will be normalized to the em size, i.e. 1 = 1 em /// The coordinates will be normalized to the em size, i.e. 1 = 1 em
EM_NORMALIZED FONT_SCALING_EM_NORMALIZED,
/// The incorrect legacy version that was in effect before version 1.12, coordinate values are divided by 64 - DO NOT USE - for backwards compatibility only
FONT_SCALING_LEGACY
}; };
/// Initializes the FreeType library. /// Initializes the FreeType library.
@ -76,9 +76,9 @@ FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
/// Unloads a font. /// Unloads a font.
void destroyFont(FontHandle *font); void destroyFont(FontHandle *font);
/// Outputs the metrics of a font. /// Outputs the metrics of a font.
bool getFontMetrics(FontMetrics &metrics, FontHandle *font, FontCoordinateScaling coordinateScaling = FontCoordinateScaling::LEGACY); bool getFontMetrics(FontMetrics &metrics, FontHandle *font, FontCoordinateScaling coordinateScaling = FONT_SCALING_LEGACY);
/// Outputs the width of the space and tab characters. /// Outputs the width of the space and tab characters.
bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font, FontCoordinateScaling coordinateScaling = FontCoordinateScaling::LEGACY); bool getFontWhitespaceWidth(double &spaceAdvance, double &tabAdvance, FontHandle *font, FontCoordinateScaling coordinateScaling = FONT_SCALING_LEGACY);
/// Outputs the total number of glyphs available in the font. /// Outputs the total number of glyphs available in the font.
bool getGlyphCount(unsigned &output, FontHandle *font); bool getGlyphCount(unsigned &output, FontHandle *font);
/// Outputs the glyph index corresponding to the specified Unicode character. /// Outputs the glyph index corresponding to the specified Unicode character.
@ -90,8 +90,8 @@ bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, FontCoordinat
bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *outAdvance = NULL); bool loadGlyph(Shape &output, FontHandle *font, GlyphIndex glyphIndex, double *outAdvance = NULL);
bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *outAdvance = NULL); bool loadGlyph(Shape &output, FontHandle *font, unicode_t unicode, double *outAdvance = NULL);
/// Outputs the kerning distance adjustment between two specific glyphs. /// Outputs the kerning distance adjustment between two specific glyphs.
bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1, FontCoordinateScaling coordinateScaling = FontCoordinateScaling::LEGACY); bool getKerning(double &output, FontHandle *font, GlyphIndex glyphIndex0, GlyphIndex glyphIndex1, FontCoordinateScaling coordinateScaling = FONT_SCALING_LEGACY);
bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1, FontCoordinateScaling coordinateScaling = FontCoordinateScaling::LEGACY); bool getKerning(double &output, FontHandle *font, unicode_t unicode0, unicode_t unicode1, FontCoordinateScaling coordinateScaling = FONT_SCALING_LEGACY);
#ifndef MSDFGEN_DISABLE_VARIABLE_FONTS #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
/// Sets a single variation axis of a variable font. /// Sets a single variation axis of a variable font.

View File

@ -555,7 +555,7 @@ int main(int argc, const char *const *argv) {
bool glyphIndexSpecified = false; bool glyphIndexSpecified = false;
GlyphIndex glyphIndex; GlyphIndex glyphIndex;
unicode_t unicode = 0; unicode_t unicode = 0;
FontCoordinateScaling fontCoordinateScaling = FontCoordinateScaling::LEGACY; FontCoordinateScaling fontCoordinateScaling = FONT_SCALING_LEGACY;
bool fontCoordinateScalingSpecified = false; bool fontCoordinateScalingSpecified = false;
#endif #endif
@ -642,17 +642,17 @@ int main(int argc, const char *const *argv) {
continue; continue;
} }
ARG_CASE("-noemnormalize", 0) { ARG_CASE("-noemnormalize", 0) {
fontCoordinateScaling = FontCoordinateScaling::KEEP_INTEGERS; fontCoordinateScaling = FONT_SCALING_NONE;
fontCoordinateScalingSpecified = true; fontCoordinateScalingSpecified = true;
continue; continue;
} }
ARG_CASE("-emnormalize", 0) { ARG_CASE("-emnormalize", 0) {
fontCoordinateScaling = FontCoordinateScaling::EM_NORMALIZED; fontCoordinateScaling = FONT_SCALING_EM_NORMALIZED;
fontCoordinateScalingSpecified = true; fontCoordinateScalingSpecified = true;
continue; continue;
} }
ARG_CASE("-legacyfontscaling", 0) { ARG_CASE("-legacyfontscaling", 0) {
fontCoordinateScaling = FontCoordinateScaling::LEGACY; fontCoordinateScaling = FONT_SCALING_LEGACY;
fontCoordinateScalingSpecified = true; fontCoordinateScalingSpecified = true;
continue; continue;
} }
@ -694,7 +694,7 @@ int main(int argc, const char *const *argv) {
ARG_CASE("-legacy", 0) { ARG_CASE("-legacy", 0) {
legacyMode = true; legacyMode = true;
#ifdef MSDFGEN_EXTENSIONS #ifdef MSDFGEN_EXTENSIONS
fontCoordinateScaling = FontCoordinateScaling::LEGACY; fontCoordinateScaling = FONT_SCALING_LEGACY;
fontCoordinateScalingSpecified = true; fontCoordinateScalingSpecified = true;
#endif #endif
continue; continue;
@ -1044,7 +1044,7 @@ int main(int argc, const char *const *argv) {
if (!fontCoordinateScalingSpecified && (!autoFrame || scaleSpecified || rangeMode == RANGE_UNIT || mode == METRICS || printMetrics || shapeExport)) { if (!fontCoordinateScalingSpecified && (!autoFrame || scaleSpecified || rangeMode == RANGE_UNIT || mode == METRICS || printMetrics || shapeExport)) {
fputs( fputs(
"Warning: Using legacy font coordinate conversion for compatibility reasons.\n" "Warning: Using legacy font coordinate conversion for compatibility reasons.\n"
" The scaling behavior in this configuration will likely change in a future version resulting in different output.\n" " The implicit scaling behavior will likely change in a future version resulting in different output.\n"
" To silence this warning, use one of the following options:\n" " To silence this warning, use one of the following options:\n"
" -noemnormalize to switch to the correct native font coordinates,\n" " -noemnormalize to switch to the correct native font coordinates,\n"
" -emnormalize to switch to coordinates normalized to 1 em, or\n" " -emnormalize to switch to coordinates normalized to 1 em, or\n"