2
0
Эх сурвалжийг харах

Minor FontCoordinateScaling tweaks

Chlumsky 1 жил өмнө
parent
commit
c7a724c173
3 өөрчлөгдсөн 21 нэмэгдсэн , 21 устгасан
  1. 6 6
      ext/import-font.cpp
  2. 9 9
      ext/import-font.h
  3. 6 6
      main.cpp

+ 6 - 6
ext/import-font.cpp

@@ -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) {
     switch (coordinateScaling) {
-        case FontCoordinateScaling::LEGACY:
-            return MSDFGEN_LEGACY_FONT_COORDINATE_SCALE;
-        case FontCoordinateScaling::KEEP_INTEGERS:
+        case FONT_SCALING_NONE:
             return 1;
-        case FontCoordinateScaling::EM_NORMALIZED:
+        case FONT_SCALING_EM_NORMALIZED:
             return 1./(face->units_per_EM ? face->units_per_EM : 1);
+        case FONT_SCALING_LEGACY:
+            return MSDFGEN_LEGACY_FONT_COORDINATE_SCALE;
     }
     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) {
-    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) {
-    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) {

+ 9 - 9
ext/import-font.h

@@ -48,13 +48,13 @@ struct FontVariationAxis {
 };
 
 /// The scaling applied to font glyph coordinates when loading a glyph
-enum class FontCoordinateScaling {
-    /// The incorrect legacy version that was in effect before version 1.12, coordinate values are divided by 64
-    LEGACY,
+enum FontCoordinateScaling {
     /// 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
-    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.
@@ -76,9 +76,9 @@ FontHandle *loadFontData(FreetypeHandle *library, const byte *data, int length);
 /// Unloads a font.
 void destroyFont(FontHandle *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.
-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.
 bool getGlyphCount(unsigned &output, FontHandle *font);
 /// 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, unicode_t unicode, double *outAdvance = NULL);
 /// 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, unicode_t unicode0, unicode_t unicode1, 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 = FONT_SCALING_LEGACY);
 
 #ifndef MSDFGEN_DISABLE_VARIABLE_FONTS
 /// Sets a single variation axis of a variable font.

+ 6 - 6
main.cpp

@@ -555,7 +555,7 @@ int main(int argc, const char *const *argv) {
     bool glyphIndexSpecified = false;
     GlyphIndex glyphIndex;
     unicode_t unicode = 0;
-    FontCoordinateScaling fontCoordinateScaling = FontCoordinateScaling::LEGACY;
+    FontCoordinateScaling fontCoordinateScaling = FONT_SCALING_LEGACY;
     bool fontCoordinateScalingSpecified = false;
 #endif
 
@@ -642,17 +642,17 @@ int main(int argc, const char *const *argv) {
             continue;
         }
         ARG_CASE("-noemnormalize", 0) {
-            fontCoordinateScaling = FontCoordinateScaling::KEEP_INTEGERS;
+            fontCoordinateScaling = FONT_SCALING_NONE;
             fontCoordinateScalingSpecified = true;
             continue;
         }
         ARG_CASE("-emnormalize", 0) {
-            fontCoordinateScaling = FontCoordinateScaling::EM_NORMALIZED;
+            fontCoordinateScaling = FONT_SCALING_EM_NORMALIZED;
             fontCoordinateScalingSpecified = true;
             continue;
         }
         ARG_CASE("-legacyfontscaling", 0) {
-            fontCoordinateScaling = FontCoordinateScaling::LEGACY;
+            fontCoordinateScaling = FONT_SCALING_LEGACY;
             fontCoordinateScalingSpecified = true;
             continue;
         }
@@ -694,7 +694,7 @@ int main(int argc, const char *const *argv) {
         ARG_CASE("-legacy", 0) {
             legacyMode = true;
         #ifdef MSDFGEN_EXTENSIONS
-            fontCoordinateScaling = FontCoordinateScaling::LEGACY;
+            fontCoordinateScaling = FONT_SCALING_LEGACY;
             fontCoordinateScalingSpecified = true;
         #endif
             continue;
@@ -1044,7 +1044,7 @@ int main(int argc, const char *const *argv) {
             if (!fontCoordinateScalingSpecified && (!autoFrame || scaleSpecified || rangeMode == RANGE_UNIT || mode == METRICS || printMetrics || shapeExport)) {
                 fputs(
                     "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"
                     "           -noemnormalize to switch to the correct native font coordinates,\n"
                     "           -emnormalize to switch to coordinates normalized to 1 em, or\n"