summaryrefslogtreecommitdiffstats
path: root/src/truetype/ttinterp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/truetype/ttinterp.h')
-rw-r--r--src/truetype/ttinterp.h147
1 files changed, 137 insertions, 10 deletions
diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h
index 32706d0..53f0944 100644
--- a/src/truetype/ttinterp.h
+++ b/src/truetype/ttinterp.h
@@ -4,7 +4,7 @@
/* */
/* TrueType bytecode interpreter (specification). */
/* */
-/* Copyright 1996-2015 by */
+/* Copyright 1996-2016 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -16,8 +16,8 @@
/***************************************************************************/
-#ifndef __TTINTERP_H__
-#define __TTINTERP_H__
+#ifndef TTINTERP_H_
+#define TTINTERP_H_
#include <ft2build.h>
#include "ttobjs.h"
@@ -99,7 +99,7 @@ FT_BEGIN_HEADER
} TT_CallRec, *TT_CallStack;
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY
/*************************************************************************/
/* */
@@ -138,7 +138,7 @@ FT_BEGIN_HEADER
} SPH_Font_Class;
-#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */
/*************************************************************************/
@@ -170,6 +170,7 @@ FT_BEGIN_HEADER
pts,
twilight;
+ FT_Long pointSize; /* in 26.6 format */
FT_Size_Metrics metrics;
TT_Size_Metrics tt_metrics; /* size metrics */
@@ -247,9 +248,135 @@ FT_BEGIN_HEADER
TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */
TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */
- FT_Bool grayscale; /* are we hinting for grayscale? */
-
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+ FT_Bool grayscale; /* bi-level hinting and */
+ /* grayscale rendering */
+
+#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
+ /*
+ * Modern TrueType fonts are usually rendered through Microsoft's
+ * collection of rendering techniques called ClearType (e.g., subpixel
+ * rendering and subpixel hinting). When ClearType was introduced, most
+ * fonts were not ready. Microsoft decided to implement a backwards
+ * compatibility mode that employed several simple to complicated
+ * assumptions and tricks that modified the interpretation of the
+ * bytecode contained in these fonts to make them look ClearType-y
+ * somehow. Most (web)fonts that were released since then have come to
+ * rely on these hacks to render correctly, even some of Microsoft's
+ * flagship ClearType fonts (Calibri, Cambria, Segoe UI).
+ *
+ * The minimal subpixel hinting code (interpreter version 40) employs a
+ * small list of font-agnostic hacks to bludgeon non-native-ClearType
+ * fonts (except tricky ones[1]) into submission. It will not try to
+ * toggle hacks for specific fonts for performance and complexity
+ * reasons. The focus is on modern (web)fonts rather than legacy fonts
+ * that were made for black-and-white rendering.
+ *
+ * Major hacks
+ *
+ * - Any point movement on the x axis is ignored (cf. `Direct_Move' and
+ * `Direct_Move_X'). This has the smallest code footprint and single
+ * biggest effect. The ClearType way to increase resolution is
+ * supersampling the x axis, the FreeType way is ignoring instructions
+ * on the x axis, which gives the same result in the majority of
+ * cases.
+ *
+ * - Points are not moved post-IUP (neither on the x nor on the y axis),
+ * except the x component of diagonal moves post-IUP (cf.
+ * `Direct_Move', `Direct_Move_Y', `Move_Zp2_Point'). Post-IUP
+ * changes are commonly used to `fix' pixel patterns which has little
+ * use outside monochrome rendering.
+ *
+ * - SHPIX and DELTAP don't execute unless moving a composite on the
+ * y axis or moving a previously y touched point. SHPIX additionally
+ * denies movement on the x axis (cf. `Ins_SHPIX' and `Ins_DELTAP').
+ * Both instructions are commonly used to `fix' pixel patterns for
+ * monochrome or Windows's GDI rendering but make little sense for
+ * FreeType rendering. Both can distort the outline. See [2] for
+ * details.
+ *
+ * - The hdmx table and modifications to phantom points are ignored.
+ * Bearings and advance widths remain unchanged (except rounding them
+ * outside the interpreter!), cf. `compute_glyph_metrics' and
+ * `TT_Hint_Glyph'. Letting non-native-ClearType fonts modify spacing
+ * might mess up spacing.
+ *
+ * Minor hacks
+ *
+ * - FLIPRGON, FLIPRGOFF, and FLIPPT don't execute post-IUP. This
+ * prevents dents in e.g. Arial-Regular's `D' and `G' glyphs at
+ * various sizes.
+ *
+ * (Post-IUP is the state after both IUP[x] and IUP[y] have been
+ * executed.)
+ *
+ * The best results are achieved for fonts that were from the outset
+ * designed with ClearType in mind, meaning they leave the x axis mostly
+ * alone and don't mess with the `final' outline to produce more
+ * pleasing pixel patterns. The harder the designer tried to produce
+ * very specific patterns (`superhinting') for pre-ClearType-displays,
+ * the worse the results.
+ *
+ * Microsoft defines a way to turn off backwards compatibility and
+ * interpret instructions as before (called `native ClearType')[2][3].
+ * The font designer then regains full control and is responsible for
+ * making the font work correctly with ClearType without any
+ * hand-holding by the interpreter or rasterizer[4]. The v40
+ * interpreter assumes backwards compatibility by default, which can be
+ * turned off the same way by executing the following in the control
+ * program (cf. `Ins_INSTCTRL').
+ *
+ * #PUSH 4,3
+ * INSTCTRL[]
+ *
+ * [1] Tricky fonts as FreeType defines them rely on the bytecode
+ * interpreter to display correctly. Hacks can interfere with them,
+ * so they get treated like native ClearType fonts (v40 with
+ * backwards compatibility turned off). Cf. `TT_RunIns'.
+ *
+ * [2] Proposed by Microsoft's Greg Hitchcock in
+ * https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx
+ *
+ * [3] Beat Stamm describes it in more detail:
+ * http://www.beatstamm.com/typography/RTRCh4.htm#Sec12
+ *
+ * [4] The list of `native ClearType' fonts is small at the time of this
+ * writing; I found the following on a Windows 10 Update 1511
+ * installation: Constantia, Corbel, Sitka, Malgun Gothic, Microsoft
+ * JhengHei (Bold and UI Bold), Microsoft YaHei (Bold and UI Bold),
+ * SimSun, NSimSun, and Yu Gothic.
+ *
+ */
+
+ /* Using v40 implies subpixel hinting. Used to detect interpreter */
+ /* version switches. `_lean' to differentiate from the Infinality */
+ /* `subpixel_hinting', which is managed differently. */
+ FT_Bool subpixel_hinting_lean;
+
+ /* Long side of a LCD subpixel is vertical (e.g., screen is rotated). */
+ /* `_lean' to differentiate from the Infinality `vertical_lcd', which */
+ /* is managed differently. */
+ FT_Bool vertical_lcd_lean;
+
+ /* Default to backwards compatibility mode in v40 interpreter. If */
+ /* this is false, it implies the interpreter is in v35 or in native */
+ /* ClearType mode. */
+ FT_Bool backwards_compatibility;
+
+ /* Useful for detecting and denying post-IUP trickery that is usually */
+ /* used to fix pixel patterns (`superhinting'). */
+ FT_Bool iupx_called;
+ FT_Bool iupy_called;
+
+ /* ClearType hinting and grayscale rendering, as used by Universal */
+ /* Windows Platform apps (Windows 8 and above). Like the standard */
+ /* colorful ClearType mode, it utilizes a vastly increased virtual */
+ /* resolution on the x axis. Different from bi-level hinting and */
+ /* grayscale rendering, the old mode from Win9x days that roughly */
+ /* adheres to the physical pixel grid on both axes. */
+ FT_Bool grayscale_cleartype;
+#endif /* TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL */
+
+#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY
TT_Round_Func func_round_sphn; /* subpixel rounding function */
FT_Bool subpixel_hinting; /* Using subpixel hinting? */
@@ -279,7 +406,7 @@ FT_BEGIN_HEADER
FT_ULong sph_in_func_flags; /* flags to indicate if in */
/* special functions */
-#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */
} TT_ExecContextRec;
@@ -382,7 +509,7 @@ FT_BEGIN_HEADER
FT_END_HEADER
-#endif /* __TTINTERP_H__ */
+#endif /* TTINTERP_H_ */
/* END */