summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype2/src/cid/cidgload.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/freetype2/src/cid/cidgload.c')
-rw-r--r--Build/source/libs/freetype2/src/cid/cidgload.c327
1 files changed, 186 insertions, 141 deletions
diff --git a/Build/source/libs/freetype2/src/cid/cidgload.c b/Build/source/libs/freetype2/src/cid/cidgload.c
index e7a70e8a48d..ed706ade7df 100644
--- a/Build/source/libs/freetype2/src/cid/cidgload.c
+++ b/Build/source/libs/freetype2/src/cid/cidgload.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 Glyph Loader (body). */
/* */
-/* Copyright 1996-2001 by */
+/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -37,81 +37,148 @@
FT_CALLBACK_DEF( FT_Error )
- cid_load_glyph( T1_Decoder* decoder,
- FT_UInt glyph_index )
+ cid_load_glyph( T1_Decoder decoder,
+ FT_UInt glyph_index )
{
- CID_Face face = (CID_Face)decoder->builder.face;
- CID_Info* cid = &face->cid;
- FT_Byte* p;
- FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes;
- FT_UInt fd_select;
- FT_ULong off1, glyph_len;
- FT_Stream stream = face->root.stream;
- FT_Error error = 0;
-
-
- /* read the CID font dict index and charstring offset from the CIDMap */
- if ( FILE_Seek( cid->data_offset + cid->cidmap_offset +
- glyph_index * entry_len ) ||
- ACCESS_Frame( 2 * entry_len ) )
- goto Exit;
-
- p = (FT_Byte*)stream->cursor;
- fd_select = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
- off1 = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
- p += cid->fd_bytes;
- glyph_len = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1;
-
- FORGET_Frame();
-
- /* now, if the glyph is not empty, set up the subrs array, and parse */
- /* the charstrings */
- if ( glyph_len > 0 )
+ CID_Face face = (CID_Face)decoder->builder.face;
+ CID_FaceInfo cid = &face->cid;
+ FT_Byte* p;
+ FT_UInt fd_select;
+ FT_Stream stream = face->cid_stream;
+ FT_Error error = 0;
+ FT_Byte* charstring = 0;
+ FT_Memory memory = face->root.memory;
+ FT_ULong glyph_length = 0;
+ PSAux_Service psaux = (PSAux_Service)face->psaux;
+
+
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
+
+ /* For incremental fonts get the character data using */
+ /* the callback function. */
+ if ( face->root.internal->incremental_interface )
{
- CID_FontDict* dict;
- CID_Subrs* cid_subrs = face->subrs + fd_select;
- FT_Byte* charstring;
- FT_Memory memory = face->root.memory;
+ FT_Data glyph_data;
- /* setup subrs */
+ error = face->root.internal->incremental_interface->funcs->get_glyph_data(
+ face->root.internal->incremental_interface->object,
+ glyph_index,
+ &glyph_data );
+ if ( error )
+ goto Exit;
+
+ p = (FT_Byte*)glyph_data.pointer;
+ fd_select = (FT_UInt)cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
+
+ if ( glyph_data.length != 0 )
+ {
+ glyph_length = glyph_data.length - cid->fd_bytes;
+ FT_ALLOC( charstring, glyph_length );
+ if ( !error )
+ ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes,
+ glyph_length );
+ }
+
+ face->root.internal->incremental_interface->funcs->free_glyph_data(
+ face->root.internal->incremental_interface->object,
+ &glyph_data );
+
+ if ( error )
+ goto Exit;
+ }
+
+ else
+
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
+
+ /* For ordinary fonts read the CID font dictionary index */
+ /* and charstring offset from the CIDMap. */
+ {
+ FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes;
+ FT_ULong off1;
+
+
+ if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset +
+ glyph_index * entry_len ) ||
+ FT_FRAME_ENTER( 2 * entry_len ) )
+ goto Exit;
+
+ p = (FT_Byte*)stream->cursor;
+ fd_select = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
+ off1 = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
+ p += cid->fd_bytes;
+ glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1;
+ FT_FRAME_EXIT();
+
+ if ( glyph_length == 0 )
+ goto Exit;
+ if ( FT_ALLOC( charstring, glyph_length ) )
+ goto Exit;
+ if ( FT_STREAM_READ_AT( cid->data_offset + off1,
+ charstring, glyph_length ) )
+ goto Exit;
+ }
+
+ /* Now set up the subrs array and parse the charstrings. */
+ {
+ CID_FaceDict dict;
+ CID_Subrs cid_subrs = face->subrs + fd_select;
+ FT_Int cs_offset;
+
+
+ /* Set up subrs */
decoder->num_subrs = cid_subrs->num_subrs;
decoder->subrs = cid_subrs->code;
decoder->subrs_len = 0;
- /* setup font matrix */
+ /* Set up font matrix */
dict = cid->font_dicts + fd_select;
decoder->font_matrix = dict->font_matrix;
decoder->font_offset = dict->font_offset;
decoder->lenIV = dict->private_dict.lenIV;
- /* the charstrings are encoded (stupid!) */
- /* load the charstrings, then execute it */
+ /* Decode the charstring. */
- if ( ALLOC( charstring, glyph_len ) )
- goto Exit;
+ /* Adjustment for seed bytes. */
+ cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
- if ( !FILE_Read_At( cid->data_offset + off1, charstring, glyph_len ) )
- {
- FT_Int cs_offset;
+ /* Decrypt only if lenIV >= 0. */
+ if ( decoder->lenIV >= 0 )
+ psaux->t1_decrypt( charstring, glyph_length, 4330 );
+ error = decoder->funcs.parse_charstrings(
+ decoder, charstring + cs_offset,
+ (FT_Int)glyph_length - cs_offset );
+ }
- /* Adjustment for seed bytes. */
- cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
-
- /* Decrypt only if lenIV >= 0. */
- if ( decoder->lenIV >= 0 )
- cid_decrypt( charstring, glyph_len, 4330 );
+ FT_FREE( charstring );
- error = decoder->funcs.parse_charstrings( decoder,
- charstring + cs_offset,
- glyph_len - cs_offset );
- }
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
- FREE( charstring );
+ /* 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 */
+
Exit:
return error;
}
@@ -138,15 +205,15 @@
/*************************************************************************/
- FT_LOCAL_DEF FT_Error
- CID_Compute_Max_Advance( CID_Face face,
- FT_Int* max_advance )
+ FT_LOCAL_DEF( FT_Error )
+ cid_face_compute_max_advance( CID_Face face,
+ FT_Int* max_advance )
{
- FT_Error error;
- T1_Decoder decoder;
- FT_Int glyph_index;
+ FT_Error error;
+ T1_DecoderRec decoder;
+ FT_Int glyph_index;
- PSAux_Interface* psaux = (PSAux_Interface*)face->psaux;
+ PSAux_Service psaux = (PSAux_Service)face->psaux;
*max_advance = 0;
@@ -185,60 +252,47 @@
#endif /* 0 */
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /********** *********/
- /********** *********/
- /********** UNHINTED GLYPH LOADER *********/
- /********** *********/
- /********** The following code is in charge of loading a *********/
- /********** single outline. It completely ignores hinting *********/
- /********** and is used when FT_LOAD_NO_HINTING is set. *********/
- /********** *********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
- FT_LOCAL_DEF FT_Error
- CID_Load_Glyph( CID_GlyphSlot glyph,
- CID_Size size,
- FT_Int glyph_index,
- FT_Int load_flags )
+ FT_LOCAL_DEF( FT_Error )
+ cid_slot_load_glyph( FT_GlyphSlot cidglyph, /* CID_GlyphSlot */
+ FT_Size cidsize, /* CID_Size */
+ FT_UInt glyph_index,
+ FT_Int32 load_flags )
{
- FT_Error error;
- T1_Decoder decoder;
- CID_Face face = (CID_Face)glyph->root.face;
- FT_Bool hinting;
+ CID_GlyphSlot glyph = (CID_GlyphSlot)cidglyph;
+ CID_Size size = (CID_Size)cidsize;
+ FT_Error error;
+ T1_DecoderRec decoder;
+ CID_Face face = (CID_Face)cidglyph->face;
+ FT_Bool hinting;
- PSAux_Interface* psaux = (PSAux_Interface*)face->psaux;
- FT_Matrix font_matrix;
- FT_Vector font_offset;
+ PSAux_Service psaux = (PSAux_Service)face->psaux;
+ FT_Matrix font_matrix;
+ FT_Vector font_offset;
if ( load_flags & FT_LOAD_NO_RECURSE )
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
- glyph->x_scale = size->root.metrics.x_scale;
- glyph->y_scale = size->root.metrics.y_scale;
+ glyph->x_scale = cidsize->metrics.x_scale;
+ glyph->y_scale = cidsize->metrics.y_scale;
- glyph->root.outline.n_points = 0;
- glyph->root.outline.n_contours = 0;
+ cidglyph->outline.n_points = 0;
+ cidglyph->outline.n_contours = 0;
hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
( load_flags & FT_LOAD_NO_HINTING ) == 0 );
- glyph->root.format = ft_glyph_format_outline;
+ cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
{
error = psaux->t1_decoder_funcs->init( &decoder,
- (FT_Face)face,
- (FT_Size)size,
- (FT_GlyphSlot)glyph,
+ cidglyph->face,
+ cidsize,
+ cidglyph,
0, /* glyph names -- XXX */
0, /* blend == 0 */
hinting,
+ FT_LOAD_TARGET_MODE( load_flags ),
cid_load_glyph );
/* set up the decoder */
@@ -259,18 +313,18 @@
/* bearing the yMax */
if ( !error )
{
- glyph->root.outline.flags &= ft_outline_owner;
- glyph->root.outline.flags |= ft_outline_reverse_fill;
+ cidglyph->outline.flags &= FT_OUTLINE_OWNER;
+ cidglyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
/* for composite glyphs, return only left side bearing and */
/* advance width */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
- FT_Slot_Internal internal = glyph->root.internal;
+ FT_Slot_Internal internal = cidglyph->internal;
- glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x;
- glyph->root.metrics.horiAdvance = decoder.builder.advance.x;
+ cidglyph->metrics.horiBearingX = decoder.builder.left_bearing.x;
+ cidglyph->metrics.horiAdvance = decoder.builder.advance.x;
internal->glyph_matrix = font_matrix;
internal->glyph_delta = font_offset;
@@ -279,32 +333,41 @@
else
{
FT_BBox cbox;
- FT_Glyph_Metrics* metrics = &glyph->root.metrics;
+ FT_Glyph_Metrics* metrics = &cidglyph->metrics;
+ FT_Vector advance;
/* copy the _unscaled_ advance width */
- metrics->horiAdvance = decoder.builder.advance.x;
- glyph->root.linearHoriAdvance = decoder.builder.advance.x;
- glyph->root.internal->glyph_transformed = 0;
+ metrics->horiAdvance = decoder.builder.advance.x;
+ cidglyph->linearHoriAdvance = decoder.builder.advance.x;
+ cidglyph->internal->glyph_transformed = 0;
- /* make up vertical metrics */
- metrics->vertBearingX = 0;
- metrics->vertBearingY = 0;
- metrics->vertAdvance = 0;
+ /* make up vertical ones */
+ metrics->vertAdvance = ( face->cid.font_bbox.yMax -
+ face->cid.font_bbox.yMin ) >> 16;
+ cidglyph->linearVertAdvance = metrics->vertAdvance;
- glyph->root.linearVertAdvance = 0;
- glyph->root.format = ft_glyph_format_outline;
+ cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
- if ( size && size->root.metrics.y_ppem < 24 )
- glyph->root.outline.flags |= ft_outline_high_precision;
+ if ( size && cidsize->metrics.y_ppem < 24 )
+ cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
/* apply the font matrix */
- FT_Outline_Transform( &glyph->root.outline, &font_matrix );
+ FT_Outline_Transform( &cidglyph->outline, &font_matrix );
- FT_Outline_Translate( &glyph->root.outline,
+ FT_Outline_Translate( &cidglyph->outline,
font_offset.x,
font_offset.y );
+ advance.x = metrics->horiAdvance;
+ advance.y = 0;
+ FT_Vector_Transform( &advance, &font_matrix );
+ metrics->horiAdvance = advance.x + font_offset.x;
+ advance.x = 0;
+ advance.y = metrics->vertAdvance;
+ FT_Vector_Transform( &advance, &font_matrix );
+ metrics->vertAdvance = advance.y + font_offset.y;
+
if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 )
{
/* scale the outline and the metrics */
@@ -316,51 +379,33 @@
/* First of all, scale the points */
- if ( !hinting )
+ if ( !hinting || !decoder.builder.hints_funcs )
for ( n = cur->n_points; n > 0; n--, vec++ )
{
vec->x = FT_MulFix( vec->x, x_scale );
vec->y = FT_MulFix( vec->y, y_scale );
}
- FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
-
/* Then scale the metrics */
metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
-
- metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
- metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
-
- if ( hinting )
- {
- metrics->horiAdvance = ( metrics->horiAdvance + 32 ) & -64;
- metrics->vertAdvance = ( metrics->vertAdvance + 32 ) & -64;
-
- metrics->vertBearingX = ( metrics->vertBearingX + 32 ) & -64;
- metrics->vertBearingY = ( metrics->vertBearingY + 32 ) & -64;
- }
}
/* compute the other metrics */
- FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
-
- /* grid fit the bounding box if necessary */
- if ( hinting )
- {
- cbox.xMin &= -64;
- cbox.yMin &= -64;
- cbox.xMax = ( cbox.xMax + 63 ) & -64;
- cbox.yMax = ( cbox.yMax + 63 ) & -64;
- }
+ FT_Outline_Get_CBox( &cidglyph->outline, &cbox );
metrics->width = cbox.xMax - cbox.xMin;
metrics->height = cbox.yMax - cbox.yMin;
metrics->horiBearingX = cbox.xMin;
metrics->horiBearingY = cbox.yMax;
+
+ /* make up vertical ones */
+ ft_synthesize_vertical_metrics( metrics,
+ metrics->vertAdvance );
}
}
+
return error;
}