-
Notifications
You must be signed in to change notification settings - Fork 208
/
cffdecode.c
2423 lines (1939 loc) · 67 KB
/
cffdecode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
*
* cffdecode.c
*
* PostScript CFF (Type 2) decoding routines (body).
*
* Copyright (C) 2017-2022 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 <freetype/freetype.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/internal/ftserv.h>
#include <freetype/internal/services/svcfftl.h>
#include "cffdecode.h"
#include "psobjs.h"
#include "psauxerr.h"
/**************************************************************************
*
* 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 cffdecode
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
typedef enum CFF_Operator_
{
cff_op_unknown = 0,
cff_op_rmoveto,
cff_op_hmoveto,
cff_op_vmoveto,
cff_op_rlineto,
cff_op_hlineto,
cff_op_vlineto,
cff_op_rrcurveto,
cff_op_hhcurveto,
cff_op_hvcurveto,
cff_op_rcurveline,
cff_op_rlinecurve,
cff_op_vhcurveto,
cff_op_vvcurveto,
cff_op_flex,
cff_op_hflex,
cff_op_hflex1,
cff_op_flex1,
cff_op_endchar,
cff_op_hstem,
cff_op_vstem,
cff_op_hstemhm,
cff_op_vstemhm,
cff_op_hintmask,
cff_op_cntrmask,
cff_op_dotsection, /* deprecated, acts as no-op */
cff_op_abs,
cff_op_add,
cff_op_sub,
cff_op_div,
cff_op_neg,
cff_op_random,
cff_op_mul,
cff_op_sqrt,
cff_op_blend,
cff_op_drop,
cff_op_exch,
cff_op_index,
cff_op_roll,
cff_op_dup,
cff_op_put,
cff_op_get,
cff_op_store,
cff_op_load,
cff_op_and,
cff_op_or,
cff_op_not,
cff_op_eq,
cff_op_ifelse,
cff_op_callsubr,
cff_op_callgsubr,
cff_op_return,
/* Type 1 opcodes: invalid but seen in real life */
cff_op_hsbw,
cff_op_closepath,
cff_op_callothersubr,
cff_op_pop,
cff_op_seac,
cff_op_sbw,
cff_op_setcurrentpoint,
/* do not remove */
cff_op_max
} CFF_Operator;
#define CFF_COUNT_CHECK_WIDTH 0x80
#define CFF_COUNT_EXACT 0x40
#define CFF_COUNT_CLEAR_STACK 0x20
/* count values which have the `CFF_COUNT_CHECK_WIDTH' flag set are */
/* used for checking the width and requested numbers of arguments */
/* only; they are set to zero afterwards */
/* the other two flags are informative only and unused currently */
static const FT_Byte cff_argument_counts[] =
{
0, /* unknown */
2 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT, /* rmoveto */
1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
0 | CFF_COUNT_CLEAR_STACK, /* rlineto */
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK, /* rrcurveto */
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
0 | CFF_COUNT_CLEAR_STACK,
13, /* flex */
7,
9,
11,
0 | CFF_COUNT_CHECK_WIDTH, /* endchar */
2 | CFF_COUNT_CHECK_WIDTH, /* hstem */
2 | CFF_COUNT_CHECK_WIDTH,
2 | CFF_COUNT_CHECK_WIDTH,
2 | CFF_COUNT_CHECK_WIDTH,
0 | CFF_COUNT_CHECK_WIDTH, /* hintmask */
0 | CFF_COUNT_CHECK_WIDTH, /* cntrmask */
0, /* dotsection */
1, /* abs */
2,
2,
2,
1,
0,
2,
1,
1, /* blend */
1, /* drop */
2,
1,
2,
1,
2, /* put */
1,
4,
3,
2, /* and */
2,
1,
2,
4,
1, /* callsubr */
1,
0,
2, /* hsbw */
0,
0,
0,
5, /* seac */
4, /* sbw */
2 /* setcurrentpoint */
};
static FT_Error
cff_operator_seac( CFF_Decoder* decoder,
FT_Pos asb,
FT_Pos adx,
FT_Pos ady,
FT_Int bchar,
FT_Int achar )
{
FT_Error error;
CFF_Builder* builder = &decoder->builder;
FT_Int bchar_index, achar_index;
TT_Face face = decoder->builder.face;
FT_Vector left_bearing, advance;
FT_Byte* charstring;
FT_ULong charstring_len;
FT_Pos glyph_width;
if ( decoder->seac )
{
FT_ERROR(( "cff_operator_seac: invalid nested seac\n" ));
return FT_THROW( Syntax_Error );
}
adx = ADD_LONG( adx, decoder->builder.left_bearing.x );
ady = ADD_LONG( ady, decoder->builder.left_bearing.y );
#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* Incremental fonts don't necessarily have valid charsets. */
/* They use the character code, not the glyph index, in this case. */
if ( face->root.internal->incremental_interface )
{
bchar_index = bchar;
achar_index = achar;
}
else
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
{
CFF_Font cff = (CFF_Font)( face->extra.data );
bchar_index = cff_lookup_glyph_by_stdcharcode( cff, bchar );
achar_index = cff_lookup_glyph_by_stdcharcode( cff, achar );
}
if ( bchar_index < 0 || achar_index < 0 )
{
FT_ERROR(( "cff_operator_seac:"
" invalid seac character code arguments\n" ));
return FT_THROW( Syntax_Error );
}
/* If we are trying to load a composite glyph, do not load the */
/* accent character and return the array of subglyphs. */
if ( builder->no_recurse )
{
FT_GlyphSlot glyph = (FT_GlyphSlot)builder->glyph;
FT_GlyphLoader loader = glyph->internal->loader;
FT_SubGlyph subg;
/* reallocate subglyph array if necessary */
error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 );
if ( error )
goto Exit;
subg = loader->current.subglyphs;
/* subglyph 0 = base character */
subg->index = bchar_index;
subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES |
FT_SUBGLYPH_FLAG_USE_MY_METRICS;
subg->arg1 = 0;
subg->arg2 = 0;
subg++;
/* subglyph 1 = accent character */
subg->index = achar_index;
subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
subg->arg1 = (FT_Int)( adx >> 16 );
subg->arg2 = (FT_Int)( ady >> 16 );
/* set up remaining glyph fields */
glyph->num_subglyphs = 2;
glyph->subglyphs = loader->base.subglyphs;
glyph->format = FT_GLYPH_FORMAT_COMPOSITE;
loader->current.num_subglyphs = 2;
}
FT_GlyphLoader_Prepare( builder->loader );
/* First load `bchar' in builder */
error = decoder->get_glyph_callback( face, (FT_UInt)bchar_index,
&charstring, &charstring_len );
if ( !error )
{
/* the seac operator must not be nested */
decoder->seac = TRUE;
error = cff_decoder_parse_charstrings( decoder, charstring,
charstring_len, 0 );
decoder->seac = FALSE;
decoder->free_glyph_callback( face, &charstring, charstring_len );
if ( error )
goto Exit;
}
/* Save the left bearing, advance and glyph width of the base */
/* character as they will be erased by the next load. */
left_bearing = builder->left_bearing;
advance = builder->advance;
glyph_width = decoder->glyph_width;
builder->left_bearing.x = 0;
builder->left_bearing.y = 0;
builder->pos_x = SUB_LONG( adx, asb );
builder->pos_y = ady;
/* Now load `achar' on top of the base outline. */
error = decoder->get_glyph_callback( face, (FT_UInt)achar_index,
&charstring, &charstring_len );
if ( !error )
{
/* the seac operator must not be nested */
decoder->seac = TRUE;
error = cff_decoder_parse_charstrings( decoder, charstring,
charstring_len, 0 );
decoder->seac = FALSE;
decoder->free_glyph_callback( face, &charstring, charstring_len );
if ( error )
goto Exit;
}
/* Restore the left side bearing, advance and glyph width */
/* of the base character. */
builder->left_bearing = left_bearing;
builder->advance = advance;
decoder->glyph_width = glyph_width;
builder->pos_x = 0;
builder->pos_y = 0;
Exit:
return error;
}
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/********** *********/
/********** *********/
/********** GENERIC CHARSTRING PARSING *********/
/********** *********/
/********** *********/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**************************************************************************
*
* @Function:
* cff_compute_bias
*
* @Description:
* Computes the bias value in dependence of the number of glyph
* subroutines.
*
* @Input:
* in_charstring_type ::
* The `CharstringType' value of the top DICT
* dictionary.
*
* num_subrs ::
* The number of glyph subroutines.
*
* @Return:
* The bias value.
*/
static FT_Int
cff_compute_bias( FT_Int in_charstring_type,
FT_UInt num_subrs )
{
FT_Int result;
if ( in_charstring_type == 1 )
result = 0;
else if ( num_subrs < 1240 )
result = 107;
else if ( num_subrs < 33900U )
result = 1131;
else
result = 32768U;
return result;
}
FT_LOCAL_DEF( FT_Int )
cff_lookup_glyph_by_stdcharcode( CFF_Font cff,
FT_Int charcode )
{
FT_UInt n;
FT_UShort glyph_sid;
FT_Service_CFFLoad cffload;
/* CID-keyed fonts don't have glyph names */
if ( !cff->charset.sids )
return -1;
/* check range of standard char code */
if ( charcode < 0 || charcode > 255 )
return -1;
#if 0
/* retrieve cffload from list of current modules */
FT_Service_CFFLoad cffload;
FT_FACE_FIND_GLOBAL_SERVICE( face, cffload, CFF_LOAD );
if ( !cffload )
{
FT_ERROR(( "cff_lookup_glyph_by_stdcharcode:"
" the `cffload' module is not available\n" ));
return FT_THROW( Unimplemented_Feature );
}
#endif
cffload = (FT_Service_CFFLoad)cff->cffload;
/* Get code to SID mapping from `cff_standard_encoding'. */
glyph_sid = cffload->get_standard_encoding( (FT_UInt)charcode );
for ( n = 0; n < cff->num_glyphs; n++ )
{
if ( cff->charset.sids[n] == glyph_sid )
return (FT_Int)n;
}
return -1;
}
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
/**************************************************************************
*
* @Function:
* cff_decoder_parse_charstrings
*
* @Description:
* Parses a given Type 2 charstrings program.
*
* @InOut:
* decoder ::
* The current Type 1 decoder.
*
* @Input:
* charstring_base ::
* The base of the charstring stream.
*
* charstring_len ::
* The length in bytes of the charstring stream.
*
* in_dict ::
* Set to 1 if function is called from top or
* private DICT (needed for Multiple Master CFFs).
*
* @Return:
* FreeType error code. 0 means success.
*/
FT_LOCAL_DEF( FT_Error )
cff_decoder_parse_charstrings( CFF_Decoder* decoder,
FT_Byte* charstring_base,
FT_ULong charstring_len,
FT_Bool in_dict )
{
FT_Error error;
CFF_Decoder_Zone* zone;
FT_Byte* ip;
FT_Byte* limit;
CFF_Builder* builder = &decoder->builder;
FT_Pos x, y;
FT_Fixed* stack;
FT_Int charstring_type =
decoder->cff->top_font.font_dict.charstring_type;
FT_UShort num_designs =
decoder->cff->top_font.font_dict.num_designs;
FT_UShort num_axes =
decoder->cff->top_font.font_dict.num_axes;
T2_Hints_Funcs hinter;
/* set default width */
decoder->num_hints = 0;
decoder->read_width = 1;
/* initialize the decoder */
decoder->top = decoder->stack;
decoder->zone = decoder->zones;
zone = decoder->zones;
stack = decoder->top;
hinter = (T2_Hints_Funcs)builder->hints_funcs;
builder->path_begun = 0;
if ( !charstring_base )
return FT_Err_Ok;
zone->base = charstring_base;
limit = zone->limit = charstring_base + charstring_len;
ip = zone->cursor = zone->base;
error = FT_Err_Ok;
x = builder->pos_x;
y = builder->pos_y;
/* begin hints recording session, if any */
if ( hinter )
hinter->open( hinter->hints );
/* now execute loop */
while ( ip < limit )
{
CFF_Operator op;
FT_Byte v;
/*********************************************************************
*
* Decode operator or operand
*/
v = *ip++;
if ( v >= 32 || v == 28 )
{
FT_Int shift = 16;
FT_Int32 val;
/* this is an operand, push it on the stack */
/* if we use shifts, all computations are done with unsigned */
/* values; the conversion to a signed value is the last step */
if ( v == 28 )
{
if ( ip + 1 >= limit )
goto Syntax_Error;
val = (FT_Short)( ( (FT_UShort)ip[0] << 8 ) | ip[1] );
ip += 2;
}
else if ( v < 247 )
val = (FT_Int32)v - 139;
else if ( v < 251 )
{
if ( ip >= limit )
goto Syntax_Error;
val = ( (FT_Int32)v - 247 ) * 256 + *ip++ + 108;
}
else if ( v < 255 )
{
if ( ip >= limit )
goto Syntax_Error;
val = -( (FT_Int32)v - 251 ) * 256 - *ip++ - 108;
}
else
{
if ( ip + 3 >= limit )
goto Syntax_Error;
val = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
( (FT_UInt32)ip[1] << 16 ) |
( (FT_UInt32)ip[2] << 8 ) |
(FT_UInt32)ip[3] );
ip += 4;
if ( charstring_type == 2 )
shift = 0;
}
if ( decoder->top - stack >= CFF_MAX_OPERANDS )
goto Stack_Overflow;
val = (FT_Int32)( (FT_UInt32)val << shift );
*decoder->top++ = val;
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !( val & 0xFFFFL ) )
FT_TRACE4(( " %hd", (FT_Short)( (FT_UInt32)val >> 16 ) ));
else
FT_TRACE4(( " %.5f", val / 65536.0 ));
#endif
}
else
{
/* The specification says that normally arguments are to be taken */
/* from the bottom of the stack. However, this seems not to be */
/* correct, at least for Acroread 7.0.8 on GNU/Linux: It pops the */
/* arguments similar to a PS interpreter. */
FT_Fixed* args = decoder->top;
FT_Int num_args = (FT_Int)( args - decoder->stack );
FT_Int req_args;
/* find operator */
op = cff_op_unknown;
switch ( v )
{
case 1:
op = cff_op_hstem;
break;
case 3:
op = cff_op_vstem;
break;
case 4:
op = cff_op_vmoveto;
break;
case 5:
op = cff_op_rlineto;
break;
case 6:
op = cff_op_hlineto;
break;
case 7:
op = cff_op_vlineto;
break;
case 8:
op = cff_op_rrcurveto;
break;
case 9:
op = cff_op_closepath;
break;
case 10:
op = cff_op_callsubr;
break;
case 11:
op = cff_op_return;
break;
case 12:
if ( ip >= limit )
goto Syntax_Error;
v = *ip++;
switch ( v )
{
case 0:
op = cff_op_dotsection;
break;
case 1: /* this is actually the Type1 vstem3 operator */
op = cff_op_vstem;
break;
case 2: /* this is actually the Type1 hstem3 operator */
op = cff_op_hstem;
break;
case 3:
op = cff_op_and;
break;
case 4:
op = cff_op_or;
break;
case 5:
op = cff_op_not;
break;
case 6:
op = cff_op_seac;
break;
case 7:
op = cff_op_sbw;
break;
case 8:
op = cff_op_store;
break;
case 9:
op = cff_op_abs;
break;
case 10:
op = cff_op_add;
break;
case 11:
op = cff_op_sub;
break;
case 12:
op = cff_op_div;
break;
case 13:
op = cff_op_load;
break;
case 14:
op = cff_op_neg;
break;
case 15:
op = cff_op_eq;
break;
case 16:
op = cff_op_callothersubr;
break;
case 17:
op = cff_op_pop;
break;
case 18:
op = cff_op_drop;
break;
case 20:
op = cff_op_put;
break;
case 21:
op = cff_op_get;
break;
case 22:
op = cff_op_ifelse;
break;
case 23:
op = cff_op_random;
break;
case 24:
op = cff_op_mul;
break;
case 26:
op = cff_op_sqrt;
break;
case 27:
op = cff_op_dup;
break;
case 28:
op = cff_op_exch;
break;
case 29:
op = cff_op_index;
break;
case 30:
op = cff_op_roll;
break;
case 33:
op = cff_op_setcurrentpoint;
break;
case 34:
op = cff_op_hflex;
break;
case 35:
op = cff_op_flex;
break;
case 36:
op = cff_op_hflex1;
break;
case 37:
op = cff_op_flex1;
break;
default:
FT_TRACE4(( " unknown op (12, %d)\n", v ));
break;
}
break;
case 13:
op = cff_op_hsbw;
break;
case 14:
op = cff_op_endchar;
break;
case 16:
op = cff_op_blend;
break;
case 18:
op = cff_op_hstemhm;
break;
case 19:
op = cff_op_hintmask;
break;
case 20:
op = cff_op_cntrmask;
break;
case 21:
op = cff_op_rmoveto;
break;
case 22:
op = cff_op_hmoveto;
break;
case 23:
op = cff_op_vstemhm;
break;
case 24:
op = cff_op_rcurveline;
break;
case 25:
op = cff_op_rlinecurve;
break;
case 26:
op = cff_op_vvcurveto;
break;
case 27:
op = cff_op_hhcurveto;
break;
case 29:
op = cff_op_callgsubr;
break;
case 30:
op = cff_op_vhcurveto;
break;
case 31:
op = cff_op_hvcurveto;
break;
default:
FT_TRACE4(( " unknown op (%d)\n", v ));
break;
}
if ( op == cff_op_unknown )
continue;
/* in Multiple Master CFFs, T2 charstrings can appear in */
/* dictionaries, but some operators are prohibited */
if ( in_dict )
{
switch ( op )
{
case cff_op_hstem:
case cff_op_vstem:
case cff_op_vmoveto:
case cff_op_rlineto:
case cff_op_hlineto:
case cff_op_vlineto:
case cff_op_rrcurveto:
case cff_op_hstemhm:
case cff_op_hintmask:
case cff_op_cntrmask:
case cff_op_rmoveto:
case cff_op_hmoveto:
case cff_op_vstemhm:
case cff_op_rcurveline:
case cff_op_rlinecurve:
case cff_op_vvcurveto:
case cff_op_hhcurveto:
case cff_op_vhcurveto:
case cff_op_hvcurveto:
case cff_op_hflex:
case cff_op_flex:
case cff_op_hflex1:
case cff_op_flex1:
case cff_op_callsubr:
case cff_op_callgsubr:
/* deprecated opcodes */
case cff_op_dotsection:
/* invalid Type 1 opcodes */
case cff_op_hsbw:
case cff_op_closepath:
case cff_op_callothersubr:
case cff_op_seac:
case cff_op_sbw:
case cff_op_setcurrentpoint:
goto MM_Error;
default:
break;
}
}
/* check arguments */
req_args = cff_argument_counts[op];
if ( req_args & CFF_COUNT_CHECK_WIDTH )
{
if ( num_args > 0 && decoder->read_width )
{
/* If `nominal_width' is non-zero, the number is really a */
/* difference against `nominal_width'. Else, the number here */
/* is truly a width, not a difference against `nominal_width'. */
/* If the font does not set `nominal_width', then */
/* `nominal_width' defaults to zero, and so we can set */
/* `glyph_width' to `nominal_width' plus number on the stack */
/* -- for either case. */
FT_Int set_width_ok;
switch ( op )
{
case cff_op_hmoveto:
case cff_op_vmoveto:
set_width_ok = num_args & 2;
break;
case cff_op_hstem:
case cff_op_vstem:
case cff_op_hstemhm:
case cff_op_vstemhm:
case cff_op_rmoveto:
case cff_op_hintmask:
case cff_op_cntrmask:
set_width_ok = num_args & 1;
break;
case cff_op_endchar:
/* If there is a width specified for endchar, we either have */
/* 1 argument or 5 arguments. We like to argue. */
set_width_ok = in_dict
? 0
: ( ( num_args == 5 ) || ( num_args == 1 ) );
break;
default:
set_width_ok = 0;
break;
}
if ( set_width_ok )
{
decoder->glyph_width = decoder->nominal_width +
( stack[0] >> 16 );
if ( decoder->width_only )
{
/* we only want the advance width; stop here */
break;
}
/* Consumed an argument. */
num_args--;
}
}
decoder->read_width = 0;
req_args = 0;
}
req_args &= 0x000F;
if ( num_args < req_args )
goto Stack_Underflow;
args -= req_args;
num_args -= req_args;
/* At this point, `args' points to the first argument of the */
/* operand in case `req_args' isn't zero. Otherwise, we have */
/* to adjust `args' manually. */
/* Note that we only pop arguments from the stack which we */
/* really need and can digest so that we can continue in case */
/* of superfluous stack elements. */
switch ( op )
{
case cff_op_hstem:
case cff_op_vstem:
case cff_op_hstemhm:
case cff_op_vstemhm:
/* the number of arguments is always even here */
FT_TRACE4(( "%s\n",
op == cff_op_hstem ? " hstem" :
( op == cff_op_vstem ? " vstem" :
( op == cff_op_hstemhm ? " hstemhm" : " vstemhm" ) ) ));
if ( hinter )
hinter->stems( hinter->hints,
( op == cff_op_hstem || op == cff_op_hstemhm ),
num_args / 2,
args - ( num_args & ~1 ) );
decoder->num_hints += num_args / 2;
args = stack;
break;
case cff_op_hintmask:
case cff_op_cntrmask:
FT_TRACE4(( "%s", op == cff_op_hintmask ? " hintmask"
: " cntrmask" ));
/* implement vstem when needed -- */
/* the specification doesn't say it, but this also works */
/* with the 'cntrmask' operator */
/* */
if ( num_args > 0 )
{
if ( hinter )
hinter->stems( hinter->hints,
0,
num_args / 2,
args - ( num_args & ~1 ) );