2000-06-16 08:49:56 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* cidload.c */
|
|
|
|
/* */
|
|
|
|
/* CID-keyed Type1 font loader (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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
#include FT_CONFIG_CONFIG_H
|
|
|
|
#include FT_MULTIPLE_MASTERS_H
|
|
|
|
#include FT_INTERNAL_TYPE1_TYPES_H
|
|
|
|
#include FT_INTERNAL_TYPE1_ERRORS_H
|
2000-12-13 20:55:11 +01:00
|
|
|
#include FT_SOURCE_FILE(cid,cidload.h)
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h> /* for isspace(), isalnum() */
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
2000-06-01 05:27:48 +02:00
|
|
|
#undef FT_COMPONENT
|
2000-06-16 08:49:56 +02:00
|
|
|
#define FT_COMPONENT trace_cidload
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-07-01 00:24:36 +02:00
|
|
|
/* read a single offset */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_LOCAL_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Long cid_get_offset( FT_Byte** start,
|
|
|
|
FT_Byte offsize )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Long result;
|
|
|
|
FT_Byte* p = *start;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
for ( result = 0; offsize > 0; offsize-- )
|
2000-07-01 00:24:36 +02:00
|
|
|
{
|
|
|
|
result <<= 8;
|
|
|
|
result |= *p++;
|
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
*start = p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_LOCAL_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
void cid_decrypt( FT_Byte* buffer,
|
|
|
|
FT_Int length,
|
|
|
|
FT_UShort seed )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
while ( length > 0 )
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Byte plain;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
plain = ( *buffer ^ ( seed >> 8 ) );
|
|
|
|
seed = ( *buffer + seed ) * 52845 + 22719;
|
2000-06-01 05:27:48 +02:00
|
|
|
*buffer++ = plain;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** TYPE 1 SYMBOL PARSING *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
static
|
2000-08-24 00:47:44 +02:00
|
|
|
FT_Error cid_load_keyword( CID_Face face,
|
|
|
|
CID_Loader* loader,
|
|
|
|
const T1_Field* keyword )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-07-01 00:24:36 +02:00
|
|
|
FT_Error error;
|
|
|
|
CID_Parser* parser = &loader->parser;
|
|
|
|
FT_Byte* object;
|
2000-08-24 00:47:44 +02:00
|
|
|
void* dummy_object;
|
2000-07-01 00:24:36 +02:00
|
|
|
CID_Info* cid = &face->cid;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* if the keyword has a dedicated callback, call it */
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( keyword->type == t1_field_callback )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-08-24 00:47:44 +02:00
|
|
|
keyword->reader( (FT_Face)face, parser );
|
|
|
|
error = parser->root.error;
|
2000-06-01 05:27:48 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we must now compute the address of our target object */
|
2000-06-16 08:49:56 +02:00
|
|
|
switch ( keyword->location )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
case t1_field_cid_info:
|
2000-06-16 21:34:52 +02:00
|
|
|
object = (FT_Byte*)cid;
|
2000-06-16 08:49:56 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t1_field_font_info:
|
2000-06-16 21:34:52 +02:00
|
|
|
object = (FT_Byte*)&cid->font_info;
|
2000-06-16 08:49:56 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
CID_FontDict* dict;
|
|
|
|
|
|
|
|
|
|
|
|
if ( parser->num_dict < 0 )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
FT_ERROR(( "cid_load_keyword: invalid use of `%s'!\n",
|
|
|
|
keyword->ident ));
|
|
|
|
error = T1_Err_Syntax_Error;
|
|
|
|
goto Exit;
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
dict = cid->font_dicts + parser->num_dict;
|
|
|
|
switch ( keyword->location )
|
|
|
|
{
|
|
|
|
case t1_field_private:
|
2000-06-16 21:34:52 +02:00
|
|
|
object = (FT_Byte*)&dict->private_dict;
|
2000-06-16 08:49:56 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-06-16 21:34:52 +02:00
|
|
|
object = (FT_Byte*)dict;
|
2000-06-16 08:49:56 +02:00
|
|
|
}
|
|
|
|
}
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
dummy_object = object;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* now, load the keyword data in the object's field(s) */
|
|
|
|
if ( keyword->type == t1_field_integer_array ||
|
|
|
|
keyword->type == t1_field_fixed_array )
|
2000-08-24 00:47:44 +02:00
|
|
|
error = CID_Load_Field_Table( &loader->parser, keyword,
|
|
|
|
&dummy_object );
|
2000-06-01 05:27:48 +02:00
|
|
|
else
|
2000-08-24 00:47:44 +02:00
|
|
|
error = CID_Load_Field( &loader->parser, keyword, &dummy_object );
|
2000-06-01 05:27:48 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-06-16 08:49:56 +02:00
|
|
|
}
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error parse_font_bbox( CID_Face face,
|
2000-06-16 08:49:56 +02:00
|
|
|
CID_Parser* parser )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2001-03-10 20:04:41 +01:00
|
|
|
FT_Fixed temp[4];
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_BBox* bbox = &face->cid.font_bbox;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2001-03-10 20:04:41 +01:00
|
|
|
(void)CID_ToFixedArray( parser, 4, temp, 0 );
|
|
|
|
bbox->xMin = FT_RoundFix( temp[0] );
|
|
|
|
bbox->yMin = FT_RoundFix( temp[1] );
|
|
|
|
bbox->xMax = FT_RoundFix( temp[2] );
|
|
|
|
bbox->yMax = FT_RoundFix( temp[3] );
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
return T1_Err_Ok; /* this is a callback function; */
|
|
|
|
/* we must return an error code */
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error parse_font_matrix( CID_Face face,
|
2000-06-16 08:49:56 +02:00
|
|
|
CID_Parser* parser )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Matrix* matrix;
|
2000-08-24 00:47:44 +02:00
|
|
|
FT_Vector* offset;
|
2000-06-01 05:27:48 +02:00
|
|
|
CID_FontDict* dict;
|
2001-03-10 20:04:41 +01:00
|
|
|
FT_Face root = (FT_Face)&face->root;
|
2000-08-24 00:47:44 +02:00
|
|
|
FT_Fixed temp[6];
|
2001-03-10 20:04:41 +01:00
|
|
|
FT_Fixed temp_scale;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2001-03-11 12:28:39 +01:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( parser->num_dict >= 0 )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
dict = face->cid.font_dicts + parser->num_dict;
|
|
|
|
matrix = &dict->font_matrix;
|
2000-08-24 00:47:44 +02:00
|
|
|
offset = &dict->font_offset;
|
|
|
|
|
|
|
|
(void)CID_ToFixedArray( parser, 6, temp, 3 );
|
|
|
|
|
2001-03-10 20:04:41 +01:00
|
|
|
temp_scale = ABS( temp[3] );
|
|
|
|
|
2001-03-11 12:28:39 +01:00
|
|
|
/* Set Units per EM based on FontMatrix values. We set the value to */
|
|
|
|
/* `1000/temp_scale', because temp_scale was already multiplied by */
|
|
|
|
/* 1000 (in t1_tofixed(), from psobjs.c). */
|
|
|
|
root->units_per_EM = FT_DivFix( 0x10000L,
|
|
|
|
FT_DivFix( temp_scale, 1000 ) );
|
2001-03-10 20:04:41 +01:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
/* we need to scale the values by 1.0/temp[3] */
|
2001-03-10 20:04:41 +01:00
|
|
|
if ( temp_scale != 0x10000L )
|
2000-08-24 00:47:44 +02:00
|
|
|
{
|
2001-03-10 20:04:41 +01:00
|
|
|
temp[0] = FT_DivFix( temp[0], temp_scale );
|
|
|
|
temp[1] = FT_DivFix( temp[1], temp_scale );
|
|
|
|
temp[2] = FT_DivFix( temp[2], temp_scale );
|
|
|
|
temp[4] = FT_DivFix( temp[4], temp_scale );
|
|
|
|
temp[5] = FT_DivFix( temp[5], temp_scale );
|
2000-08-24 00:47:44 +02:00
|
|
|
temp[3] = 0x10000L;
|
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
matrix->xx = temp[0];
|
|
|
|
matrix->yx = temp[1];
|
|
|
|
matrix->xy = temp[2];
|
|
|
|
matrix->yy = temp[3];
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-05 06:53:31 +02:00
|
|
|
/* note that the font offsets are expressed in integer font units */
|
2000-10-04 00:03:09 +02:00
|
|
|
offset->x = temp[4] >> 16;
|
|
|
|
offset->y = temp[5] >> 16;
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
return T1_Err_Ok; /* this is a callback function; */
|
|
|
|
/* we must return an error code */
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error parse_fd_array( CID_Face face,
|
2000-06-16 08:49:56 +02:00
|
|
|
CID_Parser* parser )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
CID_Info* cid = &face->cid;
|
|
|
|
FT_Memory memory = face->root.memory;
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error error = T1_Err_Ok;
|
|
|
|
FT_Long num_dicts;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
num_dicts = CID_ToInt( parser );
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
if ( !cid->font_dicts )
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Int n;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
if ( ALLOC_ARRAY( cid->font_dicts, num_dicts, CID_FontDict ) )
|
|
|
|
goto Exit;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-16 21:34:52 +02:00
|
|
|
cid->num_dicts = (FT_UInt)num_dicts;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
/* don't forget to set a few defaults */
|
2000-06-01 05:27:48 +02:00
|
|
|
for ( n = 0; n < cid->num_dicts; n++ )
|
|
|
|
{
|
|
|
|
CID_FontDict* dict = cid->font_dicts + n;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* default value for lenIV */
|
2000-06-01 05:27:48 +02:00
|
|
|
dict->private_dict.lenIV = 4;
|
|
|
|
}
|
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2000-08-24 00:47:44 +02:00
|
|
|
const T1_Field cid_field_records[] =
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-07-08 02:41:13 +02:00
|
|
|
#ifdef FT_FLAT_COMPILE
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-07-08 02:41:13 +02:00
|
|
|
#include "cidtokens.h"
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-07-08 02:41:13 +02:00
|
|
|
#else
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-07-08 02:41:13 +02:00
|
|
|
#include <cid/cidtokens.h>
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-07-08 02:41:13 +02:00
|
|
|
#endif
|
2000-07-08 21:51:42 +02:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
T1_FIELD_CALLBACK( "FontBBox", parse_font_bbox )
|
|
|
|
T1_FIELD_CALLBACK( "FDArray", parse_fd_array )
|
|
|
|
T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix )
|
2000-08-29 18:50:01 +02:00
|
|
|
{ 0, t1_field_cid_info, t1_field_none, 0, 0, 0, 0, 0 }
|
2000-06-01 05:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2000-06-16 08:49:56 +02:00
|
|
|
int is_alpha( char c )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-07-31 14:14:27 +02:00
|
|
|
return ( isalnum( (int)c ) ||
|
|
|
|
c == '.' ||
|
|
|
|
c == '_' );
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2000-08-24 00:47:44 +02:00
|
|
|
FT_Error cid_parse_dict( CID_Face face,
|
|
|
|
CID_Loader* loader,
|
|
|
|
FT_Byte* base,
|
|
|
|
FT_Long size )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
CID_Parser* parser = &loader->parser;
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
parser->root.cursor = base;
|
|
|
|
parser->root.limit = base + size;
|
|
|
|
parser->root.error = 0;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Byte* cur = base;
|
|
|
|
FT_Byte* limit = cur + size;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
for ( ;cur < limit; cur++ )
|
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
/* look for `%ADOBeginFontDict' */
|
2000-06-01 05:27:48 +02:00
|
|
|
if ( *cur == '%' && cur + 20 < limit &&
|
|
|
|
strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 )
|
|
|
|
{
|
|
|
|
cur += 17;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* if /FDArray was found, then cid->num_dicts is > 0, and */
|
|
|
|
/* we can start increasing parser->num_dict */
|
|
|
|
if ( face->cid.num_dicts > 0 )
|
|
|
|
parser->num_dict++;
|
|
|
|
}
|
|
|
|
/* look for immediates */
|
2000-06-16 08:49:56 +02:00
|
|
|
else if ( *cur == '/' && cur + 2 < limit )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Byte* cur2;
|
|
|
|
FT_Int len;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
cur++;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
cur2 = cur;
|
2000-06-16 08:49:56 +02:00
|
|
|
while ( cur2 < limit && is_alpha( *cur2 ) )
|
|
|
|
cur2++;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2001-03-10 18:07:42 +01:00
|
|
|
len = (FT_Int)( cur2 - cur );
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( len > 0 && len < 22 )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-07-01 00:24:36 +02:00
|
|
|
/* now compare the immediate name to the keyword table */
|
2000-08-24 00:47:44 +02:00
|
|
|
const T1_Field* keyword = cid_field_records;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Byte* name;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 21:34:52 +02:00
|
|
|
name = (FT_Byte*)keyword->ident;
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( !name )
|
|
|
|
break;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( cur[0] == name[0] &&
|
2000-06-16 21:34:52 +02:00
|
|
|
len == (FT_Int)strlen( (const char*)name ) )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Int n;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
for ( n = 1; n < len; n++ )
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( cur[n] != name[n] )
|
2000-06-01 05:27:48 +02:00
|
|
|
break;
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( n >= len )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
/* we found it - run the parsing callback */
|
2000-08-24 00:47:44 +02:00
|
|
|
parser->root.cursor = cur2;
|
|
|
|
CID_Skip_Spaces( parser );
|
2000-08-24 18:29:15 +02:00
|
|
|
parser->root.error = cid_load_keyword( face,
|
|
|
|
loader,
|
|
|
|
keyword );
|
2000-08-24 00:47:44 +02:00
|
|
|
if ( parser->root.error )
|
|
|
|
return parser->root.error;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
cur = parser->root.cursor;
|
2000-06-01 05:27:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keyword++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-24 00:47:44 +02:00
|
|
|
return parser->root.error;
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read the subrmap and the subrs of each font dict */
|
|
|
|
static
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error cid_read_subrs( CID_Face face )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
CID_Info* cid = &face->cid;
|
|
|
|
FT_Memory memory = face->root.memory;
|
|
|
|
FT_Stream stream = face->root.stream;
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error error;
|
2000-06-28 01:20:35 +02:00
|
|
|
FT_Int n;
|
2000-06-01 05:27:48 +02:00
|
|
|
CID_Subrs* subr;
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_UInt max_offsets = 0;
|
|
|
|
FT_ULong* offsets = 0;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
if ( ALLOC_ARRAY( face->subrs, cid->num_dicts, CID_Subrs ) )
|
|
|
|
goto Exit;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
subr = face->subrs;
|
|
|
|
for ( n = 0; n < cid->num_dicts; n++, subr++ )
|
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
CID_FontDict* dict = cid->font_dicts + n;
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_UInt count, num_subrs = dict->num_subrs;
|
|
|
|
FT_ULong data_len;
|
|
|
|
FT_Byte* p;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* reallocate offsets array if needed */
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( num_subrs + 1 > max_offsets )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_UInt new_max = ( num_subrs + 1 + 3 ) & -4;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
2000-06-16 21:34:52 +02:00
|
|
|
if ( REALLOC_ARRAY( offsets, max_offsets, new_max, FT_ULong ) )
|
2000-06-01 05:27:48 +02:00
|
|
|
goto Fail;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
max_offsets = new_max;
|
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* read the subrmap's offsets */
|
|
|
|
if ( FILE_Seek( cid->data_offset + dict->subrmap_offset ) ||
|
2000-06-16 08:49:56 +02:00
|
|
|
ACCESS_Frame( ( num_subrs + 1 ) * dict->sd_bytes ) )
|
2000-06-01 05:27:48 +02:00
|
|
|
goto Fail;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
p = (FT_Byte*)stream->cursor;
|
|
|
|
for ( count = 0; count <= num_subrs; count++ )
|
2000-06-28 06:19:49 +02:00
|
|
|
offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes );
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
FORGET_Frame();
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
/* now, compute the size of subrs charstrings, */
|
|
|
|
/* allocate, and read them */
|
2000-06-01 05:27:48 +02:00
|
|
|
data_len = offsets[num_subrs] - offsets[0];
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-07-01 00:24:36 +02:00
|
|
|
if ( ALLOC_ARRAY( subr->code, num_subrs + 1, FT_Byte* ) ||
|
|
|
|
ALLOC( subr->code[0], data_len ) )
|
2000-06-01 05:27:48 +02:00
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
if ( FILE_Seek( cid->data_offset + offsets[0] ) ||
|
|
|
|
FILE_Read( subr->code[0], data_len ) )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* set up pointers */
|
|
|
|
for ( count = 1; count <= num_subrs; count++ )
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_UInt len;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
len = offsets[count] - offsets[count - 1];
|
|
|
|
subr->code[count] = subr->code[count - 1] + len;
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
/* decrypt subroutines */
|
2000-06-01 05:27:48 +02:00
|
|
|
for ( count = 0; count < num_subrs; count++ )
|
|
|
|
{
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_UInt len;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
len = offsets[count + 1] - offsets[count];
|
2000-06-01 05:27:48 +02:00
|
|
|
cid_decrypt( subr->code[count], len, 4330 );
|
|
|
|
}
|
|
|
|
|
|
|
|
subr->num_subrs = num_subrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
FREE( offsets );
|
|
|
|
return error;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
Fail:
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( face->subrs )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
for ( n = 0; n < cid->num_dicts; n++ )
|
|
|
|
{
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( face->subrs[n].code )
|
2000-06-01 05:27:48 +02:00
|
|
|
FREE( face->subrs[n].code[0] );
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
FREE( face->subrs[n].code );
|
|
|
|
}
|
|
|
|
FREE( face->subrs );
|
|
|
|
}
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
static
|
2000-06-16 08:49:56 +02:00
|
|
|
void t1_init_loader( CID_Loader* loader,
|
|
|
|
CID_Face face )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
2000-07-04 20:12:13 +02:00
|
|
|
FT_UNUSED( face );
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
MEM_Set( loader, 0, sizeof ( *loader ) );
|
2000-06-01 05:27:48 +02:00
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
static
|
2000-06-16 08:49:56 +02:00
|
|
|
void t1_done_loader( CID_Loader* loader )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
CID_Parser* parser = &loader->parser;
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
/* finalize parser */
|
|
|
|
CID_Done_Parser( parser );
|
|
|
|
}
|
|
|
|
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_LOCAL_DEF
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error CID_Open_Face( CID_Face face )
|
2000-06-01 05:27:48 +02:00
|
|
|
{
|
|
|
|
CID_Loader loader;
|
|
|
|
CID_Parser* parser;
|
2000-06-16 21:34:52 +02:00
|
|
|
FT_Error error;
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
t1_init_loader( &loader, face );
|
|
|
|
|
|
|
|
parser = &loader.parser;
|
2000-08-24 00:47:44 +02:00
|
|
|
error = CID_New_Parser( parser, face->root.stream, face->root.memory,
|
|
|
|
(PSAux_Interface*)face->psaux );
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
2000-08-24 00:47:44 +02:00
|
|
|
error = cid_parse_dict( face, &loader,
|
|
|
|
parser->postscript,
|
|
|
|
parser->postscript_len );
|
2000-06-16 08:49:56 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-06-01 05:27:48 +02:00
|
|
|
|
|
|
|
face->cid.data_offset = loader.parser.data_offset;
|
|
|
|
error = cid_read_subrs( face );
|
2000-06-16 08:49:56 +02:00
|
|
|
|
2000-06-01 05:27:48 +02:00
|
|
|
Exit:
|
|
|
|
t1_done_loader( &loader );
|
|
|
|
return error;
|
|
|
|
}
|
2000-06-16 08:49:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|