2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* pshalgo.c
|
|
|
|
*
|
|
|
|
* PostScript hinting algorithm (body).
|
|
|
|
*
|
2021-01-17 07:18:48 +01:00
|
|
|
* Copyright (C) 2001-2021 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftobjs.h>
|
|
|
|
#include <freetype/internal/ftdebug.h>
|
|
|
|
#include <freetype/internal/ftcalc.h>
|
2003-05-29 00:42:41 +02:00
|
|
|
#include "pshalgo.h"
|
2002-07-03 23:00:26 +02:00
|
|
|
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
#include "pshnterr.h"
|
|
|
|
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#undef FT_COMPONENT
|
2018-08-15 18:13:17 +02:00
|
|
|
#define FT_COMPONENT pshalgo
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#ifdef DEBUG_HINTER
|
2015-04-14 04:40:17 +02:00
|
|
|
PSH_Hint_Table ps_debug_hint_table = NULL;
|
|
|
|
PSH_HintFunc ps_debug_hint_func = NULL;
|
|
|
|
PSH_Glyph ps_debug_glyph = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
#define COMPUTE_INFLEXS /* compute inflection points to optimize `S' */
|
|
|
|
/* and similar glyphs */
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** BASIC HINTS RECORDINGS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* return true if two stem hints overlap */
|
2002-07-03 23:00:26 +02:00
|
|
|
static FT_Int
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_overlap( PSH_Hint hint1,
|
|
|
|
PSH_Hint hint2 )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2018-08-26 12:22:51 +02:00
|
|
|
return ADD_INT( hint1->org_pos, hint1->org_len ) >= hint2->org_pos &&
|
|
|
|
ADD_INT( hint2->org_pos, hint2->org_len ) >= hint1->org_pos;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* destroy hints table */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_done( PSH_Hint_Table table,
|
|
|
|
FT_Memory memory )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_FREE( table->zones );
|
|
|
|
table->num_zones = 0;
|
2015-04-14 04:40:17 +02:00
|
|
|
table->zone = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
FT_FREE( table->sort );
|
|
|
|
FT_FREE( table->hints );
|
|
|
|
table->num_hints = 0;
|
|
|
|
table->max_hints = 0;
|
2015-04-14 04:40:17 +02:00
|
|
|
table->sort_global = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* deactivate all hints in a table */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_deactivate( PSH_Hint_Table table )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_UInt count = table->max_hints;
|
|
|
|
PSH_Hint hint = table->hints;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
for ( ; count > 0; count--, hint++ )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_deactivate( hint );
|
2002-07-03 23:00:26 +02:00
|
|
|
hint->order = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* internal function to record a new hint */
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_record( PSH_Hint_Table table,
|
|
|
|
FT_UInt idx )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint hint = table->hints + idx;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( idx >= table->max_hints )
|
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "psh_hint_table_record: invalid hint index %d\n", idx ));
|
2002-07-03 23:00:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore active hints */
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_hint_is_active( hint ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
return;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_activate( hint );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* now scan the current active hint set to check */
|
|
|
|
/* whether `hint' overlaps with another hint */
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint* sorted = table->sort_global;
|
|
|
|
FT_UInt count = table->num_hints;
|
|
|
|
PSH_Hint hint2;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2015-04-14 04:40:17 +02:00
|
|
|
hint->parent = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
for ( ; count > 0; count--, sorted++ )
|
|
|
|
{
|
|
|
|
hint2 = sorted[0];
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_hint_overlap( hint, hint2 ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
hint->parent = hint2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( table->num_hints < table->max_hints )
|
|
|
|
table->sort_global[table->num_hints++] = hint;
|
|
|
|
else
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "psh_hint_table_record: too many sorted hints! BUG!\n" ));
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_record_mask( PSH_Hint_Table table,
|
|
|
|
PS_Mask hint_mask )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_Int mask = 0, val = 0;
|
|
|
|
FT_Byte* cursor = hint_mask->bytes;
|
|
|
|
FT_UInt idx, limit;
|
|
|
|
|
|
|
|
|
|
|
|
limit = hint_mask->num_bits;
|
|
|
|
|
|
|
|
for ( idx = 0; idx < limit; idx++ )
|
|
|
|
{
|
|
|
|
if ( mask == 0 )
|
|
|
|
{
|
|
|
|
val = *cursor++;
|
|
|
|
mask = 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( val & mask )
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_record( table, idx );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create hints table */
|
|
|
|
static FT_Error
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_init( PSH_Hint_Table table,
|
|
|
|
PS_Hint_Table hints,
|
|
|
|
PS_Mask_Table hint_masks,
|
|
|
|
PS_Mask_Table counter_masks,
|
|
|
|
FT_Memory memory )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2004-03-03 17:06:17 +01:00
|
|
|
FT_UInt count;
|
2002-07-03 23:00:26 +02:00
|
|
|
FT_Error error;
|
|
|
|
|
|
|
|
FT_UNUSED( counter_masks );
|
|
|
|
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
count = hints->num_hints;
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
/* allocate our tables */
|
|
|
|
if ( FT_NEW_ARRAY( table->sort, 2 * count ) ||
|
|
|
|
FT_NEW_ARRAY( table->hints, count ) ||
|
|
|
|
FT_NEW_ARRAY( table->zones, 2 * count + 1 ) )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
table->max_hints = count;
|
|
|
|
table->sort_global = table->sort + count;
|
|
|
|
table->num_hints = 0;
|
|
|
|
table->num_zones = 0;
|
2015-04-14 04:40:17 +02:00
|
|
|
table->zone = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* initialize the `table->hints' array */
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint write = table->hints;
|
|
|
|
PS_Hint read = hints->hints;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
for ( ; count > 0; count--, write++, read++ )
|
|
|
|
{
|
|
|
|
write->org_pos = read->pos;
|
|
|
|
write->org_len = read->len;
|
|
|
|
write->flags = read->flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* we now need to determine the initial `parent' stems; first */
|
2002-07-03 23:00:26 +02:00
|
|
|
/* activate the hints that are given by the initial hint masks */
|
|
|
|
if ( hint_masks )
|
|
|
|
{
|
2004-03-03 17:06:17 +01:00
|
|
|
PS_Mask mask = hint_masks->masks;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
count = hint_masks->num_masks;
|
2002-07-03 23:00:26 +02:00
|
|
|
table->hint_masks = hint_masks;
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
for ( ; count > 0; count--, mask++ )
|
|
|
|
psh_hint_table_record_mask( table, mask );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
2004-03-03 17:06:17 +01:00
|
|
|
/* finally, do a linear parse in case some hints were left alone */
|
2002-07-03 23:00:26 +02:00
|
|
|
if ( table->num_hints != table->max_hints )
|
|
|
|
{
|
2004-03-03 17:06:17 +01:00
|
|
|
FT_UInt idx;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "psh_hint_table_init: missing/incorrect hint masks\n" ));
|
2004-03-03 17:06:17 +01:00
|
|
|
|
|
|
|
count = table->max_hints;
|
|
|
|
for ( idx = 0; idx < count; idx++ )
|
|
|
|
psh_hint_table_record( table, idx );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_activate_mask( PSH_Hint_Table table,
|
|
|
|
PS_Mask hint_mask )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_Int mask = 0, val = 0;
|
|
|
|
FT_Byte* cursor = hint_mask->bytes;
|
|
|
|
FT_UInt idx, limit, count;
|
|
|
|
|
|
|
|
|
|
|
|
limit = hint_mask->num_bits;
|
|
|
|
count = 0;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_deactivate( table );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
for ( idx = 0; idx < limit; idx++ )
|
|
|
|
{
|
|
|
|
if ( mask == 0 )
|
|
|
|
{
|
|
|
|
val = *cursor++;
|
|
|
|
mask = 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( val & mask )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint hint = &table->hints[idx];
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_hint_is_active( hint ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_UInt count2;
|
|
|
|
|
|
|
|
#if 0
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint* sort = table->sort;
|
|
|
|
PSH_Hint hint2;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
for ( count2 = count; count2 > 0; count2--, sort++ )
|
|
|
|
{
|
|
|
|
hint2 = sort[0];
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_hint_overlap( hint, hint2 ) )
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "psh_hint_table_activate_mask:"
|
|
|
|
" found overlapping hints\n" ))
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
count2 = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( count2 == 0 )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_activate( hint );
|
2002-07-03 23:00:26 +02:00
|
|
|
if ( count < table->max_hints )
|
|
|
|
table->sort[count++] = hint;
|
|
|
|
else
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "psh_hint_tableactivate_mask:"
|
|
|
|
" too many active hints\n" ));
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
table->num_hints = count;
|
|
|
|
|
|
|
|
/* now, sort the hints; they are guaranteed to not overlap */
|
|
|
|
/* so we can compare their "org_pos" field directly */
|
|
|
|
{
|
2021-09-13 22:29:08 +02:00
|
|
|
FT_UInt i1, i2;
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint hint1, hint2;
|
|
|
|
PSH_Hint* sort = table->sort;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* a simple bubble sort will do, since in 99% of cases, the hints */
|
|
|
|
/* will be already sorted -- and the sort will be linear */
|
2021-09-13 22:29:08 +02:00
|
|
|
for ( i1 = 1; i1 < count; i1++ )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
hint1 = sort[i1];
|
2021-09-13 22:29:08 +02:00
|
|
|
/* this loop stops when i2 wraps around after reaching 0 */
|
|
|
|
for ( i2 = i1 - 1; i2 < i1; i2-- )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
hint2 = sort[i2];
|
|
|
|
|
|
|
|
if ( hint2->org_pos < hint1->org_pos )
|
|
|
|
break;
|
|
|
|
|
|
|
|
sort[i2 + 1] = hint2;
|
|
|
|
sort[i2] = hint1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** HINTS GRID-FITTING AND OPTIMIZATION *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2003-03-27 22:35:44 +01:00
|
|
|
#if 1
|
2002-09-08 23:29:11 +02:00
|
|
|
static FT_Pos
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_dimension_quantize_len( PSH_Dimension dim,
|
|
|
|
FT_Pos len,
|
|
|
|
FT_Bool do_snapping )
|
2002-09-08 23:29:11 +02:00
|
|
|
{
|
|
|
|
if ( len <= 64 )
|
|
|
|
len = 64;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FT_Pos delta = len - dim->stdw.widths[0].cur;
|
|
|
|
|
|
|
|
|
|
|
|
if ( delta < 0 )
|
|
|
|
delta = -delta;
|
|
|
|
|
|
|
|
if ( delta < 40 )
|
|
|
|
{
|
|
|
|
len = dim->stdw.widths[0].cur;
|
|
|
|
if ( len < 48 )
|
|
|
|
len = 48;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( len < 3 * 64 )
|
|
|
|
{
|
|
|
|
delta = ( len & 63 );
|
|
|
|
len &= -64;
|
|
|
|
|
|
|
|
if ( delta < 10 )
|
|
|
|
len += delta;
|
|
|
|
|
|
|
|
else if ( delta < 32 )
|
|
|
|
len += 10;
|
|
|
|
|
|
|
|
else if ( delta < 54 )
|
|
|
|
len += 54;
|
|
|
|
|
|
|
|
else
|
|
|
|
len += delta;
|
|
|
|
}
|
|
|
|
else
|
2003-12-24 02:10:46 +01:00
|
|
|
len = FT_PIX_ROUND( len );
|
2002-09-08 23:29:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( do_snapping )
|
2003-12-24 02:10:46 +01:00
|
|
|
len = FT_PIX_ROUND( len );
|
2002-09-08 23:29:11 +02:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2003-01-31 00:24:18 +01:00
|
|
|
#endif /* 0 */
|
2002-09-08 23:29:11 +02:00
|
|
|
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#ifdef DEBUG_HINTER
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
ps_simple_scale( PSH_Hint_Table table,
|
|
|
|
FT_Fixed scale,
|
|
|
|
FT_Fixed delta,
|
|
|
|
FT_Int dimension )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_UInt count;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
for ( count = 0; count < table->max_hints; count++ )
|
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
PSH_Hint hint = table->hints + count;
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
hint->cur_pos = FT_MulFix( hint->org_pos, scale ) + delta;
|
|
|
|
hint->cur_len = FT_MulFix( hint->org_len, scale );
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( ps_debug_hint_func )
|
|
|
|
ps_debug_hint_func( hint, dimension );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
2002-07-26 16:52:29 +02:00
|
|
|
|
|
|
|
#endif /* DEBUG_HINTER */
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
static FT_Fixed
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_snap_stem_side_delta( FT_Fixed pos,
|
|
|
|
FT_Fixed len )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
FT_Fixed delta1 = FT_PIX_ROUND( pos ) - pos;
|
|
|
|
FT_Fixed delta2 = FT_PIX_ROUND( pos + len ) - pos - len;
|
2002-07-26 16:52:29 +02:00
|
|
|
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
if ( FT_ABS( delta1 ) <= FT_ABS( delta2 ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
return delta1;
|
|
|
|
else
|
|
|
|
return delta2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_align( PSH_Hint hint,
|
|
|
|
PSH_Globals globals,
|
|
|
|
FT_Int dimension,
|
|
|
|
PSH_Glyph glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
PSH_Dimension dim = &globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Fixed delta = dim->scale_delta;
|
|
|
|
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_hint_is_fitted( hint ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_Pos pos = FT_MulFix( hint->org_pos, scale ) + delta;
|
|
|
|
FT_Pos len = FT_MulFix( hint->org_len, scale );
|
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
FT_Int do_snapping;
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
FT_Pos fit_len;
|
2002-07-03 23:00:26 +02:00
|
|
|
PSH_AlignmentRec align;
|
|
|
|
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
|
|
|
|
/* ignore stem alignments when requested through the hint flags */
|
2002-09-08 23:29:11 +02:00
|
|
|
if ( ( dimension == 0 && !glyph->do_horz_hints ) ||
|
|
|
|
( dimension == 1 && !glyph->do_vert_hints ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
hint->cur_pos = pos;
|
|
|
|
hint->cur_len = len;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_set_fitted( hint );
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
return;
|
2002-07-26 16:52:29 +02:00
|
|
|
}
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
/* perform stem snapping when requested - this is necessary
|
|
|
|
* for monochrome and LCD hinting modes only
|
|
|
|
*/
|
2002-09-08 23:29:11 +02:00
|
|
|
do_snapping = ( dimension == 0 && glyph->do_horz_snapping ) ||
|
|
|
|
( dimension == 1 && glyph->do_vert_snapping );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
hint->cur_len = fit_len = len;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
/* check blue zones for horizontal stems */
|
2002-08-19 08:06:44 +02:00
|
|
|
align.align = PSH_BLUE_ALIGN_NONE;
|
2002-07-03 23:00:26 +02:00
|
|
|
align.align_bot = align.align_top = 0;
|
|
|
|
|
|
|
|
if ( dimension == 1 )
|
|
|
|
psh_blues_snap_stem( &globals->blues,
|
2018-08-29 15:28:21 +02:00
|
|
|
ADD_INT( hint->org_pos, hint->org_len ),
|
2002-07-03 23:00:26 +02:00
|
|
|
hint->org_pos,
|
|
|
|
&align );
|
|
|
|
|
|
|
|
switch ( align.align )
|
|
|
|
{
|
|
|
|
case PSH_BLUE_ALIGN_TOP:
|
|
|
|
/* the top of the stem is aligned against a blue zone */
|
|
|
|
hint->cur_pos = align.align_top - fit_len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSH_BLUE_ALIGN_BOT:
|
|
|
|
/* the bottom of the stem is aligned against a blue zone */
|
|
|
|
hint->cur_pos = align.align_bot;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT:
|
|
|
|
/* both edges of the stem are aligned against blue zones */
|
|
|
|
hint->cur_pos = align.align_bot;
|
|
|
|
hint->cur_len = align.align_top - align.align_bot;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint parent = hint->parent;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
{
|
|
|
|
FT_Pos par_org_center, par_cur_center;
|
|
|
|
FT_Pos cur_org_center, cur_delta;
|
|
|
|
|
|
|
|
|
|
|
|
/* ensure that parent is already fitted */
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_hint_is_fitted( parent ) )
|
|
|
|
psh_hint_align( parent, globals, dimension, glyph );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-03-02 08:01:20 +01:00
|
|
|
/* keep original relation between hints, this is, use the */
|
|
|
|
/* scaled distance between the centers of the hints to */
|
|
|
|
/* compute the new position */
|
2002-08-19 08:06:44 +02:00
|
|
|
par_org_center = parent->org_pos + ( parent->org_len >> 1 );
|
|
|
|
par_cur_center = parent->cur_pos + ( parent->cur_len >> 1 );
|
|
|
|
cur_org_center = hint->org_pos + ( hint->org_len >> 1 );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
cur_delta = FT_MulFix( cur_org_center - par_org_center, scale );
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
pos = par_cur_center + cur_delta - ( len >> 1 );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
hint->cur_pos = pos;
|
|
|
|
hint->cur_len = fit_len;
|
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
/* Stem adjustment tries to snap stem widths to standard
|
|
|
|
* ones. This is important to prevent unpleasant rounding
|
|
|
|
* artefacts.
|
|
|
|
*/
|
2003-01-08 10:52:32 +01:00
|
|
|
if ( glyph->do_stem_adjust )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-01-08 10:52:32 +01:00
|
|
|
if ( len <= 64 )
|
|
|
|
{
|
2003-04-23 17:17:43 +02:00
|
|
|
/* the stem is less than one pixel; we will center it
|
|
|
|
* around the nearest pixel center
|
|
|
|
*/
|
2007-02-25 22:06:43 +01:00
|
|
|
if ( len >= 32 )
|
2007-02-21 17:47:49 +01:00
|
|
|
{
|
2007-02-25 22:06:43 +01:00
|
|
|
/* This is a special case where we also widen the stem
|
|
|
|
* and align it to the pixel grid.
|
|
|
|
*
|
|
|
|
* stem_center = pos + (len/2)
|
|
|
|
* nearest_pixel_center = FT_ROUND(stem_center-32)+32
|
|
|
|
* new_pos = nearest_pixel_center-32
|
|
|
|
* = FT_ROUND(stem_center-32)
|
|
|
|
* = FT_FLOOR(stem_center-32+32)
|
|
|
|
* = FT_FLOOR(stem_center)
|
|
|
|
* new_len = 64
|
|
|
|
*/
|
|
|
|
pos = FT_PIX_FLOOR( pos + ( len >> 1 ) );
|
|
|
|
len = 64;
|
2007-02-21 17:47:49 +01:00
|
|
|
}
|
2007-02-25 22:06:43 +01:00
|
|
|
else if ( len > 0 )
|
2007-02-21 17:47:49 +01:00
|
|
|
{
|
2007-02-25 22:06:43 +01:00
|
|
|
/* This is a very small stem; we simply align it to the
|
2012-03-11 13:48:25 +01:00
|
|
|
* pixel grid, trying to find the minimum displacement.
|
2007-02-25 22:06:43 +01:00
|
|
|
*
|
|
|
|
* left = pos
|
|
|
|
* right = pos + len
|
|
|
|
* left_nearest_edge = ROUND(pos)
|
|
|
|
* right_nearest_edge = ROUND(right)
|
|
|
|
*
|
|
|
|
* if ( ABS(left_nearest_edge - left) <=
|
|
|
|
* ABS(right_nearest_edge - right) )
|
|
|
|
* new_pos = left
|
|
|
|
* else
|
|
|
|
* new_pos = right
|
|
|
|
*/
|
|
|
|
FT_Pos left_nearest = FT_PIX_ROUND( pos );
|
|
|
|
FT_Pos right_nearest = FT_PIX_ROUND( pos + len );
|
|
|
|
FT_Pos left_disp = left_nearest - pos;
|
|
|
|
FT_Pos right_disp = right_nearest - ( pos + len );
|
|
|
|
|
|
|
|
|
|
|
|
if ( left_disp < 0 )
|
|
|
|
left_disp = -left_disp;
|
|
|
|
if ( right_disp < 0 )
|
|
|
|
right_disp = -right_disp;
|
|
|
|
if ( left_disp <= right_disp )
|
|
|
|
pos = left_nearest;
|
|
|
|
else
|
|
|
|
pos = right_nearest;
|
2007-02-21 17:47:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-25 22:06:43 +01:00
|
|
|
/* this is a ghost stem; we simply round it */
|
|
|
|
pos = FT_PIX_ROUND( pos );
|
2007-02-21 17:47:49 +01:00
|
|
|
}
|
2003-01-08 10:52:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
len = psh_dimension_quantize_len( dim, len, 0 );
|
2003-01-08 10:52:32 +01:00
|
|
|
}
|
2002-09-08 23:29:11 +02:00
|
|
|
}
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
/* now that we have a good hinted stem width, try to position */
|
|
|
|
/* the stem along a pixel grid integer coordinate */
|
2003-05-29 00:42:41 +02:00
|
|
|
hint->cur_pos = pos + psh_hint_snap_stem_side_delta( pos, len );
|
2002-09-08 23:29:11 +02:00
|
|
|
hint->cur_len = len;
|
|
|
|
}
|
|
|
|
}
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
if ( do_snapping )
|
|
|
|
{
|
2003-01-31 00:24:18 +01:00
|
|
|
pos = hint->cur_pos;
|
2002-09-08 23:29:11 +02:00
|
|
|
len = hint->cur_len;
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
if ( len < 64 )
|
|
|
|
len = 64;
|
|
|
|
else
|
2003-12-24 02:10:46 +01:00
|
|
|
len = FT_PIX_ROUND( len );
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
switch ( align.align )
|
|
|
|
{
|
|
|
|
case PSH_BLUE_ALIGN_TOP:
|
|
|
|
hint->cur_pos = align.align_top - len;
|
|
|
|
hint->cur_len = len;
|
|
|
|
break;
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
case PSH_BLUE_ALIGN_BOT:
|
|
|
|
hint->cur_len = len;
|
|
|
|
break;
|
2002-08-30 00:50:17 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
case PSH_BLUE_ALIGN_BOT | PSH_BLUE_ALIGN_TOP:
|
|
|
|
/* don't touch */
|
|
|
|
break;
|
2002-08-30 00:50:17 +02:00
|
|
|
|
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
default:
|
2002-08-30 00:50:17 +02:00
|
|
|
hint->cur_len = len;
|
2002-09-08 23:29:11 +02:00
|
|
|
if ( len & 64 )
|
2003-12-24 02:10:46 +01:00
|
|
|
pos = FT_PIX_FLOOR( pos + ( len >> 1 ) ) + 32;
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
else
|
2003-12-24 02:10:46 +01:00
|
|
|
pos = FT_PIX_ROUND( pos + ( len >> 1 ) );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-09-08 23:29:11 +02:00
|
|
|
hint->cur_pos = pos - ( len >> 1 );
|
|
|
|
hint->cur_len = len;
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
* include/freetype/freetype.h, src/base/ftobjs.h,
freetype/internal/ftobjs.h, freetype/internal/psaux.h,
freetype/internal/pshints.h, src/psaux/t1decode.c, src/cff/cffgload.h,
src/cff/cffgload.c, src/pshinter/pshalgo1.h, src/pshinter/pshalgo1.c,
src/pshinter/pshalgo2.h, src/pshinter/pshalgo2.c, src/pshinter/pshalgo3.h,
src/pshinter/pshalgo3.c: Adding support for hinter-specific bit flags,
and the new FT_Set_Hint_Flags high-level API
2002-07-09 00:26:11 +02:00
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_set_fitted( hint );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_HINTER
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( ps_debug_hint_func )
|
|
|
|
ps_debug_hint_func( hint, dimension );
|
2002-07-03 23:00:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-27 22:35:44 +01:00
|
|
|
#if 0 /* not used for now, experimental */
|
|
|
|
|
2003-01-30 15:57:38 +01:00
|
|
|
/*
|
2018-06-03 09:01:17 +02:00
|
|
|
* A variant to perform "light" hinting (i.e. FT_RENDER_MODE_LIGHT)
|
|
|
|
* of stems
|
2003-01-30 15:57:38 +01:00
|
|
|
*/
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_align_light( PSH_Hint hint,
|
|
|
|
PSH_Globals globals,
|
|
|
|
FT_Int dimension,
|
|
|
|
PSH_Glyph glyph )
|
2003-01-30 15:57:38 +01:00
|
|
|
{
|
|
|
|
PSH_Dimension dim = &globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Fixed delta = dim->scale_delta;
|
|
|
|
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_hint_is_fitted( hint ) )
|
2003-01-30 15:57:38 +01:00
|
|
|
{
|
|
|
|
FT_Pos pos = FT_MulFix( hint->org_pos, scale ) + delta;
|
|
|
|
FT_Pos len = FT_MulFix( hint->org_len, scale );
|
|
|
|
|
|
|
|
FT_Pos fit_len;
|
|
|
|
|
|
|
|
PSH_AlignmentRec align;
|
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
|
2003-01-30 15:57:38 +01:00
|
|
|
/* ignore stem alignments when requested through the hint flags */
|
|
|
|
if ( ( dimension == 0 && !glyph->do_horz_hints ) ||
|
|
|
|
( dimension == 1 && !glyph->do_vert_hints ) )
|
|
|
|
{
|
|
|
|
hint->cur_pos = pos;
|
|
|
|
hint->cur_len = len;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_set_fitted( hint );
|
2003-01-30 15:57:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fit_len = len;
|
|
|
|
|
|
|
|
hint->cur_len = fit_len;
|
|
|
|
|
|
|
|
/* check blue zones for horizontal stems */
|
|
|
|
align.align = PSH_BLUE_ALIGN_NONE;
|
|
|
|
align.align_bot = align.align_top = 0;
|
|
|
|
|
|
|
|
if ( dimension == 1 )
|
|
|
|
psh_blues_snap_stem( &globals->blues,
|
2018-08-29 15:28:21 +02:00
|
|
|
ADD_INT( hint->org_pos, hint->org_len ),
|
2003-01-30 15:57:38 +01:00
|
|
|
hint->org_pos,
|
|
|
|
&align );
|
|
|
|
|
|
|
|
switch ( align.align )
|
|
|
|
{
|
|
|
|
case PSH_BLUE_ALIGN_TOP:
|
|
|
|
/* the top of the stem is aligned against a blue zone */
|
|
|
|
hint->cur_pos = align.align_top - fit_len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSH_BLUE_ALIGN_BOT:
|
|
|
|
/* the bottom of the stem is aligned against a blue zone */
|
|
|
|
hint->cur_pos = align.align_bot;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT:
|
|
|
|
/* both edges of the stem are aligned against blue zones */
|
|
|
|
hint->cur_pos = align.align_bot;
|
|
|
|
hint->cur_len = align.align_top - align.align_bot;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint parent = hint->parent;
|
2003-01-30 15:57:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
{
|
|
|
|
FT_Pos par_org_center, par_cur_center;
|
|
|
|
FT_Pos cur_org_center, cur_delta;
|
|
|
|
|
|
|
|
|
|
|
|
/* ensure that parent is already fitted */
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_hint_is_fitted( parent ) )
|
|
|
|
psh_hint_align_light( parent, globals, dimension, glyph );
|
2003-01-30 15:57:38 +01:00
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
par_org_center = parent->org_pos + ( parent->org_len / 2 );
|
|
|
|
par_cur_center = parent->cur_pos + ( parent->cur_len / 2 );
|
|
|
|
cur_org_center = hint->org_pos + ( hint->org_len / 2 );
|
2003-01-30 15:57:38 +01:00
|
|
|
|
|
|
|
cur_delta = FT_MulFix( cur_org_center - par_org_center, scale );
|
|
|
|
pos = par_cur_center + cur_delta - ( len >> 1 );
|
|
|
|
}
|
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
/* Stems less than one pixel wide are easy -- we want to
|
|
|
|
* make them as dark as possible, so they must fall within
|
|
|
|
* one pixel. If the stem is split between two pixels
|
|
|
|
* then snap the edge that is nearer to the pixel boundary
|
|
|
|
* to the pixel boundary.
|
|
|
|
*/
|
|
|
|
if ( len <= 64 )
|
2003-01-30 15:57:38 +01:00
|
|
|
{
|
|
|
|
if ( ( pos + len + 63 ) / 64 != pos / 64 + 1 )
|
2003-05-29 00:42:41 +02:00
|
|
|
pos += psh_hint_snap_stem_side_delta ( pos, len );
|
2003-01-30 15:57:38 +01:00
|
|
|
}
|
2003-04-23 17:17:43 +02:00
|
|
|
|
|
|
|
/* Position stems other to minimize the amount of mid-grays.
|
|
|
|
* There are, in general, two positions that do this,
|
|
|
|
* illustrated as A) and B) below.
|
|
|
|
*
|
|
|
|
* + + + +
|
|
|
|
*
|
|
|
|
* A) |--------------------------------|
|
|
|
|
* B) |--------------------------------|
|
|
|
|
* C) |--------------------------------|
|
|
|
|
*
|
|
|
|
* Position A) (split the excess stem equally) should be better
|
|
|
|
* for stems of width N + f where f < 0.5.
|
|
|
|
*
|
|
|
|
* Position B) (split the deficiency equally) should be better
|
|
|
|
* for stems of width N + f where f > 0.5.
|
|
|
|
*
|
|
|
|
* It turns out though that minimizing the total number of lit
|
|
|
|
* pixels is also important, so position C), with one edge
|
|
|
|
* aligned with a pixel boundary is actually preferable
|
2016-04-09 05:21:34 +02:00
|
|
|
* to A). There are also more possible positions for C) than
|
2003-04-23 17:17:43 +02:00
|
|
|
* for A) or B), so it involves less distortion of the overall
|
|
|
|
* character shape.
|
|
|
|
*/
|
2003-01-30 15:57:38 +01:00
|
|
|
else /* len > 64 */
|
|
|
|
{
|
2003-04-23 17:17:43 +02:00
|
|
|
FT_Fixed frac_len = len & 63;
|
|
|
|
FT_Fixed center = pos + ( len >> 1 );
|
|
|
|
FT_Fixed delta_a, delta_b;
|
|
|
|
|
2003-01-30 15:57:38 +01:00
|
|
|
|
|
|
|
if ( ( len / 64 ) & 1 )
|
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
delta_a = FT_PIX_FLOOR( center ) + 32 - center;
|
|
|
|
delta_b = FT_PIX_ROUND( center ) - center;
|
2003-01-30 15:57:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
delta_a = FT_PIX_ROUND( center ) - center;
|
|
|
|
delta_b = FT_PIX_FLOOR( center ) + 32 - center;
|
2003-01-30 15:57:38 +01:00
|
|
|
}
|
|
|
|
|
2003-04-23 17:17:43 +02:00
|
|
|
/* We choose between B) and C) above based on the amount
|
2016-04-09 05:21:34 +02:00
|
|
|
* of fractional stem width; for small amounts, choose
|
2003-04-23 17:17:43 +02:00
|
|
|
* C) always, for large amounts, B) always, and inbetween,
|
|
|
|
* pick whichever one involves less stem movement.
|
|
|
|
*/
|
|
|
|
if ( frac_len < 32 )
|
2003-01-30 15:57:38 +01:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
pos += psh_hint_snap_stem_side_delta ( pos, len );
|
2003-01-30 15:57:38 +01:00
|
|
|
}
|
2003-04-23 17:17:43 +02:00
|
|
|
else if ( frac_len < 48 )
|
2003-01-30 15:57:38 +01:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_Fixed side_delta = psh_hint_snap_stem_side_delta ( pos,
|
|
|
|
len );
|
2003-04-23 17:17:43 +02:00
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
if ( FT_ABS( side_delta ) < FT_ABS( delta_b ) )
|
2003-01-30 15:57:38 +01:00
|
|
|
pos += side_delta;
|
|
|
|
else
|
|
|
|
pos += delta_b;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos += delta_b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hint->cur_pos = pos;
|
|
|
|
}
|
|
|
|
} /* switch */
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_set_fitted( hint );
|
2003-01-30 15:57:38 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_HINTER
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( ps_debug_hint_func )
|
|
|
|
ps_debug_hint_func( hint, dimension );
|
2003-01-30 15:57:38 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-27 22:35:44 +01:00
|
|
|
#endif /* 0 */
|
|
|
|
|
2003-01-30 15:57:38 +01:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_align_hints( PSH_Hint_Table table,
|
|
|
|
PSH_Globals globals,
|
|
|
|
FT_Int dimension,
|
|
|
|
PSH_Glyph glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint hint;
|
2002-07-03 23:00:26 +02:00
|
|
|
FT_UInt count;
|
|
|
|
|
|
|
|
#ifdef DEBUG_HINTER
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
PSH_Dimension dim = &globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Fixed delta = dim->scale_delta;
|
|
|
|
|
|
|
|
|
|
|
|
if ( ps_debug_no_vert_hints && dimension == 0 )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
ps_simple_scale( table, scale, delta, dimension );
|
2002-07-03 23:00:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ps_debug_no_horz_hints && dimension == 1 )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
ps_simple_scale( table, scale, delta, dimension );
|
2002-07-03 23:00:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2021-08-23 04:32:07 +02:00
|
|
|
#endif /* DEBUG_HINTER */
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
hint = table->hints;
|
|
|
|
count = table->max_hints;
|
|
|
|
|
|
|
|
for ( ; count > 0; count--, hint++ )
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_align( hint, globals, dimension, glyph );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** POINTS INTERPOLATION ROUTINES *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#define xxDEBUG_ZONES
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_ZONES
|
|
|
|
|
2009-01-13 18:34:48 +01:00
|
|
|
#include FT_CONFIG_STANDARD_LIBRARY_H
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_print_zone( PSH_Zone zone )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2016-12-29 10:38:51 +01:00
|
|
|
printf( "zone [scale,delta,min,max] = [%.5f,%.2f,%d,%d]\n",
|
2002-07-26 16:52:29 +02:00
|
|
|
zone->scale / 65536.0,
|
|
|
|
zone->delta / 64.0,
|
2002-07-03 23:00:26 +02:00
|
|
|
zone->min,
|
|
|
|
zone->max );
|
|
|
|
}
|
|
|
|
|
2002-07-26 16:52:29 +02:00
|
|
|
#endif /* DEBUG_ZONES */
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** HINTER GLYPH MANAGEMENT *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2006-11-02 18:21:02 +01:00
|
|
|
#define psh_corner_is_flat ft_corner_is_flat
|
|
|
|
#define psh_corner_orientation ft_corner_orientation
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef COMPUTE_INFLEXS
|
2006-10-23 10:56:57 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
/* compute all inflex points in a given glyph */
|
2002-08-19 08:06:44 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_compute_inflections( PSH_Glyph glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2002-08-19 08:06:44 +02:00
|
|
|
FT_UInt n;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
for ( n = 0; n < glyph->num_contours; n++ )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point first, start, end, before, after;
|
2006-10-23 10:56:57 +02:00
|
|
|
FT_Pos in_x, in_y, out_x, out_y;
|
|
|
|
FT_Int orient_prev, orient_cur;
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_Int finished = 0;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
/* we need at least 4 points to create an inflection point */
|
|
|
|
if ( glyph->contours[n].count < 4 )
|
|
|
|
continue;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
/* compute first segment in contour */
|
2002-08-22 08:04:32 +02:00
|
|
|
first = glyph->contours[n].start;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
start = end = first;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
end = end->next;
|
|
|
|
if ( end == first )
|
|
|
|
goto Skip;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
in_x = end->org_u - start->org_u;
|
|
|
|
in_y = end->org_v - start->org_v;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-11-09 17:31:52 +01:00
|
|
|
} while ( in_x == 0 && in_y == 0 );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
/* extend the segment start whenever possible */
|
|
|
|
before = start;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
start = before;
|
|
|
|
before = before->prev;
|
|
|
|
if ( before == first )
|
|
|
|
goto Skip;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
out_x = start->org_u - before->org_u;
|
|
|
|
out_y = start->org_v - before->org_v;
|
|
|
|
|
|
|
|
} while ( out_x == 0 && out_y == 0 );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
orient_prev = psh_corner_orientation( in_x, in_y, out_x, out_y );
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2007-01-10 14:15:56 +01:00
|
|
|
} while ( orient_prev == 0 );
|
2002-08-19 08:06:44 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
first = start;
|
|
|
|
in_x = out_x;
|
|
|
|
in_y = out_y;
|
2002-08-19 08:06:44 +02:00
|
|
|
|
|
|
|
/* now, process all segments in the contour */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* first, extend current segment's end whenever possible */
|
|
|
|
after = end;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
end = after;
|
|
|
|
after = after->next;
|
|
|
|
if ( after == first )
|
|
|
|
finished = 1;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
out_x = after->org_u - end->org_u;
|
|
|
|
out_y = after->org_v - end->org_v;
|
2002-08-19 08:06:44 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
} while ( out_x == 0 && out_y == 0 );
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
orient_cur = psh_corner_orientation( in_x, in_y, out_x, out_y );
|
2002-08-19 08:06:44 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
} while ( orient_cur == 0 );
|
2002-08-19 08:06:44 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
if ( ( orient_cur ^ orient_prev ) < 0 )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_point_set_inflex( start );
|
2002-08-19 08:06:44 +02:00
|
|
|
start = start->next;
|
|
|
|
}
|
|
|
|
while ( start != end );
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_point_set_inflex( start );
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
start = end;
|
|
|
|
end = after;
|
|
|
|
orient_prev = orient_cur;
|
|
|
|
in_x = out_x;
|
|
|
|
in_y = out_y;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
} while ( !finished );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
Skip:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
#endif /* COMPUTE_INFLEXS */
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_done( PSH_Glyph glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = glyph->memory;
|
|
|
|
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_hint_table_done( &glyph->hint_tables[1], memory );
|
|
|
|
psh_hint_table_done( &glyph->hint_tables[0], memory );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
FT_FREE( glyph->points );
|
|
|
|
FT_FREE( glyph->contours );
|
|
|
|
|
|
|
|
glyph->num_points = 0;
|
|
|
|
glyph->num_contours = 0;
|
|
|
|
|
2015-04-14 04:40:17 +02:00
|
|
|
glyph->memory = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-04 04:48:23 +02:00
|
|
|
static PSH_Dir
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_compute_dir( FT_Pos dx,
|
|
|
|
FT_Pos dy )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2021-11-08 09:41:54 +01:00
|
|
|
FT_Pos ax, ay;
|
|
|
|
PSH_Dir result = PSH_DIR_NONE;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2013-01-09 06:25:32 +01:00
|
|
|
ax = FT_ABS( dx );
|
|
|
|
ay = FT_ABS( dy );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
if ( ay * 12 < ax )
|
|
|
|
{
|
|
|
|
/* |dy| <<< |dx| means a near-horizontal segment */
|
2003-05-29 00:42:41 +02:00
|
|
|
result = ( dx >= 0 ) ? PSH_DIR_RIGHT : PSH_DIR_LEFT;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
else if ( ax * 12 < ay )
|
|
|
|
{
|
|
|
|
/* |dx| <<< |dy| means a near-vertical segment */
|
2003-05-29 00:42:41 +02:00
|
|
|
result = ( dy >= 0 ) ? PSH_DIR_UP : PSH_DIR_DOWN;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
/* load outline point coordinates into hinter glyph */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_load_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
|
|
|
FT_Vector* vec = glyph->outline->points;
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point point = glyph->points;
|
2002-08-19 08:06:44 +02:00
|
|
|
FT_UInt count = glyph->num_points;
|
|
|
|
|
|
|
|
|
|
|
|
for ( ; count > 0; count--, point++, vec++ )
|
|
|
|
{
|
|
|
|
point->flags2 = 0;
|
|
|
|
point->hint = NULL;
|
|
|
|
if ( dimension == 0 )
|
|
|
|
{
|
|
|
|
point->org_u = vec->x;
|
|
|
|
point->org_v = vec->y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
point->org_u = vec->y;
|
|
|
|
point->org_v = vec->x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_HINTER
|
|
|
|
point->org_x = vec->x;
|
|
|
|
point->org_y = vec->y;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* save hinted point coordinates back to outline */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_save_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
|
|
|
FT_UInt n;
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point point = glyph->points;
|
2002-08-19 08:06:44 +02:00
|
|
|
FT_Vector* vec = glyph->outline->points;
|
|
|
|
char* tags = glyph->outline->tags;
|
|
|
|
|
|
|
|
|
|
|
|
for ( n = 0; n < glyph->num_points; n++ )
|
|
|
|
{
|
|
|
|
if ( dimension == 0 )
|
|
|
|
vec[n].x = point->cur_u;
|
|
|
|
else
|
|
|
|
vec[n].y = point->cur_u;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_point_is_strong( point ) )
|
2002-08-19 08:06:44 +02:00
|
|
|
tags[n] |= (char)( ( dimension == 0 ) ? 32 : 64 );
|
|
|
|
|
|
|
|
#ifdef DEBUG_HINTER
|
|
|
|
|
|
|
|
if ( dimension == 0 )
|
|
|
|
{
|
|
|
|
point->cur_x = point->cur_u;
|
|
|
|
point->flags_x = point->flags2 | point->flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
point->cur_y = point->cur_u;
|
|
|
|
point->flags_y = point->flags2 | point->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
point++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
static FT_Error
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_init( PSH_Glyph glyph,
|
|
|
|
FT_Outline* outline,
|
|
|
|
PS_Hints ps_hints,
|
|
|
|
PSH_Globals globals )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory;
|
|
|
|
|
|
|
|
|
|
|
|
/* clear all fields */
|
2016-09-28 19:06:21 +02:00
|
|
|
FT_ZERO( glyph );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-01-15 12:02:07 +01:00
|
|
|
memory = glyph->memory = globals->memory;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
/* allocate and setup points + contours arrays */
|
|
|
|
if ( FT_NEW_ARRAY( glyph->points, outline->n_points ) ||
|
|
|
|
FT_NEW_ARRAY( glyph->contours, outline->n_contours ) )
|
|
|
|
goto Exit;
|
|
|
|
|
2015-02-22 15:59:02 +01:00
|
|
|
glyph->num_points = (FT_UInt)outline->n_points;
|
|
|
|
glyph->num_contours = (FT_UInt)outline->n_contours;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_UInt first = 0, next, n;
|
|
|
|
PSH_Point points = glyph->points;
|
|
|
|
PSH_Contour contour = glyph->contours;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
for ( n = 0; n < glyph->num_contours; n++ )
|
|
|
|
{
|
2015-02-22 15:59:02 +01:00
|
|
|
FT_UInt count;
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point point;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2015-02-22 15:59:02 +01:00
|
|
|
next = (FT_UInt)outline->contours[n] + 1;
|
2002-07-03 23:00:26 +02:00
|
|
|
count = next - first;
|
|
|
|
|
|
|
|
contour->start = points + first;
|
2015-02-22 15:59:02 +01:00
|
|
|
contour->count = count;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
if ( count > 0 )
|
|
|
|
{
|
|
|
|
point = points + first;
|
|
|
|
|
|
|
|
point->prev = points + next - 1;
|
|
|
|
point->contour = contour;
|
|
|
|
|
|
|
|
for ( ; count > 1; count-- )
|
|
|
|
{
|
|
|
|
point[0].next = point + 1;
|
|
|
|
point[1].prev = point;
|
|
|
|
point++;
|
|
|
|
point->contour = contour;
|
|
|
|
}
|
|
|
|
point->next = points + first;
|
|
|
|
}
|
|
|
|
|
|
|
|
contour++;
|
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point points = glyph->points;
|
|
|
|
PSH_Point point = points;
|
2002-07-03 23:00:26 +02:00
|
|
|
FT_Vector* vec = outline->points;
|
|
|
|
FT_UInt n;
|
|
|
|
|
|
|
|
|
|
|
|
for ( n = 0; n < glyph->num_points; n++, point++ )
|
|
|
|
{
|
* include/freetype/internal/ftdriver.h,
include/freetype/internal/ftobjs.h,
include/freetype/internal/psaux.h, src/cid/cidgload.c,
src/psaux/psobjs.c, src/psaux/t1decode.c, src/psaux/psobjs.h,
src/pshinter/pshrec.c, src/pshinter/pshalgo.c,
src/psnames/psmodule.c, src/raster/ftraster.c, src/sfnt/sfobjs.c,
src/smooth/ftgrays.c, src/smooth/ftsmooth.c, src/truetype/ttobjs.c,
src/truetype/ttdriver.c, src/truetype/ttgload.c, src/type1/t1afm.c,
src/type1/t1gload.c, src/type1/t1gload.h, src/type1/t1load.c,
src/type1/t1objs.c, src/type42/t42parse.c, src/type42/t42parse.h:
Many casts and slight argument type changes to make it work with
a 16bit compiler.
2003-06-05 06:31:05 +02:00
|
|
|
FT_Int n_prev = (FT_Int)( point->prev - points );
|
|
|
|
FT_Int n_next = (FT_Int)( point->next - points );
|
2002-07-03 23:00:26 +02:00
|
|
|
FT_Pos dxi, dyi, dxo, dyo;
|
|
|
|
|
|
|
|
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
if ( !( outline->tags[n] & FT_CURVE_TAG_ON ) )
|
2003-05-29 00:42:41 +02:00
|
|
|
point->flags = PSH_POINT_OFF;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
dxi = vec[n].x - vec[n_prev].x;
|
|
|
|
dyi = vec[n].y - vec[n_prev].y;
|
|
|
|
|
2021-10-04 04:48:23 +02:00
|
|
|
point->dir_in = psh_compute_dir( dxi, dyi );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
dxo = vec[n_next].x - vec[n].x;
|
|
|
|
dyo = vec[n_next].y - vec[n].y;
|
|
|
|
|
2021-10-04 04:48:23 +02:00
|
|
|
point->dir_out = psh_compute_dir( dxo, dyo );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
/* detect smooth points */
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( point->flags & PSH_POINT_OFF )
|
|
|
|
point->flags |= PSH_POINT_SMOOTH;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
else if ( point->dir_in == point->dir_out )
|
|
|
|
{
|
2006-10-24 07:28:45 +02:00
|
|
|
if ( point->dir_out != PSH_DIR_NONE ||
|
2006-10-23 10:56:57 +02:00
|
|
|
psh_corner_is_flat( dxi, dyi, dxo, dyo ) )
|
2003-05-29 00:42:41 +02:00
|
|
|
point->flags |= PSH_POINT_SMOOTH;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glyph->outline = outline;
|
|
|
|
glyph->globals = globals;
|
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
#ifdef COMPUTE_INFLEXS
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_load_points( glyph, 0 );
|
|
|
|
psh_glyph_compute_inflections( glyph );
|
2002-08-19 08:06:44 +02:00
|
|
|
#endif /* COMPUTE_INFLEXS */
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
/* now deal with hints tables */
|
2003-05-29 00:42:41 +02:00
|
|
|
error = psh_hint_table_init( &glyph->hint_tables [0],
|
|
|
|
&ps_hints->dimension[0].hints,
|
|
|
|
&ps_hints->dimension[0].masks,
|
|
|
|
&ps_hints->dimension[0].counters,
|
|
|
|
memory );
|
2002-07-03 23:00:26 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
error = psh_hint_table_init( &glyph->hint_tables [1],
|
|
|
|
&ps_hints->dimension[1].hints,
|
|
|
|
&ps_hints->dimension[1].masks,
|
|
|
|
&ps_hints->dimension[1].counters,
|
|
|
|
memory );
|
2002-07-03 23:00:26 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
/* compute all extrema in a glyph for a given dimension */
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_compute_extrema( PSH_Glyph glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2002-08-22 08:04:32 +02:00
|
|
|
FT_UInt n;
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
/* first of all, compute all local extrema */
|
|
|
|
for ( n = 0; n < glyph->num_contours; n++ )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point first = glyph->contours[n].start;
|
|
|
|
PSH_Point point, before, after;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2003-05-28 07:52:05 +02:00
|
|
|
if ( glyph->contours[n].count == 0 )
|
|
|
|
continue;
|
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
point = first;
|
|
|
|
before = point;
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
before = before->prev;
|
|
|
|
if ( before == first )
|
|
|
|
goto Skip;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
} while ( before->org_u == point->org_u );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
first = point = before->next;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
after = point;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
after = after->next;
|
|
|
|
if ( after == first )
|
|
|
|
goto Next;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
} while ( after->org_u == point->org_u );
|
2002-08-19 08:06:44 +02:00
|
|
|
|
|
|
|
if ( before->org_u < point->org_u )
|
|
|
|
{
|
|
|
|
if ( after->org_u < point->org_u )
|
|
|
|
{
|
|
|
|
/* local maximum */
|
|
|
|
goto Extremum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* before->org_u > point->org_u */
|
|
|
|
{
|
|
|
|
if ( after->org_u > point->org_u )
|
|
|
|
{
|
|
|
|
/* local minimum */
|
|
|
|
Extremum:
|
|
|
|
do
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_point_set_extremum( point );
|
2002-08-19 08:06:44 +02:00
|
|
|
point = point->next;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
} while ( point != after );
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
before = after->prev;
|
|
|
|
point = after;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
} /* for */
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
Next:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2004-02-27 21:32:39 +01:00
|
|
|
/* for each extremum, determine its direction along the */
|
|
|
|
/* orthogonal axis */
|
2002-07-03 23:00:26 +02:00
|
|
|
for ( n = 0; n < glyph->num_points; n++ )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point point, before, after;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-22 00:06:41 +02:00
|
|
|
point = &glyph->points[n];
|
|
|
|
before = point;
|
|
|
|
after = point;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_point_is_extremum( point ) )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
before = before->prev;
|
|
|
|
if ( before == point )
|
|
|
|
goto Skip;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
} while ( before->org_v == point->org_v );
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
after = after->next;
|
|
|
|
if ( after == point )
|
|
|
|
goto Skip;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
} while ( after->org_v == point->org_v );
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( before->org_v < point->org_v &&
|
|
|
|
after->org_v > point->org_v )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_point_set_positive( point );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2002-08-19 08:06:44 +02:00
|
|
|
else if ( before->org_v > point->org_v &&
|
|
|
|
after->org_v < point->org_v )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_point_set_negative( point );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
Skip:
|
|
|
|
;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-04 04:48:23 +02:00
|
|
|
/* the min and max are based on contour orientation and fill rule */
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2006-10-23 10:56:57 +02:00
|
|
|
psh_hint_table_find_strong_points( PSH_Hint_Table table,
|
|
|
|
PSH_Point point,
|
|
|
|
FT_UInt count,
|
|
|
|
FT_Int threshold,
|
2021-10-04 04:48:23 +02:00
|
|
|
PSH_Dir major_dir )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Hint* sort = table->sort;
|
|
|
|
FT_UInt num_hints = table->num_hints;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( ; count > 0; count--, point++ )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
2021-10-05 05:10:59 +02:00
|
|
|
PSH_Dir point_dir;
|
|
|
|
FT_Pos org_u = point->org_u;
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( psh_point_is_strong( point ) )
|
|
|
|
continue;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2021-11-08 09:41:54 +01:00
|
|
|
point_dir =
|
|
|
|
(PSH_Dir)( ( point->dir_in | point->dir_out ) & major_dir );
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2021-10-04 04:48:23 +02:00
|
|
|
if ( point_dir & ( PSH_DIR_DOWN | PSH_DIR_RIGHT ) )
|
2006-10-23 10:56:57 +02:00
|
|
|
{
|
2021-10-04 04:45:42 +02:00
|
|
|
FT_UInt nn;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2021-10-04 04:45:42 +02:00
|
|
|
for ( nn = 0; nn < num_hints; nn++ )
|
|
|
|
{
|
|
|
|
PSH_Hint hint = sort[nn];
|
|
|
|
FT_Pos d = org_u - hint->org_pos;
|
2006-10-23 10:56:57 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2021-10-04 04:45:42 +02:00
|
|
|
if ( d < threshold && -d < threshold )
|
|
|
|
{
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
point->flags2 |= PSH_POINT_EDGE_MIN;
|
|
|
|
point->hint = hint;
|
|
|
|
break;
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-04 04:45:42 +02:00
|
|
|
}
|
2021-10-04 04:48:23 +02:00
|
|
|
else if ( point_dir & ( PSH_DIR_UP | PSH_DIR_LEFT ) )
|
2021-10-04 04:45:42 +02:00
|
|
|
{
|
|
|
|
FT_UInt nn;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2021-10-04 04:45:42 +02:00
|
|
|
for ( nn = 0; nn < num_hints; nn++ )
|
|
|
|
{
|
|
|
|
PSH_Hint hint = sort[nn];
|
|
|
|
FT_Pos d = org_u - hint->org_pos - hint->org_len;
|
2006-10-23 10:56:57 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2021-10-04 04:45:42 +02:00
|
|
|
if ( d < threshold && -d < threshold )
|
|
|
|
{
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
point->flags2 |= PSH_POINT_EDGE_MAX;
|
|
|
|
point->hint = hint;
|
|
|
|
break;
|
2006-10-23 10:56:57 +02:00
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#if 1
|
2006-10-23 10:56:57 +02:00
|
|
|
else if ( psh_point_is_extremum( point ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
/* treat extrema as special cases for stem edge alignment */
|
|
|
|
FT_UInt nn, min_flag, max_flag;
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( major_dir == PSH_DIR_HORIZONTAL )
|
|
|
|
{
|
|
|
|
min_flag = PSH_POINT_POSITIVE;
|
|
|
|
max_flag = PSH_POINT_NEGATIVE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_flag = PSH_POINT_NEGATIVE;
|
|
|
|
max_flag = PSH_POINT_POSITIVE;
|
|
|
|
}
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2002-08-19 08:06:44 +02:00
|
|
|
if ( point->flags2 & min_flag )
|
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( nn = 0; nn < num_hints; nn++ )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
PSH_Hint hint = sort[nn];
|
|
|
|
FT_Pos d = org_u - hint->org_pos;
|
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( d < threshold && -d < threshold )
|
|
|
|
{
|
|
|
|
point->flags2 |= PSH_POINT_EDGE_MIN;
|
|
|
|
point->hint = hint;
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
break;
|
|
|
|
}
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( point->flags2 & max_flag )
|
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( nn = 0; nn < num_hints; nn++ )
|
|
|
|
{
|
|
|
|
PSH_Hint hint = sort[nn];
|
|
|
|
FT_Pos d = org_u - hint->org_pos - hint->org_len;
|
2002-08-22 08:04:32 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( d < threshold && -d < threshold )
|
|
|
|
{
|
|
|
|
point->flags2 |= PSH_POINT_EDGE_MAX;
|
|
|
|
point->hint = hint;
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !point->hint )
|
2002-08-19 08:06:44 +02:00
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( nn = 0; nn < num_hints; nn++ )
|
|
|
|
{
|
|
|
|
PSH_Hint hint = sort[nn];
|
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2018-08-29 15:28:21 +02:00
|
|
|
if ( org_u >= hint->org_pos &&
|
|
|
|
org_u <= ADD_INT( hint->org_pos, hint->org_len ) )
|
2006-10-23 10:56:57 +02:00
|
|
|
{
|
|
|
|
point->hint = hint;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-08-19 08:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
2002-08-22 08:04:32 +02:00
|
|
|
|
|
|
|
#endif /* 1 */
|
2006-10-23 10:56:57 +02:00
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
/* the accepted shift for strong points in fractional pixels */
|
2004-03-02 08:01:20 +01:00
|
|
|
#define PSH_STRONG_THRESHOLD 32
|
|
|
|
|
|
|
|
/* the maximum shift value in font units */
|
|
|
|
#define PSH_STRONG_THRESHOLD_MAXIMUM 30
|
2004-02-23 19:22:32 +01:00
|
|
|
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
/* find strong points in a glyph */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_find_strong_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2004-03-02 08:01:20 +01:00
|
|
|
/* a point is `strong' if it is located on a stem edge and */
|
|
|
|
/* has an `in' or `out' tangent parallel to the hint's direction */
|
2004-02-23 19:22:32 +01:00
|
|
|
|
|
|
|
PSH_Hint_Table table = &glyph->hint_tables[dimension];
|
|
|
|
PS_Mask mask = table->hint_masks->masks;
|
|
|
|
FT_UInt num_masks = table->hint_masks->num_masks;
|
|
|
|
FT_UInt first = 0;
|
2021-10-04 04:48:23 +02:00
|
|
|
PSH_Dir major_dir = ( dimension == 0 ) ? PSH_DIR_VERTICAL
|
2016-12-25 22:55:25 +01:00
|
|
|
: PSH_DIR_HORIZONTAL;
|
2004-02-23 19:22:32 +01:00
|
|
|
PSH_Dimension dim = &glyph->globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Int threshold;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
threshold = (FT_Int)FT_DivFix( PSH_STRONG_THRESHOLD, scale );
|
2004-03-02 08:01:20 +01:00
|
|
|
if ( threshold > PSH_STRONG_THRESHOLD_MAXIMUM )
|
|
|
|
threshold = PSH_STRONG_THRESHOLD_MAXIMUM;
|
2004-02-23 19:22:32 +01:00
|
|
|
|
2004-03-02 08:01:20 +01:00
|
|
|
/* process secondary hints to `selected' points */
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( num_masks > 1 && glyph->num_points > 0 )
|
|
|
|
{
|
2010-06-12 01:32:20 +02:00
|
|
|
/* the `endchar' op can reduce the number of points */
|
|
|
|
first = mask->end_point > glyph->num_points
|
|
|
|
? glyph->num_points
|
|
|
|
: mask->end_point;
|
2004-02-23 19:22:32 +01:00
|
|
|
mask++;
|
|
|
|
for ( ; num_masks > 1; num_masks--, mask++ )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2015-02-22 20:41:03 +01:00
|
|
|
FT_UInt next = FT_MIN( mask->end_point, glyph->num_points );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2015-02-22 20:41:03 +01:00
|
|
|
if ( next > first )
|
2004-02-23 19:22:32 +01:00
|
|
|
{
|
2015-02-22 20:41:03 +01:00
|
|
|
FT_UInt count = next - first;
|
2004-02-23 19:22:32 +01:00
|
|
|
PSH_Point point = glyph->points + first;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
psh_hint_table_activate_mask( table, mask );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
psh_hint_table_find_strong_points( table, point, count,
|
|
|
|
threshold, major_dir );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2004-02-23 19:22:32 +01:00
|
|
|
first = next;
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2004-02-23 19:22:32 +01:00
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
/* process primary hints for all points */
|
|
|
|
if ( num_masks == 1 )
|
|
|
|
{
|
|
|
|
FT_UInt count = glyph->num_points;
|
|
|
|
PSH_Point point = glyph->points;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
psh_hint_table_activate_mask( table, table->hint_masks->masks );
|
2006-10-23 10:56:57 +02:00
|
|
|
|
|
|
|
psh_hint_table_find_strong_points( table, point, count,
|
|
|
|
threshold, major_dir );
|
2004-02-23 19:22:32 +01:00
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-27 21:32:39 +01:00
|
|
|
/* now, certain points may have been attached to a hint and */
|
|
|
|
/* not marked as strong; update their flags then */
|
2004-02-23 19:22:32 +01:00
|
|
|
{
|
|
|
|
FT_UInt count = glyph->num_points;
|
|
|
|
PSH_Point point = glyph->points;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
for ( ; count > 0; count--, point++ )
|
|
|
|
if ( point->hint && !psh_point_is_strong( point ) )
|
|
|
|
psh_point_set_strong( point );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-02 08:01:20 +01:00
|
|
|
/* find points in a glyph which are in a blue zone and have `in' or */
|
|
|
|
/* `out' tangents parallel to the horizontal axis */
|
|
|
|
static void
|
|
|
|
psh_glyph_find_blue_points( PSH_Blues blues,
|
|
|
|
PSH_Glyph glyph )
|
|
|
|
{
|
|
|
|
PSH_Blue_Table table;
|
|
|
|
PSH_Blue_Zone zone;
|
|
|
|
FT_UInt glyph_count = glyph->num_points;
|
|
|
|
FT_UInt blue_count;
|
|
|
|
PSH_Point point = glyph->points;
|
|
|
|
|
|
|
|
|
|
|
|
for ( ; glyph_count > 0; glyph_count--, point++ )
|
|
|
|
{
|
|
|
|
FT_Pos y;
|
|
|
|
|
|
|
|
|
|
|
|
/* check tangents */
|
2021-10-04 04:48:23 +02:00
|
|
|
if ( !( point->dir_in & PSH_DIR_HORIZONTAL ) &&
|
|
|
|
!( point->dir_out & PSH_DIR_HORIZONTAL ) )
|
2004-03-02 08:01:20 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* skip strong points */
|
|
|
|
if ( psh_point_is_strong( point ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
y = point->org_u;
|
|
|
|
|
|
|
|
/* look up top zones */
|
|
|
|
table = &blues->normal_top;
|
|
|
|
blue_count = table->count;
|
|
|
|
zone = table->zones;
|
|
|
|
|
|
|
|
for ( ; blue_count > 0; blue_count--, zone++ )
|
|
|
|
{
|
|
|
|
FT_Pos delta = y - zone->org_bottom;
|
|
|
|
|
|
|
|
|
|
|
|
if ( delta < -blues->blue_fuzz )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( y <= zone->org_top + blues->blue_fuzz )
|
|
|
|
if ( blues->no_overshoots || delta <= blues->blue_threshold )
|
|
|
|
{
|
|
|
|
point->cur_u = zone->cur_bottom;
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
psh_point_set_fitted( point );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look up bottom zones */
|
|
|
|
table = &blues->normal_bottom;
|
|
|
|
blue_count = table->count;
|
|
|
|
zone = table->zones + blue_count - 1;
|
|
|
|
|
|
|
|
for ( ; blue_count > 0; blue_count--, zone-- )
|
|
|
|
{
|
|
|
|
FT_Pos delta = zone->org_top - y;
|
|
|
|
|
|
|
|
|
|
|
|
if ( delta < -blues->blue_fuzz )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( y >= zone->org_bottom - blues->blue_fuzz )
|
|
|
|
if ( blues->no_overshoots || delta < blues->blue_threshold )
|
|
|
|
{
|
|
|
|
point->cur_u = zone->cur_top;
|
|
|
|
psh_point_set_strong( point );
|
|
|
|
psh_point_set_fitted( point );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
/* interpolate strong points with the help of hinted coordinates */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_interpolate_strong_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2002-07-26 16:52:29 +02:00
|
|
|
PSH_Dimension dim = &glyph->globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
FT_UInt count = glyph->num_points;
|
|
|
|
PSH_Point point = glyph->points;
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
for ( ; count > 0; count--, point++ )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2004-02-23 19:22:32 +01:00
|
|
|
PSH_Hint hint = point->hint;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( hint )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2004-02-23 19:22:32 +01:00
|
|
|
FT_Pos delta;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( psh_point_is_edge_min( point ) )
|
|
|
|
point->cur_u = hint->cur_pos;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
else if ( psh_point_is_edge_max( point ) )
|
|
|
|
point->cur_u = hint->cur_pos + hint->cur_len;
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delta = point->org_u - hint->org_pos;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( delta <= 0 )
|
|
|
|
point->cur_u = hint->cur_pos + FT_MulFix( delta, scale );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
else if ( delta >= hint->org_len )
|
|
|
|
point->cur_u = hint->cur_pos + hint->cur_len +
|
|
|
|
FT_MulFix( delta - hint->org_len, scale );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2010-09-13 07:32:22 +02:00
|
|
|
else /* hint->org_len > 0 */
|
2004-02-23 19:22:32 +01:00
|
|
|
point->cur_u = hint->cur_pos +
|
|
|
|
FT_MulDiv( delta, hint->cur_len,
|
|
|
|
hint->org_len );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2004-02-23 19:22:32 +01:00
|
|
|
psh_point_set_fitted( point );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
#define PSH_MAX_STRONG_INTERNAL 16
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_interpolate_normal_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#if 1
|
2004-02-27 21:32:39 +01:00
|
|
|
/* first technique: a point is strong if it is a local extremum */
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
PSH_Dimension dim = &glyph->globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Memory memory = glyph->memory;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
PSH_Point* strongs = NULL;
|
2006-10-24 07:28:45 +02:00
|
|
|
PSH_Point strongs_0[PSH_MAX_STRONG_INTERNAL];
|
2006-10-23 10:56:57 +02:00
|
|
|
FT_UInt num_strongs = 0;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
PSH_Point points = glyph->points;
|
|
|
|
PSH_Point points_end = points + glyph->num_points;
|
|
|
|
PSH_Point point;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
/* first count the number of strong points */
|
|
|
|
for ( point = points; point < points_end; point++ )
|
|
|
|
{
|
|
|
|
if ( psh_point_is_strong( point ) )
|
|
|
|
num_strongs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( num_strongs == 0 ) /* nothing to do here */
|
|
|
|
return;
|
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
/* allocate an array to store a list of points, */
|
|
|
|
/* stored in increasing org_u order */
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( num_strongs <= PSH_MAX_STRONG_INTERNAL )
|
|
|
|
strongs = strongs_0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2007-01-04 17:46:46 +01:00
|
|
|
if ( FT_NEW_ARRAY( strongs, num_strongs ) )
|
2006-10-23 10:56:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_strongs = 0;
|
|
|
|
for ( point = points; point < points_end; point++ )
|
|
|
|
{
|
2006-10-24 07:28:45 +02:00
|
|
|
PSH_Point* insert;
|
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
|
|
|
|
if ( !psh_point_is_strong( point ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for ( insert = strongs + num_strongs; insert > strongs; insert-- )
|
|
|
|
{
|
|
|
|
if ( insert[-1]->org_u <= point->org_u )
|
|
|
|
break;
|
|
|
|
|
|
|
|
insert[0] = insert[-1];
|
|
|
|
}
|
|
|
|
insert[0] = point;
|
|
|
|
num_strongs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now try to interpolate all normal points */
|
|
|
|
for ( point = points; point < points_end; point++ )
|
2004-02-23 19:22:32 +01:00
|
|
|
{
|
|
|
|
if ( psh_point_is_strong( point ) )
|
|
|
|
continue;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-27 21:32:39 +01:00
|
|
|
/* sometimes, some local extrema are smooth points */
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( psh_point_is_smooth( point ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( point->dir_in == PSH_DIR_NONE ||
|
|
|
|
point->dir_in != point->dir_out )
|
2002-07-03 23:00:26 +02:00
|
|
|
continue;
|
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
if ( !psh_point_is_extremum( point ) &&
|
|
|
|
!psh_point_is_inflex( point ) )
|
|
|
|
continue;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2004-02-23 19:22:32 +01:00
|
|
|
point->flags &= ~PSH_POINT_SMOOTH;
|
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
/* find best enclosing point coordinates then interpolate */
|
2004-02-23 19:22:32 +01:00
|
|
|
{
|
2006-10-23 10:56:57 +02:00
|
|
|
PSH_Point before, after;
|
|
|
|
FT_UInt nn;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( nn = 0; nn < num_strongs; nn++ )
|
|
|
|
if ( strongs[nn]->org_u > point->org_u )
|
|
|
|
break;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( nn == 0 ) /* point before the first strong point */
|
|
|
|
{
|
|
|
|
after = strongs[0];
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
point->cur_u = after->cur_u +
|
2006-10-24 07:28:45 +02:00
|
|
|
FT_MulFix( point->org_u - after->org_u,
|
|
|
|
scale );
|
2006-10-23 10:56:57 +02:00
|
|
|
}
|
|
|
|
else
|
2004-02-23 19:22:32 +01:00
|
|
|
{
|
2006-10-24 07:28:45 +02:00
|
|
|
before = strongs[nn - 1];
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
for ( nn = num_strongs; nn > 0; nn-- )
|
2006-10-24 07:28:45 +02:00
|
|
|
if ( strongs[nn - 1]->org_u < point->org_u )
|
2006-10-23 10:56:57 +02:00
|
|
|
break;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( nn == num_strongs ) /* point is after last strong point */
|
|
|
|
{
|
2006-10-24 07:28:45 +02:00
|
|
|
before = strongs[nn - 1];
|
2004-02-23 19:22:32 +01:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
point->cur_u = before->cur_u +
|
2006-10-24 07:28:45 +02:00
|
|
|
FT_MulFix( point->org_u - before->org_u,
|
|
|
|
scale );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
2006-10-23 10:56:57 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FT_Pos u;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
after = strongs[nn];
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
/* now interpolate point between before and after */
|
|
|
|
u = point->org_u;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( u == before->org_u )
|
|
|
|
point->cur_u = before->cur_u;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
else if ( u == after->org_u )
|
|
|
|
point->cur_u = after->cur_u;
|
2004-02-23 19:22:32 +01:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
else
|
|
|
|
point->cur_u = before->cur_u +
|
2006-10-24 07:28:45 +02:00
|
|
|
FT_MulDiv( u - before->org_u,
|
|
|
|
after->cur_u - before->cur_u,
|
|
|
|
after->org_u - before->org_u );
|
2006-10-23 10:56:57 +02:00
|
|
|
}
|
|
|
|
}
|
2004-02-23 19:22:32 +01:00
|
|
|
psh_point_set_fitted( point );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
}
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2006-10-23 10:56:57 +02:00
|
|
|
if ( strongs != strongs_0 )
|
|
|
|
FT_FREE( strongs );
|
2006-10-24 07:28:45 +02:00
|
|
|
|
2002-07-26 16:52:29 +02:00
|
|
|
#endif /* 1 */
|
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* interpolate other points */
|
|
|
|
static void
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_interpolate_other_points( PSH_Glyph glyph,
|
|
|
|
FT_Int dimension )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2002-07-26 16:52:29 +02:00
|
|
|
PSH_Dimension dim = &glyph->globals->dimension[dimension];
|
|
|
|
FT_Fixed scale = dim->scale_mult;
|
|
|
|
FT_Fixed delta = dim->scale_delta;
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Contour contour = glyph->contours;
|
2002-07-26 16:52:29 +02:00
|
|
|
FT_UInt num_contours = glyph->num_contours;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
for ( ; num_contours > 0; num_contours--, contour++ )
|
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_Point start = contour->start;
|
|
|
|
PSH_Point first, next, point;
|
|
|
|
FT_UInt fit_count;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* count the number of strong points in this contour */
|
|
|
|
next = start + contour->count;
|
|
|
|
fit_count = 0;
|
2015-04-14 04:40:17 +02:00
|
|
|
first = NULL;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
for ( point = start; point < next; point++ )
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_point_is_fitted( point ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
|
|
|
if ( !first )
|
|
|
|
first = point;
|
|
|
|
|
|
|
|
fit_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there are less than 2 fitted points in the contour, we */
|
|
|
|
/* simply scale and eventually translate the contour points */
|
|
|
|
if ( fit_count < 2 )
|
|
|
|
{
|
|
|
|
if ( fit_count == 1 )
|
|
|
|
delta = first->cur_u - FT_MulFix( first->org_u, scale );
|
|
|
|
|
|
|
|
for ( point = start; point < next; point++ )
|
|
|
|
if ( point != first )
|
|
|
|
point->cur_u = FT_MulFix( point->org_u, scale ) + delta;
|
|
|
|
|
|
|
|
goto Next_Contour;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there are more than 2 strong points in this contour; we */
|
|
|
|
/* need to interpolate weak points between them */
|
|
|
|
start = first;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* skip consecutive fitted points */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
next = first->next;
|
|
|
|
if ( next == start )
|
|
|
|
goto Next_Contour;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( !psh_point_is_fitted( next ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find next fitted point after unfitted one */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
next = next->next;
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( psh_point_is_fitted( next ) )
|
2002-07-03 23:00:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now interpolate between them */
|
|
|
|
{
|
|
|
|
FT_Pos org_a, org_ab, cur_a, cur_ab;
|
|
|
|
FT_Pos org_c, org_ac, cur_c;
|
|
|
|
FT_Fixed scale_ab;
|
|
|
|
|
|
|
|
|
|
|
|
if ( first->org_u <= next->org_u )
|
|
|
|
{
|
|
|
|
org_a = first->org_u;
|
|
|
|
cur_a = first->cur_u;
|
|
|
|
org_ab = next->org_u - org_a;
|
|
|
|
cur_ab = next->cur_u - cur_a;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
org_a = next->org_u;
|
|
|
|
cur_a = next->cur_u;
|
|
|
|
org_ab = first->org_u - org_a;
|
|
|
|
cur_ab = first->cur_u - cur_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
scale_ab = 0x10000L;
|
|
|
|
if ( org_ab > 0 )
|
|
|
|
scale_ab = FT_DivFix( cur_ab, org_ab );
|
|
|
|
|
|
|
|
point = first->next;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
org_c = point->org_u;
|
|
|
|
org_ac = org_c - org_a;
|
|
|
|
|
|
|
|
if ( org_ac <= 0 )
|
|
|
|
{
|
|
|
|
/* on the left of the interpolation zone */
|
|
|
|
cur_c = cur_a + FT_MulFix( org_ac, scale );
|
|
|
|
}
|
|
|
|
else if ( org_ac >= org_ab )
|
|
|
|
{
|
|
|
|
/* on the right on the interpolation zone */
|
|
|
|
cur_c = cur_a + cur_ab + FT_MulFix( org_ac - org_ab, scale );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* within the interpolation zone */
|
|
|
|
cur_c = cur_a + FT_MulFix( org_ac, scale_ab );
|
|
|
|
}
|
|
|
|
|
|
|
|
point->cur_u = cur_c;
|
|
|
|
|
|
|
|
point = point->next;
|
|
|
|
|
|
|
|
} while ( point != next );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keep going until all points in the contours have been processed */
|
|
|
|
first = next;
|
|
|
|
|
|
|
|
} while ( first != start );
|
|
|
|
|
|
|
|
Next_Contour:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** HIGH-LEVEL INTERFACE *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
FT_Error
|
2003-05-29 00:42:41 +02:00
|
|
|
ps_hints_apply( PS_Hints ps_hints,
|
|
|
|
FT_Outline* outline,
|
|
|
|
PSH_Globals globals,
|
|
|
|
FT_Render_Mode hint_mode )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
PSH_GlyphRec glyphrec;
|
|
|
|
PSH_Glyph glyph = &glyphrec;
|
|
|
|
FT_Error error;
|
2002-07-03 23:00:26 +02:00
|
|
|
#ifdef DEBUG_HINTER
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_Memory memory;
|
2002-07-03 23:00:26 +02:00
|
|
|
#endif
|
2003-05-29 00:42:41 +02:00
|
|
|
FT_Int dimension;
|
2002-07-03 23:00:26 +02:00
|
|
|
|
|
|
|
|
2003-05-21 00:06:38 +02:00
|
|
|
/* something to do? */
|
|
|
|
if ( outline->n_points == 0 || outline->n_contours == 0 )
|
2013-03-14 11:21:17 +01:00
|
|
|
return FT_Err_Ok;
|
2003-05-21 00:06:38 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#ifdef DEBUG_HINTER
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
memory = globals->memory;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
if ( ps_debug_glyph )
|
2002-07-03 23:00:26 +02:00
|
|
|
{
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_done( ps_debug_glyph );
|
|
|
|
FT_FREE( ps_debug_glyph );
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( FT_NEW( glyph ) )
|
|
|
|
return error;
|
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
ps_debug_glyph = glyph;
|
2002-07-26 16:52:29 +02:00
|
|
|
|
|
|
|
#endif /* DEBUG_HINTER */
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2003-05-29 00:42:41 +02:00
|
|
|
error = psh_glyph_init( glyph, outline, ps_hints, globals );
|
2002-07-03 23:00:26 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
2003-05-20 07:01:49 +02:00
|
|
|
/* try to optimize the y_scale so that the top of non-capital letters
|
|
|
|
* is aligned on a pixel boundary whenever possible
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
PSH_Dimension dim_x = &glyph->globals->dimension[0];
|
|
|
|
PSH_Dimension dim_y = &glyph->globals->dimension[1];
|
|
|
|
|
2007-03-06 12:59:24 +01:00
|
|
|
FT_Fixed x_scale = dim_x->scale_mult;
|
|
|
|
FT_Fixed y_scale = dim_y->scale_mult;
|
2003-05-20 07:01:49 +02:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
FT_Fixed old_x_scale = x_scale;
|
|
|
|
FT_Fixed old_y_scale = y_scale;
|
|
|
|
|
2007-03-06 12:59:24 +01:00
|
|
|
FT_Fixed scaled;
|
|
|
|
FT_Fixed fitted;
|
2003-05-20 07:01:49 +02:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
FT_Bool rescale = FALSE;
|
|
|
|
|
2003-05-20 07:01:49 +02:00
|
|
|
|
|
|
|
scaled = FT_MulFix( globals->blues.normal_top.zones->org_ref, y_scale );
|
2003-12-24 02:10:46 +01:00
|
|
|
fitted = FT_PIX_ROUND( scaled );
|
2003-05-20 07:01:49 +02:00
|
|
|
|
2005-04-09 11:50:39 +02:00
|
|
|
if ( fitted != 0 && scaled != fitted )
|
|
|
|
{
|
2008-05-18 23:49:02 +02:00
|
|
|
rescale = TRUE;
|
|
|
|
|
2003-05-20 07:01:49 +02:00
|
|
|
y_scale = FT_MulDiv( y_scale, fitted, scaled );
|
|
|
|
|
|
|
|
if ( fitted < scaled )
|
|
|
|
x_scale -= x_scale / 50;
|
|
|
|
|
|
|
|
psh_globals_set_scale( glyph->globals, x_scale, y_scale, 0, 0 );
|
|
|
|
}
|
2002-09-08 23:29:11 +02:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
glyph->do_horz_hints = 1;
|
|
|
|
glyph->do_vert_hints = 1;
|
2002-09-08 23:29:11 +02:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
glyph->do_horz_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO ||
|
|
|
|
hint_mode == FT_RENDER_MODE_LCD );
|
2003-01-08 10:52:32 +01:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
glyph->do_vert_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO ||
|
|
|
|
hint_mode == FT_RENDER_MODE_LCD_V );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2017-05-02 12:32:19 +02:00
|
|
|
glyph->do_stem_adjust = FT_BOOL( hint_mode != FT_RENDER_MODE_LIGHT );
|
2002-07-03 23:00:26 +02:00
|
|
|
|
2008-05-18 23:49:02 +02:00
|
|
|
for ( dimension = 0; dimension < 2; dimension++ )
|
|
|
|
{
|
|
|
|
/* load outline coordinates into glyph */
|
|
|
|
psh_glyph_load_points( glyph, dimension );
|
|
|
|
|
|
|
|
/* compute local extrema */
|
|
|
|
psh_glyph_compute_extrema( glyph );
|
|
|
|
|
|
|
|
/* compute aligned stem/hints positions */
|
|
|
|
psh_hint_table_align_hints( &glyph->hint_tables[dimension],
|
|
|
|
glyph->globals,
|
|
|
|
dimension,
|
|
|
|
glyph );
|
|
|
|
|
|
|
|
/* find strong points, align them, then interpolate others */
|
|
|
|
psh_glyph_find_strong_points( glyph, dimension );
|
|
|
|
if ( dimension == 1 )
|
|
|
|
psh_glyph_find_blue_points( &globals->blues, glyph );
|
|
|
|
psh_glyph_interpolate_strong_points( glyph, dimension );
|
|
|
|
psh_glyph_interpolate_normal_points( glyph, dimension );
|
|
|
|
psh_glyph_interpolate_other_points( glyph, dimension );
|
|
|
|
|
|
|
|
/* save hinted coordinates back to outline */
|
|
|
|
psh_glyph_save_points( glyph, dimension );
|
|
|
|
|
|
|
|
if ( rescale )
|
|
|
|
psh_globals_set_scale( glyph->globals,
|
|
|
|
old_x_scale, old_y_scale, 0, 0 );
|
|
|
|
}
|
2002-07-03 23:00:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
#ifndef DEBUG_HINTER
|
2003-05-29 00:42:41 +02:00
|
|
|
psh_glyph_done( glyph );
|
2002-07-03 23:00:26 +02:00
|
|
|
#endif
|
2002-07-26 16:52:29 +02:00
|
|
|
|
2002-07-03 23:00:26 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|