summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorWerner Lemberg <wl@gnu.org>2017-04-22 13:27:21 +0200
committerWerner Lemberg <wl@gnu.org>2017-04-26 11:39:53 +0200
commit5aa6716a5eb8409f606886b5d4e63476d85a3519 (patch)
tree9e802a4bd0e221dceb162c98fc7c0a02413fa8d3 /include
parent69da54cacc0056a40fc7f88278c4c60fd35e7bb9 (diff)
downloadfreetype2-5aa6716a5eb8409f606886b5d4e63476d85a3519.tar.gz
Add new `slight' auto-hinting mode.
This mode uses fractional advance widths and doesn't scale glyphs horizontally, only applying vertical scaling and hinting. At the same time, the behaviour of the `light' auto-hinter gets restored for backwards compatibility: Both vertical and horizontal scaling is again based on rounded metrics values (this was changed in a commit from 2017-03-30 as a side effect). To be more precise, the behaviour is restored for TrueType fonts only; for other font formats like Type 1, this is a new feature of the `light' hinting mode. * include/freetype/freetype.h (FT_LOAD_TARGET_SLIGHT): New macro. (FT_RENDER_MODE_SLIGHT): New render mode. * include/freetype/internal/ftobjs.h (FT_Size_InternalRec): Add `autohint_mode' and `autohint_metrics' fields. * src/autofit/afcjk.c (af_cjk_hints_init), src/autofit/aflatin.c (af_latin_hints_init), src/autofit/aflatin2 (af_latin2_hints_init): Updated. * src/autofit/afloader.c (af_loader_embolden_glyph_in_slot): Use `autohint_metrics'. (af_loader_load_glyph): s/internal/slot_internal/. Initialize `autohint_metrics' and `autohint_mode' depending on current auto-hint mode. Use `autohint_metrics'. Updated. * src/base/ftadvanc.c (LOAD_ADVANCE_FAST_CHECK): Updated. * src/base/ftobjs.c (FT_Load_Glyph): Updated. (FT_New_Size): Allocate `internal' object. * src/pshinter/pshalgo.c (ps_hints_apply): Updated. * src/smooth/ftsmooth.c (ft_smooth_render): Updated.
Diffstat (limited to 'include')
-rw-r--r--include/freetype/freetype.h31
-rw-r--r--include/freetype/internal/ftobjs.h9
2 files changed, 38 insertions, 2 deletions
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 4ed86b981..e579056d0 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -221,6 +221,7 @@ FT_BEGIN_HEADER
/* */
/* FT_LOAD_TARGET_NORMAL */
/* FT_LOAD_TARGET_LIGHT */
+ /* FT_LOAD_TARGET_SLIGHT */
/* FT_LOAD_TARGET_MONO */
/* FT_LOAD_TARGET_LCD */
/* FT_LOAD_TARGET_LCD_V */
@@ -1755,7 +1756,8 @@ FT_BEGIN_HEADER
/* `slot->format' is also changed to @FT_GLYPH_FORMAT_BITMAP. */
/* */
/* Here is a small pseudo code fragment that shows how to use */
- /* `lsb_delta' and `rsb_delta': */
+ /* `lsb_delta' and `rsb_delta' to improve (integer) positioning of */
+ /* glyphs: */
/* */
/* { */
/* FT_Pos origin_x = 0; */
@@ -2941,6 +2943,18 @@ FT_BEGIN_HEADER
* driver, if the driver itself and the font support it, or by the
* auto-hinter.
*
+ * Use this hinting mode if you mainly need integer advance widths
+ * and want to avoid sub-pixel rendering.
+ *
+ * FT_LOAD_TARGET_SLIGHT ::
+ * This is similar to @FT_LOAD_TARGET_LIGHT with a main difference:
+ * Advance widths are not rounded to integer values; instead, the
+ * linearly scaled values are used. In particular this implies that
+ * you have to apply sub-pixel rendering.
+ *
+ * In general, this mode yields better results than
+ * @FT_LOAD_TARGET_LIGHT.
+ *
* FT_LOAD_TARGET_MONO ::
* Strong hinting algorithm that should only be used for monochrome
* output. The result is probably unpleasant if the glyph is rendered
@@ -2975,11 +2989,19 @@ FT_BEGIN_HEADER
* FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD );
* }
*
+ * In general, you should stick with one rendering mode. For example,
+ * switching between @FT_LOAD_TARGET_LIGHT and @FT_LOAD_TARGET_SLIGHT
+ * enforces a lot of recomputation, which is slow. Another reason is
+ * caching: Selecting a different mode usually causes changes in both
+ * the outlines and the rasterized bitmaps; it is thus necessary to
+ * empty the cache after a mode switch to avoid false hits.
+ *
*/
#define FT_LOAD_TARGET_( x ) ( (FT_Int32)( (x) & 15 ) << 16 )
#define FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL )
#define FT_LOAD_TARGET_LIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT )
+#define FT_LOAD_TARGET_SLIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_SLIGHT )
#define FT_LOAD_TARGET_MONO FT_LOAD_TARGET_( FT_RENDER_MODE_MONO )
#define FT_LOAD_TARGET_LCD FT_LOAD_TARGET_( FT_RENDER_MODE_LCD )
#define FT_LOAD_TARGET_LCD_V FT_LOAD_TARGET_( FT_RENDER_MODE_LCD_V )
@@ -3060,6 +3082,12 @@ FT_BEGIN_HEADER
/* indirectly to define hinting algorithm selectors. See */
/* @FT_LOAD_TARGET_XXX for details. */
/* */
+ /* FT_RENDER_MODE_SLIGHT :: */
+ /* This is equivalent to @FT_RENDER_MODE_NORMAL. It is only */
+ /* defined as a separate value because render modes are also used */
+ /* indirectly to define hinting algorithm selectors. See */
+ /* @FT_LOAD_TARGET_XXX for details. */
+ /* */
/* FT_RENDER_MODE_MONO :: */
/* This mode corresponds to 1-bit bitmaps (with 2~levels of */
/* opacity). */
@@ -3092,6 +3120,7 @@ FT_BEGIN_HEADER
{
FT_RENDER_MODE_NORMAL = 0,
FT_RENDER_MODE_LIGHT,
+ FT_RENDER_MODE_SLIGHT,
FT_RENDER_MODE_MONO,
FT_RENDER_MODE_LCD,
FT_RENDER_MODE_LCD_V,
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index c8526e6fd..558409166 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -443,7 +443,11 @@ FT_BEGIN_HEADER
/* object. */
/* */
/* <Fields> */
- /* module_data :: Data specific to a driver module. */
+ /* module_data :: Data specific to a driver module. */
+ /* */
+ /* autohint_mode :: The used auto-hinting mode. */
+ /* */
+ /* autohint_metrics :: Metrics used by the auto-hinter. */
/* */
/*************************************************************************/
@@ -451,6 +455,9 @@ FT_BEGIN_HEADER
{
void* module_data;
+ FT_Render_Mode autohint_mode;
+ FT_Size_Metrics autohint_metrics;
+
} FT_Size_InternalRec;