freetype/src/cid/cidparse.c
Werner Lemberg 1f7f0e87e5 Complete redesign of error codes. Please check ftmoderr.h for more
details.

* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed.  Replaced with files
local to the module.  All extra error codes have been moved to
`fterrors.h'.

* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.

* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.

* include/freetype/ftmoderr.h: New file, defining the module error
offsets.  Its structure is similar to `fterrors.h'.

* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.

* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.

All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.

All make files have been updated to include the local error files.


* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.

* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 17:30:41 +00:00

158 lines
5.3 KiB
C

/***************************************************************************/
/* */
/* cidparse.c */
/* */
/* CID-keyed Type1 parser (body). */
/* */
/* Copyright 1996-2000 by */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include "cidparse.h"
#include "ciderrs.h"
#include <string.h> /* for strncmp() */
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_cidparse
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** INPUT STREAM PARSER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF
FT_Error CID_New_Parser( CID_Parser* parser,
FT_Stream stream,
FT_Memory memory,
PSAux_Interface* psaux )
{
FT_Error error;
FT_ULong base_offset, offset, ps_len;
FT_Byte buffer[256 + 10];
FT_Int buff_len;
MEM_Set( parser, 0, sizeof ( *parser ) );
psaux->t1_parser_funcs->init( &parser->root, 0, 0, memory );
parser->stream = stream;
base_offset = FILE_Pos();
/* first of all, check the font format in the header */
if ( ACCESS_Frame( 31 ) )
goto Exit;
if ( strncmp( (char *)stream->cursor,
"%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )
{
FT_TRACE2(( "[not a valid CID-keyed font]\n" ));
error = CID_Err_Unknown_File_Format;
}
FORGET_Frame();
if ( error )
goto Exit;
/* now, read the rest of the file, until we find a `StartData' */
buff_len = 256;
for (;;)
{
FT_Byte *p, *limit = buffer + 256;
FT_ULong top_position;
/* fill input buffer */
buff_len -= 256;
if ( buff_len > 0 )
MEM_Move( buffer, limit, buff_len );
p = buffer + buff_len;
if ( FILE_Read( p, 256 + 10 - buff_len ) )
goto Exit;
top_position = FILE_Pos() - buff_len;
buff_len = 256 + 10;
/* look for `StartData' */
for ( p = buffer; p < limit; p++ )
{
if ( p[0] == 'S' && strncmp( (char*)p, "StartData", 9 ) == 0 )
{
/* save offset of binary data after `StartData' */
offset = (FT_ULong)( top_position - ( limit - p ) + 10 );
goto Found;
}
}
}
Found:
/* we have found the start of the binary data. We will now */
/* rewind and extract the frame of corresponding to the Postscript */
/* section */
ps_len = offset - base_offset;
if ( FILE_Seek( base_offset ) ||
EXTRACT_Frame( ps_len, parser->postscript ) )
goto Exit;
parser->data_offset = offset;
parser->postscript_len = ps_len;
parser->root.base = parser->postscript;
parser->root.cursor = parser->postscript;
parser->root.limit = parser->root.cursor + ps_len;
parser->num_dict = -1;
Exit:
return error;
}
FT_LOCAL_DEF
void CID_Done_Parser( CID_Parser* parser )
{
/* always free the private dictionary */
if ( parser->postscript )
{
FT_Stream stream = parser->stream;
RELEASE_Frame( parser->postscript );
}
parser->root.funcs.done( &parser->root );
}
/* END */