ReactOS 0.4.16-dev-257-g6aa11ac
cidload.c File Reference
#include <ft2build.h>
#include "cidload.h"
#include "ciderrs.h"
#include "cidtoken.h"
Include dependency graph for cidload.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   trace_cidload
 

Functions

 cid_get_offset (FT_Byte **start, FT_Byte offsize)
 
static FT_Error cid_load_keyword (CID_Face face, CID_Loader *loader, const T1_Field keyword)
 
 cid_parse_font_matrix (CID_Face face, CID_Parser *parser)
 
 parse_fd_array (CID_Face face, CID_Parser *parser)
 
 parse_expansion_factor (CID_Face face, CID_Parser *parser)
 
static FT_Error cid_parse_dict (CID_Face face, CID_Loader *loader, FT_Byte *base, FT_ULong size)
 
static FT_Error cid_read_subrs (CID_Face face)
 
static void cid_init_loader (CID_Loader *loader, CID_Face face)
 
static void cid_done_loader (CID_Loader *loader)
 
static FT_Error cid_hex_to_binary (FT_Byte *data, FT_ULong data_len, FT_ULong offset, CID_Face face)
 
 cid_face_open (CID_Face face, FT_Int face_index)
 

Variables

static const T1_FieldRec cid_field_records []
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   trace_cidload

Definition at line 37 of file cidload.c.

Function Documentation

◆ cid_done_loader()

static void cid_done_loader ( CID_Loader loader)
static

Definition at line 581 of file cidload.c.

582 {
583 CID_Parser* parser = &loader->parser;
584
585
586 /* finalize parser */
588 }
cid_parser_done(CID_Parser *parser)
Definition: cidparse.c:263
FT_BEGIN_HEADER struct CID_Parser_ CID_Parser
Definition: import.c:81

Referenced by cid_face_open().

◆ cid_face_open()

cid_face_open ( CID_Face  face,
FT_Int  face_index 
)

Definition at line 690 of file cidload.c.

692 {
693 CID_Loader loader;
695 FT_Memory memory = face->root.memory;
697 FT_Int n;
698
699 CID_FaceInfo cid = &face->cid;
700
701 FT_ULong binary_length;
702 FT_ULong entry_len;
703
704
705 cid_init_loader( &loader, face );
706
707 parser = &loader.parser;
708 error = cid_parser_new( parser, face->root.stream, face->root.memory,
709 (PSAux_Service)face->psaux );
710 if ( error )
711 goto Exit;
712
713 error = cid_parse_dict( face, &loader,
714 parser->postscript,
715 parser->postscript_len );
716 if ( error )
717 goto Exit;
718
719 if ( face_index < 0 )
720 goto Exit;
721
722 if ( FT_NEW( face->cid_stream ) )
723 goto Exit;
724
725 if ( parser->binary_length )
726 {
727 if ( parser->binary_length >
728 face->root.stream->size - parser->data_offset )
729 {
730 FT_TRACE0(( "cid_face_open: adjusting length of binary data\n"
731 " (from %d to %d bytes)\n",
732 parser->binary_length,
733 face->root.stream->size - parser->data_offset ));
734 parser->binary_length = face->root.stream->size -
735 parser->data_offset;
736 }
737
738 /* we must convert the data section from hexadecimal to binary */
739 if ( FT_ALLOC( face->binary_data, parser->binary_length ) ||
740 FT_SET_ERROR( cid_hex_to_binary( face->binary_data,
741 parser->binary_length,
742 parser->data_offset,
743 face ) ) )
744 goto Exit;
745
746 FT_Stream_OpenMemory( face->cid_stream,
747 face->binary_data, parser->binary_length );
748 cid->data_offset = 0;
749 }
750 else
751 {
752 *face->cid_stream = *face->root.stream;
753 cid->data_offset = loader.parser.data_offset;
754 }
755
756 /* sanity tests */
757
758 if ( cid->fd_bytes < 0 || cid->gd_bytes < 1 )
759 {
760 FT_ERROR(( "cid_parse_dict:"
761 " Invalid `FDBytes' or `GDBytes' value\n" ));
762 error = FT_THROW( Invalid_File_Format );
763 goto Exit;
764 }
765
766 /* allow at most 32bit offsets */
767 if ( cid->fd_bytes > 4 || cid->gd_bytes > 4 )
768 {
769 FT_ERROR(( "cid_parse_dict:"
770 " Values of `FDBytes' or `GDBytes' larger than 4\n"
771 " "
772 " are not supported\n" ));
773 error = FT_THROW( Invalid_File_Format );
774 goto Exit;
775 }
776
777 binary_length = face->cid_stream->size - cid->data_offset;
778 entry_len = (FT_ULong)( cid->fd_bytes + cid->gd_bytes );
779
780 for ( n = 0; n < cid->num_dicts; n++ )
781 {
782 CID_FaceDict dict = cid->font_dicts + n;
783
784
785 if ( dict->sd_bytes < 0 ||
786 ( dict->num_subrs && dict->sd_bytes < 1 ) )
787 {
788 FT_ERROR(( "cid_parse_dict: Invalid `SDBytes' value\n" ));
789 error = FT_THROW( Invalid_File_Format );
790 goto Exit;
791 }
792
793 if ( dict->sd_bytes > 4 )
794 {
795 FT_ERROR(( "cid_parse_dict:"
796 " Values of `SDBytes' larger than 4"
797 " are not supported\n" ));
798 error = FT_THROW( Invalid_File_Format );
799 goto Exit;
800 }
801
802 if ( dict->subrmap_offset > binary_length )
803 {
804 FT_ERROR(( "cid_parse_dict: Invalid `SubrMapOffset' value\n" ));
805 error = FT_THROW( Invalid_File_Format );
806 goto Exit;
807 }
808
809 /* `num_subrs' is scanned as a signed integer */
810 if ( (FT_Int)dict->num_subrs < 0 ||
811 ( dict->sd_bytes &&
812 dict->num_subrs > ( binary_length - dict->subrmap_offset ) /
813 (FT_UInt)dict->sd_bytes ) )
814 {
815 FT_ERROR(( "cid_parse_dict: Invalid `SubrCount' value\n" ));
816 error = FT_THROW( Invalid_File_Format );
817 goto Exit;
818 }
819 }
820
821 if ( cid->cidmap_offset > binary_length )
822 {
823 FT_ERROR(( "cid_parse_dict: Invalid `CIDMapOffset' value\n" ));
824 error = FT_THROW( Invalid_File_Format );
825 goto Exit;
826 }
827
828 if ( entry_len &&
829 cid->cid_count >
830 ( binary_length - cid->cidmap_offset ) / entry_len )
831 {
832 FT_ERROR(( "cid_parse_dict: Invalid `CIDCount' value\n" ));
833 error = FT_THROW( Invalid_File_Format );
834 goto Exit;
835 }
836
837 /* we can now safely proceed */
839
840 Exit:
841 cid_done_loader( &loader );
842 return error;
843 }
static FT_Error cid_read_subrs(CID_Face face)
Definition: cidload.c:438
static void cid_init_loader(CID_Loader *loader, CID_Face face)
Definition: cidload.c:571
static void cid_done_loader(CID_Loader *loader)
Definition: cidload.c:581
static FT_Error cid_hex_to_binary(FT_Byte *data, FT_ULong data_len, FT_ULong offset, CID_Face face)
Definition: cidload.c:592
static FT_Error cid_parse_dict(CID_Face face, CID_Loader *loader, FT_Byte *base, FT_ULong size)
Definition: cidload.c:320
FT_BEGIN_HEADER struct CID_Loader_ CID_Loader
cid_parser_new(CID_Parser *parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux)
Definition: cidparse.c:57
#define FT_TRACE0(varformat)
Definition: ftdebug.h:157
#define FT_ERROR(varformat)
Definition: ftdebug.h:181
#define FT_THROW(e)
Definition: ftdebug.h:213
#define FT_NEW(ptr)
Definition: ftmemory.h:331
#define FT_SET_ERROR(expression)
Definition: ftmemory.h:42
#define FT_ALLOC(ptr, size)
Definition: ftmemory.h:303
FT_Stream_OpenMemory(FT_Stream stream, const FT_Byte *base, FT_ULong size)
Definition: ftstream.c:35
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:300
unsigned int FT_UInt
Definition: fttypes.h:231
signed int FT_Int
Definition: fttypes.h:220
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:116
static TfClientId cid
static void Exit(void)
Definition: sock.c:1330
FT_ULong subrmap_offset
Definition: t1tables.h:356
FT_UInt num_subrs
Definition: t1tables.h:355
FT_Int sd_bytes
Definition: t1tables.h:357

Referenced by cid_face_init().

◆ cid_get_offset()

cid_get_offset ( FT_Byte **  start,
FT_Byte  offsize 
)

Definition at line 42 of file cidload.c.

44 {
46 FT_Byte* p = *start;
47
48
49 for ( result = 0; offsize > 0; offsize-- )
50 {
51 result <<= 8;
52 result |= *p++;
53 }
54
55 *start = p;
56 return result;
57 }
unsigned char FT_Byte
Definition: fttypes.h:154
GLuint start
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304

Referenced by cid_load_glyph(), and cid_read_subrs().

◆ cid_hex_to_binary()

static FT_Error cid_hex_to_binary ( FT_Byte data,
FT_ULong  data_len,
FT_ULong  offset,
CID_Face  face 
)
static

Definition at line 592 of file cidload.c.

596 {
597 FT_Stream stream = face->root.stream;
599
600 FT_Byte buffer[256];
601 FT_Byte *p, *plimit;
602 FT_Byte *d, *dlimit;
603 FT_Byte val;
604
605 FT_Bool upper_nibble, done;
606
607
608 if ( FT_STREAM_SEEK( offset ) )
609 goto Exit;
610
611 d = data;
612 dlimit = d + data_len;
613 p = buffer;
614 plimit = p;
615
616 upper_nibble = 1;
617 done = 0;
618
619 while ( d < dlimit )
620 {
621 if ( p >= plimit )
622 {
623 FT_ULong oldpos = FT_STREAM_POS();
624 FT_ULong size = stream->size - oldpos;
625
626
627 if ( size == 0 )
628 {
629 error = FT_THROW( Syntax_Error );
630 goto Exit;
631 }
632
633 if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) )
634 goto Exit;
635 p = buffer;
636 plimit = p + FT_STREAM_POS() - oldpos;
637 }
638
639 if ( ft_isdigit( *p ) )
640 val = (FT_Byte)( *p - '0' );
641 else if ( *p >= 'a' && *p <= 'f' )
642 val = (FT_Byte)( *p - 'a' );
643 else if ( *p >= 'A' && *p <= 'F' )
644 val = (FT_Byte)( *p - 'A' + 10 );
645 else if ( *p == ' ' ||
646 *p == '\t' ||
647 *p == '\r' ||
648 *p == '\n' ||
649 *p == '\f' ||
650 *p == '\0' )
651 {
652 p++;
653 continue;
654 }
655 else if ( *p == '>' )
656 {
657 val = 0;
658 done = 1;
659 }
660 else
661 {
662 error = FT_THROW( Syntax_Error );
663 goto Exit;
664 }
665
666 if ( upper_nibble )
667 *d = (FT_Byte)( val << 4 );
668 else
669 {
670 *d = (FT_Byte)( *d + val );
671 d++;
672 }
673
674 upper_nibble = (FT_Byte)( 1 - upper_nibble );
675
676 if ( done )
677 break;
678
679 p++;
680 }
681
683
684 Exit:
685 return error;
686 }
return FT_Err_Ok
Definition: ftbbox.c:511
#define ft_isdigit(x)
Definition: ftobjs.h:118
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:489
#define FT_STREAM_POS()
Definition: ftstream.h:486
#define FT_STREAM_READ(buffer, count)
Definition: ftstream.h:497
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
GLuint GLfloat * val
Definition: glext.h:7180
GLintptr offset
Definition: glext.h:5920
#define d
Definition: ke_i.h:81
Definition: parse.h:23
unsigned int size
Definition: parse.h:27

Referenced by cid_face_open().

◆ cid_init_loader()

static void cid_init_loader ( CID_Loader loader,
CID_Face  face 
)
static

Definition at line 571 of file cidload.c.

573 {
574 FT_UNUSED( face );
575
576 FT_ZERO( loader );
577 }
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
#define FT_ZERO(p)
Definition: ftmemory.h:237

Referenced by cid_face_open().

◆ cid_load_keyword()

static FT_Error cid_load_keyword ( CID_Face  face,
CID_Loader loader,
const T1_Field  keyword 
)
static

Definition at line 70 of file cidload.c.

73 {
75 CID_Parser* parser = &loader->parser;
77 void* dummy_object;
78 CID_FaceInfo cid = &face->cid;
79
80
81 /* if the keyword has a dedicated callback, call it */
82 if ( keyword->type == T1_FIELD_TYPE_CALLBACK )
83 {
84 keyword->reader( (FT_Face)face, parser );
85 error = parser->root.error;
86 goto Exit;
87 }
88
89 /* we must now compute the address of our target object */
90 switch ( keyword->location )
91 {
93 object = (FT_Byte*)cid;
94 break;
95
97 object = (FT_Byte*)&cid->font_info;
98 break;
99
101 object = (FT_Byte*)&face->font_extra;
102 break;
103
105 object = (FT_Byte*)&cid->font_bbox;
106 break;
107
108 default:
109 {
110 CID_FaceDict dict;
111
112
113 if ( parser->num_dict < 0 || parser->num_dict >= cid->num_dicts )
114 {
115 FT_ERROR(( "cid_load_keyword: invalid use of `%s'\n",
116 keyword->ident ));
117 error = FT_THROW( Syntax_Error );
118 goto Exit;
119 }
120
121 dict = cid->font_dicts + parser->num_dict;
122 switch ( keyword->location )
123 {
125 object = (FT_Byte*)&dict->private_dict;
126 break;
127
128 default:
129 object = (FT_Byte*)dict;
130 }
131 }
132 }
133
134 dummy_object = object;
135
136 /* now, load the keyword data in the object's field(s) */
137 if ( keyword->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
139 error = cid_parser_load_field_table( &loader->parser, keyword,
140 &dummy_object );
141 else
142 error = cid_parser_load_field( &loader->parser,
143 keyword, &dummy_object );
144 Exit:
145 return error;
146 }
#define cid_parser_load_field(p, f, o)
Definition: cidparse.h:112
#define cid_parser_load_field_table(p, f, o)
Definition: cidparse.h:114
if(dx< 0)
Definition: linetemp.h:194
@ T1_FIELD_TYPE_INTEGER_ARRAY
Definition: psaux.h:211
@ T1_FIELD_TYPE_CALLBACK
Definition: psaux.h:213
@ T1_FIELD_TYPE_FIXED_ARRAY
Definition: psaux.h:212
@ T1_FIELD_LOCATION_FONT_EXTRA
Definition: psaux.h:225
@ T1_FIELD_LOCATION_CID_INFO
Definition: psaux.h:223
@ T1_FIELD_LOCATION_BBOX
Definition: psaux.h:228
@ T1_FIELD_LOCATION_PRIVATE
Definition: psaux.h:227
@ T1_FIELD_LOCATION_FONT_INFO
Definition: psaux.h:226
unsigned int error
Definition: inffile.c:97

Referenced by cid_parse_dict().

◆ cid_parse_dict()

static FT_Error cid_parse_dict ( CID_Face  face,
CID_Loader loader,
FT_Byte base,
FT_ULong  size 
)
static

Definition at line 320 of file cidload.c.

324 {
325 CID_Parser* parser = &loader->parser;
326
327
328 parser->root.cursor = base;
329 parser->root.limit = base + size;
330 parser->root.error = FT_Err_Ok;
331
332 {
333 FT_Byte* cur = base;
334 FT_Byte* limit = cur + size;
335
336
337 for (;;)
338 {
339 FT_Byte* newlimit;
340
341
342 parser->root.cursor = cur;
344
345 if ( parser->root.cursor >= limit )
346 newlimit = limit - 1 - 17;
347 else
348 newlimit = parser->root.cursor - 17;
349
350 /* look for `%ADOBeginFontDict' */
351 for ( ; cur < newlimit; cur++ )
352 {
353 if ( *cur == '%' &&
354 ft_strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 )
355 {
356 /* if /FDArray was found, then cid->num_dicts is > 0, and */
357 /* we can start increasing parser->num_dict */
358 if ( face->cid.num_dicts > 0 )
359 parser->num_dict++;
360 }
361 }
362
363 cur = parser->root.cursor;
364 /* no error can occur in cid_parser_skip_spaces */
365 if ( cur >= limit )
366 break;
367
369 if ( parser->root.cursor >= limit || parser->root.error )
370 break;
371
372 /* look for immediates */
373 if ( *cur == '/' && cur + 2 < limit )
374 {
375 FT_UInt len;
376
377
378 cur++;
379 len = (FT_UInt)( parser->root.cursor - cur );
380
381 if ( len > 0 && len < 22 )
382 {
383 /* now compare the immediate name to the keyword table */
385
386
387 for (;;)
388 {
389 FT_Byte* name;
390
391
392 name = (FT_Byte*)keyword->ident;
393 if ( !name )
394 break;
395
396 if ( cur[0] == name[0] &&
397 len == ft_strlen( (const char*)name ) )
398 {
399 FT_UInt n;
400
401
402 for ( n = 1; n < len; n++ )
403 if ( cur[n] != name[n] )
404 break;
405
406 if ( n >= len )
407 {
408 /* we found it - run the parsing callback */
410 loader,
411 keyword );
412 if ( parser->root.error )
413 return parser->root.error;
414 break;
415 }
416 }
417 keyword++;
418 }
419 }
420 }
421
422 cur = parser->root.cursor;
423 }
424
425 if ( !face->cid.num_dicts )
426 {
427 FT_ERROR(( "cid_parse_dict: No font dictionary found\n" ));
428 return FT_THROW( Invalid_File_Format );
429 }
430 }
431
432 return parser->root.error;
433 }
static FT_Error cid_load_keyword(CID_Face face, CID_Loader *loader, const T1_Field keyword)
Definition: cidload.c:70
static const T1_FieldRec cid_field_records[]
Definition: cidload.c:306
#define cid_parser_skip_PS_token(p)
Definition: cidparse.h:97
#define cid_parser_skip_spaces(p)
Definition: cidparse.h:95
#define ft_strncmp
Definition: ftstdlib.h:89
#define ft_strlen
Definition: ftstdlib.h:88
FxCollectionEntry * cur
GLint limit
Definition: glext.h:10326
GLenum GLsizei len
Definition: glext.h:6722
struct T1_FieldRec_ * T1_Field
Definition: psaux.h:171
Definition: name.c:39

Referenced by cid_face_open().

◆ cid_parse_font_matrix()

cid_parse_font_matrix ( CID_Face  face,
CID_Parser parser 
)

Definition at line 150 of file cidload.c.

152 {
153 CID_FaceDict dict;
154 FT_Face root = (FT_Face)&face->root;
155 FT_Fixed temp[6];
156 FT_Fixed temp_scale;
157
158
159 if ( parser->num_dict >= 0 && parser->num_dict < face->cid.num_dicts )
160 {
164
165
166 dict = face->cid.font_dicts + parser->num_dict;
167 matrix = &dict->font_matrix;
168 offset = &dict->font_offset;
169
170 /* input is scaled by 1000 to accommodate default FontMatrix */
172
173 if ( result < 6 )
174 return FT_THROW( Invalid_File_Format );
175
176 temp_scale = FT_ABS( temp[3] );
177
178 if ( temp_scale == 0 )
179 {
180 FT_ERROR(( "cid_parse_font_matrix: invalid font matrix\n" ));
181 return FT_THROW( Invalid_File_Format );
182 }
183
184 /* atypical case */
185 if ( temp_scale != 0x10000L )
186 {
187 /* set units per EM based on FontMatrix values */
188 root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale );
189
190 temp[0] = FT_DivFix( temp[0], temp_scale );
191 temp[1] = FT_DivFix( temp[1], temp_scale );
192 temp[2] = FT_DivFix( temp[2], temp_scale );
193 temp[4] = FT_DivFix( temp[4], temp_scale );
194 temp[5] = FT_DivFix( temp[5], temp_scale );
195 temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
196 }
197
198 matrix->xx = temp[0];
199 matrix->yx = temp[1];
200 matrix->xy = temp[2];
201 matrix->yy = temp[3];
202
203 /* note that the font offsets are expressed in integer font units */
204 offset->x = temp[4] >> 16;
205 offset->y = temp[5] >> 16;
206 }
207
208 return FT_Err_Ok;
209 }
#define cid_parser_to_fixed_array(p, m, f, t)
Definition: cidparse.h:105
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:608
struct FT_FaceRec_ * FT_Face
Definition: freetype.h:503
#define FT_ABS(a)
Definition: ftobjs.h:74
signed long FT_Fixed
Definition: fttypes.h:288
unsigned short FT_UShort
Definition: fttypes.h:209
GLuint GLenum matrix
Definition: glext.h:9407
static calc_node_t temp
Definition: rpn_ieee.c:38
FT_Matrix font_matrix
Definition: t1tables.h:352
FT_Vector font_offset
Definition: t1tables.h:353

◆ cid_read_subrs()

static FT_Error cid_read_subrs ( CID_Face  face)
static

Definition at line 438 of file cidload.c.

439 {
440 CID_FaceInfo cid = &face->cid;
441 FT_Memory memory = face->root.memory;
442 FT_Stream stream = face->cid_stream;
444 FT_Int n;
445 CID_Subrs subr;
446 FT_UInt max_offsets = 0;
448 PSAux_Service psaux = (PSAux_Service)face->psaux;
449
450
451 if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) )
452 goto Exit;
453
454 subr = face->subrs;
455 for ( n = 0; n < cid->num_dicts; n++, subr++ )
456 {
457 CID_FaceDict dict = cid->font_dicts + n;
459 FT_UInt count, num_subrs = dict->num_subrs;
460 FT_ULong data_len;
461 FT_Byte* p;
462
463
464 if ( !num_subrs )
465 continue;
466
467 /* reallocate offsets array if needed */
468 if ( num_subrs + 1 > max_offsets )
469 {
470 FT_UInt new_max = FT_PAD_CEIL( num_subrs + 1, 4 );
471
472
473 if ( new_max <= max_offsets )
474 {
475 error = FT_THROW( Syntax_Error );
476 goto Fail;
477 }
478
479 if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) )
480 goto Fail;
481
482 max_offsets = new_max;
483 }
484
485 /* read the subrmap's offsets */
486 if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
487 FT_FRAME_ENTER( ( num_subrs + 1 ) * (FT_UInt)dict->sd_bytes ) )
488 goto Fail;
489
490 p = (FT_Byte*)stream->cursor;
491 for ( count = 0; count <= num_subrs; count++ )
493
495
496 /* offsets must be ordered */
497 for ( count = 1; count <= num_subrs; count++ )
498 if ( offsets[count - 1] > offsets[count] )
499 {
500 FT_ERROR(( "cid_read_subrs: offsets are not ordered\n" ));
501 error = FT_THROW( Invalid_File_Format );
502 goto Fail;
503 }
504
505 if ( offsets[num_subrs] > stream->size - cid->data_offset )
506 {
507 FT_ERROR(( "cid_read_subrs: too large `subrs' offsets\n" ));
508 error = FT_THROW( Invalid_File_Format );
509 goto Fail;
510 }
511
512 /* now, compute the size of subrs charstrings, */
513 /* allocate, and read them */
514 data_len = offsets[num_subrs] - offsets[0];
515
516 if ( FT_NEW_ARRAY( subr->code, num_subrs + 1 ) ||
517 FT_ALLOC( subr->code[0], data_len ) )
518 goto Fail;
519
520 if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) ||
521 FT_STREAM_READ( subr->code[0], data_len ) )
522 goto Fail;
523
524 /* set up pointers */
525 for ( count = 1; count <= num_subrs; count++ )
526 {
528
529
530 len = offsets[count] - offsets[count - 1];
531 subr->code[count] = subr->code[count - 1] + len;
532 }
533
534 /* decrypt subroutines, but only if lenIV >= 0 */
535 if ( lenIV >= 0 )
536 {
537 for ( count = 0; count < num_subrs; count++ )
538 {
540
541
542 len = offsets[count + 1] - offsets[count];
543 psaux->t1_decrypt( subr->code[count], len, 4330 );
544 }
545 }
546
547 subr->num_subrs = (FT_Int)num_subrs;
548 }
549
550 Exit:
551 FT_FREE( offsets );
552 return error;
553
554 Fail:
555 if ( face->subrs )
556 {
557 for ( n = 0; n < cid->num_dicts; n++ )
558 {
559 if ( face->subrs[n].code )
560 FT_FREE( face->subrs[n].code[0] );
561
562 FT_FREE( face->subrs[n].code );
563 }
564 FT_FREE( face->subrs );
565 }
566 goto Exit;
567 }
cid_get_offset(FT_Byte **start, FT_Byte offsize)
Definition: cidload.c:42
#define NULL
Definition: types.h:112
int Fail
Definition: ehthrow.cxx:24
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:333
#define FT_FREE(ptr)
Definition: ftmemory.h:329
#define FT_RENEW_ARRAY(ptr, curcnt, newcnt)
Definition: ftmemory.h:336
#define FT_PAD_CEIL(x, n)
Definition: ftobjs.h:90
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:512
#define FT_FRAME_EXIT()
Definition: ftstream.h:517
static const FxOffsetAndName offsets[]
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define for
Definition: utility.h:88
struct PSAux_ServiceRec_ * PSAux_Service
PS_PrivateRec private_dict
Definition: t1tables.h:343
FT_Byte ** code
Definition: t1types.h:133
FT_Int num_subrs
Definition: t1types.h:132
void(* t1_decrypt)(FT_Byte *buffer, FT_Offset length, FT_UShort seed)
Definition: psaux.h:1287
FT_Int lenIV
Definition: t1tables.h:141
lenIV
Definition: t1tokens.h:60

Referenced by cid_face_open().

◆ parse_expansion_factor()

parse_expansion_factor ( CID_Face  face,
CID_Parser parser 
)

Definition at line 287 of file cidload.c.

289 {
290 CID_FaceDict dict;
291
292
293 if ( parser->num_dict >= 0 && parser->num_dict < face->cid.num_dicts )
294 {
295 dict = face->cid.font_dicts + parser->num_dict;
296
299 }
300
301 return FT_Err_Ok;
302 }
#define cid_parser_to_fixed(p, t)
Definition: cidparse.h:101
FT_Fixed expansion_factor
Definition: t1tables.h:348
FT_Fixed expansion_factor
Definition: t1tables.h:169

◆ parse_fd_array()

parse_fd_array ( CID_Face  face,
CID_Parser parser 
)

Definition at line 213 of file cidload.c.

215 {
216 CID_FaceInfo cid = &face->cid;
217 FT_Memory memory = face->root.memory;
218 FT_Stream stream = parser->stream;
220 FT_Long num_dicts;
221
222
223 num_dicts = cid_parser_to_int( parser );
224 if ( num_dicts < 0 )
225 {
226 FT_ERROR(( "parse_fd_array: invalid number of dictionaries\n" ));
227 error = FT_THROW( Invalid_File_Format );
228 goto Exit;
229 }
230
231 /*
232 * A single entry in the FDArray must (at least) contain the following
233 * structure elements.
234 *
235 * %ADOBeginFontDict 18
236 * X dict begin 13
237 * /FontMatrix [X X X X] 22
238 * /Private X dict begin 22
239 * end 4
240 * end 4
241 * %ADOEndFontDict 16
242 *
243 * This needs 18+13+22+22+4+4+16=99 bytes or more. Normally, you also
244 * need a `dup X' at the very beginning and a `put' at the end, so a
245 * rough guess using 100 bytes as the minimum is justified.
246 */
247 if ( (FT_ULong)num_dicts > stream->size / 100 )
248 {
249 FT_TRACE0(( "parse_fd_array: adjusting FDArray size"
250 " (from %d to %d)\n",
251 num_dicts,
252 stream->size / 100 ));
253 num_dicts = (FT_Long)( stream->size / 100 );
254 }
255
256 if ( !cid->font_dicts )
257 {
258 FT_Int n;
259
260
261 if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) )
262 goto Exit;
263
264 cid->num_dicts = num_dicts;
265
266 /* don't forget to set a few defaults */
267 for ( n = 0; n < cid->num_dicts; n++ )
268 {
269 CID_FaceDict dict = cid->font_dicts + n;
270
271
272 /* default value for lenIV */
273 dict->private_dict.lenIV = 4;
274 }
275 }
276
277 Exit:
278 return error;
279 }
#define cid_parser_to_int(p)
Definition: cidparse.h:100
signed long FT_Long
Definition: fttypes.h:242

Variable Documentation

◆ cid_field_records

const T1_FieldRec cid_field_records[]
static
Initial value:
=
{
T1_FIELD_CALLBACK( "ExpansionFactor", parse_expansion_factor, 0 )
}
parse_expansion_factor(CID_Face face, CID_Parser *parser)
Definition: cidload.c:287
@ T1_FIELD_TYPE_NONE
Definition: psaux.h:202
#define T1_FIELD_CALLBACK(_ident, _name, _dict)
Definition: psaux.h:349

Definition at line 306 of file cidload.c.

Referenced by cid_parse_dict().