From 84f034aed978098869ba966fc280a2c89857dc2a Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 8 Feb 2012 07:31:32 +0100 Subject: [PATCH] A first try to integrate the Infinality patches for the autohinter. It provides a framework for properties and adds a single property, `adjust glyph heights'. --- include/freetype/config/ftheader.h | 14 ++- include/freetype/ftautoh.h | 195 +++++++++++++++++++++++++++++ include/freetype/ftchapters.h | 1 + include/freetype/internal/ftobjs.h | 14 ++- src/autofit/aflatin.c | 19 ++- src/base/ftautoh.c | 84 +++++++++++++ src/base/ftobjs.c | 4 +- 7 files changed, 324 insertions(+), 7 deletions(-) create mode 100644 include/freetype/ftautoh.h create mode 100644 src/base/ftautoh.c diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h index 2a7b8c4e0..aebeb1742 100644 --- a/include/freetype/config/ftheader.h +++ b/include/freetype/config/ftheader.h @@ -4,7 +4,7 @@ /* */ /* Build macros of the FreeType 2 library. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 by */ +/* Copyright 1996-2008, 2010, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -706,6 +706,18 @@ #define FT_LCD_FILTER_H + /************************************************************************* + * + * @macro: + * FT_AUTOHINTER_H + * + * @description: + * A macro used in #include statements to name the file containing the + * FreeType~2 API which controls the behaviour of the auto-hinter. + */ +#define FT_AUTOHINTER_H + + /************************************************************************* * * @macro: diff --git a/include/freetype/ftautoh.h b/include/freetype/ftautoh.h new file mode 100644 index 000000000..d4356212f --- /dev/null +++ b/include/freetype/ftautoh.h @@ -0,0 +1,195 @@ +/***************************************************************************/ +/* */ +/* ftautoh.h */ +/* */ +/* FreeType API for setting and accessing auto-hinter properties */ +/* (specification). */ +/* */ +/* Copyright 2012 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef __FTAUTOH_H__ +#define __FTAUTOH_H__ + +#include +#include FT_FREETYPE_H + +#ifdef FREETYPE_H +#error "freetype.h of FreeType 1 has been loaded!" +#error "Please fix the directory search order for header files" +#error "so that freetype.h of FreeType 2 is found first." +#endif + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /*
*/ + /* autohinter */ + /* */ + /* */ + /* The Auto-hinter */ + /* */ + /* <Abstract> */ + /* Controlling the behaviour of the auto-hinting engine. */ + /* */ + /* <Description> */ + /* This section contains the declaration of functions specific to the */ + /* auto-hinter. */ + /* */ + /*************************************************************************/ + + + /********************************************************************** + * + * @enum: + * FT_AUTOHINTER_XXX + * + * @description: + * A list of bit-field constants used with + * @FT_Library_GetAutohinterProperties, + * @FT_Face_GetAutohinterProperties, + * @FT_Library_SetAutohinterProperties, and + * @FT_Face_SetAutohinterProperties to control the behaviour of the + * auto-hinter. + * + * @values: + * FT_AUTOHINTER_DEFAULT:: + * Corresponding to~0, this value indicates the default value. + * + * FT_AUTOHINTER_INCREASE_GLYPH_HEIGHTS :: + * For glyphs in the size range 5 < PPEM < 15, round up the glyph + * height much more often than normally. + */ +#define FT_AUTOHINTER_DEFAULT 0x0 +#define FT_AUTOHINTER_INCREASE_GLYPH_HEIGHTS ( 1L << 0 ) + + + /********************************************************************** + * + * @function: + * FT_Library_GetAutohinterProperties + * + * @description: + * Retrieve the global property flags which control the behaviour of the + * auto-hinter. + * + * @output: + * properties :: + * The current global auto-hinter property flags, consisting of + * @FT_AUTOHINTER_XXX constants which are ORed together. + * + * Use @FT_Face_GetAutohinterProperties to retrieve the local + * properties of a face. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Library_GetAutohinterProperties( FT_Library library, + FT_Int32 *properties ); + + + /********************************************************************** + * + * @function: + * FT_Library_SetAutohinterProperties + * + * @description: + * Set the global property flags which control the behaviour of the + * auto-hinter. + * + * @input: + * properties :: + * The auto-hinter property flags to be set globally, consisting of + * @FT_AUTOHINTER_XXX constants which are ORed together. All faces + * created after a call to this function inherit the new auto-hinter + * properties. + * + * Use @FT_Face_SetAutohinterProperties to override the properties + * locally. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Library_SetAutohinterProperties( FT_Library library, + FT_Int32 properties ); + + + /********************************************************************** + * + * @function: + * FT_Face_GetAutohinterProperties + * + * @description: + * Retrieve the property flags which control the behaviour of the + * auto-hinter for the given face. + * + * @input: + * face :: + * A handle to the input face. + * + * @output: + * properties :: + * The current auto-hinter property flags of the given face, + * consisting of @FT_AUTOHINTER_XXX constants which are ORed + * together. + * + * @return: + * FreeType error code. 0~means success. + * + */ + FT_EXPORT( FT_Error ) + FT_Face_GetAutohinterProperties( FT_Face face, + FT_Int32 *properties ); + + + /********************************************************************** + * + * @function: + * FT_Face_SetAutohinterProperties + * + * @description: + * Set the property flags which control the behaviour of the autolhinter + * for the given face. + * + * @input: + * face :: + * A handle to the input face. + * + * properties :: + * The auto-hinter property flags to be set for the given face, + * consisting of @FT_AUTOHINTER_XXX constants which are ORed + * together. + * + * By default, a face inherits the global auto-hinter properties (set + * with @FT_Library_SetAutohinterProperties, if any) at the time of + * its creation. Using this function you can override them locally. + * + * @return: + * FreeType error code. 0~means success. + */ + FT_EXPORT( FT_Error ) + FT_Face_SetAutohinterProperties( FT_Face face, + FT_Int32 properties ); + + /* */ + +FT_END_HEADER + +#endif /* __FTAUTOH_H__ */ + + +/* END */ diff --git a/include/freetype/ftchapters.h b/include/freetype/ftchapters.h index 6cdf54e49..ad0a6b0b3 100644 --- a/include/freetype/ftchapters.h +++ b/include/freetype/ftchapters.h @@ -100,5 +100,6 @@ /* lzw */ /* bzip2 */ /* lcd_filtering */ +/* autohinter */ /* */ /***************************************************************************/ diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 5c227e19e..0259f844a 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (specification). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2010 by */ +/* Copyright 1996-2006, 2008, 2010, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -305,6 +305,9 @@ FT_BEGIN_HEADER /* this data when first opened. This field exists only if */ /* @FT_CONFIG_OPTION_INCREMENTAL is defined. */ /* */ + /* auto_hinter_flags :: */ + /* Flags controlling the behaviour of the auto-hinter locally. */ + /* */ /* ignore_unpatented_hinter :: */ /* This boolean flag instructs the glyph loader to ignore the */ /* native font hinter, if one is found. This is exclusively used */ @@ -333,6 +336,8 @@ FT_BEGIN_HEADER FT_Incremental_InterfaceRec* incremental_interface; #endif + FT_Int32 auto_hinter_flags; + FT_Bool ignore_unpatented_hinter; FT_UInt refcount; @@ -803,7 +808,10 @@ FT_BEGIN_HEADER /* handle to the current renderer for the */ /* FT_GLYPH_FORMAT_OUTLINE format. */ /* */ - /* auto_hinter :: XXX */ + /* auto_hinter :: The current auto-hinter. */ + /* */ + /* auto_hinter_flags :: Flags controlling the behaviour of the */ + /* auto-hinter globally. */ /* */ /* raster_pool :: The raster object's render pool. This can */ /* ideally be changed dynamically at run-time. */ @@ -850,6 +858,8 @@ FT_BEGIN_HEADER FT_ListRec renderers; /* list of renderers */ FT_Renderer cur_renderer; /* current outline renderer */ FT_Module auto_hinter; + FT_Int32 auto_hinter_flags; /* global flags controlling */ + /* the autohinter behaviour */ FT_Byte* raster_pool; /* scan-line conversion */ /* render pool */ diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c index 30145a2b7..5853d9ec4 100644 --- a/src/autofit/aflatin.c +++ b/src/autofit/aflatin.c @@ -4,7 +4,7 @@ /* */ /* Auto-fitter hinting routines for latin script (body). */ /* */ -/* Copyright 2003-2011 by */ +/* Copyright 2003-2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -18,6 +18,7 @@ #include <ft2build.h> #include FT_ADVANCES_H +#include FT_AUTOHINTER_H #include FT_INTERNAL_DEBUG_H #include "aflatin.h" @@ -569,10 +570,22 @@ if ( blue ) { - FT_Pos scaled = FT_MulFix( blue->shoot.org, scaler->y_scale ); - FT_Pos fitted = ( scaled + 40 ) & ~63; + FT_Pos scaled; + FT_Pos threshold; + FT_Pos fitted; + scaled = FT_MulFix( blue->shoot.org, scaler->y_scale ); + + threshold = 40; + if ( ( metrics->root.scaler.face->internal->auto_hinter_flags & + FT_AUTOHINTER_INCREASE_GLYPH_HEIGHTS ) && + metrics->root.scaler.face->size->metrics.x_ppem < 15 && + metrics->root.scaler.face->size->metrics.x_ppem > 5 ) + threshold = 52; + + fitted = ( scaled + threshold ) & ~63; + if ( scaled != fitted ) { #if 0 diff --git a/src/base/ftautoh.c b/src/base/ftautoh.c new file mode 100644 index 000000000..b704abefa --- /dev/null +++ b/src/base/ftautoh.c @@ -0,0 +1,84 @@ +/***************************************************************************/ +/* */ +/* ftautoh.c */ +/* */ +/* FreeType API for setting and accessing auto-hinter properties */ +/* (body). */ +/* */ +/* Copyright 2012 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include <ft2build.h> +#include FT_INTERNAL_OBJECTS_H + + + /* documentation is in ftautoh.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Library_GetAutohinterProperties( FT_Library library, + FT_Int32 *properties ) + { + if ( !library || !properties ) + return FT_Err_Invalid_Argument; + + *properties = library->auto_hinter_flags; + + return FT_Err_Ok; + } + + + /* documentation is in ftautoh.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Library_SetAutohinterProperties( FT_Library face, + FT_Int32 properties ) + { + if ( !library ) + return FT_Err_Invalid_Argument; + + library->auto_hinter_flags = properties; + + return FT_Err_Ok; + } + + + /* documentation is in ftautoh.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Face_GetAutohinterProperties( FT_Face face, + FT_Int32 *properties ) + { + if ( !face || !properties ) + return FT_Err_Invalid_Argument; + + *properties = face->internal->auto_hinter_flags; + + return FT_Err_Ok; + } + + + /* documentation is in ftautoh.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Face_SetAutohinterProperties( FT_Face face, + FT_Int32 properties ) + { + if ( !face ) + return FT_Err_Invalid_Argument; + + face->internal->auto_hinter_flags = properties; + + return FT_Err_Ok; + } + + +/* END */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index b776a951b..00c945551 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (body). */ /* */ -/* Copyright 1996-2011 by */ +/* Copyright 1996-2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -2222,6 +2222,8 @@ internal->transform_delta.x = 0; internal->transform_delta.y = 0; + internal->auto_hinter_flags = library->auto_hinter_flags; + internal->refcount = 1; }