Add support for the hexadicimal representation of binary data

started with `StartData' in CID-keyed Type 1 fonts.

* include/freetype/internal/t1types.h (CID_FaceRec): Add new
members `binary_data' and `cid_stream'.

* src/cid/cidload.c (cid_read_subrs): Use `face->cid_stream'.
(cid_hex_to_binary): New auxiliary function.
(cid_face_open): Add new argument `face_index' to return quickly
if less than zero.  Updated all callers.
Call `cid_hex_to_binary', then open and assign memory stream to
`face->cid_stream' if `parser->binary_length' is non-zero.
* src/cid/cidload.h: Updated.

* src/cid/cidobjs.c (cid_face_done): Free `binary_data' and
`cid_stream'.

* src/cid/cidparse.c (cid_parser_new): Check arguments to
`StartData' and set parser->binary_length accordingly.
* src/cid/cidparse.h (CID_Parser): New member `binary_length'.

* src/cid/cidgload.c (cid_load_glyph): Use `face->cid_stream'.

* docs/CHANGES: Updated.


include/freetype/config/ftstdlib.h (ft_atoi): Replaced with...
(ft_atol): This.
* src/base/ftdbgmem.c: s/atol/ft_atol/.
* src/type42/t42drivr.c: s/ft_atoi/ft_atol/.
This commit is contained in:
Werner Lemberg 2004-01-23 19:52:40 +00:00
parent c464f6be08
commit f4c46c688e
12 changed files with 200 additions and 31 deletions

View File

@ -1,3 +1,37 @@
2004-01-22 Werner Lemberg <wl@gnu.org>
Add support for the hexadicimal representation of binary data
started with `StartData' in CID-keyed Type 1 fonts.
* include/freetype/internal/t1types.h (CID_FaceRec): Add new
members `binary_data' and `cid_stream'.
* src/cid/cidload.c (cid_read_subrs): Use `face->cid_stream'.
(cid_hex_to_binary): New auxiliary function.
(cid_face_open): Add new argument `face_index' to return quickly
if less than zero. Updated all callers.
Call `cid_hex_to_binary', then open and assign memory stream to
`face->cid_stream' if `parser->binary_length' is non-zero.
* src/cid/cidload.h: Updated.
* src/cid/cidobjs.c (cid_face_done): Free `binary_data' and
`cid_stream'.
* src/cid/cidparse.c (cid_parser_new): Check arguments to
`StartData' and set parser->binary_length accordingly.
* src/cid/cidparse.h (CID_Parser): New member `binary_length'.
* src/cid/cidgload.c (cid_load_glyph): Use `face->cid_stream'.
* docs/CHANGES: Updated.
2004-01-21 Werner Lemberg <wl@gnu.org>
include/freetype/config/ftstdlib.h (ft_atoi): Replaced with...
(ft_atol): This.
* src/base/ftdbgmem.c: s/atol/ft_atol/.
* src/type42/t42drivr.c: s/ft_atoi/ft_atol/.
2004-01-20 Masatake YAMATO <jet@gyve.org>
* include/freetype/ftcache.h: Delete duplicated definition of

View File

@ -38,6 +38,11 @@ LATEST CHANGES BETWEEN 2.1.8 and 2.1.7
`tttables.h') is available to get the language ID of a
TrueType/SFNT cmap.
- The hexadecimal format of data after the `StartData' command in
CID-keyed Type 1 fonts is now supported. While this can't occur
in file-based fonts, it can happen in document-embedded
resources of PostScript documents.
- The cache sub-system has been rewritten.
- There is now support for deinstallation of faces.

View File

@ -5,7 +5,7 @@
/* ANSI-specific library and header configuration file (specification */
/* only). */
/* */
/* Copyright 2002, 2003 by */
/* Copyright 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -110,7 +110,7 @@
#define ft_qsort qsort
#define ft_exit exit /* only used to exit from unhandled exceptions */
#define ft_atoi atoi
#define ft_atol atol
/**********************************************************************/

View File

@ -5,7 +5,7 @@
/* Basic Type1/Type2 type definitions and interface (specification */
/* only). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -173,6 +173,8 @@ FT_BEGIN_HEADER
void* psaux;
CID_FaceInfoRec cid;
void* afm_data;
FT_Byte* binary_data; /* used if hex data has been converted */
FT_Stream cid_stream;
CID_Subrs subrs;
/* since FT 2.1 - interface to PostScript hinter */

View File

@ -4,7 +4,7 @@
/* */
/* Memory debugger (body). */
/* */
/* Copyright 2001, 2002, 2003 by */
/* Copyright 2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -604,7 +604,7 @@
p = getenv( "FT2_ALLOC_TOTAL_MAX" );
if ( p != NULL )
{
FT_Long total_max = atol(p);
FT_Long total_max = ft_atol(p);
if ( total_max > 0 )
{
@ -616,7 +616,7 @@
p = getenv( "FT2_ALLOC_COUNT_MAX" );
if ( p != NULL )
{
FT_Long total_count = atol(p);
FT_Long total_count = ft_atol(p);
if ( total_count > 0 )
{

View File

@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 Glyph Loader (body). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -44,7 +44,7 @@
CID_FaceInfo cid = &face->cid;
FT_Byte* p;
FT_UInt fd_select;
FT_Stream stream = face->root.stream;
FT_Stream stream = face->cid_stream;
FT_Error error = 0;
FT_Byte* charstring = 0;
FT_Memory memory = face->root.memory;

View File

@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (body). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -363,7 +363,7 @@
{
CID_FaceInfo cid = &face->cid;
FT_Memory memory = face->root.memory;
FT_Stream stream = face->root.stream;
FT_Stream stream = face->cid_stream;
FT_Error error;
FT_Int n;
CID_Subrs subr;
@ -399,7 +399,7 @@
/* read the subrmap's offsets */
if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) )
FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) )
goto Fail;
p = (FT_Byte*)stream->cursor;
@ -487,11 +487,111 @@
}
static FT_Error
cid_hex_to_binary( FT_Byte* data,
FT_Long data_len,
FT_ULong offset,
CID_Face face )
{
FT_Stream stream = face->root.stream;
FT_Error error;
FT_Byte buffer[256];
FT_Byte *p, *plimit;
FT_Byte *d, *dlimit;
FT_Byte val;
FT_Bool upper_nibble, done;
if ( FT_STREAM_SEEK( offset ) )
goto Exit;
d = data;
dlimit = d + data_len;
p = buffer;
plimit = p;
upper_nibble = 1;
done = 0;
while ( d < dlimit )
{
if ( p >= plimit )
{
FT_ULong oldpos = FT_STREAM_POS();
FT_ULong size = stream->size - oldpos;
if ( size == 0 )
{
error = CID_Err_Syntax_Error;
goto Exit;
}
if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) )
goto Exit;
p = buffer;
plimit = p + FT_STREAM_POS() - oldpos;
}
if ( ft_isdigit( *p ) )
val = *p - '0';
else if ( *p >= 'a' && *p <= 'f' )
val = *p - 'a';
else if ( *p >= 'A' && *p <= 'F' )
val = *p - 'A' + 10;
else if ( *p == ' ' ||
*p == '\t' ||
*p == '\r' ||
*p == '\n' ||
*p == '\f' ||
*p == '\0' )
{
p++;
continue;
}
else if ( *p == '>' )
{
val = 0;
done = 1;
}
else
{
error = CID_Err_Syntax_Error;
goto Exit;
}
if ( upper_nibble )
*d = val << 4;
else
{
*d += val;
d++;
}
upper_nibble = 1 - upper_nibble;
if ( done )
break;
p++;
}
error = CID_Err_Ok;
Exit:
return error;
}
FT_LOCAL_DEF( FT_Error )
cid_face_open( CID_Face face )
cid_face_open( CID_Face face,
FT_Int face_index )
{
CID_Loader loader;
CID_Parser* parser;
FT_Memory memory = face->root.memory;
FT_Error error;
@ -509,7 +609,30 @@
if ( error )
goto Exit;
face->cid.data_offset = loader.parser.data_offset;
if ( face_index < 0 )
goto Exit;
if ( parser->binary_length )
{
/* we must convert the data section from hexadecimal to binary */
if ( FT_ALLOC( face->binary_data, parser->binary_length ) ||
cid_hex_to_binary( face->binary_data, parser->binary_length,
parser->data_offset, face ) )
goto Exit;
if ( FT_NEW( face->cid_stream ) )
goto Exit;
FT_Stream_OpenMemory( face->cid_stream,
face->binary_data, parser->binary_length );
face->cid.data_offset = 0;
}
else
{
face->cid_stream = face->root.stream;
face->cid.data_offset = loader.parser.data_offset;
}
error = cid_read_subrs( face );
Exit:

View File

@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (specification). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -41,7 +41,8 @@ FT_BEGIN_HEADER
FT_Byte offsize );
FT_LOCAL( FT_Error )
cid_face_open( CID_Face face );
cid_face_open( CID_Face face,
FT_Int face_index );
FT_END_HEADER

View File

@ -4,7 +4,7 @@
/* */
/* CID objects manager (body). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -234,6 +234,9 @@
face->root.family_name = 0;
face->root.style_name = 0;
FT_FREE( face->binary_data );
FT_FREE( face->cid_stream );
}
}
@ -275,7 +278,6 @@
FT_UNUSED( num_params );
FT_UNUSED( params );
FT_UNUSED( face_index );
FT_UNUSED( stream );
@ -305,7 +307,7 @@
if ( FT_STREAM_SEEK( 0 ) )
goto Exit;
error = cid_face_open( face );
error = cid_face_open( face, face_index );
if ( error )
goto Exit;

View File

@ -140,22 +140,23 @@
/* in a comment or string. We also get its arguments to find out */
/* whether the data is represented in binary or hex format. */
arg1 = parser->root.cursor;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
arg2 = parser->root.cursor;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
limit = parser->root.limit;
cur = parser->root.cursor;
arg1 = cur;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
arg2 = cur;
cid_parser_skip_PS_token( parser );
cid_parser_skip_spaces ( parser );
while ( cur < limit )
{
if ( *cur == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 )
{
if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
parser->data_type = 1;
parser->binary_length = ft_atol( (const char *)arg2 );
limit = parser->root.limit;
cur = parser->root.cursor;
goto Exit;

View File

@ -50,8 +50,8 @@ FT_BEGIN_HEADER
/* data_offset :: The start position of the binary data (i.e., the */
/* end of the data to be parsed. */
/* */
/* data_type :: If true, the binary data is represented in */
/* hexadecimal format. */
/* binary_length :: The length of the data after the `StartData' */
/* command if the data format is hexadecimal. */
/* */
/* cid :: A structure which holds the information about */
/* the current font. */
@ -67,7 +67,8 @@ FT_BEGIN_HEADER
FT_Long postscript_len;
FT_ULong data_offset;
FT_Bool data_type;
FT_Long binary_length;
CID_FaceInfo cid;
FT_Int num_dict;

View File

@ -4,7 +4,7 @@
/* */
/* High-level Type 42 driver interface (body). */
/* */
/* Copyright 2002, 2003 by Roberto Alameda. */
/* Copyright 2002, 2003, 2004 by Roberto Alameda. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
@ -95,7 +95,7 @@
gname = face->type1.glyph_names[i];
if ( !ft_strcmp( glyph_name, gname ) )
return ft_atoi( (const char *)face->type1.charstrings[i] );
return (FT_UInt)ft_atol( (const char *)face->type1.charstrings[i] );
}
return 0;