|
|
58509f |
From a0455468fdb8dd1959596d0c8c8a3ff07ee495a3 Mon Sep 17 00:00:00 2001
|
|
|
58509f |
From: Nikolaus Waxweiler <madigens@gmail.com>
|
|
|
58509f |
Date: Sat, 20 May 2017 07:28:46 +0200
|
|
|
58509f |
Subject: [truetype] Always use interpreter v35 for B/W rendering (#51051).
|
|
|
58509f |
|
|
|
58509f |
* src/truetype/ttgload.c (tt_loader_init)
|
|
|
58509f |
[TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL]: Adjust
|
|
|
58509f |
`subpixel_hinting_lean', `grayscale_cleartype', and
|
|
|
58509f |
`vertical_lcd_lean' accordingly.
|
|
|
58509f |
|
|
|
58509f |
* src/truetype/ttinterp.c (Ins_GETINFO): Updated.
|
|
|
58509f |
(TT_RunIns): Update `backward_compatibility' flag.
|
|
|
58509f |
|
|
|
58509f |
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
|
|
|
58509f |
index 68a9b4ad5..e5a3da37a 100644
|
|
|
58509f |
--- a/src/truetype/ttgload.c
|
|
|
58509f |
+++ b/src/truetype/ttgload.c
|
|
|
58509f |
@@ -2339,13 +2339,19 @@
|
|
|
58509f |
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
|
|
|
58509f |
if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 )
|
|
|
58509f |
{
|
|
|
58509f |
- subpixel_hinting_lean = TRUE;
|
|
|
58509f |
- grayscale_cleartype = !FT_BOOL( load_flags &
|
|
|
58509f |
- FT_LOAD_TARGET_LCD ||
|
|
|
58509f |
- load_flags &
|
|
|
58509f |
- FT_LOAD_TARGET_LCD_V );
|
|
|
58509f |
- exec->vertical_lcd_lean = FT_BOOL( load_flags &
|
|
|
58509f |
- FT_LOAD_TARGET_LCD_V );
|
|
|
58509f |
+ subpixel_hinting_lean =
|
|
|
58509f |
+ FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) !=
|
|
|
58509f |
+ FT_RENDER_MODE_MONO );
|
|
|
58509f |
+ grayscale_cleartype =
|
|
|
58509f |
+ FT_BOOL( subpixel_hinting_lean &&
|
|
|
58509f |
+ !( ( load_flags &
|
|
|
58509f |
+ FT_LOAD_TARGET_LCD ) ||
|
|
|
58509f |
+ ( load_flags &
|
|
|
58509f |
+ FT_LOAD_TARGET_LCD_V ) ) );
|
|
|
58509f |
+ exec->vertical_lcd_lean =
|
|
|
58509f |
+ FT_BOOL( subpixel_hinting_lean &&
|
|
|
58509f |
+ ( load_flags &
|
|
|
58509f |
+ FT_LOAD_TARGET_LCD_V ) );
|
|
|
58509f |
}
|
|
|
58509f |
else
|
|
|
58509f |
{
|
|
|
58509f |
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
|
|
|
58509f |
index af31408cb..0c48c2562 100644
|
|
|
58509f |
--- a/src/truetype/ttinterp.c
|
|
|
58509f |
+++ b/src/truetype/ttinterp.c
|
|
|
58509f |
@@ -7345,7 +7345,7 @@
|
|
|
58509f |
/* */
|
|
|
58509f |
/* The only smoothing method FreeType supports unless someone sets */
|
|
|
58509f |
/* FT_LOAD_TARGET_MONO. */
|
|
|
58509f |
- if ( ( args[0] & 2048 ) != 0 )
|
|
|
58509f |
+ if ( ( args[0] & 2048 ) != 0 && exc->subpixel_hinting_lean )
|
|
|
58509f |
K |= 1 << 18;
|
|
|
58509f |
|
|
|
58509f |
/********************************/
|
|
|
58509f |
@@ -7589,11 +7589,21 @@
|
|
|
58509f |
#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */
|
|
|
58509f |
|
|
|
58509f |
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
|
|
|
58509f |
- /* Toggle backward compatibility according to what font says, except */
|
|
|
58509f |
- /* when it's a `tricky' font that heavily relies on the interpreter to */
|
|
|
58509f |
- /* render glyphs correctly, e.g. DFKai-SB. Backward compatibility */
|
|
|
58509f |
- /* hacks may break it. */
|
|
|
58509f |
+ /*
|
|
|
58509f |
+ * Toggle backward compatibility according to what font wants, except
|
|
|
58509f |
+ * when
|
|
|
58509f |
+ *
|
|
|
58509f |
+ * 1) we have a `tricky' font that heavily relies on the interpreter to
|
|
|
58509f |
+ * render glyphs correctly, for example DFKai-SB, or
|
|
|
58509f |
+ * 2) FT_RENDER_MODE_MONO (i.e, monochome rendering) is requested.
|
|
|
58509f |
+ *
|
|
|
58509f |
+ * In those cases, backward compatibility needs to be turned off to get
|
|
|
58509f |
+ * correct rendering. The rendering is then completely up to the
|
|
|
58509f |
+ * font's programming.
|
|
|
58509f |
+ *
|
|
|
58509f |
+ */
|
|
|
58509f |
if ( SUBPIXEL_HINTING_MINIMAL &&
|
|
|
58509f |
+ exc->subpixel_hinting_lean &&
|
|
|
58509f |
!FT_IS_TRICKY( &exc->face->root ) )
|
|
|
58509f |
exc->backward_compatibility = !( exc->GS.instruct_control & 4 );
|
|
|
58509f |
else
|
|
|
58509f |
diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h
|
|
|
58509f |
index 55e472091..abbecfcee 100644
|
|
|
58509f |
--- a/src/truetype/ttinterp.h
|
|
|
58509f |
+++ b/src/truetype/ttinterp.h
|
|
|
58509f |
@@ -253,23 +253,38 @@ FT_BEGIN_HEADER
|
|
|
58509f |
|
|
|
58509f |
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
|
|
|
58509f |
/*
|
|
|
58509f |
- * Modern TrueType fonts are usually rendered through Microsoft's
|
|
|
58509f |
- * collection of rendering techniques called ClearType (e.g., subpixel
|
|
|
58509f |
- * rendering and subpixel hinting). When ClearType was introduced, most
|
|
|
58509f |
- * fonts were not ready. Microsoft decided to implement a backward
|
|
|
58509f |
- * compatibility mode that employed several simple to complicated
|
|
|
58509f |
- * assumptions and tricks that modified the interpretation of the
|
|
|
58509f |
- * bytecode contained in these fonts to make them look ClearType-y
|
|
|
58509f |
- * somehow. Most (web)fonts that were released since then have come to
|
|
|
58509f |
- * rely on these hacks to render correctly, even some of Microsoft's
|
|
|
58509f |
- * flagship ClearType fonts (Calibri, Cambria, Segoe UI).
|
|
|
58509f |
+ * FreeType supports ClearType-like hinting of TrueType fonts through
|
|
|
58509f |
+ * the version 40 interpreter. This is achieved through several hacks
|
|
|
58509f |
+ * in the base (v35) interpreter, as detailed below.
|
|
|
58509f |
*
|
|
|
58509f |
- * The minimal subpixel hinting code (interpreter version 40) employs a
|
|
|
58509f |
- * small list of font-agnostic hacks to bludgeon non-native-ClearType
|
|
|
58509f |
- * fonts (except tricky ones[1]) into submission. It will not try to
|
|
|
58509f |
- * toggle hacks for specific fonts for performance and complexity
|
|
|
58509f |
- * reasons. The focus is on modern (web)fonts rather than legacy fonts
|
|
|
58509f |
- * that were made for black-and-white rendering.
|
|
|
58509f |
+ * ClearType is an umbrella term for several rendering techniques
|
|
|
58509f |
+ * employed by Microsoft's various GUI and rendering toolkit
|
|
|
58509f |
+ * implementations, most importantly: subpixel rendering for using the
|
|
|
58509f |
+ * RGB subpixels of LCDs to approximately triple the perceived
|
|
|
58509f |
+ * resolution on the x-axis and subpixel hinting for positioning stems
|
|
|
58509f |
+ * on subpixel borders. TrueType programming is explicit, i.e., fonts
|
|
|
58509f |
+ * must be programmed to take advantage of ClearType's possibilities.
|
|
|
58509f |
+ *
|
|
|
58509f |
+ * When ClearType was introduced, it seemed unlikely that all fonts
|
|
|
58509f |
+ * would be reprogrammed, so Microsoft decided to implement a backward
|
|
|
58509f |
+ * compatibility mode. It employs several simple to complicated
|
|
|
58509f |
+ * assumptions and tricks, many of them font-dependent, that modify the
|
|
|
58509f |
+ * interpretation of the bytecode contained in these fonts to retrofit
|
|
|
58509f |
+ * them into a ClearType-y look. The quality of the results varies.
|
|
|
58509f |
+ * Most (web)fonts that were released since then have come to rely on
|
|
|
58509f |
+ * these hacks to render correctly, even some of Microsoft's flagship
|
|
|
58509f |
+ * fonts (e.g., Calibri, Cambria, Segoe UI).
|
|
|
58509f |
+ *
|
|
|
58509f |
+ * FreeType's minimal subpixel hinting code (interpreter version 40)
|
|
|
58509f |
+ * employs a small list of font-agnostic hacks loosely based on the
|
|
|
58509f |
+ * public information available on Microsoft's compatibility mode[2].
|
|
|
58509f |
+ * The focus is on modern (web)fonts rather than legacy fonts that were
|
|
|
58509f |
+ * made for monochrome rendering. It will not match ClearType rendering
|
|
|
58509f |
+ * exactly. Unlike the `Infinality' code (interpreter version 38) that
|
|
|
58509f |
+ * came before, it will not try to toggle hacks for specific fonts for
|
|
|
58509f |
+ * performance and complexity reasons. It will fall back to version 35
|
|
|
58509f |
+ * behavior for tricky fonts[1] or when monochrome rendering is
|
|
|
58509f |
+ * requested.
|
|
|
58509f |
*
|
|
|
58509f |
* Major hacks
|
|
|
58509f |
*
|
|
|
58509f |
@@ -347,7 +362,8 @@ FT_BEGIN_HEADER
|
|
|
58509f |
*
|
|
|
58509f |
*/
|
|
|
58509f |
|
|
|
58509f |
- /* Using v40 implies subpixel hinting. Used to detect interpreter */
|
|
|
58509f |
+ /* Using v40 implies subpixel hinting, unless FT_RENDER_MODE_MONO has been
|
|
|
58509f |
+ * requested. Used to detect interpreter */
|
|
|
58509f |
/* version switches. `_lean' to differentiate from the Infinality */
|
|
|
58509f |
/* `subpixel_hinting', which is managed differently. */
|
|
|
58509f |
FT_Bool subpixel_hinting_lean;
|