The incremental interface now passes the old metrics when asking for

replacement metrics so that they can be modified, not just replaced.
For example, CFF fonts need this.
This commit is contained in:
Graham Asher 2003-02-13 17:49:27 +00:00
parent 9f26ba72e7
commit 09495b4acf
5 changed files with 96 additions and 83 deletions

View File

@ -174,21 +174,22 @@ FT_BEGIN_HEADER
* vertical ::
* If true, return vertical metrics.
*
* ametrics ::
* This parameter is used for both input and output.
* The original glyph metrics, if any, in font units. If metrics are
* not available all the values must be set to zero.
*
* @output:
* ametrics ::
* The glyph metrics in font units.
*
* afound ::
* True if there are metrics at all.
* The replacement glyph metrics in font units.
*
*/
typedef FT_Error
(*FT_Incremental_GetGlyphMetricsFunc)
( FT_Incremental incremental,
FT_UInt glyph_index,
FT_Bool vertical,
FT_Incremental_MetricsRec *ametrics,
FT_Bool *afound );
( FT_Incremental incremental,
FT_UInt glyph_index,
FT_Bool vertical,
FT_Incremental_MetricsRec *ametrics );
/**************************************************************************

View File

@ -2363,6 +2363,29 @@
cff_builder_done( &decoder.builder );
}
#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* Incremental fonts can optionally override the metrics. */
if ( !error &&
face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Incremental_MetricsRec metrics;
metrics.bearing_x = decoder.builder.left_bearing.x;
metrics.bearing_y = decoder.builder.left_bearing.y;
metrics.advance = decoder.builder.advance.x;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, FALSE, &metrics );
decoder.builder.left_bearing.x = metrics.bearing_x;
decoder.builder.left_bearing.y = metrics.bearing_y;
decoder.builder.advance.x = metrics.advance;
decoder.builder.advance.y = 0;
}
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
font_matrix = cff->top_font.font_dict.font_matrix;
font_offset = cff->top_font.font_dict.font_offset;

View File

@ -89,7 +89,7 @@
else
#endif
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* For ordinary fonts read the CID font dictionary index */
/* and charstring offset from the CIDMap. */
@ -162,23 +162,21 @@
face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Bool found = FALSE;
FT_Incremental_MetricsRec metrics;
metrics.bearing_x = decoder->builder.left_bearing.x;
metrics.bearing_y = decoder->builder.left_bearing.y;
metrics.advance = decoder->builder.advance.x;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, FALSE, &metrics, &found );
if ( found )
{
decoder->builder.left_bearing.x = metrics.bearing_x;
decoder->builder.left_bearing.y = metrics.bearing_y;
decoder->builder.advance.x = metrics.advance;
decoder->builder.advance.y = 0;
}
glyph_index, FALSE, &metrics );
decoder->builder.left_bearing.x = metrics.bearing_x;
decoder->builder.left_bearing.y = metrics.bearing_y;
decoder->builder.advance.x = metrics.advance;
decoder->builder.advance.y = 0;
}
#endif
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
Exit:
return error;

View File

@ -808,42 +808,33 @@
FT_Short left_bearing = 0;
FT_UShort advance_width = 0;
#ifdef FT_CONFIG_OPTION_INCREMENTAL
FT_Bool metrics_found = FALSE;
Get_HMetrics( face, glyph_index,
(FT_Bool)!( loader->load_flags &
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
&left_bearing,
&advance_width );
#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font see if there are */
/* overriding metrics for this glyph. */
if ( face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Incremental_MetricsRec m;
FT_Incremental_MetricsRec metrics;
metrics.bearing_x = left_bearing;
metrics.bearing_y = 0;
metrics.advance = advance_width;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, FALSE, &m, &metrics_found );
glyph_index, FALSE, &metrics );
if ( error )
goto Exit;
left_bearing = (FT_Short)m.bearing_x;
advance_width = (FT_UShort)m.advance;
left_bearing = (FT_Short)metrics.bearing_x;
advance_width = (FT_UShort)metrics.advance;
}
if ( !metrics_found )
Get_HMetrics( face, glyph_index,
(FT_Bool)!( loader->load_flags &
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
&left_bearing,
&advance_width );
#else
Get_HMetrics( face, glyph_index,
(FT_Bool)!( loader->load_flags &
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
&left_bearing,
&advance_width );
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
loader->left_bearing = left_bearing;
@ -1326,7 +1317,6 @@
exec->is_composite = TRUE;
exec->pedantic_hinting =
(FT_Bool)( loader->load_flags & FT_LOAD_PEDANTIC );
error = TT_Run_Context( exec, ((TT_Size)loader->size)->debug );
if ( error && exec->pedantic_hinting )
goto Fail;
@ -1449,33 +1439,9 @@
FT_Pos left; /* scaled vertical left side bearing */
FT_Pos top; /* scaled vertical top side bearing */
FT_Pos advance; /* scaled vertical advance height */
FT_Bool metrics_found = FALSE;
#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font see if there are */
/* overriding metrics for this glyph. */
if ( face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Incremental_MetricsRec m;
FT_Error error =
face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, TRUE, &m, &metrics_found );
if ( error )
return error;
top_bearing = (FT_Short)m.bearing_y;
advance_height = (FT_UShort)m.advance;
}
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* Get the unscaled top bearing and advance height. */
if ( !metrics_found && face->vertical_info &&
if ( face->vertical_info &&
face->vertical.number_Of_VMetrics > 0 )
{
/* Don't assume that both the vertical header and vertical */
@ -1516,8 +1482,35 @@
}
}
#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font see if there are */
/* overriding metrics for this glyph. */
if ( face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Incremental_MetricsRec metrics;
FT_Error error = 0;
metrics.bearing_x = 0;
metrics.bearing_y = top_bearing;
metrics.advance = advance_height;
error =
face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, TRUE, &metrics );
if ( error )
return error;
top_bearing = (FT_Short)metrics.bearing_y;
advance_height = (FT_UShort)metrics.advance;
}
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* We must adjust the top_bearing value from the bounding box given */
/* in the glyph header to te bounding box calculated with */
/* in the glyph header to the bounding box calculated with */
/* FT_Get_Outline_CBox(). */
/* scale the metrics */

View File

@ -76,7 +76,7 @@
glyph_index, char_string );
else
#endif
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* For ordinary fonts get the character data stored in the face record. */
{
@ -95,23 +95,21 @@
if ( !error && face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
FT_Bool found = FALSE;
FT_Incremental_MetricsRec metrics;
metrics.bearing_x = decoder->builder.left_bearing.x;
metrics.bearing_y = decoder->builder.left_bearing.y;
metrics.advance = decoder->builder.advance.x;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
glyph_index, FALSE, &metrics, &found );
if ( found )
{
decoder->builder.left_bearing.x = metrics.bearing_x;
decoder->builder.left_bearing.y = metrics.bearing_y;
decoder->builder.advance.x = metrics.advance;
decoder->builder.advance.y = 0;
}
glyph_index, FALSE, &metrics );
decoder->builder.left_bearing.x = metrics.bearing_x;
decoder->builder.left_bearing.y = metrics.bearing_y;
decoder->builder.advance.x = metrics.advance;
decoder->builder.advance.y = 0;
}
#endif
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
return error;
}
@ -137,7 +135,7 @@
face->root.internal->incremental_interface->object,
&glyph_data );
}
#endif
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
return error;
}