Commit 65c39c2b authored by David Turner's avatar David Turner
Browse files

Postscript hinter advances

parent 604d2579
......@@ -166,12 +166,15 @@ FT_BEGIN_HEADER
/* glyph_delta :: The 2d translation vector corresponding to */
/* the glyph transformation, if necessary. */
/* */
/* glyph_hints :: format-specific glyph hints management */
/* */
typedef struct FT_Slot_InternalRec_
{
FT_GlyphLoader* loader;
FT_Bool glyph_transformed;
FT_Matrix glyph_matrix;
FT_Vector glyph_delta;
void* glyph_hints;
} FT_GlyphSlot_InternalRec;
......
......@@ -506,7 +506,9 @@ FT_BEGIN_HEADER
FT_Error error; /* only used for memory errors */
FT_Bool metrics_only;
T1_Builder_Funcs funcs;
T1_Hints_Funcs hints_funcs;
T1_Builder_Funcs funcs;
};
......
......@@ -9,6 +9,7 @@
/**********************************************************************/
/**********************************************************************/
#if 0
/****************************************************************
*
* @constant: PS_GLOBALS_MAX_BLUE_ZONES
......@@ -134,6 +135,7 @@
} PS_GlobalsRec;
#endif
/* */
#endif /* __PS_GLOBALS_H__ */
......@@ -20,8 +20,178 @@
#ifndef __PSHINTS_H__
#define __PSHINTS_H__
#include <ft2build.h>
#include FT_TYPES_H
#include FT_INTERNAL_POSTSCRIPT_GLOBALS_H
FT_BEGIN_HEADER
/**********************************************************************/
/**********************************************************************/
/***** *****/
/***** EXTERNAL REPRESENTATION OF GLOBALS *****/
/***** *****/
/**********************************************************************/
/**********************************************************************/
/****************************************************************
*
* @constant: PS_GLOBALS_MAX_BLUE_ZONES
*
* @description:
* the maximum number of blue zones in a font global hints
* structure. See @PS_Globals_BluesRec
*/
#define PS_GLOBALS_MAX_BLUE_ZONES 16
/****************************************************************
*
* @constant: PS_GLOBALS_MAX_STD_WIDTHS
*
* @description:
* the maximum number of standard and snap widths in either the
* horizontal or vertical direction. See @PS_Globals_WidthsRec
*/
#define PS_GLOBALS_MAX_STD_WIDTHS 16
/****************************************************************
*
* @type: PS_Globals
*
* @description:
* a handle to a @PS_GlobalsRec structure used to
* describe the global hints of a given font
*/
typedef struct PS_GlobalsRec_* PS_Globals;
/****************************************************************
*
* @struct: PS_Globals_BluesRec
*
* @description:
* a structure used to model the global blue zones of a given
* font
*
* @fields:
* count :: number of blue zones
* zones :: an array of (count*2) coordinates describing the zones
*
* count_family :: number of family blue zones
* zones_family :: an array of (count_family*2) coordinates describing
* the family blue zones
*
* scale :: the blue scale to be used (fixed float)
* shift :: the blue shift to be used
* fuzz :: the blue fuzz to be used
*
* @note:
* each blue zone is modeled by a (reference,overshoot) coordinate pair
* in the table. zones can be placed in any order..
*/
typedef struct PS_Globals_BluesRec
{
FT_UInt count;
FT_Int16 zones[ 2*PS_GLOBALS_MAX_BLUE_ZONES ];
FT_UInt count_family;
FT_Int16 zones_family[ 2*PS_GLOBALS_MAX_BLUE_ZONES ];
FT_Fixed scale;
FT_Int16 shift;
FT_Int16 fuzz;
} PS_Globals_BluesRec, *PS_Globals_Blues;
/****************************************************************
*
* @type: PS_Global_Widths;
*
* @description:
* a handle to a @PS_Globals_WidthsRec structure used to model
* the global standard and snap widths in a given direction
*/
typedef struct PS_Globals_WidthsRec_* PS_Globals_Widths;
/****************************************************************
*
* @struct: PS_Globals_WidthsRec
*
* @description:
* a structure used to model the global standard and snap widths
* in a given font
*
* @fields:
* count :: number of widths
* widths :: an array of 'count' widths in font units.
*
* @note:
* 'widths[0]' must be the standard width or height, while
* remaining elements of the array are snap widths or heights
*/
typedef struct PS_Globals_WidthsRec_
{
FT_UInt count;
FT_Int16 widths[ PS_GLOBALS_MAX_STD_WIDTHS ];
} PS_Globals_WidthsRec;
/****************************************************************
*
* @struct: PS_Globals_GlobalsRec
*
* @description:
* a structure used to model the global hints for a given font
*
* @fields:
* horizontal :: horizontal widths
* vertical :: vertical heights
* blues :: blue zones
*/
typedef struct PS_GlobalsRec_
{
PS_Globals_WidthsRec horizontal;
PS_Globals_WidthsRec vertical;
PS_Globals_BluesRec blues;
} PS_GlobalsRec;
/**********************************************************************/
/**********************************************************************/
/***** *****/
/***** INTERNAL REPRESENTATION OF GLOBALS *****/
/***** *****/
/**********************************************************************/
/**********************************************************************/
typedef struct PSH_GlobalsRec_* PSH_Globals;
typedef FT_Error (*PSH_Globals_NewFunc)( FT_Memory memory,
PSH_Globals* aglobals );
typedef FT_Error (*PSH_Globals_ResetFunc)( PSH_Globals globals,
PS_Globals ps_globals );
typedef FT_Error (*PSH_Globals_SetScaleFunc)( PSH_Globals globals,
FT_Fixed x_scale,
FT_Fixed y_scale,
FT_Fixed x_delta,
FT_Fixed y_delta );
typedef void (*PSH_Globals_DestroyFunc)( PSH_Globals globals );
typedef struct
{
PSH_Globals_NewFunc create;
PSH_Globals_ResetFunc reset;
PSH_Globals_SetScaleFunc set_scale;
PSH_Globals_DestroyFunc destroy;
} PSH_Globals_FuncsRec, *PSH_Globals_Funcs;
/**********************************************************************/
/**********************************************************************/
/***** *****/
......@@ -106,7 +276,7 @@ FT_BEGIN_HEADER
* use horizontal coordinates (x) for vertical stems (dim=1)
*
* "coords[0]" is the absolute stem position (lowest coordinate)
* "corods[1]" is the length.
* "coords[1]" is the length.
*
* the length can be negative, in which case it must be either
* -20 or -21 in order and will be interpreted as a "ghost" stem,
......@@ -145,7 +315,7 @@ FT_BEGIN_HEADER
/************************************************************************
*
* @functype: T1_Hints_ResetStemsFunc
* @functype: T1_Hints_ResetFunc
*
* @description:
* a method of the @T1_Hints class used to reset the stems hints
......@@ -156,8 +326,8 @@ FT_BEGIN_HEADER
* end_point :: index of last point in the input glyph in which
* the previously defined hints apply
*/
typedef void (*T1_Hints_ResetStemsFunc)( T1_Hints hints,
FT_UInt end_point );
typedef void (*T1_Hints_ResetFunc)( T1_Hints hints,
FT_UInt end_point );
/************************************************************************
*
......@@ -178,8 +348,38 @@ FT_BEGIN_HEADER
* the error code will be set to indicate that an error occured
* during the recording session
*/
typedef FT_Error (*T1_Hint_RecordCloseFunc)( T1_Hints hints,
FT_UInt end_point );
typedef FT_Error (*T1_Hints_CloseFunc)( T1_Hints hints,
FT_UInt end_point );
/************************************************************************
*
* @functype: T1_Hints_ApplyFunc
*
* @description:
* a method of the @T1_Hints class used to apply hints to the
* corresponding glyph outline. Must be called once all hints
* have been recorded.
*
* @input:
* hints :: handle to Type 1 hints recorder
* outline :: pointer to target outline descriptor
* globals :: the hinter globals for this font
*
* @return:
* error code. 0 means success
*
* @note:
* on input, all points within the outline are in font coordinates.
* on output, they're in 1/64th of pixels.
*
* the scaling transform is taken from the "globals" object, which
* must correspond to the same font than the glyph
*/
typedef FT_Error (*T1_Hints_ApplyFunc)( T1_Hints hints,
FT_Outline* outline,
PSH_Globals globals );
/************************************************************************
*
......@@ -189,19 +389,23 @@ FT_BEGIN_HEADER
* the structure used to provide the API to @T1_Hints objects
*
* @fields:
* hints :: handle to T1 Hints recorder
* open :: open recording session
* close :: close recording session
* stem :: set simple stem
* stem3 :: set counter-controlled stems
* reset :: reset stem hints
* apply :: apply the hints to the corresponding glyph outline
*/
typedef struct T1_Hints_FuncsRec_
{
T1_Hints hints;
T1_Hints_OpenFunc open;
T1_Hints_CloseFunc close;
T1_Hints_SetStemFunc stem;
T1_Hints_SetStem3Func stem3;
T1_Hints_ResetFunc reset;
T1_Hints_ApplyFunc apply;
} T1_Hints_FuncsRec;
......@@ -387,6 +591,35 @@ FT_BEGIN_HEADER
typedef FT_Error (*T2_Hints_CloseFunc) ( T2_Hints hints,
FT_UInt end_point );
/************************************************************************
*
* @functype: T2_Hints_ApplyFunc
*
* @description:
* a method of the @T2_Hints class used to apply hints to the
* corresponding glyph outline. Must be called after the "close" method
*
* @input:
* hints :: handle to Type 2 hints recorder
* outline :: pointer to target outline descriptor
* globals :: the hinter globals for this font
*
* @return:
* error code. 0 means success
*
* @note:
* on input, all points within the outline are in font coordinates.
* on output, they're in 1/64th of pixels.
*
* the scaling transform is taken from the "globals" object, which
* must correspond to the same font than the glyph
*/
typedef FT_Error (*T2_Hints_ApplyFunc)( T2_Hints hints,
FT_Outline* outline,
PSH_Globals globals );
/************************************************************************
*
* @struct: T2_Hints_FuncsRec
......@@ -395,24 +628,36 @@ FT_BEGIN_HEADER
* the structure used to provide the API to @T2_Hints objects
*
* @fields:
* hints :: handle to T2 hints recorder object
* open :: open recording session
* close :: close recording session
* stems :: set dimension's stems table
* hintmask :: set hint masks
* counter :: set counter masks
* apply :: apply the hints on the corresponding glyph outline
*/
typedef struct T2_Hints_FuncsRec_
{
T2_Hints hints;
T2_Hints_OpenFunc open;
T2_Hints_CloseFunc close;
T2_Hints_StemsFunc stems;
T2_Hints_MaskFunc hintmask;
T2_Hints_CounterFunc counter;
T2_Hints_ApplyFunc apply;
} T2_Hints_FuncsRec;
/* */
/* */
typedef struct PSHinter_Interface_
{
PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module );
T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module );
T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module );
} PSHinter_Interface, *PSHinter_InterfacePtr;
FT_END_HEADER
......
......@@ -24,7 +24,7 @@
#include<ft2build.h>
#include FT_TYPE1_TABLES_H
#include FT_INTERNAL_POSTSCRIPT_NAMES_H
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
FT_BEGIN_HEADER
......@@ -172,6 +172,9 @@ FT_BEGIN_HEADER
/* support for Multiple Masters fonts */
T1_Blend* blend;
/* since FT 2.1 - interface to Postscript hinter */
void* pshinter;
} T1_FaceRec;
......
......@@ -14,6 +14,7 @@ SubDirHdrs [ FT2_SubDir src ] ;
#
HDRMACRO [ FT2_SubDir include internal internal.h ] ;
SubInclude FT2_TOP src pshinter ;
SubInclude FT2_TOP src autohint ;
SubInclude FT2_TOP src base ;
SubInclude FT2_TOP src cache ;
......
......@@ -717,7 +717,7 @@ THE SOFTWARE.
else
encodingOffset = GET_ShortLE();
if ( encodingOffset != (signed short)0xFFFF )
if ( encodingOffset != 0xFFFF )
{
tmpEncoding[j].enc = ( ( ( i / ( lastCol - firstCol + 1 ) ) +
firstRow ) * 256 ) +
......
......@@ -1077,10 +1077,12 @@
FT_GlyphLoader* loader = glyph->internal->loader;
builder->loader = loader;
builder->base = &loader->base.outline;
builder->current = &loader->current.outline;
builder->loader = loader;
builder->base = &loader->base.outline;
builder->current = &loader->current.outline;
FT_GlyphLoader_Rewind( loader );
builder->hints_func = (T1_Hints_Funcs) glyph->internal->glyph_hints;
}
if ( size )
......
......@@ -18,6 +18,7 @@
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
#include FT_OUTLINE_H
#include "t1decode.h"
......@@ -325,6 +326,7 @@
T1_Builder* builder = &decoder->builder;
FT_Pos x, y;
T1_Hints_Funcs hinter;
/* we don't want to touch the source code -- use macro trick */
#define start_point T1_Builder_Start_Point
......@@ -341,6 +343,8 @@
builder->path_begun = 0;
hinter = builder->hints_funcs;
zone->base = charstring_base;
limit = zone->limit = charstring_base + charstring_len;
ip = zone->cursor = zone->base;
......@@ -350,6 +354,10 @@
x = builder->pos_x;
y = builder->pos_y;
/* begin hints recording session, if any */
if ( hinter )
hinter->open( hinter->hints );
/* now, execute loop */
while ( ip < limit )
{
......@@ -613,6 +621,10 @@
goto Syntax_Error;
}
ip += 2;
if ( hinter )
hinter->reset( hinter->hints, builder->current->n_points );
break;
case 12:
......@@ -707,7 +719,11 @@
FT_TRACE4(( " endchar" ));
close_contour( builder );
/* close hints recording session */
if ( hinter )
hinter->close( hinter->hints, builder->current->n_points );
/* add current outline to the glyph slot */
FT_GlyphLoader_Add( builder->loader );
......@@ -973,22 +989,38 @@
case op_hstem:
FT_TRACE4(( " hstem" ));
/* record horizontal hint */
if ( hinter )
hinter->stem( hinter->hints, 0, top );
break;
case op_hstem3:
FT_TRACE4(( " hstem3" ));
/* record horizontal counter-controlled hints */
if ( hinter )
hinter->stem3( hinter->hints, 0, top );
break;
case op_vstem:
FT_TRACE4(( " vstem" ));
/* record vertical hint */
if ( hinter )
hinter->stem( hinter->hints, 1, top );
break;
case op_vstem3:
FT_TRACE4(( " vstem3" ));
/* record vertical counter-controlled hints */
if ( hinter )
hinter->stem3( hinter->hints, 1, top );
break;
case op_setcurrentpoint:
......@@ -1011,6 +1043,7 @@
} /* while ip < limit */
FT_TRACE4(( "..end..\n\n" ));
return error;
Syntax_Error:
......
# FreeType 2 src/pshinter Jamfile (c) 2001 David Turner
#
SubDir FT2_TOP src pshinter ;
SubDirHdrs [ FT2_SubDir src pshinter ] ;
{
local _sources ;
if $(FT2_MULTI)
{
_sources = pshrec pshglob pshfit pshmod ;
}
else
{
_sources = pshinter ;
}
Library $(FT2_LIB) : $(_sources).c ;
}
# end of src/psaux Jamfile
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include "pshfit.h"
/* return true iff two hints overlap */
static FT_Int
psh_hint_overlap( PSH_Hint hint1,
PSH_Hint hint2 )
{
return ( hint1->org_pos + hint1->org_len >= hint2->org_pos &&
hint2->org_pos + hint2->org_len >= hint1->org_pos );
}
/* destroy hints table */
static void
psh_hint_table_done( PSH_Hint_Table table,
FT_Memory memory )
{
FREE( table->zones );
table->num_zones = 0;
table->zone = 0;
FREE( table->sort );
FREE( table->hints );
table->num_hints = 0;
table->max_hints = 0;
table->sort_global = 0;
}
/* deactivate all hints in a table */
static void
psh_hint_table_deactivate( PSH_Hint_Table table )
{
FT_UInt count = table->max_hints;
PSH_Hint hint = table->hints;
for ( ; count > 0; count--, hint++ )
{
psh_hint_deactivate(hint);
hint->order = -1;
}
}
/* internal function used to record a new hint */
static void
psh_hint_table_record( PSH_Hint_Table table,
FT_UInt index )
{
PSH_Hint hint = table->hints + index;
if ( index >= table->max_hints )
{
FT_ERROR(( "%s.activate: invalid hint index %d\n", index ));
return;
}
/* ignore active hints */
if ( psh_hint_is_active(hint) )