2005-03-03 18:09:08 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* afloader.c */
|
|
|
|
/* */
|
|
|
|
/* Auto-fitter glyph loading routines (body). */
|
|
|
|
/* */
|
2013-03-14 10:27:35 +01:00
|
|
|
/* Copyright 2003-2009, 2011-2013 by */
|
2005-03-03 18:09:08 +01: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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2012-10-20 08:34:57 +02:00
|
|
|
#include "afglobal.h"
|
2004-03-27 09:43:17 +01:00
|
|
|
#include "afloader.h"
|
|
|
|
#include "afhints.h"
|
2005-03-23 17:45:24 +01:00
|
|
|
#include "aferrors.h"
|
2012-09-14 12:26:57 +02:00
|
|
|
#include "afmodule.h"
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* Initialize glyph loader. */
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
2012-09-14 12:26:57 +02:00
|
|
|
af_loader_init( AF_Module module )
|
2004-03-27 09:43:17 +01:00
|
|
|
{
|
2012-09-14 12:26:57 +02:00
|
|
|
AF_Loader loader = module->loader;
|
|
|
|
FT_Memory memory = module->root.library->memory;
|
|
|
|
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_ZERO( loader );
|
|
|
|
|
|
|
|
af_glyph_hints_init( &loader->hints, memory );
|
2011-04-18 19:05:28 +02:00
|
|
|
#ifdef FT_DEBUG_AUTOFIT
|
2006-11-02 17:37:35 +01:00
|
|
|
_af_debug_hints = &loader->hints;
|
|
|
|
#endif
|
2006-04-13 09:51:58 +02:00
|
|
|
return FT_GlyphLoader_New( memory, &loader->gloader );
|
2004-03-27 09:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* Reset glyph loader and compute globals if necessary. */
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
2012-09-14 12:26:57 +02:00
|
|
|
af_loader_reset( AF_Module module,
|
2005-03-02 12:24:23 +01:00
|
|
|
FT_Face face )
|
2004-03-27 09:43:17 +01:00
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2012-09-14 12:26:57 +02:00
|
|
|
AF_Loader loader = module->loader;
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
loader->face = face;
|
2005-03-02 12:24:23 +01:00
|
|
|
loader->globals = (AF_FaceGlobals)face->autohint.data;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
FT_GlyphLoader_Rewind( loader->gloader );
|
|
|
|
|
|
|
|
if ( loader->globals == NULL )
|
|
|
|
{
|
2012-09-18 15:23:41 +02:00
|
|
|
error = af_face_globals_new( face, &loader->globals, module );
|
2004-03-27 09:43:17 +01:00
|
|
|
if ( !error )
|
|
|
|
{
|
2005-03-02 12:24:23 +01:00
|
|
|
face->autohint.data =
|
|
|
|
(FT_Pointer)loader->globals;
|
|
|
|
face->autohint.finalizer =
|
|
|
|
(FT_Generic_Finalizer)af_face_globals_free;
|
2004-03-27 09:43:17 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* Finalize glyph loader. */
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_LOCAL_DEF( void )
|
2012-09-14 12:26:57 +02:00
|
|
|
af_loader_done( AF_Module module )
|
2004-03-27 09:43:17 +01:00
|
|
|
{
|
2012-09-14 12:26:57 +02:00
|
|
|
AF_Loader loader = module->loader;
|
|
|
|
|
|
|
|
|
2005-02-28 23:09:07 +01:00
|
|
|
af_glyph_hints_done( &loader->hints );
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
loader->face = NULL;
|
|
|
|
loader->globals = NULL;
|
|
|
|
|
2011-04-18 19:05:28 +02:00
|
|
|
#ifdef FT_DEBUG_AUTOFIT
|
2006-11-02 17:37:35 +01:00
|
|
|
_af_debug_hints = NULL;
|
|
|
|
#endif
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_GlyphLoader_Done( loader->gloader );
|
|
|
|
loader->gloader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* Load a single glyph component. This routine calls itself */
|
|
|
|
/* recursively, if necessary, and does the main work of */
|
|
|
|
/* `af_loader_load_glyph.' */
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
static FT_Error
|
|
|
|
af_loader_load_g( AF_Loader loader,
|
|
|
|
AF_Scaler scaler,
|
|
|
|
FT_UInt glyph_index,
|
|
|
|
FT_Int32 load_flags,
|
|
|
|
FT_UInt depth )
|
|
|
|
{
|
2005-03-02 12:24:23 +01:00
|
|
|
FT_Error error;
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_Face face = loader->face;
|
|
|
|
FT_GlyphLoader gloader = loader->gloader;
|
|
|
|
AF_ScriptMetrics metrics = loader->metrics;
|
|
|
|
AF_GlyphHints hints = &loader->hints;
|
|
|
|
FT_GlyphSlot slot = face->glyph;
|
|
|
|
FT_Slot_Internal internal = slot->internal;
|
[autofit] Return correct linear advance width values.
This was quite a subtle bug which accidentally showed up with glyph
`afii10023' of arial.ttf (version 2.76). This glyph is a composite;
the first component, `E', has an advance width of 1366 font units,
while the advance width of the composite itself (which looks like
uppercase `E' with dieresis) is 1367 font units. I think this is
actually a bug in the font itself, because there is no reason that
this glyph has not the same width as uppercase `E' without the
dieresis. Anyway, it helped identify this problem.
Using the TrueType hinter, the correct value (1367) of `afii10023'
was returned, but the autohinter mysteriously returned 1366.
Digging in the code showed that the autohinter recursively calls
FT_Load_Glyph to load the glyph, adding the FT_LOAD_NO_SCALE load
flag. However, the `linearHoriAdvance' field is still returned as a
scaled value. To avoid scaling twice, the old code in autofit reset
`linearHoriAdvance', using the `horiAdvance' field. This seemed to
work since FT_LOAD_NO_SCALE was in use, but it failed actually,
because `horiAdvance' is defined as the distance of the first
subglyph's phantom points, which in turn are initialized using the
advance width of the first subglyph. And as the given example
shows, these widths can differ.
* src/autofit/afloader.c (af_loader_load_g): Temporarily set
FT_LOAD_LINEAR_DESIGN while calling FT_Load_Glyph to get unscaled
values for the linear advance widths.
2012-03-11 15:20:32 +01:00
|
|
|
FT_Int32 flags;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
|
[autofit] Return correct linear advance width values.
This was quite a subtle bug which accidentally showed up with glyph
`afii10023' of arial.ttf (version 2.76). This glyph is a composite;
the first component, `E', has an advance width of 1366 font units,
while the advance width of the composite itself (which looks like
uppercase `E' with dieresis) is 1367 font units. I think this is
actually a bug in the font itself, because there is no reason that
this glyph has not the same width as uppercase `E' without the
dieresis. Anyway, it helped identify this problem.
Using the TrueType hinter, the correct value (1367) of `afii10023'
was returned, but the autohinter mysteriously returned 1366.
Digging in the code showed that the autohinter recursively calls
FT_Load_Glyph to load the glyph, adding the FT_LOAD_NO_SCALE load
flag. However, the `linearHoriAdvance' field is still returned as a
scaled value. To avoid scaling twice, the old code in autofit reset
`linearHoriAdvance', using the `horiAdvance' field. This seemed to
work since FT_LOAD_NO_SCALE was in use, but it failed actually,
because `horiAdvance' is defined as the distance of the first
subglyph's phantom points, which in turn are initialized using the
advance width of the first subglyph. And as the given example
shows, these widths can differ.
* src/autofit/afloader.c (af_loader_load_g): Temporarily set
FT_LOAD_LINEAR_DESIGN while calling FT_Load_Glyph to get unscaled
values for the linear advance widths.
2012-03-11 15:20:32 +01:00
|
|
|
flags = load_flags | FT_LOAD_LINEAR_DESIGN;
|
|
|
|
error = FT_Load_Glyph( face, glyph_index, flags );
|
2004-03-27 09:43:17 +01:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
loader->transformed = internal->glyph_transformed;
|
|
|
|
if ( loader->transformed )
|
|
|
|
{
|
|
|
|
FT_Matrix inverse;
|
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
loader->trans_matrix = internal->glyph_matrix;
|
|
|
|
loader->trans_delta = internal->glyph_delta;
|
|
|
|
|
|
|
|
inverse = loader->trans_matrix;
|
|
|
|
FT_Matrix_Invert( &inverse );
|
|
|
|
FT_Vector_Transform( &loader->trans_delta, &inverse );
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( slot->format )
|
|
|
|
{
|
2005-03-02 12:24:23 +01:00
|
|
|
case FT_GLYPH_FORMAT_OUTLINE:
|
|
|
|
/* translate the loaded glyph when an internal transform is needed */
|
|
|
|
if ( loader->transformed )
|
|
|
|
FT_Outline_Translate( &slot->outline,
|
|
|
|
loader->trans_delta.x,
|
|
|
|
loader->trans_delta.y );
|
|
|
|
|
2012-07-09 08:19:25 +02:00
|
|
|
/* copy the outline points in the loader's current */
|
|
|
|
/* extra points which are used to keep original glyph coordinates */
|
2005-10-28 18:14:14 +02:00
|
|
|
error = FT_GLYPHLOADER_CHECK_POINTS( gloader,
|
|
|
|
slot->outline.n_points + 4,
|
|
|
|
slot->outline.n_contours );
|
2005-03-02 12:24:23 +01:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
FT_ARRAY_COPY( gloader->current.outline.points,
|
|
|
|
slot->outline.points,
|
|
|
|
slot->outline.n_points );
|
|
|
|
|
|
|
|
FT_ARRAY_COPY( gloader->current.outline.contours,
|
|
|
|
slot->outline.contours,
|
|
|
|
slot->outline.n_contours );
|
|
|
|
|
|
|
|
FT_ARRAY_COPY( gloader->current.outline.tags,
|
|
|
|
slot->outline.tags,
|
|
|
|
slot->outline.n_points );
|
|
|
|
|
|
|
|
gloader->current.outline.n_points = slot->outline.n_points;
|
|
|
|
gloader->current.outline.n_contours = slot->outline.n_contours;
|
|
|
|
|
|
|
|
/* compute original horizontal phantom points (and ignore */
|
|
|
|
/* vertical ones) */
|
|
|
|
loader->pp1.x = hints->x_delta;
|
|
|
|
loader->pp1.y = hints->y_delta;
|
|
|
|
loader->pp2.x = FT_MulFix( slot->metrics.horiAdvance,
|
|
|
|
hints->x_scale ) + hints->x_delta;
|
|
|
|
loader->pp2.y = hints->y_delta;
|
|
|
|
|
|
|
|
/* 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 */
|
2013-07-30 23:17:04 +02:00
|
|
|
if ( metrics->script_class->script_hints_apply )
|
|
|
|
metrics->script_class->script_hints_apply( hints,
|
|
|
|
&gloader->current.outline,
|
|
|
|
metrics );
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* we now need to adjust the metrics according to the change in */
|
|
|
|
/* width/positioning that occurred during the hinting process */
|
2007-01-26 16:05:41 +01:00
|
|
|
if ( scaler->render_mode != FT_RENDER_MODE_LIGHT )
|
2005-03-02 12:24:23 +01:00
|
|
|
{
|
2007-05-15 08:49:37 +02:00
|
|
|
FT_Pos old_rsb, old_lsb, new_lsb;
|
2005-03-02 12:24:23 +01:00
|
|
|
FT_Pos pp1x_uh, pp2x_uh;
|
2005-03-03 18:09:08 +01:00
|
|
|
AF_AxisHints axis = &hints->axis[AF_DIMENSION_HORZ];
|
2005-03-02 12:24:23 +01:00
|
|
|
AF_Edge edge1 = axis->edges; /* leftmost edge */
|
|
|
|
AF_Edge edge2 = edge1 +
|
|
|
|
axis->num_edges - 1; /* rightmost edge */
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2006-01-22 08:09:54 +01:00
|
|
|
|
2006-02-09 15:17:04 +01:00
|
|
|
if ( axis->num_edges > 1 && AF_HINTS_DO_ADVANCE( hints ) )
|
2005-03-02 12:24:23 +01:00
|
|
|
{
|
2009-04-27 19:40:35 +02:00
|
|
|
old_rsb = loader->pp2.x - edge2->opos;
|
|
|
|
old_lsb = edge1->opos;
|
|
|
|
new_lsb = edge1->pos;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
/* remember unhinted values to later account */
|
|
|
|
/* for rounding errors */
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
pp1x_uh = new_lsb - old_lsb;
|
|
|
|
pp2x_uh = edge2->pos + old_rsb;
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
/* prefer too much space over too little space */
|
|
|
|
/* for very small sizes */
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
if ( old_lsb < 24 )
|
2007-02-12 22:28:21 +01:00
|
|
|
pp1x_uh -= 8;
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
if ( old_rsb < 24 )
|
2007-02-12 22:28:21 +01:00
|
|
|
pp2x_uh += 8;
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
loader->pp1.x = FT_PIX_ROUND( pp1x_uh );
|
|
|
|
loader->pp2.x = FT_PIX_ROUND( pp2x_uh );
|
2004-06-05 08:27:08 +02:00
|
|
|
|
2007-02-12 22:28:21 +01:00
|
|
|
if ( loader->pp1.x >= new_lsb && old_lsb > 0 )
|
2006-12-07 22:18:09 +01:00
|
|
|
loader->pp1.x -= 64;
|
|
|
|
|
2007-02-12 22:28:21 +01:00
|
|
|
if ( loader->pp2.x <= edge2->pos && old_rsb > 0 )
|
2006-12-07 22:18:09 +01:00
|
|
|
loader->pp2.x += 64;
|
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
slot->lsb_delta = loader->pp1.x - pp1x_uh;
|
|
|
|
slot->rsb_delta = loader->pp2.x - pp2x_uh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-27 19:40:35 +02:00
|
|
|
FT_Pos pp1x = loader->pp1.x;
|
|
|
|
FT_Pos pp2x = loader->pp2.x;
|
|
|
|
|
2006-03-23 21:58:20 +01:00
|
|
|
|
2007-01-26 16:05:41 +01:00
|
|
|
loader->pp1.x = FT_PIX_ROUND( pp1x );
|
|
|
|
loader->pp2.x = FT_PIX_ROUND( pp2x );
|
2006-03-23 21:58:20 +01:00
|
|
|
|
|
|
|
slot->lsb_delta = loader->pp1.x - pp1x;
|
|
|
|
slot->rsb_delta = loader->pp2.x - pp2x;
|
2004-03-27 09:43:17 +01:00
|
|
|
}
|
2005-03-02 12:24:23 +01:00
|
|
|
}
|
2007-01-26 16:05:41 +01:00
|
|
|
else
|
|
|
|
{
|
2009-04-27 19:40:35 +02:00
|
|
|
FT_Pos pp1x = loader->pp1.x;
|
|
|
|
FT_Pos pp2x = loader->pp2.x;
|
|
|
|
|
2007-01-26 16:05:41 +01:00
|
|
|
|
|
|
|
loader->pp1.x = FT_PIX_ROUND( pp1x + hints->xmin_delta );
|
2007-01-30 11:33:53 +01:00
|
|
|
loader->pp2.x = FT_PIX_ROUND( pp2x + hints->xmax_delta );
|
2007-01-26 16:05:41 +01:00
|
|
|
|
|
|
|
slot->lsb_delta = loader->pp1.x - pp1x;
|
|
|
|
slot->rsb_delta = loader->pp2.x - pp2x;
|
|
|
|
}
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
/* good, we simply add the glyph to our loader's base */
|
|
|
|
FT_GlyphLoader_Add( gloader );
|
|
|
|
break;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
case FT_GLYPH_FORMAT_COMPOSITE:
|
|
|
|
{
|
|
|
|
FT_UInt nn, num_subglyphs = slot->num_subglyphs;
|
|
|
|
FT_UInt num_base_subgs, start_point;
|
|
|
|
FT_SubGlyph subglyph;
|
|
|
|
|
|
|
|
|
|
|
|
start_point = gloader->base.outline.n_points;
|
|
|
|
|
|
|
|
/* first of all, copy the subglyph descriptors in the glyph loader */
|
|
|
|
error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
FT_ARRAY_COPY( gloader->current.subglyphs,
|
|
|
|
slot->subglyphs,
|
|
|
|
num_subglyphs );
|
|
|
|
|
|
|
|
gloader->current.num_subglyphs = num_subglyphs;
|
2005-03-02 12:24:23 +01:00
|
|
|
num_base_subgs = gloader->base.num_subglyphs;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* now read each subglyph independently */
|
2004-03-27 09:43:17 +01:00
|
|
|
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 = loader->pp1;
|
|
|
|
pp2 = loader->pp2;
|
|
|
|
|
|
|
|
num_base_points = gloader->base.outline.n_points;
|
|
|
|
|
|
|
|
error = af_loader_load_g( loader, scaler, 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 = loader->pp1;
|
|
|
|
pp2 = loader->pp2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loader->pp1 = pp1;
|
|
|
|
loader->pp2 = pp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_points = gloader->base.outline.n_points;
|
|
|
|
num_new_points = num_points - num_base_points;
|
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* now perform the transformation required for this subglyph */
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
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* limit = cur + num_new_points;
|
|
|
|
|
|
|
|
|
2006-04-13 09:51:58 +02:00
|
|
|
for ( ; cur < limit; cur++ )
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_Vector_Transform( cur, &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 )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Composite );
|
2004-03-27 09:43:17 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
l += num_base_points;
|
|
|
|
|
2012-07-09 08:19:25 +02:00
|
|
|
/* for now, only use the current point coordinates; */
|
|
|
|
/* we eventually may consider another approach */
|
2004-03-27 09:43:17 +01:00
|
|
|
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, hints->x_scale ) + hints->x_delta;
|
|
|
|
y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta;
|
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
x = FT_PIX_ROUND( x );
|
|
|
|
y = FT_PIX_ROUND( y );
|
2004-03-27 09:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
FT_Outline dummy = gloader->base.outline;
|
|
|
|
|
|
|
|
|
|
|
|
dummy.points += num_base_points;
|
|
|
|
dummy.n_points = (short)num_new_points;
|
|
|
|
|
|
|
|
FT_Outline_Translate( &dummy, x, y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* we don't support other formats (yet?) */
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Unimplemented_Feature );
|
2004-03-27 09:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Hint_Metrics:
|
|
|
|
if ( depth == 0 )
|
|
|
|
{
|
2006-02-27 10:18:07 +01:00
|
|
|
FT_BBox bbox;
|
|
|
|
FT_Vector vvector;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
|
2006-02-27 10:18:07 +01:00
|
|
|
vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX;
|
|
|
|
vvector.y = slot->metrics.vertBearingY - slot->metrics.horiBearingY;
|
|
|
|
vvector.x = FT_MulFix( vvector.x, metrics->scaler.x_scale );
|
|
|
|
vvector.y = FT_MulFix( vvector.y, metrics->scaler.y_scale );
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
/* transform the hinted outline if needed */
|
|
|
|
if ( loader->transformed )
|
2006-02-27 10:18:07 +01:00
|
|
|
{
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_Outline_Transform( &gloader->base.outline, &loader->trans_matrix );
|
2006-02-27 10:18:07 +01:00
|
|
|
FT_Vector_Transform( &vvector, &loader->trans_matrix );
|
|
|
|
}
|
2007-06-11 07:37:35 +02:00
|
|
|
#if 1
|
2004-03-27 09:43:17 +01:00
|
|
|
/* we must translate our final outline by -pp1.x and compute */
|
|
|
|
/* the new metrics */
|
|
|
|
if ( loader->pp1.x )
|
|
|
|
FT_Outline_Translate( &gloader->base.outline, -loader->pp1.x, 0 );
|
2007-06-11 07:37:35 +02:00
|
|
|
#endif
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_Outline_Get_CBox( &gloader->base.outline, &bbox );
|
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
bbox.xMin = FT_PIX_FLOOR( bbox.xMin );
|
|
|
|
bbox.yMin = FT_PIX_FLOOR( bbox.yMin );
|
|
|
|
bbox.xMax = FT_PIX_CEIL( bbox.xMax );
|
|
|
|
bbox.yMax = FT_PIX_CEIL( bbox.yMax );
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
slot->metrics.width = bbox.xMax - bbox.xMin;
|
|
|
|
slot->metrics.height = bbox.yMax - bbox.yMin;
|
|
|
|
slot->metrics.horiBearingX = bbox.xMin;
|
|
|
|
slot->metrics.horiBearingY = bbox.yMax;
|
|
|
|
|
2006-02-27 10:18:07 +01:00
|
|
|
slot->metrics.vertBearingX = FT_PIX_FLOOR( bbox.xMin + vvector.x );
|
|
|
|
slot->metrics.vertBearingY = FT_PIX_FLOOR( bbox.yMax + vvector.y );
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
/* for mono-width fonts (like Andale, Courier, etc.) we need */
|
2009-04-27 19:40:35 +02:00
|
|
|
/* to keep the original rounded advance width; ditto for */
|
|
|
|
/* digits if all have the same advance width */
|
2004-03-27 09:43:17 +01:00
|
|
|
#if 0
|
|
|
|
if ( !FT_IS_FIXED_WIDTH( slot->face ) )
|
|
|
|
slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
|
|
|
|
else
|
|
|
|
slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
|
|
|
|
x_scale );
|
|
|
|
#else
|
2012-02-29 13:33:33 +01:00
|
|
|
if ( scaler->render_mode != FT_RENDER_MODE_LIGHT &&
|
|
|
|
( FT_IS_FIXED_WIDTH( slot->face ) ||
|
|
|
|
( af_face_globals_is_digit( loader->globals, glyph_index ) &&
|
|
|
|
metrics->digits_have_same_width ) ) )
|
2007-03-26 15:37:17 +02:00
|
|
|
{
|
2004-06-04 19:41:59 +02:00
|
|
|
slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
|
|
|
|
metrics->scaler.x_scale );
|
2007-03-26 15:37:17 +02:00
|
|
|
|
2007-03-28 23:17:11 +02:00
|
|
|
/* Set delta values to 0. Otherwise code that uses them is */
|
|
|
|
/* going to ruin the fixed advance width. */
|
2007-03-26 15:37:17 +02:00
|
|
|
slot->lsb_delta = 0;
|
|
|
|
slot->rsb_delta = 0;
|
|
|
|
}
|
2009-04-27 19:40:35 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* non-spacing glyphs must stay as-is */
|
|
|
|
if ( slot->metrics.horiAdvance )
|
|
|
|
slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
|
|
|
|
}
|
2004-03-27 09:43:17 +01:00
|
|
|
#endif
|
|
|
|
|
2006-02-27 10:18:07 +01:00
|
|
|
slot->metrics.vertAdvance = FT_MulFix( slot->metrics.vertAdvance,
|
2011-02-26 17:32:38 +01:00
|
|
|
metrics->scaler.y_scale );
|
2006-02-27 10:18:07 +01:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
slot->metrics.horiAdvance = FT_PIX_ROUND( slot->metrics.horiAdvance );
|
2006-02-27 10:18:07 +01:00
|
|
|
slot->metrics.vertAdvance = FT_PIX_ROUND( slot->metrics.vertAdvance );
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
/* now copy outline into glyph slot */
|
|
|
|
FT_GlyphLoader_Rewind( internal->loader );
|
|
|
|
error = FT_GlyphLoader_CopyPoints( internal->loader, gloader );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
2012-02-17 14:55:27 +01:00
|
|
|
/* reassign all outline fields except flags to protect them */
|
|
|
|
slot->outline.n_contours = internal->loader->base.outline.n_contours;
|
|
|
|
slot->outline.n_points = internal->loader->base.outline.n_points;
|
|
|
|
slot->outline.points = internal->loader->base.outline.points;
|
|
|
|
slot->outline.tags = internal->loader->base.outline.tags;
|
|
|
|
slot->outline.contours = internal->loader->base.outline.contours;
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
slot->format = FT_GLYPH_FORMAT_OUTLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-26 17:32:38 +01:00
|
|
|
/* Load a glyph. */
|
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
2012-09-14 12:26:57 +02:00
|
|
|
af_loader_load_glyph( AF_Module module,
|
2004-03-27 09:43:17 +01:00
|
|
|
FT_Face face,
|
|
|
|
FT_UInt gindex,
|
2012-02-07 09:40:11 +01:00
|
|
|
FT_Int32 load_flags )
|
2004-03-27 09:43:17 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2012-09-14 12:26:57 +02:00
|
|
|
FT_Size size = face->size;
|
|
|
|
AF_Loader loader = module->loader;
|
2004-03-27 09:43:17 +01:00
|
|
|
AF_ScalerRec scaler;
|
|
|
|
|
2005-03-02 12:24:23 +01:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
if ( !size )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Argument );
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
FT_ZERO( &scaler );
|
|
|
|
|
|
|
|
scaler.face = face;
|
|
|
|
scaler.x_scale = size->metrics.x_scale;
|
|
|
|
scaler.x_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
|
|
|
|
scaler.y_scale = size->metrics.y_scale;
|
|
|
|
scaler.y_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
|
|
|
|
|
|
|
|
scaler.render_mode = FT_LOAD_TARGET_MODE( load_flags );
|
|
|
|
scaler.flags = 0; /* XXX: fix this */
|
|
|
|
|
2012-09-14 12:26:57 +02:00
|
|
|
error = af_loader_reset( module, face );
|
2004-03-27 09:43:17 +01:00
|
|
|
if ( !error )
|
|
|
|
{
|
|
|
|
AF_ScriptMetrics metrics;
|
2007-06-11 07:37:35 +02:00
|
|
|
FT_UInt options = 0;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
2007-06-11 23:15:09 +02:00
|
|
|
|
2007-06-11 07:37:35 +02:00
|
|
|
#ifdef FT_OPTION_AUTOFIT2
|
|
|
|
/* XXX: undocumented hook to activate the latin2 hinter */
|
2007-06-11 23:15:09 +02:00
|
|
|
if ( load_flags & ( 1UL << 20 ) )
|
2007-06-11 07:37:35 +02:00
|
|
|
options = 2;
|
|
|
|
#endif
|
2005-03-02 12:24:23 +01:00
|
|
|
|
|
|
|
error = af_face_globals_get_metrics( loader->globals, gindex,
|
2007-06-11 07:37:35 +02:00
|
|
|
options, &metrics );
|
2004-03-27 09:43:17 +01:00
|
|
|
if ( !error )
|
|
|
|
{
|
|
|
|
loader->metrics = metrics;
|
|
|
|
|
2013-07-30 23:17:04 +02:00
|
|
|
if ( metrics->script_class->script_metrics_scale )
|
|
|
|
metrics->script_class->script_metrics_scale( metrics, &scaler );
|
2005-03-01 16:48:29 +01:00
|
|
|
else
|
|
|
|
metrics->scaler = scaler;
|
2004-03-27 09:43:17 +01:00
|
|
|
|
|
|
|
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
|
|
|
|
load_flags &= ~FT_LOAD_RENDER;
|
|
|
|
|
2013-07-30 23:17:04 +02:00
|
|
|
if ( metrics->script_class->script_hints_init )
|
2008-02-17 09:22:08 +01:00
|
|
|
{
|
2013-07-30 23:17:04 +02:00
|
|
|
error = metrics->script_class->script_hints_init( &loader->hints,
|
|
|
|
metrics );
|
2008-02-17 09:22:08 +01:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
}
|
2004-06-04 19:41:59 +02:00
|
|
|
|
2004-03-27 09:43:17 +01:00
|
|
|
error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 );
|
|
|
|
}
|
|
|
|
}
|
2004-06-04 19:41:59 +02:00
|
|
|
Exit:
|
2004-03-27 09:43:17 +01:00
|
|
|
return error;
|
|
|
|
}
|
2005-03-02 12:24:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|