zenilib: zenilib/jni/external/freetype2/src/psaux/afmparse.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
afmparse.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* afmparse.c */
4 /* */
5 /* AFM parser (body). */
6 /* */
7 /* Copyright 2006-2010, 2012 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
17
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 #include FT_INTERNAL_POSTSCRIPT_AUX_H
21
22 #include "afmparse.h"
23 #include "psconv.h"
24
25 #include "psauxerr.h"
26
27
28 /***************************************************************************/
29 /* */
30 /* AFM_Stream */
31 /* */
32 /* The use of AFM_Stream is largely inspired by parseAFM.[ch] from t1lib. */
33 /* */
34 /* */
35
36 enum
37 {
38 AFM_STREAM_STATUS_NORMAL,
39 AFM_STREAM_STATUS_EOC,
40 AFM_STREAM_STATUS_EOL,
41 AFM_STREAM_STATUS_EOF
42 };
43
44
45 typedef struct AFM_StreamRec_
46 {
47 FT_Byte* cursor;
48 FT_Byte* base;
49 FT_Byte* limit;
50
51 FT_Int status;
52
53 } AFM_StreamRec;
54
55
56 #ifndef EOF
57 #define EOF -1
58 #endif
59
60
61 /* this works because empty lines are ignored */
62 #define AFM_IS_NEWLINE( ch ) ( (ch) == '\r' || (ch) == '\n' )
63
64 #define AFM_IS_EOF( ch ) ( (ch) == EOF || (ch) == '\x1a' )
65 #define AFM_IS_SPACE( ch ) ( (ch) == ' ' || (ch) == '\t' )
66
67 /* column separator; there is no `column' in the spec actually */
68 #define AFM_IS_SEP( ch ) ( (ch) == ';' )
69
70 #define AFM_GETC() \
71 ( ( (stream)->cursor < (stream)->limit ) ? *(stream)->cursor++ \
72 : EOF )
73
74 #define AFM_STREAM_KEY_BEGIN( stream ) \
75 (char*)( (stream)->cursor - 1 )
76
77 #define AFM_STREAM_KEY_LEN( stream, key ) \
78 ( (char*)(stream)->cursor - key - 1 )
79
80 #define AFM_STATUS_EOC( stream ) \
81 ( (stream)->status >= AFM_STREAM_STATUS_EOC )
82
83 #define AFM_STATUS_EOL( stream ) \
84 ( (stream)->status >= AFM_STREAM_STATUS_EOL )
85
86 #define AFM_STATUS_EOF( stream ) \
87 ( (stream)->status >= AFM_STREAM_STATUS_EOF )
88
89
90 static int
91 afm_stream_skip_spaces( AFM_Stream stream )
92 {
93 int ch = 0; /* make stupid compiler happy */
94
95
96 if ( AFM_STATUS_EOC( stream ) )
97 return ';';
98
99 while ( 1 )
100 {
101 ch = AFM_GETC();
102 if ( !AFM_IS_SPACE( ch ) )
103 break;
104 }
105
106 if ( AFM_IS_NEWLINE( ch ) )
107 stream->status = AFM_STREAM_STATUS_EOL;
108 else if ( AFM_IS_SEP( ch ) )
109 stream->status = AFM_STREAM_STATUS_EOC;
110 else if ( AFM_IS_EOF( ch ) )
111 stream->status = AFM_STREAM_STATUS_EOF;
112
113 return ch;
114 }
115
116
117 /* read a key or value in current column */
118 static char*
119 afm_stream_read_one( AFM_Stream stream )
120 {
121 char* str;
122 int ch;
123
124
125 afm_stream_skip_spaces( stream );
126 if ( AFM_STATUS_EOC( stream ) )
127 return NULL;
128
129 str = AFM_STREAM_KEY_BEGIN( stream );
130
131 while ( 1 )
132 {
133 ch = AFM_GETC();
134 if ( AFM_IS_SPACE( ch ) )
135 break;
136 else if ( AFM_IS_NEWLINE( ch ) )
137 {
138 stream->status = AFM_STREAM_STATUS_EOL;
139 break;
140 }
141 else if ( AFM_IS_SEP( ch ) )
142 {
143 stream->status = AFM_STREAM_STATUS_EOC;
144 break;
145 }
146 else if ( AFM_IS_EOF( ch ) )
147 {
148 stream->status = AFM_STREAM_STATUS_EOF;
149 break;
150 }
151 }
152
153 return str;
154 }
155
156
157 /* read a string (i.e., read to EOL) */
158 static char*
159 afm_stream_read_string( AFM_Stream stream )
160 {
161 char* str;
162 int ch;
163
164
165 afm_stream_skip_spaces( stream );
166 if ( AFM_STATUS_EOL( stream ) )
167 return NULL;
168
169 str = AFM_STREAM_KEY_BEGIN( stream );
170
171 /* scan to eol */
172 while ( 1 )
173 {
174 ch = AFM_GETC();
175 if ( AFM_IS_NEWLINE( ch ) )
176 {
177 stream->status = AFM_STREAM_STATUS_EOL;
178 break;
179 }
180 else if ( AFM_IS_EOF( ch ) )
181 {
182 stream->status = AFM_STREAM_STATUS_EOF;
183 break;
184 }
185 }
186
187 return str;
188 }
189
190
191 /*************************************************************************/
192 /* */
193 /* AFM_Parser */
194 /* */
195 /* */
196
197 /* all keys defined in Ch. 7-10 of 5004.AFM_Spec.pdf */
198 typedef enum AFM_Token_
199 {
200 AFM_TOKEN_ASCENDER,
201 AFM_TOKEN_AXISLABEL,
202 AFM_TOKEN_AXISTYPE,
203 AFM_TOKEN_B,
204 AFM_TOKEN_BLENDAXISTYPES,
205 AFM_TOKEN_BLENDDESIGNMAP,
206 AFM_TOKEN_BLENDDESIGNPOSITIONS,
207 AFM_TOKEN_C,
208 AFM_TOKEN_CC,
209 AFM_TOKEN_CH,
210 AFM_TOKEN_CAPHEIGHT,
211 AFM_TOKEN_CHARWIDTH,
212 AFM_TOKEN_CHARACTERSET,
213 AFM_TOKEN_CHARACTERS,
214 AFM_TOKEN_DESCENDER,
215 AFM_TOKEN_ENCODINGSCHEME,
216 AFM_TOKEN_ENDAXIS,
217 AFM_TOKEN_ENDCHARMETRICS,
218 AFM_TOKEN_ENDCOMPOSITES,
219 AFM_TOKEN_ENDDIRECTION,
220 AFM_TOKEN_ENDFONTMETRICS,
221 AFM_TOKEN_ENDKERNDATA,
222 AFM_TOKEN_ENDKERNPAIRS,
223 AFM_TOKEN_ENDTRACKKERN,
224 AFM_TOKEN_ESCCHAR,
225 AFM_TOKEN_FAMILYNAME,
226 AFM_TOKEN_FONTBBOX,
227 AFM_TOKEN_FONTNAME,
228 AFM_TOKEN_FULLNAME,
229 AFM_TOKEN_ISBASEFONT,
230 AFM_TOKEN_ISCIDFONT,
231 AFM_TOKEN_ISFIXEDPITCH,
232 AFM_TOKEN_ISFIXEDV,
233 AFM_TOKEN_ITALICANGLE,
234 AFM_TOKEN_KP,
235 AFM_TOKEN_KPH,
236 AFM_TOKEN_KPX,
237 AFM_TOKEN_KPY,
238 AFM_TOKEN_L,
239 AFM_TOKEN_MAPPINGSCHEME,
240 AFM_TOKEN_METRICSSETS,
241 AFM_TOKEN_N,
242 AFM_TOKEN_NOTICE,
243 AFM_TOKEN_PCC,
244 AFM_TOKEN_STARTAXIS,
245 AFM_TOKEN_STARTCHARMETRICS,
246 AFM_TOKEN_STARTCOMPOSITES,
247 AFM_TOKEN_STARTDIRECTION,
248 AFM_TOKEN_STARTFONTMETRICS,
249 AFM_TOKEN_STARTKERNDATA,
250 AFM_TOKEN_STARTKERNPAIRS,
251 AFM_TOKEN_STARTKERNPAIRS0,
252 AFM_TOKEN_STARTKERNPAIRS1,
253 AFM_TOKEN_STARTTRACKKERN,
254 AFM_TOKEN_STDHW,
255 AFM_TOKEN_STDVW,
256 AFM_TOKEN_TRACKKERN,
257 AFM_TOKEN_UNDERLINEPOSITION,
258 AFM_TOKEN_UNDERLINETHICKNESS,
259 AFM_TOKEN_VV,
260 AFM_TOKEN_VVECTOR,
261 AFM_TOKEN_VERSION,
262 AFM_TOKEN_W,
263 AFM_TOKEN_W0,
264 AFM_TOKEN_W0X,
265 AFM_TOKEN_W0Y,
266 AFM_TOKEN_W1,
267 AFM_TOKEN_W1X,
268 AFM_TOKEN_W1Y,
269 AFM_TOKEN_WX,
270 AFM_TOKEN_WY,
271 AFM_TOKEN_WEIGHT,
272 AFM_TOKEN_WEIGHTVECTOR,
273 AFM_TOKEN_XHEIGHT,
274 N_AFM_TOKENS,
275 AFM_TOKEN_UNKNOWN
276
277 } AFM_Token;
278
279
280 static const char* const afm_key_table[N_AFM_TOKENS] =
281 {
282 "Ascender",
283 "AxisLabel",
284 "AxisType",
285 "B",
286 "BlendAxisTypes",
287 "BlendDesignMap",
288 "BlendDesignPositions",
289 "C",
290 "CC",
291 "CH",
292 "CapHeight",
293 "CharWidth",
294 "CharacterSet",
295 "Characters",
296 "Descender",
297 "EncodingScheme",
298 "EndAxis",
299 "EndCharMetrics",
300 "EndComposites",
301 "EndDirection",
302 "EndFontMetrics",
303 "EndKernData",
304 "EndKernPairs",
305 "EndTrackKern",
306 "EscChar",
307 "FamilyName",
308 "FontBBox",
309 "FontName",
310 "FullName",
311 "IsBaseFont",
312 "IsCIDFont",
313 "IsFixedPitch",
314 "IsFixedV",
315 "ItalicAngle",
316 "KP",
317 "KPH",
318 "KPX",
319 "KPY",
320 "L",
321 "MappingScheme",
322 "MetricsSets",
323 "N",
324 "Notice",
325 "PCC",
326 "StartAxis",
327 "StartCharMetrics",
328 "StartComposites",
329 "StartDirection",
330 "StartFontMetrics",
331 "StartKernData",
332 "StartKernPairs",
333 "StartKernPairs0",
334 "StartKernPairs1",
335 "StartTrackKern",
336 "StdHW",
337 "StdVW",
338 "TrackKern",
339 "UnderlinePosition",
340 "UnderlineThickness",
341 "VV",
342 "VVector",
343 "Version",
344 "W",
345 "W0",
346 "W0X",
347 "W0Y",
348 "W1",
349 "W1X",
350 "W1Y",
351 "WX",
352 "WY",
353 "Weight",
354 "WeightVector",
355 "XHeight"
356 };
357
358
359 /*
360 * `afm_parser_read_vals' and `afm_parser_next_key' provide
361 * high-level operations to an AFM_Stream. The rest of the
362 * parser functions should use them without accessing the
363 * AFM_Stream directly.
364 */
365
366 FT_LOCAL_DEF( FT_Int )
367 afm_parser_read_vals( AFM_Parser parser,
368 AFM_Value vals,
369 FT_UInt n )
370 {
371 AFM_Stream stream = parser->stream;
372 char* str;
373 FT_UInt i;
374
375
376 if ( n > AFM_MAX_ARGUMENTS )
377 return 0;
378
379 for ( i = 0; i < n; i++ )
380 {
381 FT_Offset len;
382 AFM_Value val = vals + i;
383
384
385 if ( val->type == AFM_VALUE_TYPE_STRING )
386 str = afm_stream_read_string( stream );
387 else
388 str = afm_stream_read_one( stream );
389
390 if ( !str )
391 break;
392
393 len = AFM_STREAM_KEY_LEN( stream, str );
394
395 switch ( val->type )
396 {
397 case AFM_VALUE_TYPE_STRING:
398 case AFM_VALUE_TYPE_NAME:
399 {
400 FT_Memory memory = parser->memory;
401 FT_Error error;
402
403
404 if ( !FT_QALLOC( val->u.s, len + 1 ) )
405 {
406 ft_memcpy( val->u.s, str, len );
407 val->u.s[len] = '\0';
408 }
409 }
410 break;
411
412 case AFM_VALUE_TYPE_FIXED:
413 val->u.f = PS_Conv_ToFixed( (FT_Byte**)(void*)&str,
414 (FT_Byte*)str + len, 0 );
415 break;
416
417 case AFM_VALUE_TYPE_INTEGER:
418 val->u.i = PS_Conv_ToInt( (FT_Byte**)(void*)&str,
419 (FT_Byte*)str + len );
420 break;
421
422 case AFM_VALUE_TYPE_BOOL:
423 val->u.b = FT_BOOL( len == 4 &&
424 !ft_strncmp( str, "true", 4 ) );
425 break;
426
427 case AFM_VALUE_TYPE_INDEX:
428 if ( parser->get_index )
429 val->u.i = parser->get_index( str, len, parser->user_data );
430 else
431 val->u.i = 0;
432 break;
433 }
434 }
435
436 return i;
437 }
438
439
440 FT_LOCAL_DEF( char* )
441 afm_parser_next_key( AFM_Parser parser,
442 FT_Bool line,
443 FT_Offset* len )
444 {
445 AFM_Stream stream = parser->stream;
446 char* key = 0; /* make stupid compiler happy */
447
448
449 if ( line )
450 {
451 while ( 1 )
452 {
453 /* skip current line */
454 if ( !AFM_STATUS_EOL( stream ) )
455 afm_stream_read_string( stream );
456
457 stream->status = AFM_STREAM_STATUS_NORMAL;
458 key = afm_stream_read_one( stream );
459
460 /* skip empty line */
461 if ( !key &&
462 !AFM_STATUS_EOF( stream ) &&
463 AFM_STATUS_EOL( stream ) )
464 continue;
465
466 break;
467 }
468 }
469 else
470 {
471 while ( 1 )
472 {
473 /* skip current column */
474 while ( !AFM_STATUS_EOC( stream ) )
475 afm_stream_read_one( stream );
476
477 stream->status = AFM_STREAM_STATUS_NORMAL;
478 key = afm_stream_read_one( stream );
479
480 /* skip empty column */
481 if ( !key &&
482 !AFM_STATUS_EOF( stream ) &&
483 AFM_STATUS_EOC( stream ) )
484 continue;
485
486 break;
487 }
488 }
489
490 if ( len )
491 *len = ( key ) ? (FT_Offset)AFM_STREAM_KEY_LEN( stream, key )
492 : 0;
493
494 return key;
495 }
496
497
498 static AFM_Token
499 afm_tokenize( const char* key,
500 FT_Offset len )
501 {
502 int n;
503
504
505 for ( n = 0; n < N_AFM_TOKENS; n++ )
506 {
507 if ( *( afm_key_table[n] ) == *key )
508 {
509 for ( ; n < N_AFM_TOKENS; n++ )
510 {
511 if ( *( afm_key_table[n] ) != *key )
512 return AFM_TOKEN_UNKNOWN;
513
514 if ( ft_strncmp( afm_key_table[n], key, len ) == 0 )
515 return (AFM_Token) n;
516 }
517 }
518 }
519
520 return AFM_TOKEN_UNKNOWN;
521 }
522
523
524 FT_LOCAL_DEF( FT_Error )
525 afm_parser_init( AFM_Parser parser,
526 FT_Memory memory,
527 FT_Byte* base,
528 FT_Byte* limit )
529 {
530 AFM_Stream stream = NULL;
531 FT_Error error;
532
533
534 if ( FT_NEW( stream ) )
535 return error;
536
537 stream->cursor = stream->base = base;
538 stream->limit = limit;
539
540 /* don't skip the first line during the first call */
541 stream->status = AFM_STREAM_STATUS_EOL;
542
543 parser->memory = memory;
544 parser->stream = stream;
545 parser->FontInfo = NULL;
546 parser->get_index = NULL;
547
548 return PSaux_Err_Ok;
549 }
550
551
552 FT_LOCAL( void )
553 afm_parser_done( AFM_Parser parser )
554 {
555 FT_Memory memory = parser->memory;
556
557
558 FT_FREE( parser->stream );
559 }
560
561
562 FT_LOCAL_DEF( FT_Error )
563 afm_parser_read_int( AFM_Parser parser,
564 FT_Int* aint )
565 {
566 AFM_ValueRec val;
567
568
569 val.type = AFM_VALUE_TYPE_INTEGER;
570
571 if ( afm_parser_read_vals( parser, &val, 1 ) == 1 )
572 {
573 *aint = val.u.i;
574
575 return PSaux_Err_Ok;
576 }
577 else
578 return PSaux_Err_Syntax_Error;
579 }
580
581
582 static FT_Error
583 afm_parse_track_kern( AFM_Parser parser )
584 {
585 AFM_FontInfo fi = parser->FontInfo;
586 AFM_TrackKern tk;
587 char* key;
588 FT_Offset len;
589 int n = -1;
590
591
592 if ( afm_parser_read_int( parser, &fi->NumTrackKern ) )
593 goto Fail;
594
595 if ( fi->NumTrackKern )
596 {
597 FT_Memory memory = parser->memory;
598 FT_Error error;
599
600
601 if ( FT_QNEW_ARRAY( fi->TrackKerns, fi->NumTrackKern ) )
602 return error;
603 }
604
605 while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
606 {
607 AFM_ValueRec shared_vals[5];
608
609
610 switch ( afm_tokenize( key, len ) )
611 {
612 case AFM_TOKEN_TRACKKERN:
613 n++;
614
615 if ( n >= fi->NumTrackKern )
616 goto Fail;
617
618 tk = fi->TrackKerns + n;
619
620 shared_vals[0].type = AFM_VALUE_TYPE_INTEGER;
621 shared_vals[1].type = AFM_VALUE_TYPE_FIXED;
622 shared_vals[2].type = AFM_VALUE_TYPE_FIXED;
623 shared_vals[3].type = AFM_VALUE_TYPE_FIXED;
624 shared_vals[4].type = AFM_VALUE_TYPE_FIXED;
625 if ( afm_parser_read_vals( parser, shared_vals, 5 ) != 5 )
626 goto Fail;
627
628 tk->degree = shared_vals[0].u.i;
629 tk->min_ptsize = shared_vals[1].u.f;
630 tk->min_kern = shared_vals[2].u.f;
631 tk->max_ptsize = shared_vals[3].u.f;
632 tk->max_kern = shared_vals[4].u.f;
633
634 break;
635
636 case AFM_TOKEN_ENDTRACKKERN:
637 case AFM_TOKEN_ENDKERNDATA:
638 case AFM_TOKEN_ENDFONTMETRICS:
639 fi->NumTrackKern = n + 1;
640 return PSaux_Err_Ok;
641
642 case AFM_TOKEN_UNKNOWN:
643 break;
644
645 default:
646 goto Fail;
647 }
648 }
649
650 Fail:
651 return PSaux_Err_Syntax_Error;
652 }
653
654
655 #undef KERN_INDEX
656 #define KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 )
657
658
659 /* compare two kerning pairs */
660 FT_CALLBACK_DEF( int )
661 afm_compare_kern_pairs( const void* a,
662 const void* b )
663 {
664 AFM_KernPair kp1 = (AFM_KernPair)a;
665 AFM_KernPair kp2 = (AFM_KernPair)b;
666
667 FT_ULong index1 = KERN_INDEX( kp1->index1, kp1->index2 );
668 FT_ULong index2 = KERN_INDEX( kp2->index1, kp2->index2 );
669
670
671 if ( index1 > index2 )
672 return 1;
673 else if ( index1 < index2 )
674 return -1;
675 else
676 return 0;
677 }
678
679
680 static FT_Error
681 afm_parse_kern_pairs( AFM_Parser parser )
682 {
683 AFM_FontInfo fi = parser->FontInfo;
684 AFM_KernPair kp;
685 char* key;
686 FT_Offset len;
687 int n = -1;
688
689
690 if ( afm_parser_read_int( parser, &fi->NumKernPair ) )
691 goto Fail;
692
693 if ( fi->NumKernPair )
694 {
695 FT_Memory memory = parser->memory;
696 FT_Error error;
697
698
699 if ( FT_QNEW_ARRAY( fi->KernPairs, fi->NumKernPair ) )
700 return error;
701 }
702
703 while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
704 {
705 AFM_Token token = afm_tokenize( key, len );
706
707
708 switch ( token )
709 {
710 case AFM_TOKEN_KP:
711 case AFM_TOKEN_KPX:
712 case AFM_TOKEN_KPY:
713 {
714 FT_Int r;
715 AFM_ValueRec shared_vals[4];
716
717
718 n++;
719
720 if ( n >= fi->NumKernPair )
721 goto Fail;
722
723 kp = fi->KernPairs + n;
724
725 shared_vals[0].type = AFM_VALUE_TYPE_INDEX;
726 shared_vals[1].type = AFM_VALUE_TYPE_INDEX;
727 shared_vals[2].type = AFM_VALUE_TYPE_INTEGER;
728 shared_vals[3].type = AFM_VALUE_TYPE_INTEGER;
729 r = afm_parser_read_vals( parser, shared_vals, 4 );
730 if ( r < 3 )
731 goto Fail;
732
733 kp->index1 = shared_vals[0].u.i;
734 kp->index2 = shared_vals[1].u.i;
735 if ( token == AFM_TOKEN_KPY )
736 {
737 kp->x = 0;
738 kp->y = shared_vals[2].u.i;
739 }
740 else
741 {
742 kp->x = shared_vals[2].u.i;
743 kp->y = ( token == AFM_TOKEN_KP && r == 4 )
744 ? shared_vals[3].u.i : 0;
745 }
746 }
747 break;
748
749 case AFM_TOKEN_ENDKERNPAIRS:
750 case AFM_TOKEN_ENDKERNDATA:
751 case AFM_TOKEN_ENDFONTMETRICS:
752 fi->NumKernPair = n + 1;
753 ft_qsort( fi->KernPairs, fi->NumKernPair,
754 sizeof ( AFM_KernPairRec ),
755 afm_compare_kern_pairs );
756 return PSaux_Err_Ok;
757
758 case AFM_TOKEN_UNKNOWN:
759 break;
760
761 default:
762 goto Fail;
763 }
764 }
765
766 Fail:
767 return PSaux_Err_Syntax_Error;
768 }
769
770
771 static FT_Error
772 afm_parse_kern_data( AFM_Parser parser )
773 {
774 FT_Error error;
775 char* key;
776 FT_Offset len;
777
778
779 while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
780 {
781 switch ( afm_tokenize( key, len ) )
782 {
783 case AFM_TOKEN_STARTTRACKKERN:
784 error = afm_parse_track_kern( parser );
785 if ( error )
786 return error;
787 break;
788
789 case AFM_TOKEN_STARTKERNPAIRS:
790 case AFM_TOKEN_STARTKERNPAIRS0:
791 error = afm_parse_kern_pairs( parser );
792 if ( error )
793 return error;
794 break;
795
796 case AFM_TOKEN_ENDKERNDATA:
797 case AFM_TOKEN_ENDFONTMETRICS:
798 return PSaux_Err_Ok;
799
800 case AFM_TOKEN_UNKNOWN:
801 break;
802
803 default:
804 goto Fail;
805 }
806 }
807
808 Fail:
809 return PSaux_Err_Syntax_Error;
810 }
811
812
813 static FT_Error
814 afm_parser_skip_section( AFM_Parser parser,
815 FT_UInt n,
816 AFM_Token end_section )
817 {
818 char* key;
819 FT_Offset len;
820
821
822 while ( n-- > 0 )
823 {
824 key = afm_parser_next_key( parser, 1, NULL );
825 if ( !key )
826 goto Fail;
827 }
828
829 while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
830 {
831 AFM_Token token = afm_tokenize( key, len );
832
833
834 if ( token == end_section || token == AFM_TOKEN_ENDFONTMETRICS )
835 return PSaux_Err_Ok;
836 }
837
838 Fail:
839 return PSaux_Err_Syntax_Error;
840 }
841
842
843 FT_LOCAL_DEF( FT_Error )
844 afm_parser_parse( AFM_Parser parser )
845 {
846 FT_Memory memory = parser->memory;
847 AFM_FontInfo fi = parser->FontInfo;
848 FT_Error error = PSaux_Err_Syntax_Error;
849 char* key;
850 FT_Offset len;
851 FT_Int metrics_sets = 0;
852
853
854 if ( !fi )
855 return PSaux_Err_Invalid_Argument;
856
857 key = afm_parser_next_key( parser, 1, &len );
858 if ( !key || len != 16 ||
859 ft_strncmp( key, "StartFontMetrics", 16 ) != 0 )
860 return PSaux_Err_Unknown_File_Format;
861
862 while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
863 {
864 AFM_ValueRec shared_vals[4];
865
866
867 switch ( afm_tokenize( key, len ) )
868 {
869 case AFM_TOKEN_METRICSSETS:
870 if ( afm_parser_read_int( parser, &metrics_sets ) )
871 goto Fail;
872
873 if ( metrics_sets != 0 && metrics_sets != 2 )
874 {
875 error = PSaux_Err_Unimplemented_Feature;
876
877 goto Fail;
878 }
879 break;
880
881 case AFM_TOKEN_ISCIDFONT:
882 shared_vals[0].type = AFM_VALUE_TYPE_BOOL;
883 if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
884 goto Fail;
885
886 fi->IsCIDFont = shared_vals[0].u.b;
887 break;
888
889 case AFM_TOKEN_FONTBBOX:
890 shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
891 shared_vals[1].type = AFM_VALUE_TYPE_FIXED;
892 shared_vals[2].type = AFM_VALUE_TYPE_FIXED;
893 shared_vals[3].type = AFM_VALUE_TYPE_FIXED;
894 if ( afm_parser_read_vals( parser, shared_vals, 4 ) != 4 )
895 goto Fail;
896
897 fi->FontBBox.xMin = shared_vals[0].u.f;
898 fi->FontBBox.yMin = shared_vals[1].u.f;
899 fi->FontBBox.xMax = shared_vals[2].u.f;
900 fi->FontBBox.yMax = shared_vals[3].u.f;
901 break;
902
903 case AFM_TOKEN_ASCENDER:
904 shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
905 if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
906 goto Fail;
907
908 fi->Ascender = shared_vals[0].u.f;
909 break;
910
911 case AFM_TOKEN_DESCENDER:
912 shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
913 if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
914 goto Fail;
915
916 fi->Descender = shared_vals[0].u.f;
917 break;
918
919 case AFM_TOKEN_STARTCHARMETRICS:
920 {
921 FT_Int n = 0;
922
923
924 if ( afm_parser_read_int( parser, &n ) )
925 goto Fail;
926
927 error = afm_parser_skip_section( parser, n,
928 AFM_TOKEN_ENDCHARMETRICS );
929 if ( error )
930 return error;
931 }
932 break;
933
934 case AFM_TOKEN_STARTKERNDATA:
935 error = afm_parse_kern_data( parser );
936 if ( error )
937 goto Fail;
938 /* fall through since we only support kern data */
939
940 case AFM_TOKEN_ENDFONTMETRICS:
941 return PSaux_Err_Ok;
942
943 default:
944 break;
945 }
946 }
947
948 Fail:
949 FT_FREE( fi->TrackKerns );
950 fi->NumTrackKern = 0;
951
952 FT_FREE( fi->KernPairs );
953 fi->NumKernPair = 0;
954
955 fi->IsCIDFont = 0;
956
957 return error;
958 }
959
960
961 /* END */
AFM_ParserRec_
Definition: psaux.h:749
afm_key_table
static const char *const afm_key_table[N_AFM_TOKENS]
Definition: afmparse.c:280
AFM_ValueRec_::s
char * s
Definition: afmparse.h:61
AFM_TOKEN_KPH
Definition: afmparse.c:235
AFM_TrackKernRec_
Definition: t1types.h:148
FT_Error
int FT_Error
Definition: fttypes.h:296
AFM_FontInfoRec_::IsCIDFont
FT_Bool IsCIDFont
Definition: t1types.h:169
val
GLuint const GLfloat * val
Definition: glew.h:2715
AFM_TOKEN_XHEIGHT
Definition: afmparse.c:273
AFM_STATUS_EOC
#define AFM_STATUS_EOC(stream)
Definition: afmparse.c:80
AFM_TOKEN_VV
Definition: afmparse.c:259
ft_strncmp
#define ft_strncmp
Definition: ftstdlib.h:88
AFM_KernPair
struct AFM_KernPairRec_ * AFM_KernPair
AFM_TOKEN_STARTCOMPOSITES
Definition: afmparse.c:246
FT_ULong
unsigned long FT_ULong
Definition: fttypes.h:249
psconv.h
AFM_TOKEN_ISCIDFONT
Definition: afmparse.c:230
AFM_TOKEN_ISBASEFONT
Definition: afmparse.c:229
AFM_TOKEN_WX
Definition: afmparse.c:269
AFM_STREAM_STATUS_EOL
Definition: afmparse.c:40
afmparse.h
AFM_TrackKernRec_::max_ptsize
FT_Fixed max_ptsize
Definition: t1types.h:153
AFM_TOKEN_B
Definition: afmparse.c:203
AFM_TOKEN_STARTDIRECTION
Definition: afmparse.c:247
AFM_Stream
struct AFM_StreamRec_ * AFM_Stream
Definition: psaux.h:727
AFM_TrackKernRec_::degree
FT_Int degree
Definition: t1types.h:150
AFM_STREAM_STATUS_EOC
Definition: afmparse.c:39
AFM_TOKEN_W
Definition: afmparse.c:262
AFM_ParserRec_::memory
FT_Memory memory
Definition: psaux.h:751
NULL
#define NULL
Definition: ftobjs.h:61
FT_Int
signed int FT_Int
Definition: fttypes.h:216
AFM_TOKEN_VVECTOR
Definition: afmparse.c:260
AFM_IS_SPACE
#define AFM_IS_SPACE(ch)
Definition: afmparse.c:65
AFM_TOKEN_ASCENDER
Definition: afmparse.c:200
afm_parser_parse
afm_parser_parse(AFM_Parser parser)
Definition: afmparse.c:844
stream
GLuint GLuint stream
Definition: glew.h:6573
n
GLclampd n
Definition: glew.h:7287
AFM_TOKEN_ENCODINGSCHEME
Definition: afmparse.c:215
AFM_TOKEN_STARTCHARMETRICS
Definition: afmparse.c:245
afm_stream_read_one
static char * afm_stream_read_one(AFM_Stream stream)
Definition: afmparse.c:119
AFM_TOKEN_UNDERLINETHICKNESS
Definition: afmparse.c:258
FT_QALLOC
#define FT_QALLOC(ptr, size)
Definition: ftmemory.h:273
FT_QNEW_ARRAY
#define FT_QNEW_ARRAY(ptr, count)
Definition: ftmemory.h:299
KERN_INDEX
#define KERN_INDEX(g1, g2)
Definition: afmparse.c:656
AFM_Token_
AFM_Token_
Definition: afmparse.c:198
afm_parse_kern_pairs
static FT_Error afm_parse_kern_pairs(AFM_Parser parser)
Definition: afmparse.c:681
AFM_TOKEN_BLENDAXISTYPES
Definition: afmparse.c:204
AFM_TOKEN_AXISLABEL
Definition: afmparse.c:201
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
AFM_IS_NEWLINE
#define AFM_IS_NEWLINE(ch)
Definition: afmparse.c:62
AFM_STREAM_KEY_BEGIN
#define AFM_STREAM_KEY_BEGIN(stream)
Definition: afmparse.c:74
AFM_ValueRec_::u
union AFM_ValueRec_::@39 u
AFM_TOKEN_BLENDDESIGNPOSITIONS
Definition: afmparse.c:206
AFM_TOKEN_AXISTYPE
Definition: afmparse.c:202
AFM_FontInfoRec_::NumTrackKern
FT_Int NumTrackKern
Definition: t1types.h:174
AFM_GETC
#define AFM_GETC()
Definition: afmparse.c:70
AFM_TOKEN_STARTAXIS
Definition: afmparse.c:244
afm_parser_next_key
afm_parser_next_key(AFM_Parser parser, FT_Bool line, FT_Offset *len)
Definition: afmparse.c:441
len
GLenum GLsizei len
Definition: glew.h:7035
AFM_TrackKernRec_::min_kern
FT_Fixed min_kern
Definition: t1types.h:152
AFM_TOKEN_CC
Definition: afmparse.c:208
AFM_TOKEN_STARTKERNPAIRS1
Definition: afmparse.c:252
AFM_TOKEN_STARTKERNPAIRS
Definition: afmparse.c:250
AFM_ValueRec_::i
FT_Int i
Definition: afmparse.h:63
afm_parser_done
afm_parser_done(AFM_Parser parser)
Definition: afmparse.c:553
AFM_TOKEN_STARTKERNDATA
Definition: afmparse.c:249
FT_Bool
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
afm_parse_track_kern
static FT_Error afm_parse_track_kern(AFM_Parser parser)
Definition: afmparse.c:583
AFM_TOKEN_CAPHEIGHT
Definition: afmparse.c:210
AFM_TOKEN_FONTBBOX
Definition: afmparse.c:226
AFM_TOKEN_DESCENDER
Definition: afmparse.c:214
AFM_TOKEN_W0
Definition: afmparse.c:263
AFM_KernPairRec_::index2
FT_Int index2
Definition: t1types.h:161
AFM_TOKEN_STDHW
Definition: afmparse.c:254
ft_qsort
#define ft_qsort
Definition: ftstdlib.h:121
AFM_TOKEN_ESCCHAR
Definition: afmparse.c:224
AFM_VALUE_TYPE_STRING
Definition: afmparse.h:47
FT_Byte
unsigned char FT_Byte
Definition: fttypes.h:150
PS_Conv_ToFixed
PS_Conv_ToFixed(FT_Byte **cursor, FT_Byte *limit, FT_Int power_ten)
Definition: psconv.c:143
AFM_TOKEN_NOTICE
Definition: afmparse.c:242
AFM_STATUS_EOF
#define AFM_STATUS_EOF(stream)
Definition: afmparse.c:86
FT_LOCAL
#define FT_LOCAL(x)
Definition: ftconfig.h:466
AFM_TOKEN_WY
Definition: afmparse.c:270
AFM_TOKEN_W0Y
Definition: afmparse.c:265
AFM_ValueRec_::f
FT_Fixed f
Definition: afmparse.h:62
AFM_TOKEN_C
Definition: afmparse.c:207
AFM_TOKEN_ENDCOMPOSITES
Definition: afmparse.c:218
AFM_VALUE_TYPE_BOOL
Definition: afmparse.h:51
AFM_TOKEN_ENDCHARMETRICS
Definition: afmparse.c:217
AFM_TOKEN_W1
Definition: afmparse.c:266
AFM_TOKEN_KPX
Definition: afmparse.c:236
FT_FREE
#define FT_FREE(ptr)
Definition: ftmemory.h:286
AFM_FontInfoRec_::Descender
FT_Fixed Descender
Definition: t1types.h:172
AFM_TOKEN_KPY
Definition: afmparse.c:237
u
ALuint u
Definition: alMain.h:58
AFM_STATUS_EOL
#define AFM_STATUS_EOL(stream)
Definition: afmparse.c:83
FT_BBox_::yMax
FT_Pos yMax
Definition: ftimage.h:119
FT_LOCAL_DEF
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:467
FT_BBox_::xMin
FT_Pos xMin
Definition: ftimage.h:118
AFM_TOKEN_ENDKERNDATA
Definition: afmparse.c:221
AFM_TrackKernRec_::min_ptsize
FT_Fixed min_ptsize
Definition: t1types.h:151
AFM_FontInfoRec_
Definition: t1types.h:167
AFM_TOKEN_ENDFONTMETRICS
Definition: afmparse.c:220
AFM_STREAM_STATUS_EOF
Definition: afmparse.c:41
AFM_TOKEN_METRICSSETS
Definition: afmparse.c:240
error
FT_Error error
Definition: cffdrivr.c:407
AFM_TOKEN_W1X
Definition: afmparse.c:267
AFM_TOKEN_ISFIXEDV
Definition: afmparse.c:232
psauxerr.h
N_AFM_TOKENS
Definition: afmparse.c:274
AFM_KernPairRec_
Definition: t1types.h:158
AFM_TOKEN_ENDTRACKKERN
Definition: afmparse.c:223
AFM_TOKEN_PCC
Definition: afmparse.c:243
AFM_TOKEN_STDVW
Definition: afmparse.c:255
AFM_TOKEN_FULLNAME
Definition: afmparse.c:228
AFM_TOKEN_TRACKKERN
Definition: afmparse.c:256
AFM_ValueRec_
Definition: afmparse.h:56
limit
GLint limit
Definition: glew.h:11829
AFM_TOKEN_BLENDDESIGNMAP
Definition: afmparse.c:205
AFM_KernPairRec_::x
FT_Int x
Definition: t1types.h:162
AFM_TOKEN_L
Definition: afmparse.c:238
afm_parse_kern_data
static FT_Error afm_parse_kern_data(AFM_Parser parser)
Definition: afmparse.c:772
afm_stream_read_string
static char * afm_stream_read_string(AFM_Stream stream)
Definition: afmparse.c:159
AFM_TOKEN_W1Y
Definition: afmparse.c:268
AFM_TOKEN_KP
Definition: afmparse.c:234
FT_CALLBACK_DEF
#define FT_CALLBACK_DEF(x)
Definition: ftconfig.h:554
AFM_FontInfoRec_::KernPairs
AFM_KernPair KernPairs
Definition: t1types.h:175
FT_BBox_::xMax
FT_Pos xMax
Definition: ftimage.h:119
afm_compare_kern_pairs
afm_compare_kern_pairs(const void *a, const void *b)
Definition: afmparse.c:661
AFM_TOKEN_CHARACTERSET
Definition: afmparse.c:212
AFM_TOKEN_STARTKERNPAIRS0
Definition: afmparse.c:251
AFM_VALUE_TYPE_INDEX
Definition: afmparse.h:52
FT_Memory
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
FT_BOOL
#define FT_BOOL(x)
Definition: fttypes.h:581
AFM_TrackKernRec_::max_kern
FT_Fixed max_kern
Definition: t1types.h:154
AFM_TOKEN_CH
Definition: afmparse.c:209
AFM_Token
enum AFM_Token_ AFM_Token
AFM_TOKEN_VERSION
Definition: afmparse.c:261
sizeof
sizeof(FT_AutofitterRec)
AFM_VALUE_TYPE_INTEGER
Definition: afmparse.h:50
AFM_KernPairRec_::y
FT_Int y
Definition: t1types.h:163
const
#define const
Definition: zconf.h:91
AFM_TOKEN_WEIGHT
Definition: afmparse.c:271
ft2build.h
AFM_TOKEN_ENDAXIS
Definition: afmparse.c:216
AFM_ValueRec_::b
FT_Bool b
Definition: afmparse.h:64
AFM_IS_SEP
#define AFM_IS_SEP(ch)
Definition: afmparse.c:68
afm_parser_read_int
afm_parser_read_int(AFM_Parser parser, FT_Int *aint)
Definition: afmparse.c:563
FT_UInt
unsigned int FT_UInt
Definition: fttypes.h:227
AFM_FontInfoRec_::TrackKerns
AFM_TrackKern TrackKerns
Definition: t1types.h:173
AFM_TOKEN_STARTTRACKKERN
Definition: afmparse.c:253
AFM_TOKEN_UNKNOWN
Definition: afmparse.c:275
afm_parser_init
afm_parser_init(AFM_Parser parser, FT_Memory memory, FT_Byte *base, FT_Byte *limit)
Definition: afmparse.c:525
AFM_KernPairRec_::index1
FT_Int index1
Definition: t1types.h:160
AFM_TOKEN_ISFIXEDPITCH
Definition: afmparse.c:231
afm_tokenize
static AFM_Token afm_tokenize(const char *key, FT_Offset len)
Definition: afmparse.c:499
afm_stream_skip_spaces
static int afm_stream_skip_spaces(AFM_Stream stream)
Definition: afmparse.c:91
r
GLdouble GLdouble GLdouble r
Definition: glew.h:1392
afm_parser_skip_section
static FT_Error afm_parser_skip_section(AFM_Parser parser, FT_UInt n, AFM_Token end_section)
Definition: afmparse.c:814
AFM_FontInfoRec_::Ascender
FT_Fixed Ascender
Definition: t1types.h:171
AFM_TOKEN_W0X
Definition: afmparse.c:264
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
AFM_TOKEN_CHARWIDTH
Definition: afmparse.c:211
AFM_TOKEN_WEIGHTVECTOR
Definition: afmparse.c:272
AFM_StreamRec
struct AFM_StreamRec_ AFM_StreamRec
str
#define str(s)
AFM_TOKEN_UNDERLINEPOSITION
Definition: afmparse.c:257
AFM_TOKEN_MAPPINGSCHEME
Definition: afmparse.c:239
AFM_VALUE_TYPE_NAME
Definition: afmparse.h:48
AFM_TOKEN_FAMILYNAME
Definition: afmparse.c:225
AFM_FontInfoRec_::FontBBox
FT_BBox FontBBox
Definition: t1types.h:170
FT_NEW
#define FT_NEW(ptr)
Definition: ftmemory.h:288
i
int i
Definition: pngrutil.c:1377
AFM_TOKEN_ENDKERNPAIRS
Definition: afmparse.c:222
AFM_ParserRec_::FontInfo
AFM_FontInfo FontInfo
Definition: psaux.h:754
AFM_STREAM_STATUS_NORMAL
Definition: afmparse.c:38
AFM_STREAM_KEY_LEN
#define AFM_STREAM_KEY_LEN(stream, key)
Definition: afmparse.c:77
PS_Conv_ToInt
PS_Conv_ToInt(FT_Byte **cursor, FT_Byte *limit)
Definition: psconv.c:120
AFM_TOKEN_N
Definition: afmparse.c:241
FT_BBox_::yMin
FT_Pos yMin
Definition: ftimage.h:118
ft_memcpy
#define ft_memcpy
Definition: ftstdlib.h:81
AFM_VALUE_TYPE_FIXED
Definition: afmparse.h:49
AFM_MAX_ARGUMENTS
#define AFM_MAX_ARGUMENTS
Definition: afmparse.h:70
AFM_TOKEN_CHARACTERS
Definition: afmparse.c:213
AFM_ValueRec_::type
enum AFM_ValueType_ type
Definition: afmparse.h:58
AFM_TOKEN_ITALICANGLE
Definition: afmparse.c:233
AFM_TOKEN_ENDDIRECTION
Definition: afmparse.c:219
AFM_FontInfoRec_::NumKernPair
FT_Int NumKernPair
Definition: t1types.h:176
AFM_TOKEN_STARTFONTMETRICS
Definition: afmparse.c:248
AFM_IS_EOF
#define AFM_IS_EOF(ch)
Definition: afmparse.c:64
afm_parser_read_vals
afm_parser_read_vals(AFM_Parser parser, AFM_Value vals, FT_UInt n)
Definition: afmparse.c:367
AFM_TOKEN_FONTNAME
Definition: afmparse.c:227
FT_Offset
size_t FT_Offset
Definition: fttypes.h:320