Al-Qurtas-Islamic-bank-The-.../src/truetype/ttsubpix.c

266 lines
8.6 KiB
C
Raw Normal View History

[truetype] Support subpixel hinting. This is the large, famous `Infinality' patch to support ClearType bytecode which has been available from http://www.infinality.net/blog/ for some time, and which has been refined over the last years. While still experimental, it is now mature enough to be included directly into FreeType. Most of the code is based on the ClearType whitepaper written by Greg Hitchcock http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx which gives a detailed overview of the necessary changes to the Microsoft rasterizer so that older fonts are supported. However, a lot of details are still missing, and this patches provides a framework to easily handle rendering issues down to the glyph level of certain fonts. Note that ClearType support is not completely implemented! In particular, full support for the options `compatible_widths', `symmetrical_smoothing, and `bgr' (via the GETINFO bytecode instruction) is missing. * src/truetype/ttsubpix.c: New file, providing code to handle `tweaks', this is, rules for certain glyphs in certain fonts (including wildcards) which need a special treatment. * src/truetype/ttsubpix.h: New file, holding the tweaking rules. * include/freetype/config/ftoption.h, src/devel/ftoption.h (TT_CONFIG_OPTION_SUBPIXEL_HINTING): New macro. * include/freetype/internal/ftobjs.h (FT_PIX_FLOOR_GRID, FT_PIX_ROUND_GRID, FT_PIX_CEIL_GRID): New macros. * src/truetype/truetype.c [TT_USE_BYTECODE_INTERPRETER]: Include `ttsubpix.c'. * src/truetype/ttgload.c: Include `ttsubpix.h'. [All changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (tt_get_metrics): Set tweak flags. (TT_Hint_Glyph): Call `FT_Outline_EmboldenXY' if necessary. (TT_Process_Simple_Glyph): Compensate emboldening if necessary. (compute_glyph_metrics): Handle `compatible widths' option. (tt_loader_init): Handle ClearType GETINFO information bits. * src/truetype/rules.mk (TT_DRC_SRC): Updated. * src/truetype/ttinterp.c: Include `ttsubpix.h'. [Where necessary, changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (Direct_Move, Direct_Move_X): Extended. (Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid, Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, Round_Super_45, SetSuperRound): Add parameter to handle the number of grid lines per pixel. (SET_SuperRound, ROUND_None, CUR_Func_round): Updated. (DO_SROUND, DOS45ROUND, DO_ODD, DO_EVEN): Updated. (DO_ROUND, DO_NROUND): Updated. (DO_RS): Take care of `Typeman' bytecode patterns. (Ins_FDEF): Add some debugging code. Commented out. (Ins_ENDF): Restore state. (Ins_CALL, Ins_LOOPCALL): Handle inline delta functions. (Ins_MD): Handle `Vacuform' rounds. (Move_Zp2_Point, Ins_SHPIX, Ins_MSIRP, Ins_MDAP, Ins_MIAP, Ins_MDRP, Ins_MIRP): Handle tweaks. (Ins_ALIGNRP): Add tweak guard. (Ins_IUP, Ins_DELTAP): Handle tweaks. (Ins_GETINFO): Handle new ClearType bits. (TT_RunIns): Handle tweaks. * src/truetype/ttinterp.h: Updated. (SPH_TweakRule, SPH_ScaleRule): New structures for tweaks. (TT_ExecContextRec): Add members for subpixel hinting support. * src/truetype/ttobjs.h (TT_DefRecord): Add `inline_delta' member.
2012-06-18 10:36:06 +02:00
/***************************************************************************/
/* */
/* ttsubpix.c */
/* */
/* TrueType Subpixel Hinting. */
/* */
/* Copyright 2010-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_DEBUG_H
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_SFNT_H
#include FT_TRUETYPE_TAGS_H
#include FT_OUTLINE_H
#include "ttsubpix.h"
#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
FT_LOCAL_DEF( FT_Bool )
is_member_of_family_class( const FT_String* detected_font_name,
const FT_String* rule_font_name )
{
FT_UInt i, j;
/* Does font name match rule family? */
if ( strcmp( detected_font_name, rule_font_name ) == 0 )
return TRUE;
/* Is font name a wildcard ""? */
if ( strcmp( rule_font_name, "" ) == 0 )
return TRUE;
/* Is font name contained in a class list? */
for ( i = 0; i < FAMILY_CLASS_RULES_SIZE; i++ )
{
if ( strcmp( FAMILY_CLASS_Rules[i].name, rule_font_name ) == 0 )
{
for ( j = 0; j < MAX_CLASS_MEMBERS; j++ )
{
if ( strcmp( FAMILY_CLASS_Rules[i].member[j], "" ) == 0 )
continue;
if ( strcmp( FAMILY_CLASS_Rules[i].member[j],
detected_font_name ) == 0 )
return TRUE;
}
}
}
return FALSE;
}
FT_LOCAL_DEF( FT_Bool )
is_member_of_style_class( const FT_String* detected_font_style,
const FT_String* rule_font_style )
{
FT_UInt i, j;
/* Does font style match rule style? */
if ( strcmp( detected_font_style, rule_font_style ) == 0 )
return TRUE;
/* Is font style a wildcard ""? */
if ( strcmp( rule_font_style, "" ) == 0 )
return TRUE;
/* Is font style contained in a class list? */
for ( i = 0; i < STYLE_CLASS_RULES_SIZE; i++ )
{
if ( strcmp( STYLE_CLASS_Rules[i].name, rule_font_style ) == 0 )
{
for ( j = 0; j < MAX_CLASS_MEMBERS; j++ )
{
if ( strcmp( STYLE_CLASS_Rules[i].member[j], "" ) == 0 )
continue;
if ( strcmp( STYLE_CLASS_Rules[i].member[j],
detected_font_style ) == 0 )
return TRUE;
}
}
}
return FALSE;
}
FT_LOCAL_DEF( FT_Bool )
sph_test_tweak( TT_Face face,
FT_String* family,
FT_UInt ppem,
FT_String* style,
FT_UInt glyph_index,
SPH_TweakRule* rule,
FT_UInt num_rules )
{
FT_UInt i;
/* rule checks may be able to be optimized further */
for ( i = 0; i < num_rules; i++ )
{
if ( family &&
( is_member_of_family_class ( family, rule[i].family ) ) )
if ( rule[i].ppem == 0 ||
rule[i].ppem == ppem )
if ( style &&
is_member_of_style_class ( style, rule[i].style ) )
if ( rule[i].glyph == 0 ||
FT_Get_Char_Index( (FT_Face)face,
rule[i].glyph ) == glyph_index )
return TRUE;
}
return FALSE;
}
FT_LOCAL_DEF( FT_UInt )
scale_test_tweak( TT_Face face,
FT_String* family,
FT_UInt ppem,
FT_String* style,
FT_UInt glyph_index,
SPH_ScaleRule* rule,
FT_UInt num_rules )
{
FT_UInt i;
/* rule checks may be able to be optimized further */
for ( i = 0; i < num_rules; i++ )
{
if ( family &&
( is_member_of_family_class ( family, rule[i].family ) ) )
if ( rule[i].ppem == 0 ||
rule[i].ppem == ppem )
if ( style &&
is_member_of_style_class( style, rule[i].style ) )
if ( rule[i].glyph == 0 ||
FT_Get_Char_Index( (FT_Face)face,
rule[i].glyph ) == glyph_index )
return rule[i].scale;
}
return 1000;
}
#define TWEAK_RULES( x ) \
if ( sph_test_tweak( face, family, ppem, style, glyph_index, \
x##_Rules, x##_RULES_SIZE ) ) \
loader->exec->sph_tweak_flags |= SPH_TWEAK_##x;
#define TWEAK_RULES_EXCEPTIONS( x ) \
if ( sph_test_tweak( face, family, ppem, style, glyph_index, \
x##_Rules_Exceptions, x##_RULES_EXCEPTIONS_SIZE ) ) \
loader->exec->sph_tweak_flags &= ~SPH_TWEAK_##x;
FT_LOCAL_DEF( void )
sph_set_tweaks( TT_Loader loader,
FT_UInt glyph_index )
{
TT_Face face = (TT_Face)loader->face;
FT_String* family = face->root.family_name;
int ppem = loader->size->metrics.x_ppem;
FT_String* style = face->root.style_name;
/* don't apply rules if style isn't set */
if ( !face->root.style_name )
return;
#ifdef SPH_DEBUG_MORE_VERBOSE
printf( "%s,%d,%s,%c=%d ",
family, ppem, style, glyph_index, glyph_index );
#endif
TWEAK_RULES( PIXEL_HINTING );
if ( loader->exec->sph_tweak_flags & SPH_TWEAK_PIXEL_HINTING )
{
loader->exec->ignore_x_mode = FALSE;
return;
}
TWEAK_RULES( ALLOW_X_DMOVE );
TWEAK_RULES( ALLOW_X_DMOVEX );
TWEAK_RULES( ALLOW_X_MOVE_ZP2 );
TWEAK_RULES( ALWAYS_DO_DELTAP );
TWEAK_RULES( ALWAYS_SKIP_DELTAP );
TWEAK_RULES( DEEMBOLDEN );
TWEAK_RULES( DELTAP_SKIP_EXAGGERATED_VALUES );
TWEAK_RULES( DO_SHPIX );
TWEAK_RULES( EMBOLDEN );
TWEAK_RULES( MIAP_HACK );
TWEAK_RULES( NORMAL_ROUND );
TWEAK_RULES( NO_ALIGNRP_AFTER_IUP );
TWEAK_RULES( NO_CALL_AFTER_IUP );
TWEAK_RULES( NO_DELTAP_AFTER_IUP );
TWEAK_RULES( RASTERIZER_35 );
TWEAK_RULES( SKIP_INLINE_DELTAS );
TWEAK_RULES( SKIP_IUP );
TWEAK_RULES( MIRP_CVT_ZERO );
TWEAK_RULES( SKIP_OFFPIXEL_Y_MOVES );
TWEAK_RULES_EXCEPTIONS( SKIP_OFFPIXEL_Y_MOVES );
TWEAK_RULES( SKIP_NONPIXEL_Y_MOVES );
TWEAK_RULES_EXCEPTIONS( SKIP_NONPIXEL_Y_MOVES );
TWEAK_RULES( ROUND_NONPIXEL_Y_MOVES );
TWEAK_RULES_EXCEPTIONS( ROUND_NONPIXEL_Y_MOVES );
if ( loader->exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 )
2012-06-29 03:34:26 +02:00
loader->exec->rasterizer_version = 35;
[truetype] Support subpixel hinting. This is the large, famous `Infinality' patch to support ClearType bytecode which has been available from http://www.infinality.net/blog/ for some time, and which has been refined over the last years. While still experimental, it is now mature enough to be included directly into FreeType. Most of the code is based on the ClearType whitepaper written by Greg Hitchcock http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx which gives a detailed overview of the necessary changes to the Microsoft rasterizer so that older fonts are supported. However, a lot of details are still missing, and this patches provides a framework to easily handle rendering issues down to the glyph level of certain fonts. Note that ClearType support is not completely implemented! In particular, full support for the options `compatible_widths', `symmetrical_smoothing, and `bgr' (via the GETINFO bytecode instruction) is missing. * src/truetype/ttsubpix.c: New file, providing code to handle `tweaks', this is, rules for certain glyphs in certain fonts (including wildcards) which need a special treatment. * src/truetype/ttsubpix.h: New file, holding the tweaking rules. * include/freetype/config/ftoption.h, src/devel/ftoption.h (TT_CONFIG_OPTION_SUBPIXEL_HINTING): New macro. * include/freetype/internal/ftobjs.h (FT_PIX_FLOOR_GRID, FT_PIX_ROUND_GRID, FT_PIX_CEIL_GRID): New macros. * src/truetype/truetype.c [TT_USE_BYTECODE_INTERPRETER]: Include `ttsubpix.c'. * src/truetype/ttgload.c: Include `ttsubpix.h'. [All changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (tt_get_metrics): Set tweak flags. (TT_Hint_Glyph): Call `FT_Outline_EmboldenXY' if necessary. (TT_Process_Simple_Glyph): Compensate emboldening if necessary. (compute_glyph_metrics): Handle `compatible widths' option. (tt_loader_init): Handle ClearType GETINFO information bits. * src/truetype/rules.mk (TT_DRC_SRC): Updated. * src/truetype/ttinterp.c: Include `ttsubpix.h'. [Where necessary, changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (Direct_Move, Direct_Move_X): Extended. (Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid, Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, Round_Super_45, SetSuperRound): Add parameter to handle the number of grid lines per pixel. (SET_SuperRound, ROUND_None, CUR_Func_round): Updated. (DO_SROUND, DOS45ROUND, DO_ODD, DO_EVEN): Updated. (DO_ROUND, DO_NROUND): Updated. (DO_RS): Take care of `Typeman' bytecode patterns. (Ins_FDEF): Add some debugging code. Commented out. (Ins_ENDF): Restore state. (Ins_CALL, Ins_LOOPCALL): Handle inline delta functions. (Ins_MD): Handle `Vacuform' rounds. (Move_Zp2_Point, Ins_SHPIX, Ins_MSIRP, Ins_MDAP, Ins_MIAP, Ins_MDRP, Ins_MIRP): Handle tweaks. (Ins_ALIGNRP): Add tweak guard. (Ins_IUP, Ins_DELTAP): Handle tweaks. (Ins_GETINFO): Handle new ClearType bits. (TT_RunIns): Handle tweaks. * src/truetype/ttinterp.h: Updated. (SPH_TweakRule, SPH_ScaleRule): New structures for tweaks. (TT_ExecContextRec): Add members for subpixel hinting support. * src/truetype/ttobjs.h (TT_DefRecord): Add `inline_delta' member.
2012-06-18 10:36:06 +02:00
else
2012-06-29 03:34:26 +02:00
loader->exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION;
/* re-execute fpgm always to avoid problems */
loader->exec->size->cvt_ready = FALSE;
tt_size_ready_bytecode( loader->exec->size,
FT_BOOL( loader->load_flags & FT_LOAD_PEDANTIC ) );
[truetype] Support subpixel hinting. This is the large, famous `Infinality' patch to support ClearType bytecode which has been available from http://www.infinality.net/blog/ for some time, and which has been refined over the last years. While still experimental, it is now mature enough to be included directly into FreeType. Most of the code is based on the ClearType whitepaper written by Greg Hitchcock http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx which gives a detailed overview of the necessary changes to the Microsoft rasterizer so that older fonts are supported. However, a lot of details are still missing, and this patches provides a framework to easily handle rendering issues down to the glyph level of certain fonts. Note that ClearType support is not completely implemented! In particular, full support for the options `compatible_widths', `symmetrical_smoothing, and `bgr' (via the GETINFO bytecode instruction) is missing. * src/truetype/ttsubpix.c: New file, providing code to handle `tweaks', this is, rules for certain glyphs in certain fonts (including wildcards) which need a special treatment. * src/truetype/ttsubpix.h: New file, holding the tweaking rules. * include/freetype/config/ftoption.h, src/devel/ftoption.h (TT_CONFIG_OPTION_SUBPIXEL_HINTING): New macro. * include/freetype/internal/ftobjs.h (FT_PIX_FLOOR_GRID, FT_PIX_ROUND_GRID, FT_PIX_CEIL_GRID): New macros. * src/truetype/truetype.c [TT_USE_BYTECODE_INTERPRETER]: Include `ttsubpix.c'. * src/truetype/ttgload.c: Include `ttsubpix.h'. [All changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (tt_get_metrics): Set tweak flags. (TT_Hint_Glyph): Call `FT_Outline_EmboldenXY' if necessary. (TT_Process_Simple_Glyph): Compensate emboldening if necessary. (compute_glyph_metrics): Handle `compatible widths' option. (tt_loader_init): Handle ClearType GETINFO information bits. * src/truetype/rules.mk (TT_DRC_SRC): Updated. * src/truetype/ttinterp.c: Include `ttsubpix.h'. [Where necessary, changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (Direct_Move, Direct_Move_X): Extended. (Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid, Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, Round_Super_45, SetSuperRound): Add parameter to handle the number of grid lines per pixel. (SET_SuperRound, ROUND_None, CUR_Func_round): Updated. (DO_SROUND, DOS45ROUND, DO_ODD, DO_EVEN): Updated. (DO_ROUND, DO_NROUND): Updated. (DO_RS): Take care of `Typeman' bytecode patterns. (Ins_FDEF): Add some debugging code. Commented out. (Ins_ENDF): Restore state. (Ins_CALL, Ins_LOOPCALL): Handle inline delta functions. (Ins_MD): Handle `Vacuform' rounds. (Move_Zp2_Point, Ins_SHPIX, Ins_MSIRP, Ins_MDAP, Ins_MIAP, Ins_MDRP, Ins_MIRP): Handle tweaks. (Ins_ALIGNRP): Add tweak guard. (Ins_IUP, Ins_DELTAP): Handle tweaks. (Ins_GETINFO): Handle new ClearType bits. (TT_RunIns): Handle tweaks. * src/truetype/ttinterp.h: Updated. (SPH_TweakRule, SPH_ScaleRule): New structures for tweaks. (TT_ExecContextRec): Add members for subpixel hinting support. * src/truetype/ttobjs.h (TT_DefRecord): Add `inline_delta' member.
2012-06-18 10:36:06 +02:00
if ( IS_HINTED( loader->load_flags ) )
{
TWEAK_RULES( TIMES_NEW_ROMAN_HACK );
TWEAK_RULES( COURIER_NEW_2_HACK );
}
if ( sph_test_tweak( face, family, ppem, style, glyph_index,
COMPATIBILITY_MODE_Rules, COMPATIBILITY_MODE_RULES_SIZE ) )
{
loader->exec->compatibility_mode |= TRUE;
loader->exec->ignore_x_mode |= TRUE;
}
else
loader->exec->compatibility_mode &= FALSE;
if ( IS_HINTED( loader->load_flags ) )
{
if ( sph_test_tweak( face, family, ppem, style, glyph_index,
COMPATIBLE_WIDTHS_Rules, COMPATIBLE_WIDTHS_RULES_SIZE ) )
loader->exec->compatible_widths |= TRUE;
}
}
#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
/* END */