]> granicus.if.org Git - libass/commitdiff
Restore hinting
authorwm4 <wm4@nowhere>
Tue, 24 Sep 2013 20:28:35 +0000 (22:28 +0200)
committerwm4 <wm4@nowhere>
Tue, 24 Sep 2013 20:28:35 +0000 (22:28 +0200)
This was broken since commit f780146. For reasons why, read the commit
message of that commit. To make it short, we set the font size to
something large and constant (256), and scale the font outlines returned
by freetype to the size we need in order to get smooth animation and
accurate positioning.

Of course, this obviously breaks hinting. Fix hinting by not using the
hack mentioned above if hinting enabled.

To mitigate the issues caused by freetype grid fitting and extremely
bad ASS scripts (such as setting font size to very small values and
scaling them up with \fscx/y), we still adjust the font size such that
the font is never scaled in Y direction (only in X direction, because
the \fscx/y tags can change aspect ratio).

Also see google code issue #46.

libass/ass.h
libass/ass_render.c

index 0778a5c62c962a589b07119c585626139dedc699..cb85a2ca5728ece3875a53d3d7a1a565904e099f 100644 (file)
@@ -56,6 +56,13 @@ typedef struct ass_image {
 /*
  * Hinting type. (see ass_set_hinting below)
  *
+ * Setting hinting to anything but ASS_HINTING_NONE will put libass in a mode
+ * that reduces compatibility with vsfilter and many ASS scripts. The main
+ * problem is that hinting conflicts with smooth scaling, which precludes
+ * animations and precise positioning.
+ *
+ * In other words, enabling hinting might break some scripts severely.
+ *
  * FreeType's native hinter is still buggy sometimes and it is recommended
  * to use the light autohinter, ASS_HINTING_LIGHT, instead.  For best
  * compatibility with problematic fonts, disable hinting.
index e592548dc3e1f5e71c185eb8eee2a60e08aa0d58..45d88bbe1fc13fa35eec0f691029ff49c11f8376 100644 (file)
@@ -1097,9 +1097,16 @@ get_outline_glyph(ASS_Renderer *priv, GlyphInfo *info)
             v.desc = drawing->desc;
             key.u.drawing.text = strdup(drawing->text);
         } else {
-            // arbitrary, not too small to prevent grid fitting rounding effects
-            // XXX: this is a rather crude hack
-            const double ft_size = 256.0;
+            double ft_size;
+            if (priv->settings.hinting == ASS_HINTING_NONE) {
+                // arbitrary, not too small to prevent grid fitting rounding effects
+                // XXX: this is a rather crude hack
+                ft_size = 256.0;
+            } else {
+                // If hinting is enabled, we want to pass the real font size
+                // to freetype. Normalize scale_y to 1.0.
+                ft_size = info->scale_y * info->font_size;
+            }
             ass_face_set_size(info->font->faces[info->face_index], ft_size);
             ass_font_set_transform(info->font,
                 info->scale_x * info->font_size / ft_size,