2000-07-19 22:02:14 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ahhint.c */
|
|
|
|
/* */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* Glyph hinter (body). */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* Copyright 2000 Catharon Productions Inc. */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* Author: David Turner */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the Catharon Typography Project and shall only */
|
|
|
|
/* be used, modified, and distributed under the terms of the Catharon */
|
|
|
|
/* Open Source License that should come with this file under the name */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* Note that this license is compatible with the FreeType license. */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#ifdef FT_FLAT_COMPILE
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#include "ahhint.h"
|
|
|
|
#include "ahglyph.h"
|
|
|
|
#include "ahangles.h"
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#else
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#include <autohint/ahhint.h>
|
|
|
|
#include <autohint/ahglyph.h>
|
|
|
|
#include <autohint/ahangles.h>
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <freetype/ftoutln.h>
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
#define FACE_GLOBALS( face ) ((AH_Face_Globals*)(face)->autohint.data)
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
#define AH_USE_IUP
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** Hinting routines ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
static int disable_horz_edges = 0;
|
|
|
|
static int disable_vert_edges = 0;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
/* snap a given width in scaled coordinates to one of the */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* current standard widths */
|
2000-07-19 22:02:14 +02:00
|
|
|
static
|
2000-07-26 16:11:15 +02:00
|
|
|
FT_Pos ah_snap_width( FT_Pos* widths,
|
|
|
|
FT_Int count,
|
|
|
|
FT_Pos width )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
int n;
|
2000-07-26 16:11:15 +02:00
|
|
|
FT_Pos best = 64 + 32 + 2;
|
2000-07-19 22:02:14 +02:00
|
|
|
FT_Pos reference = width;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
for ( n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
FT_Pos w;
|
|
|
|
FT_Pos dist;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
w = widths[n];
|
|
|
|
dist = width - w;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dist < 0 )
|
|
|
|
dist = -dist;
|
|
|
|
if ( dist < best )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
best = dist;
|
|
|
|
reference = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( width >= reference )
|
|
|
|
{
|
|
|
|
width -= 0x21;
|
|
|
|
if ( width < reference )
|
|
|
|
width = reference;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width += 0x21;
|
|
|
|
if ( width > reference )
|
|
|
|
width = reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* align one stem edge relative to the previous stem edge */
|
2000-07-19 22:02:14 +02:00
|
|
|
static
|
|
|
|
void ah_align_linked_edge( AH_Hinter* hinter,
|
|
|
|
AH_Edge* base_edge,
|
|
|
|
AH_Edge* stem_edge,
|
|
|
|
int vertical )
|
|
|
|
{
|
|
|
|
FT_Pos dist = stem_edge->opos - base_edge->opos;
|
|
|
|
AH_Globals* globals = &hinter->globals->scaled;
|
|
|
|
FT_Pos sign = 1;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( dist < 0 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
dist = -dist;
|
|
|
|
sign = -1;
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( vertical )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
dist = ah_snap_width( globals->heights, globals->num_heights, dist );
|
|
|
|
|
|
|
|
/* in the case of vertical hinting, always round */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* the stem heights to integer pixels */
|
|
|
|
if ( dist >= 64 )
|
|
|
|
dist = ( dist + 16 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
else
|
|
|
|
dist = 64;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dist = ah_snap_width( globals->widths, globals->num_widths, dist );
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( hinter->flags & ah_hinter_monochrome )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
/* monochrome horizontal hinting: snap widths to integer pixels */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* with a different threshold */
|
|
|
|
if ( dist < 64 )
|
2000-07-19 22:02:14 +02:00
|
|
|
dist = 64;
|
|
|
|
else
|
2000-07-26 16:11:15 +02:00
|
|
|
dist = ( dist + 32 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* for horizontal anti-aliased hinting, we adopt a more subtle */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* approach: we strengthen small stems, round stems whose size */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* is between 1 and 2 pixels to an integer, otherwise nothing */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dist < 48 )
|
|
|
|
dist = ( dist + 64 ) >> 1;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
else if ( dist < 128 )
|
|
|
|
dist = ( dist + 42 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
stem_edge->pos = base_edge->pos + sign * dist;
|
|
|
|
}
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void ah_align_serif_edge( AH_Hinter* hinter,
|
|
|
|
AH_Edge* base,
|
|
|
|
AH_Edge* serif )
|
|
|
|
{
|
|
|
|
FT_Pos dist;
|
|
|
|
FT_Pos sign = 1;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
UNUSED( hinter );
|
|
|
|
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
dist = serif->opos - base->opos;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dist < 0 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
dist = -dist;
|
|
|
|
sign = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do not strengthen serifs */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( base->flags & ah_edge_done )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dist > 64 )
|
|
|
|
dist = ( dist + 16 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
else if ( dist <= 32 )
|
|
|
|
dist = ( dist + 33 ) >> 1;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
serif->pos = base->pos + sign * dist;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** E D G E H I N T I N G ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
/* Another alternative edge hinting algorithm */
|
|
|
|
static
|
|
|
|
void ah_hint_edges_3( AH_Hinter* hinter )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
AH_Edge* edges;
|
|
|
|
AH_Edge* edge_limit;
|
|
|
|
AH_Outline* outline = hinter->glyph;
|
|
|
|
FT_Int dimension;
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
edges = outline->horz_edges;
|
|
|
|
edge_limit = edges + outline->num_hedges;
|
|
|
|
|
|
|
|
for ( dimension = 1; dimension >= 0; dimension-- )
|
|
|
|
{
|
|
|
|
AH_Edge* edge;
|
|
|
|
AH_Edge* before = 0;
|
|
|
|
AH_Edge* after = 0;
|
|
|
|
AH_Edge* anchor = 0;
|
|
|
|
int has_serifs = 0;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( disable_vert_edges && !dimension )
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Next_Dimension;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( disable_horz_edges && dimension )
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Next_Dimension;
|
|
|
|
|
|
|
|
/* we begin by aligning all stems relative to the blue zone */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* if needed -- that's only for horizontal edges */
|
|
|
|
if ( dimension )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
for ( edge = edges; edge < edge_limit; edge++ )
|
|
|
|
{
|
|
|
|
FT_Pos* blue;
|
2000-07-26 16:11:15 +02:00
|
|
|
AH_Edge *edge1, *edge2;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( edge->flags & ah_edge_done )
|
2000-07-19 22:02:14 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
blue = edge->blue_edge;
|
|
|
|
edge1 = 0;
|
|
|
|
edge2 = edge->link;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( blue )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
edge1 = edge;
|
|
|
|
}
|
|
|
|
else if (edge2 && edge2->blue_edge)
|
|
|
|
{
|
|
|
|
blue = edge2->blue_edge;
|
|
|
|
edge1 = edge2;
|
|
|
|
edge2 = edge;
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !edge1 )
|
2000-07-19 22:02:14 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
edge1->pos = blue[0];
|
|
|
|
edge1->flags |= ah_edge_done;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge2 && !edge2->blue_edge )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
ah_align_linked_edge( hinter, edge1, edge2, dimension );
|
|
|
|
edge2->flags |= ah_edge_done;
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !anchor )
|
2000-07-19 22:02:14 +02:00
|
|
|
anchor = edge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now, we will align all stem edges, trying to maintain the */
|
|
|
|
/* relative order of stems in the glyph.. */
|
|
|
|
before = 0;
|
|
|
|
after = 0;
|
|
|
|
for ( edge = edges; edge < edge_limit; edge++ )
|
|
|
|
{
|
|
|
|
AH_Edge *edge2;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( edge->flags & ah_edge_done )
|
2000-07-19 22:02:14 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* skip all non-stem edges */
|
|
|
|
edge2 = edge->link;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !edge2 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
has_serifs++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now, align the stem */
|
|
|
|
|
|
|
|
/* this should not happen, but it's better to be safe.. */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge2->blue_edge || edge2 < edge )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
#if 0
|
|
|
|
printf( "strange blue alignement, edge %d to %d\n",
|
2000-07-26 16:11:15 +02:00
|
|
|
edge - edges, edge2 - edges );
|
2000-07-19 22:02:14 +02:00
|
|
|
#endif
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
ah_align_linked_edge( hinter, edge2, edge, dimension );
|
|
|
|
edge->flags |= ah_edge_done;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
FT_Bool min = 0;
|
|
|
|
FT_Pos delta;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !anchor )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
edge->pos = ( edge->opos + 32 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
anchor = edge;
|
|
|
|
}
|
|
|
|
else
|
2000-07-26 16:11:15 +02:00
|
|
|
edge->pos = anchor->pos +
|
|
|
|
( ( edge->opos - anchor->opos + 32 ) & -64 );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
edge->flags |= ah_edge_done;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge > edges && edge->pos < edge[-1].pos )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
edge->pos = edge[-1].pos;
|
2000-07-26 16:11:15 +02:00
|
|
|
min = 1;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ah_align_linked_edge( hinter, edge, edge2, dimension );
|
|
|
|
delta = 0;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge2 + 1 < edge_limit &&
|
2000-07-19 22:02:14 +02:00
|
|
|
edge2[1].flags & ah_edge_done )
|
|
|
|
delta = edge2[1].pos - edge2->pos;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( delta < 0 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
edge2->pos += delta;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !min )
|
2000-07-19 22:02:14 +02:00
|
|
|
edge->pos += delta;
|
|
|
|
}
|
|
|
|
edge2->flags |= ah_edge_done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !has_serifs )
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Next_Dimension;
|
|
|
|
|
|
|
|
/* now, hint the remaining edges (serifs and single) in order */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* to complete our processing */
|
2000-07-19 22:02:14 +02:00
|
|
|
for ( edge = edges; edge < edge_limit; edge++ )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge->flags & ah_edge_done )
|
2000-07-19 22:02:14 +02:00
|
|
|
continue;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge->serif )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
ah_align_serif_edge( hinter, edge->serif, edge );
|
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
else if ( !anchor )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
edge->pos = ( edge->opos + 32 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
anchor = edge;
|
|
|
|
}
|
|
|
|
else
|
2000-07-26 16:11:15 +02:00
|
|
|
edge->pos = anchor->pos +
|
|
|
|
( ( edge->opos-anchor->opos + 32 ) & -64 );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
edge->flags |= ah_edge_done;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge > edges && edge->pos < edge[-1].pos )
|
2000-07-19 22:02:14 +02:00
|
|
|
edge->pos = edge[-1].pos;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( edge + 1 < edge_limit &&
|
|
|
|
edge[1].flags & ah_edge_done &&
|
|
|
|
edge->pos > edge[1].pos )
|
2000-07-19 22:02:14 +02:00
|
|
|
edge->pos = edge[1].pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
Next_Dimension:
|
|
|
|
edges = outline->vert_edges;
|
|
|
|
edge_limit = edges + outline->num_vedges;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOCAL_FUNC
|
|
|
|
void ah_hinter_hint_edges( AH_Hinter* hinter,
|
|
|
|
int no_horz_edges,
|
|
|
|
int no_vert_edges )
|
|
|
|
{
|
|
|
|
disable_horz_edges = no_horz_edges;
|
|
|
|
disable_vert_edges = no_vert_edges;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* AH_Interpolate_Blue_Edges( hinter ); -- doesn't seem to help */
|
|
|
|
/* reduce the problem of the disappearing eye in the `e' of Times... */
|
|
|
|
/* also, creates some artifacts near the blue zones? */
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
ah_hint_edges_3( hinter );
|
|
|
|
|
|
|
|
#if 0
|
2000-07-26 16:11:15 +02:00
|
|
|
/* outline optimizer removed temporarily */
|
|
|
|
if ( hinter->flags & ah_hinter_optimize )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
AH_Optimizer opt;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( !AH_Optimizer_Init( &opt, hinter->glyph, hinter->memory ) )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
AH_Optimizer_Compute( &opt );
|
|
|
|
AH_Optimizer_Done( &opt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** P O I N T H I N T I N G ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
static
|
|
|
|
void ah_hinter_align_edge_points( AH_Hinter* hinter )
|
|
|
|
{
|
|
|
|
AH_Outline* outline = hinter->glyph;
|
|
|
|
AH_Edge* edges;
|
|
|
|
AH_Edge* edge_limit;
|
|
|
|
FT_Int dimension;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
edges = outline->horz_edges;
|
|
|
|
edge_limit = edges + outline->num_hedges;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
for ( dimension = 1; dimension >= 0; dimension-- )
|
|
|
|
{
|
|
|
|
AH_Edge* edge;
|
|
|
|
AH_Edge* before;
|
|
|
|
AH_Edge* after;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
before = 0;
|
|
|
|
after = 0;
|
|
|
|
|
|
|
|
edge = edges;
|
|
|
|
for ( ; edge < edge_limit; edge++ )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
/* move the points of each segment */
|
|
|
|
/* in each edge to the edge's position */
|
2000-07-19 22:02:14 +02:00
|
|
|
AH_Segment* seg = edge->first;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
AH_Point* point = seg->first;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dimension )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
point->y = edge->pos;
|
|
|
|
point->flags |= ah_flah_touch_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
point->x = edge->pos;
|
|
|
|
point->flags |= ah_flah_touch_x;
|
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( point == seg->last )
|
2000-07-19 22:02:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
point = point->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
seg = seg->edge_next;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
} while ( seg != edge->first );
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
edges = outline->vert_edges;
|
|
|
|
edge_limit = edges + outline->num_vedges;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* hint the strong points -- this is equivalent to the TrueType `IP' */
|
2000-07-19 22:02:14 +02:00
|
|
|
static
|
|
|
|
void ah_hinter_align_strong_points( AH_Hinter* hinter )
|
|
|
|
{
|
|
|
|
AH_Outline* outline = hinter->glyph;
|
|
|
|
FT_Int dimension;
|
|
|
|
AH_Edge* edges;
|
|
|
|
AH_Edge* edge_limit;
|
|
|
|
AH_Point* points;
|
|
|
|
AH_Point* point_limit;
|
|
|
|
AH_Flags touch_flag;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
points = outline->points;
|
|
|
|
point_limit = points + outline->num_points;
|
|
|
|
|
|
|
|
edges = outline->horz_edges;
|
|
|
|
edge_limit = edges + outline->num_hedges;
|
|
|
|
touch_flag = ah_flah_touch_y;
|
|
|
|
|
|
|
|
for ( dimension = 1; dimension >= 0; dimension-- )
|
|
|
|
{
|
|
|
|
AH_Point* point;
|
|
|
|
AH_Edge* edge;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
if ( edges < edge_limit )
|
|
|
|
for ( point = points; point < point_limit; point++ )
|
|
|
|
{
|
|
|
|
FT_Pos u, ou, fu; /* point position */
|
|
|
|
FT_Pos delta;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
if ( point->flags & touch_flag )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
#ifndef AH_OPTION_NO_WEAK_INTERPOLATION
|
2000-07-26 16:11:15 +02:00
|
|
|
/* if this point is candidate to weak interpolation, we will */
|
2000-07-19 22:02:14 +02:00
|
|
|
/* interpolate it after all strong points have been processed */
|
|
|
|
if ( point->flags & ah_flah_weak_interpolation )
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dimension )
|
|
|
|
{
|
|
|
|
u = point->fy;
|
|
|
|
ou = point->oy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u = point->fx;
|
|
|
|
ou = point->ox;
|
|
|
|
}
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
fu = u;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* is the point before the first edge? */
|
2000-07-19 22:02:14 +02:00
|
|
|
edge = edges;
|
|
|
|
delta = edge->fpos - u;
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( delta >= 0 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
u = edge->pos - ( edge->opos - ou );
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Store_Point;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is the point after the last edge ? */
|
2000-07-26 16:11:15 +02:00
|
|
|
edge = edge_limit - 1;
|
2000-07-19 22:02:14 +02:00
|
|
|
delta = u - edge->fpos;
|
|
|
|
if ( delta >= 0 )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
u = edge->pos + ( ou - edge->opos );
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Store_Point;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise, interpolate the point in between */
|
|
|
|
{
|
|
|
|
AH_Edge* before = 0;
|
|
|
|
AH_Edge* after = 0;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
for ( edge = edges; edge < edge_limit; edge++ )
|
|
|
|
{
|
|
|
|
if ( u == edge->fpos )
|
|
|
|
{
|
|
|
|
u = edge->pos;
|
|
|
|
goto Store_Point;
|
|
|
|
}
|
|
|
|
if ( u < edge->fpos )
|
|
|
|
break;
|
|
|
|
before = edge;
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
for ( edge = edge_limit - 1; edge >= edges; edge-- )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
if ( u == edge->fpos )
|
|
|
|
{
|
|
|
|
u = edge->pos;
|
|
|
|
goto Store_Point;
|
|
|
|
}
|
|
|
|
if ( u > edge->fpos )
|
|
|
|
break;
|
|
|
|
after = edge;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assert( before && after && before != after ) */
|
|
|
|
u = before->pos + FT_MulDiv( fu - before->fpos,
|
|
|
|
after->pos - before->pos,
|
|
|
|
after->fpos - before->fpos );
|
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
Store_Point:
|
|
|
|
|
|
|
|
/* save the point position */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dimension )
|
|
|
|
point->y = u;
|
|
|
|
else
|
|
|
|
point->x = u;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
point->flags |= touch_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
edges = outline->vert_edges;
|
|
|
|
edge_limit = edges + outline->num_vedges;
|
|
|
|
touch_flag = ah_flah_touch_x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef AH_OPTION_NO_WEAK_INTERPOLATION
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
static
|
|
|
|
void ah_iup_shift( AH_Point* p1,
|
|
|
|
AH_Point* p2,
|
|
|
|
AH_Point* ref )
|
|
|
|
{
|
|
|
|
AH_Point* p;
|
|
|
|
FT_Pos delta = ref->u - ref->v;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
for ( p = p1; p < ref; p++ )
|
|
|
|
p->u = p->v + delta;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
for ( p = ref + 1; p <= p2; p++ )
|
2000-07-19 22:02:14 +02:00
|
|
|
p->u = p->v + delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void ah_iup_interp( AH_Point* p1,
|
|
|
|
AH_Point* p2,
|
|
|
|
AH_Point* ref1,
|
|
|
|
AH_Point* ref2 )
|
|
|
|
{
|
|
|
|
AH_Point* p;
|
|
|
|
FT_Pos u;
|
|
|
|
FT_Pos v1 = ref1->v;
|
|
|
|
FT_Pos v2 = ref2->v;
|
|
|
|
FT_Pos d1 = ref1->u - v1;
|
|
|
|
FT_Pos d2 = ref2->u - v2;
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( p1 > p2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( v1 == v2 )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
for ( p = p1; p <= p2; p++ )
|
|
|
|
{
|
2000-07-31 20:59:02 +02:00
|
|
|
u = p->v;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( u <= v1 )
|
|
|
|
u += d1;
|
|
|
|
else
|
|
|
|
u += d2;
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
p->u = u;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( v1 < v2 )
|
|
|
|
{
|
|
|
|
for ( p = p1; p <= p2; p++ )
|
|
|
|
{
|
|
|
|
u = p->v;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( u <= v1 )
|
|
|
|
u += d1;
|
|
|
|
else if ( u >= v2 )
|
|
|
|
u += d2;
|
|
|
|
else
|
|
|
|
u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
p->u = u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( p = p1; p <= p2; p++ )
|
|
|
|
{
|
|
|
|
u = p->v;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( u <= v2 )
|
|
|
|
u += d2;
|
|
|
|
else if ( u >= v1 )
|
|
|
|
u += d1;
|
|
|
|
else
|
|
|
|
u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
p->u = u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
/* interpolate weak points -- this is equivalent to the TrueType `IUP' */
|
2000-07-19 22:02:14 +02:00
|
|
|
static
|
|
|
|
void ah_hinter_align_weak_points( AH_Hinter* hinter )
|
|
|
|
{
|
|
|
|
AH_Outline* outline = hinter->glyph;
|
|
|
|
FT_Int dimension;
|
|
|
|
AH_Edge* edges;
|
|
|
|
AH_Edge* edge_limit;
|
|
|
|
AH_Point* points;
|
|
|
|
AH_Point* point_limit;
|
|
|
|
AH_Point** contour_limit;
|
|
|
|
AH_Flags touch_flag;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
points = outline->points;
|
|
|
|
point_limit = points + outline->num_points;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* PASS 1: Move segment points to edge positions */
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
edges = outline->horz_edges;
|
|
|
|
edge_limit = edges + outline->num_hedges;
|
|
|
|
touch_flag = ah_flah_touch_y;
|
|
|
|
|
|
|
|
contour_limit = outline->contours + outline->num_contours;
|
|
|
|
|
|
|
|
ah_setup_uv( outline, ah_uv_oy );
|
|
|
|
|
|
|
|
for ( dimension = 1; dimension >= 0; dimension-- )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
AH_Point* point;
|
|
|
|
AH_Point* end_point;
|
|
|
|
AH_Point* first_point;
|
|
|
|
AH_Point** contour;
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
point = points;
|
|
|
|
contour = outline->contours;
|
|
|
|
|
|
|
|
for ( ; contour < contour_limit; contour++ )
|
|
|
|
{
|
|
|
|
point = *contour;
|
|
|
|
end_point = point->prev;
|
|
|
|
first_point = point;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
while ( point <= end_point && !( point->flags & touch_flag ) )
|
2000-07-19 22:02:14 +02:00
|
|
|
point++;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( point <= end_point )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
AH_Point* first_touched = point;
|
|
|
|
AH_Point* cur_touched = point;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
point++;
|
|
|
|
while ( point <= end_point )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( point->flags & touch_flag )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
/* we found two successive touched points; we interpolate */
|
|
|
|
/* all contour points between them */
|
|
|
|
ah_iup_interp( cur_touched + 1, point - 1,
|
2000-07-19 22:02:14 +02:00
|
|
|
cur_touched, point );
|
|
|
|
cur_touched = point;
|
|
|
|
}
|
|
|
|
point++;
|
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( cur_touched == first_touched )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
/* this is a special case: only one point was touched in the */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* contour; we thus simply shift the whole contour */
|
2000-07-19 22:02:14 +02:00
|
|
|
ah_iup_shift( first_point, end_point, cur_touched );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* now interpolate after the last touched point to the end */
|
2000-07-26 16:11:15 +02:00
|
|
|
/* of the contour */
|
|
|
|
ah_iup_interp( cur_touched + 1, end_point,
|
2000-07-19 22:02:14 +02:00
|
|
|
cur_touched, first_touched );
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* if the first contour point isn't touched, interpolate */
|
|
|
|
/* from the contour start to the first touched point */
|
|
|
|
if ( first_touched > points )
|
|
|
|
ah_iup_interp( first_point, first_touched - 1,
|
2000-07-19 22:02:14 +02:00
|
|
|
cur_touched, first_touched );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now save the interpolated values back to x/y */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( dimension )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
for ( point = points; point < point_limit; point++ )
|
|
|
|
point->y = point->u;
|
|
|
|
|
|
|
|
touch_flag = ah_flah_touch_x;
|
|
|
|
ah_setup_uv( outline, ah_uv_ox );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( point = points; point < point_limit; point++ )
|
|
|
|
point->x = point->u;
|
|
|
|
|
|
|
|
break; /* exit loop */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
#endif /* !AH_OPTION_NO_WEAK_INTERPOLATION */
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
LOCAL_FUNC
|
|
|
|
void ah_hinter_align_points( AH_Hinter* hinter )
|
|
|
|
{
|
|
|
|
ah_hinter_align_edge_points( hinter );
|
|
|
|
|
|
|
|
#ifndef AH_OPTION_NO_STRONG_INTERPOLATION
|
|
|
|
ah_hinter_align_strong_points( hinter );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AH_OPTION_NO_WEAK_INTERPOLATION
|
|
|
|
ah_hinter_align_weak_points( hinter );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** H I N T E R O B J E C T M E T H O D S ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
/* scale and fit the global metrics */
|
|
|
|
static
|
|
|
|
void ah_hinter_scale_globals( AH_Hinter* hinter,
|
|
|
|
FT_Fixed x_scale,
|
|
|
|
FT_Fixed y_scale )
|
|
|
|
{
|
|
|
|
FT_Int n;
|
|
|
|
AH_Face_Globals* globals = hinter->globals;
|
|
|
|
AH_Globals* design = &globals->design;
|
|
|
|
AH_Globals* scaled = &globals->scaled;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
/* copy content */
|
|
|
|
*scaled = *design;
|
|
|
|
|
|
|
|
/* scale the standard widths & heights */
|
|
|
|
for ( n = 0; n < design->num_widths; n++ )
|
|
|
|
scaled->widths[n] = FT_MulFix( design->widths[n], x_scale );
|
|
|
|
|
|
|
|
for ( n = 0; n < design->num_heights; n++ )
|
|
|
|
scaled->heights[n] = FT_MulFix( design->heights[n], y_scale );
|
|
|
|
|
|
|
|
/* scale the blue zones */
|
|
|
|
for ( n = 0; n < ah_blue_max; n++ )
|
|
|
|
{
|
|
|
|
FT_Pos delta, delta2;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
delta = design->blue_shoots[n] - design->blue_refs[n];
|
2000-07-26 16:11:15 +02:00
|
|
|
delta2 = delta;
|
|
|
|
if ( delta < 0 )
|
|
|
|
delta2 = -delta2;
|
2000-07-19 22:02:14 +02:00
|
|
|
delta2 = FT_MulFix( delta2, y_scale );
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( delta2 < 32 )
|
2000-07-19 22:02:14 +02:00
|
|
|
delta2 = 0;
|
2000-07-26 16:11:15 +02:00
|
|
|
else if ( delta2 < 64 )
|
|
|
|
delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & -32 );
|
2000-07-19 22:02:14 +02:00
|
|
|
else
|
2000-07-26 16:11:15 +02:00
|
|
|
delta2 = ( delta2 + 32 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( delta < 0 )
|
|
|
|
delta2 = -delta2;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
scaled->blue_refs[n] =
|
|
|
|
( FT_MulFix( design->blue_refs[n], y_scale ) + 32 ) & -64;
|
2000-07-19 22:02:14 +02:00
|
|
|
scaled->blue_shoots[n] = scaled->blue_refs[n] + delta2;
|
|
|
|
}
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-20 05:44:50 +02:00
|
|
|
globals->x_scale = x_scale;
|
|
|
|
globals->y_scale = y_scale;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void ah_hinter_align( AH_Hinter* hinter )
|
|
|
|
{
|
|
|
|
ah_hinter_align_edge_points( hinter );
|
|
|
|
ah_hinter_align_points( hinter );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* finalize a hinter object */
|
2000-07-19 22:02:14 +02:00
|
|
|
void ah_hinter_done( AH_Hinter* hinter )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( hinter )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = hinter->memory;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
ah_loader_done( hinter->loader );
|
|
|
|
ah_outline_done( hinter->glyph );
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* note: the `globals' pointer is _not_ owned by the hinter */
|
|
|
|
/* but by the current face object, we don't need to */
|
|
|
|
/* release it */
|
2000-07-19 22:02:14 +02:00
|
|
|
hinter->globals = 0;
|
|
|
|
hinter->face = 0;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
FREE( hinter );
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* create a new empty hinter object */
|
|
|
|
FT_Error ah_hinter_new( FT_Library library,
|
|
|
|
AH_Hinter** ahinter )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
AH_Hinter* hinter = 0;
|
|
|
|
FT_Memory memory = library->memory;
|
|
|
|
FT_Error error;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
*ahinter = 0;
|
|
|
|
|
|
|
|
/* allocate object */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( ALLOC( hinter, sizeof ( *hinter ) ) )
|
|
|
|
goto Exit;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
hinter->memory = memory;
|
|
|
|
hinter->flags = 0;
|
|
|
|
|
|
|
|
/* allocate outline and loader */
|
|
|
|
error = ah_outline_new( memory, &hinter->glyph ) ||
|
|
|
|
ah_loader_new ( memory, &hinter->loader ) ||
|
|
|
|
ah_loader_create_extra( hinter->loader );
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
*ahinter = hinter;
|
|
|
|
|
|
|
|
Exit:
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( error )
|
2000-07-19 22:02:14 +02:00
|
|
|
ah_hinter_done( hinter );
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* create a face's autohint globals */
|
|
|
|
FT_Error ah_hinter_new_face_globals( AH_Hinter* hinter,
|
|
|
|
FT_Face face,
|
|
|
|
AH_Globals* globals )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = hinter->memory;
|
|
|
|
AH_Face_Globals* face_globals;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( ALLOC( face_globals, sizeof ( *face_globals ) ) )
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
hinter->face = face;
|
|
|
|
hinter->globals = face_globals;
|
2000-07-26 16:11:15 +02:00
|
|
|
|
|
|
|
if ( globals )
|
2000-07-19 22:02:14 +02:00
|
|
|
face_globals->design = *globals;
|
|
|
|
else
|
|
|
|
ah_hinter_compute_globals( hinter );
|
|
|
|
|
|
|
|
face->autohint.data = face_globals;
|
2000-07-26 16:11:15 +02:00
|
|
|
face->autohint.finalizer = (FT_Generic_Finalizer)
|
|
|
|
ah_hinter_done_face_globals;
|
2000-07-19 22:02:14 +02:00
|
|
|
face_globals->face = face;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* discard a face's autohint globals */
|
2000-08-23 04:47:57 +02:00
|
|
|
LOCAL_FUNC
|
2000-07-19 22:02:14 +02:00
|
|
|
void ah_hinter_done_face_globals( AH_Face_Globals* globals )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
FT_Face face = globals->face;
|
|
|
|
FT_Memory memory = face->memory;
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
FREE( globals );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
static
|
|
|
|
FT_Error ah_hinter_load( AH_Hinter* hinter,
|
|
|
|
FT_UInt glyph_index,
|
|
|
|
FT_UInt load_flags,
|
|
|
|
FT_UInt depth )
|
|
|
|
{
|
|
|
|
FT_Face face = hinter->face;
|
|
|
|
FT_GlyphSlot slot = face->glyph;
|
|
|
|
FT_Fixed x_scale = face->size->metrics.x_scale;
|
|
|
|
FT_Fixed y_scale = face->size->metrics.y_scale;
|
|
|
|
FT_Glyph_Metrics metrics; /* temporary metrics */
|
|
|
|
FT_Error error;
|
|
|
|
AH_Outline* outline = hinter->glyph;
|
|
|
|
AH_Loader* gloader = hinter->loader;
|
|
|
|
FT_Bool no_horz_hints =
|
|
|
|
( load_flags & AH_HINT_NO_HORZ_EDGES ) != 0;
|
|
|
|
FT_Bool no_vert_hints =
|
|
|
|
( load_flags & AH_HINT_NO_VERT_EDGES ) != 0;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* load the glyph */
|
|
|
|
error = FT_Load_Glyph( face, glyph_index, load_flags );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* save current glyph metrics */
|
|
|
|
metrics = slot->metrics;
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
switch ( slot->format )
|
|
|
|
{
|
|
|
|
case ft_glyph_format_outline:
|
|
|
|
/* first of all, copy the outline points in the loader's current */
|
|
|
|
/* extra points, which is used to keep original glyph coordinates */
|
|
|
|
error = ah_loader_check_points( gloader, slot->outline.n_points + 2,
|
|
|
|
slot->outline.n_contours );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
MEM_Copy( gloader->current.extra_points, slot->outline.points,
|
|
|
|
slot->outline.n_points * sizeof ( FT_Vector ) );
|
|
|
|
|
|
|
|
MEM_Copy( gloader->current.outline.contours, slot->outline.contours,
|
|
|
|
slot->outline.n_contours * sizeof ( short ) );
|
|
|
|
|
|
|
|
MEM_Copy( gloader->current.outline.tags, slot->outline.tags,
|
|
|
|
slot->outline.n_points * sizeof ( char ) );
|
|
|
|
|
|
|
|
gloader->current.outline.n_points = slot->outline.n_points;
|
|
|
|
gloader->current.outline.n_contours = slot->outline.n_contours;
|
|
|
|
|
|
|
|
/* compute original phantom points */
|
|
|
|
hinter->pp1.x = 0;
|
|
|
|
hinter->pp1.y = 0;
|
|
|
|
hinter->pp2.x = FT_MulFix( slot->metrics.horiAdvance, x_scale );
|
|
|
|
hinter->pp2.y = 0;
|
|
|
|
|
|
|
|
/* be sure to check for spacing glyphs */
|
|
|
|
if ( slot->outline.n_points == 0 )
|
|
|
|
goto Hint_Metrics;
|
|
|
|
|
|
|
|
/* now, load the slot image into the auto-outline, and run the */
|
|
|
|
/* automatic hinting process */
|
|
|
|
error = ah_outline_load( outline, face ); /* XXX: change to slot */
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* perform feature detection */
|
|
|
|
ah_outline_detect_features( outline );
|
|
|
|
|
|
|
|
if ( !no_horz_hints )
|
|
|
|
{
|
|
|
|
ah_outline_compute_blue_edges( outline, hinter->globals );
|
|
|
|
ah_outline_scale_blue_edges( outline, hinter->globals );
|
|
|
|
}
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* perform alignment control */
|
|
|
|
ah_hinter_hint_edges( hinter, no_horz_hints, no_vert_hints );
|
|
|
|
ah_hinter_align( hinter );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* now save the current outline into the loader's current table */
|
|
|
|
ah_outline_save( outline, gloader );
|
2000-07-19 22:02:14 +02:00
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* we now need to hint the metrics according to the change in */
|
|
|
|
/* width/positioning that occured during the hinting process */
|
|
|
|
{
|
|
|
|
FT_Pos old_width, new_width;
|
|
|
|
FT_Pos old_advance, new_advance;
|
|
|
|
FT_Pos old_lsb, new_lsb;
|
|
|
|
AH_Edge* edge1 = outline->vert_edges; /* leftmost edge */
|
|
|
|
AH_Edge* edge2 = edge1 +
|
|
|
|
outline->num_vedges - 1; /* rightmost edge */
|
2000-07-19 22:02:14 +02:00
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
old_width = edge2->opos - edge1->opos;
|
|
|
|
new_width = edge2->pos - edge1->pos;
|
|
|
|
|
|
|
|
old_advance = hinter->pp2.x;
|
|
|
|
old_lsb = edge1->opos;
|
|
|
|
new_lsb = edge1->pos;
|
|
|
|
|
|
|
|
new_advance = old_advance +
|
|
|
|
( new_width + new_lsb - old_width - old_lsb );
|
|
|
|
|
|
|
|
hinter->pp1.x = ( ( new_lsb - old_lsb ) + 32 ) & -64;
|
2000-10-31 21:42:18 +01:00
|
|
|
hinter->pp2.x = ( ( edge2->pos +
|
2000-07-26 16:11:15 +02:00
|
|
|
( old_advance - edge2->opos ) ) + 32 ) & -64;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* good, we simply add the glyph to our loader's base */
|
|
|
|
ah_loader_add( gloader );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ft_glyph_format_composite:
|
|
|
|
{
|
|
|
|
FT_UInt nn, num_subglyphs = slot->num_subglyphs;
|
|
|
|
FT_UInt num_base_subgs, start_point, start_contour;
|
|
|
|
FT_SubGlyph* subglyph;
|
|
|
|
|
|
|
|
|
|
|
|
start_point = gloader->base.outline.n_points;
|
|
|
|
start_contour = gloader->base.outline.n_contours;
|
|
|
|
|
|
|
|
/* first of all, copy the subglyph descriptors in the glyph loader */
|
|
|
|
error = ah_loader_check_subglyphs( gloader, num_subglyphs );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
MEM_Copy( gloader->current.subglyphs, slot->subglyphs,
|
|
|
|
num_subglyphs * sizeof ( FT_SubGlyph ) );
|
|
|
|
|
|
|
|
gloader->current.num_subglyphs = num_subglyphs;
|
|
|
|
num_base_subgs = gloader->base.num_subglyphs;
|
|
|
|
|
|
|
|
/* now, read each subglyph independently */
|
|
|
|
for ( nn = 0; nn < num_subglyphs; nn++ )
|
|
|
|
{
|
|
|
|
FT_Vector pp1, pp2;
|
|
|
|
FT_Pos x, y;
|
|
|
|
FT_UInt num_points, num_new_points, num_base_points;
|
|
|
|
|
|
|
|
|
|
|
|
/* gloader.current.subglyphs can change during glyph loading due */
|
|
|
|
/* to re-allocation -- we must recompute the current subglyph on */
|
|
|
|
/* each iteration */
|
|
|
|
subglyph = gloader->base.subglyphs + num_base_subgs + nn;
|
|
|
|
|
|
|
|
pp1 = hinter->pp1;
|
|
|
|
pp2 = hinter->pp2;
|
|
|
|
|
|
|
|
num_base_points = gloader->base.outline.n_points;
|
|
|
|
|
|
|
|
error = ah_hinter_load( hinter, subglyph->index,
|
|
|
|
load_flags, depth + 1 );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* recompute subglyph pointer */
|
|
|
|
subglyph = gloader->base.subglyphs + num_base_subgs + nn;
|
|
|
|
|
|
|
|
if ( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS )
|
|
|
|
{
|
|
|
|
pp1 = hinter->pp1;
|
|
|
|
pp2 = hinter->pp2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hinter->pp1 = pp1;
|
|
|
|
hinter->pp2 = pp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_points = gloader->base.outline.n_points;
|
|
|
|
num_new_points = num_points - num_base_points;
|
|
|
|
|
|
|
|
/* now perform the transform required for this subglyph */
|
|
|
|
|
|
|
|
if ( subglyph->flags & ( FT_SUBGLYPH_FLAG_SCALE |
|
|
|
|
FT_SUBGLYPH_FLAG_XY_SCALE |
|
|
|
|
FT_SUBGLYPH_FLAG_2X2 ) )
|
|
|
|
{
|
|
|
|
FT_Vector* cur = gloader->base.outline.points +
|
|
|
|
num_base_points;
|
|
|
|
FT_Vector* org = gloader->base.extra_points +
|
|
|
|
num_base_points;
|
|
|
|
FT_Vector* limit = cur + num_new_points;
|
|
|
|
|
|
|
|
|
|
|
|
for ( ; cur < limit; cur++, org++ )
|
|
|
|
{
|
|
|
|
FT_Vector_Transform( cur, &subglyph->transform );
|
|
|
|
FT_Vector_Transform( org, &subglyph->transform );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply offset */
|
|
|
|
|
|
|
|
if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) )
|
|
|
|
{
|
|
|
|
FT_Int k = subglyph->arg1;
|
|
|
|
FT_UInt l = subglyph->arg2;
|
|
|
|
FT_Vector* p1;
|
|
|
|
FT_Vector* p2;
|
|
|
|
|
|
|
|
|
|
|
|
if ( start_point + k >= num_base_points ||
|
|
|
|
l >= (FT_UInt)num_new_points )
|
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Composite;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
l += num_base_points;
|
|
|
|
|
|
|
|
/* for now, only use the current point coordinates */
|
|
|
|
/* we may consider another approach in the near future */
|
|
|
|
p1 = gloader->base.outline.points + start_point + k;
|
|
|
|
p2 = gloader->base.outline.points + start_point + l;
|
|
|
|
|
|
|
|
x = p1->x - p2->x;
|
|
|
|
y = p1->y - p2->y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = FT_MulFix( subglyph->arg1, x_scale );
|
|
|
|
y = FT_MulFix( subglyph->arg2, y_scale );
|
|
|
|
|
|
|
|
x = ( x + 32 ) & -64;
|
|
|
|
y = ( y + 32 ) & -64;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
FT_Outline dummy = gloader->base.outline;
|
|
|
|
|
|
|
|
|
|
|
|
dummy.points += num_base_points;
|
|
|
|
dummy.n_points = num_new_points;
|
|
|
|
|
|
|
|
FT_Outline_Translate( &dummy, x, y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* we don't support other formats (yet?) */
|
|
|
|
error = FT_Err_Unimplemented_Feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
Hint_Metrics:
|
|
|
|
if ( depth == 0 )
|
|
|
|
{
|
|
|
|
FT_BBox bbox;
|
|
|
|
|
|
|
|
|
|
|
|
/* we must translate our final outline by -pp1.x, and compute */
|
|
|
|
/* the new metrics */
|
|
|
|
if ( hinter->pp1.x )
|
|
|
|
FT_Outline_Translate( &gloader->base.outline, -hinter->pp1.x, 0 );
|
|
|
|
|
|
|
|
FT_Outline_Get_CBox( &gloader->base.outline, &bbox );
|
|
|
|
bbox.xMin &= -64;
|
|
|
|
bbox.yMin &= -64;
|
|
|
|
bbox.xMax = ( bbox.xMax + 63 ) & -64;
|
|
|
|
bbox.yMax = ( bbox.yMax + 63 ) & -64;
|
|
|
|
|
|
|
|
slot->metrics.width = bbox.xMax - bbox.xMin;
|
|
|
|
slot->metrics.height = bbox.yMax - bbox.yMin;
|
|
|
|
slot->metrics.horiBearingX = bbox.xMin;
|
|
|
|
slot->metrics.horiBearingY = bbox.yMax;
|
|
|
|
slot->metrics.horiAdvance = hinter->pp2.x - hinter->pp1.x;
|
|
|
|
/* XXX: TO DO - slot->linearHoriAdvance */
|
|
|
|
|
|
|
|
/* now copy outline into glyph slot */
|
|
|
|
ah_loader_rewind( slot->loader );
|
|
|
|
error = ah_loader_copy_points( slot->loader, gloader );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
slot->outline = slot->loader->base.outline;
|
|
|
|
slot->format = ft_glyph_format_outline;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* load and hint a given glyph */
|
|
|
|
FT_Error ah_hinter_load_glyph( AH_Hinter* hinter,
|
|
|
|
FT_GlyphSlot slot,
|
|
|
|
FT_Size size,
|
|
|
|
FT_UInt glyph_index,
|
|
|
|
FT_Int load_flags )
|
|
|
|
{
|
|
|
|
FT_Face face = slot->face;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Fixed x_scale = size->metrics.x_scale;
|
|
|
|
FT_Fixed y_scale = size->metrics.y_scale;
|
|
|
|
AH_Face_Globals* face_globals = FACE_GLOBALS( face );
|
|
|
|
|
|
|
|
|
|
|
|
/* first of all, we need to check that we're using the correct face and */
|
|
|
|
/* global hints to load the glyph */
|
|
|
|
if ( hinter->face != face || hinter->globals != face_globals )
|
|
|
|
{
|
|
|
|
hinter->face = face;
|
|
|
|
if ( !face_globals )
|
|
|
|
{
|
|
|
|
error = ah_hinter_new_face_globals( hinter, face, 0 );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
hinter->globals = FACE_GLOBALS( face );
|
|
|
|
face_globals = FACE_GLOBALS( face );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now, we must check the current character pixel size to see if we */
|
|
|
|
/* need to rescale the global metrics */
|
|
|
|
if ( face_globals->x_scale != x_scale ||
|
|
|
|
face_globals->y_scale != y_scale )
|
|
|
|
ah_hinter_scale_globals( hinter, x_scale, y_scale );
|
|
|
|
|
|
|
|
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE;
|
|
|
|
|
|
|
|
ah_loader_rewind( hinter->loader );
|
|
|
|
|
|
|
|
error = ah_hinter_load( hinter, glyph_index, load_flags, 0 );
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* retrieve a face's autohint globals for client applications */
|
2000-07-19 22:02:14 +02:00
|
|
|
void ah_hinter_get_global_hints( AH_Hinter* hinter,
|
|
|
|
FT_Face face,
|
2000-07-26 16:11:15 +02:00
|
|
|
void** global_hints,
|
|
|
|
long* global_len )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
AH_Globals* globals = 0;
|
|
|
|
FT_Memory memory = hinter->memory;
|
|
|
|
FT_Error error;
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
/* allocate new master globals */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( ALLOC( globals, sizeof ( *globals ) ) )
|
2000-07-19 22:02:14 +02:00
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
/* compute face globals if needed */
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( !FACE_GLOBALS( face ) )
|
2000-07-19 22:02:14 +02:00
|
|
|
{
|
|
|
|
error = ah_hinter_new_face_globals( hinter, face, 0 );
|
2000-07-26 16:11:15 +02:00
|
|
|
if ( error )
|
|
|
|
goto Fail;
|
2000-07-19 22:02:14 +02:00
|
|
|
}
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
*globals = FACE_GLOBALS( face )->design;
|
2000-07-19 22:02:14 +02:00
|
|
|
*global_hints = globals;
|
2000-07-26 16:11:15 +02:00
|
|
|
*global_len = sizeof( *globals );
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Fail:
|
|
|
|
FREE( globals );
|
2000-07-26 16:11:15 +02:00
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
*global_hints = 0;
|
|
|
|
*global_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ah_hinter_done_global_hints( AH_Hinter* hinter,
|
|
|
|
void* global_hints )
|
|
|
|
{
|
2000-07-26 16:11:15 +02:00
|
|
|
FT_Memory memory = hinter->memory;
|
|
|
|
|
|
|
|
|
2000-07-19 22:02:14 +02:00
|
|
|
FREE( global_hints );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-26 16:11:15 +02:00
|
|
|
/* END */
|