1 /***************************************************************************/
5 /* PostScript Type 1 decoding routines (body). */
7 /* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
17 /***************************************************************************/
21 #include FT_INTERNAL_CALC_H
22 #include FT_INTERNAL_DEBUG_H
23 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
32 /*************************************************************************/
34 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
35 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
36 /* messages during execution. */
39 #define FT_COMPONENT trace_t1decode
42 typedef enum T1_Operator_
72 op_max
/* never remove this one */
78 const FT_Int t1_args_count
[op_max
] =
101 -1, /* callothersubr */
105 2, /* setcurrentpoint */
106 2 /* opcode 15 (undocumented and obsolete) */
110 /*************************************************************************/
113 /* t1_lookup_glyph_by_stdcharcode */
116 /* Looks up a given glyph by its StandardEncoding charcode. Used to */
117 /* implement the SEAC Type 1 operator. */
120 /* face :: The current face object. */
122 /* charcode :: The character code to look for. */
125 /* A glyph index in the font face. Returns -1 if the corresponding */
126 /* glyph wasn't found. */
129 t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder
,
133 const FT_String
* glyph_name
;
134 FT_Service_PsCMaps psnames
= decoder
->psnames
;
137 /* check range of standard char code */
138 if ( charcode
< 0 || charcode
> 255 )
141 glyph_name
= psnames
->adobe_std_strings(
142 psnames
->adobe_std_encoding
[charcode
]);
144 for ( n
= 0; n
< decoder
->num_glyphs
; n
++ )
146 FT_String
* name
= (FT_String
*)decoder
->glyph_names
[n
];
150 name
[0] == glyph_name
[0] &&
151 ft_strcmp( name
, glyph_name
) == 0 )
159 /*************************************************************************/
162 /* t1operator_seac */
165 /* Implements the `seac' Type 1 operator for a Type 1 decoder. */
168 /* decoder :: The current CID decoder. */
170 /* asb :: The accent's side bearing. */
172 /* adx :: The horizontal offset of the accent. */
174 /* ady :: The vertical offset of the accent. */
176 /* bchar :: The base character's StandardEncoding charcode. */
178 /* achar :: The accent character's StandardEncoding charcode. */
181 /* FreeType error code. 0 means success. */
184 t1operator_seac( T1_Decoder decoder
,
192 FT_Int bchar_index
, achar_index
;
194 FT_Int n_base_points
;
195 FT_Outline
* base
= decoder
->builder
.base
;
197 FT_Vector left_bearing
, advance
;
199 #ifdef FT_CONFIG_OPTION_INCREMENTAL
200 T1_Face face
= (T1_Face
)decoder
->builder
.face
;
206 FT_ERROR(( "t1operator_seac: invalid nested seac\n" ));
207 return PSaux_Err_Syntax_Error
;
211 adx
+= decoder
->builder
.left_bearing
.x
;
213 /* `glyph_names' is set to 0 for CID fonts which do not */
214 /* include an encoding. How can we deal with these? */
215 #ifdef FT_CONFIG_OPTION_INCREMENTAL
216 if ( decoder
->glyph_names
== 0 &&
217 !face
->root
.internal
->incremental_interface
)
219 if ( decoder
->glyph_names
== 0 )
220 #endif /* FT_CONFIG_OPTION_INCREMENTAL */
222 FT_ERROR(( "t1operator_seac:"
223 " glyph names table not available in this font\n" ));
224 return PSaux_Err_Syntax_Error
;
227 #ifdef FT_CONFIG_OPTION_INCREMENTAL
228 if ( face
->root
.internal
->incremental_interface
)
230 /* the caller must handle the font encoding also */
237 bchar_index
= t1_lookup_glyph_by_stdcharcode( decoder
, bchar
);
238 achar_index
= t1_lookup_glyph_by_stdcharcode( decoder
, achar
);
241 if ( bchar_index
< 0 || achar_index
< 0 )
243 FT_ERROR(( "t1operator_seac:"
244 " invalid seac character code arguments\n" ));
245 return PSaux_Err_Syntax_Error
;
248 /* if we are trying to load a composite glyph, do not load the */
249 /* accent character and return the array of subglyphs. */
250 if ( decoder
->builder
.no_recurse
)
252 FT_GlyphSlot glyph
= (FT_GlyphSlot
)decoder
->builder
.glyph
;
253 FT_GlyphLoader loader
= glyph
->internal
->loader
;
257 /* reallocate subglyph array if necessary */
258 error
= FT_GlyphLoader_CheckSubGlyphs( loader
, 2 );
262 subg
= loader
->current
.subglyphs
;
264 /* subglyph 0 = base character */
265 subg
->index
= bchar_index
;
266 subg
->flags
= FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
|
267 FT_SUBGLYPH_FLAG_USE_MY_METRICS
;
272 /* subglyph 1 = accent character */
273 subg
->index
= achar_index
;
274 subg
->flags
= FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
;
275 subg
->arg1
= (FT_Int
)FIXED_TO_INT( adx
- asb
);
276 subg
->arg2
= (FT_Int
)FIXED_TO_INT( ady
);
278 /* set up remaining glyph fields */
279 glyph
->num_subglyphs
= 2;
280 glyph
->subglyphs
= loader
->base
.subglyphs
;
281 glyph
->format
= FT_GLYPH_FORMAT_COMPOSITE
;
283 loader
->current
.num_subglyphs
= 2;
287 /* First load `bchar' in builder */
288 /* now load the unscaled outline */
290 FT_GlyphLoader_Prepare( decoder
->builder
.loader
); /* prepare loader */
292 /* the seac operator must not be nested */
293 decoder
->seac
= TRUE
;
294 error
= t1_decoder_parse_glyph( decoder
, bchar_index
);
295 decoder
->seac
= FALSE
;
299 /* save the left bearing and width of the base character */
300 /* as they will be erased by the next load. */
302 left_bearing
= decoder
->builder
.left_bearing
;
303 advance
= decoder
->builder
.advance
;
305 decoder
->builder
.left_bearing
.x
= 0;
306 decoder
->builder
.left_bearing
.y
= 0;
308 decoder
->builder
.pos_x
= adx
- asb
;
309 decoder
->builder
.pos_y
= ady
;
311 /* Now load `achar' on top of */
312 /* the base outline */
314 /* the seac operator must not be nested */
315 decoder
->seac
= TRUE
;
316 error
= t1_decoder_parse_glyph( decoder
, achar_index
);
317 decoder
->seac
= FALSE
;
321 /* restore the left side bearing and */
322 /* advance width of the base character */
324 decoder
->builder
.left_bearing
= left_bearing
;
325 decoder
->builder
.advance
= advance
;
327 decoder
->builder
.pos_x
= 0;
328 decoder
->builder
.pos_y
= 0;
335 /*************************************************************************/
338 /* t1_decoder_parse_charstrings */
341 /* Parses a given Type 1 charstrings program. */
344 /* decoder :: The current Type 1 decoder. */
346 /* charstring_base :: The base address of the charstring stream. */
348 /* charstring_len :: The length in bytes of the charstring stream. */
351 /* FreeType error code. 0 means success. */
353 FT_LOCAL_DEF( FT_Error
)
354 t1_decoder_parse_charstrings( T1_Decoder decoder
,
355 FT_Byte
* charstring_base
,
356 FT_UInt charstring_len
)
359 T1_Decoder_Zone zone
;
362 T1_Builder builder
= &decoder
->builder
;
363 FT_Pos x
, y
, orig_x
, orig_y
;
364 FT_Int known_othersubr_result_cnt
= 0;
365 FT_Int unknown_othersubr_result_cnt
= 0;
369 T1_Hints_Funcs hinter
;
371 #ifdef FT_DEBUG_LEVEL_TRACE
376 /* we don't want to touch the source code -- use macro trick */
377 #define start_point t1_builder_start_point
378 #define check_points t1_builder_check_points
379 #define add_point t1_builder_add_point
380 #define add_point1 t1_builder_add_point1
381 #define add_contour t1_builder_add_contour
382 #define close_contour t1_builder_close_contour
385 /* compute random seed from stack address of parameter */
386 seed
= (FT_Fixed
)( ( (FT_PtrDist
)(char*)&seed
^
387 (FT_PtrDist
)(char*)&decoder
^
388 (FT_PtrDist
)(char*)&charstring_base
) &
390 seed
= ( seed
^ ( seed
>> 10 ) ^ ( seed
>> 20 ) ) & 0xFFFFL
;
394 /* First of all, initialize the decoder */
395 decoder
->top
= decoder
->stack
;
396 decoder
->zone
= decoder
->zones
;
397 zone
= decoder
->zones
;
399 builder
->parse_state
= T1_Parse_Start
;
401 hinter
= (T1_Hints_Funcs
)builder
->hints_funcs
;
403 /* a font that reads BuildCharArray without setting */
404 /* its values first is buggy, but ... */
405 FT_ASSERT( ( decoder
->len_buildchar
== 0 ) ==
406 ( decoder
->buildchar
== NULL
) );
408 if ( decoder
->len_buildchar
> 0 )
409 ft_memset( &decoder
->buildchar
[0],
411 sizeof( decoder
->buildchar
[0] ) * decoder
->len_buildchar
);
414 "Start charstring\n" ));
416 zone
->base
= charstring_base
;
417 limit
= zone
->limit
= charstring_base
+ charstring_len
;
418 ip
= zone
->cursor
= zone
->base
;
420 error
= PSaux_Err_Ok
;
422 x
= orig_x
= builder
->pos_x
;
423 y
= orig_y
= builder
->pos_y
;
425 /* begin hints recording session, if any */
427 hinter
->open( hinter
->hints
);
431 /* now, execute loop */
434 FT_Long
* top
= decoder
->top
;
435 T1_Operator op
= op_none
;
439 FT_ASSERT( known_othersubr_result_cnt
== 0 ||
440 unknown_othersubr_result_cnt
== 0 );
442 #ifdef FT_DEBUG_LEVEL_TRACE
445 FT_TRACE5(( " (%d)", decoder
->top
- decoder
->stack
));
450 /*********************************************************************/
452 /* Decode operator or operand */
456 /* first of all, decompress operator or value */
498 case 15: /* undocumented, obsolete operator */
519 FT_ERROR(( "t1_decoder_parse_charstrings:"
520 " invalid escape (12+EOF)\n" ));
545 op
= op_callothersubr
;
551 op
= op_setcurrentpoint
;
555 FT_ERROR(( "t1_decoder_parse_charstrings:"
556 " invalid escape (12+%d)\n",
562 case 255: /* four bytes integer */
563 if ( ip
+ 4 > limit
)
565 FT_ERROR(( "t1_decoder_parse_charstrings:"
566 " unexpected EOF in integer\n" ));
570 value
= (FT_Int32
)( ( (FT_Long
)ip
[0] << 24 ) |
571 ( (FT_Long
)ip
[1] << 16 ) |
572 ( (FT_Long
)ip
[2] << 8 ) |
576 /* According to the specification, values > 32000 or < -32000 must */
577 /* be followed by a `div' operator to make the result be in the */
578 /* range [-32000;32000]. We expect that the second argument of */
579 /* `div' is not a large number. Additionally, we don't handle */
580 /* stuff like `<large1> <large2> <num> div <num> div' or */
581 /* <large1> <large2> <num> div div'. This is probably not allowed */
583 if ( value
> 32000 || value
< -32000 )
587 FT_ERROR(( "t1_decoder_parse_charstrings:"
588 " no `div' after large integer\n" ));
605 value
= (FT_Int32
)ip
[-1] - 139;
610 FT_ERROR(( "t1_decoder_parse_charstrings:"
611 " unexpected EOF in integer\n" ));
616 value
= ( ( (FT_Int32
)ip
[-2] - 247 ) << 8 ) + ip
[-1] + 108;
618 value
= -( ( ( (FT_Int32
)ip
[-2] - 251 ) << 8 ) + ip
[-1] + 108 );
626 FT_ERROR(( "t1_decoder_parse_charstrings:"
627 " invalid byte (%d)\n", ip
[-1] ));
632 if ( unknown_othersubr_result_cnt
> 0 )
643 /* all operands have been transferred by previous pops */
644 unknown_othersubr_result_cnt
= 0;
649 if ( large_int
&& !( op
== op_none
|| op
== op_div
) )
651 FT_ERROR(( "t1_decoder_parse_charstrings:"
652 " no `div' after large integer\n" ));
657 /*********************************************************************/
659 /* Push value on stack, or process operator */
664 if ( top
- decoder
->stack
>= T1_MAX_CHARSTRINGS_OPERANDS
)
666 FT_ERROR(( "t1_decoder_parse_charstrings: stack overflow\n" ));
670 #ifdef FT_DEBUG_LEVEL_TRACE
672 FT_TRACE4(( " %ld", value
));
674 FT_TRACE4(( " %ld", (FT_Int32
)( value
>> 16 ) ));
680 else if ( op
== op_callothersubr
) /* callothersubr */
686 #ifdef FT_DEBUG_LEVEL_TRACE
687 FT_TRACE4(( " callothersubr\n" ));
691 if ( top
- decoder
->stack
< 2 )
692 goto Stack_Underflow
;
696 subr_no
= (FT_Int
)( top
[1] >> 16 );
697 arg_cnt
= (FT_Int
)( top
[0] >> 16 );
699 /***********************************************************/
701 /* remove all operands to callothersubr from the stack */
703 /* for handled othersubrs, where we know the number of */
704 /* arguments, we increase the stack by the value of */
705 /* known_othersubr_result_cnt */
707 /* for unhandled othersubrs the following pops adjust the */
708 /* stack pointer as necessary */
710 if ( arg_cnt
> top
- decoder
->stack
)
711 goto Stack_Underflow
;
715 known_othersubr_result_cnt
= 0;
716 unknown_othersubr_result_cnt
= 0;
718 /* XXX TODO: The checks to `arg_count == <whatever>' */
719 /* might not be correct; an othersubr expects a certain */
720 /* number of operands on the PostScript stack (as opposed */
721 /* to the T1 stack) but it doesn't have to put them there */
722 /* by itself; previous othersubrs might have left the */
723 /* operands there if they were not followed by an */
724 /* appropriate number of pops */
726 /* On the other hand, Adobe Reader 7.0.8 for Linux doesn't */
727 /* accept a font that contains charstrings like */
729 /* 100 200 2 20 callothersubr */
730 /* 300 1 20 callothersubr pop */
732 /* Perhaps this is the reason why BuildCharArray exists. */
736 case 1: /* start flex feature */
738 goto Unexpected_OtherSubr
;
740 decoder
->flex_state
= 1;
741 decoder
->num_flex_vectors
= 0;
742 if ( start_point( builder
, x
, y
) ||
743 check_points( builder
, 6 ) )
747 case 2: /* add flex vectors */
753 goto Unexpected_OtherSubr
;
755 /* note that we should not add a point for index 0; */
756 /* this will move our current position to the flex */
757 /* point without adding any point to the outline */
758 idx
= decoder
->num_flex_vectors
++;
759 if ( idx
> 0 && idx
< 7 )
763 (FT_Byte
)( idx
== 3 || idx
== 6 ) );
767 case 0: /* end flex feature */
769 goto Unexpected_OtherSubr
;
771 if ( decoder
->flex_state
== 0 ||
772 decoder
->num_flex_vectors
!= 7 )
774 FT_ERROR(( "t1_decoder_parse_charstrings:"
775 " unexpected flex end\n" ));
779 /* the two `results' are popped by the following setcurrentpoint */
780 known_othersubr_result_cnt
= 2;
783 case 3: /* change hints */
785 goto Unexpected_OtherSubr
;
787 known_othersubr_result_cnt
= 1;
790 hinter
->reset( hinter
->hints
, builder
->current
->n_points
);
795 /* counter control hints, clear stack */
796 top
= decoder
->stack
;
803 case 18: /* multiple masters */
805 PS_Blend blend
= decoder
->blend
;
806 FT_UInt num_points
, nn
, mm
;
813 FT_ERROR(( "t1_decoder_parse_charstrings:"
814 " unexpected multiple masters operator\n" ));
818 num_points
= (FT_UInt
)subr_no
- 13 + ( subr_no
== 18 );
819 if ( arg_cnt
!= (FT_Int
)( num_points
* blend
->num_designs
) )
821 FT_ERROR(( "t1_decoder_parse_charstrings:"
822 " incorrect number of multiple masters arguments\n" ));
826 /* we want to compute: */
828 /* a0*w0 + a1*w1 + ... + ak*wk */
830 /* but we only have the a0, a1-a0, a2-a0, .. ak-a0 */
831 /* however, given that w0 + w1 + ... + wk == 1, we can */
832 /* rewrite it easily as: */
834 /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + .. + (ak-a0)*wk */
836 /* where k == num_designs-1 */
838 /* I guess that's why it's written in this `compact' */
841 delta
= top
+ num_points
;
843 for ( nn
= 0; nn
< num_points
; nn
++ )
845 FT_Long tmp
= values
[0];
848 for ( mm
= 1; mm
< blend
->num_designs
; mm
++ )
849 tmp
+= FT_MulFix( *delta
++, blend
->weight_vector
[mm
] );
854 known_othersubr_result_cnt
= num_points
;
859 /* <idx> 1 19 callothersubr */
860 /* => replace elements starting from index cvi( <idx> ) */
861 /* of BuildCharArray with WeightVector */
864 PS_Blend blend
= decoder
->blend
;
867 if ( arg_cnt
!= 1 || blend
== NULL
)
868 goto Unexpected_OtherSubr
;
870 idx
= (FT_Int
)( top
[0] >> 16 );
873 idx
+ blend
->num_designs
> decoder
->len_buildchar
)
874 goto Unexpected_OtherSubr
;
876 ft_memcpy( &decoder
->buildchar
[idx
],
877 blend
->weight_vector
,
879 sizeof( blend
->weight_vector
[0] ) );
884 /* <arg1> <arg2> 2 20 callothersubr pop */
885 /* ==> push <arg1> + <arg2> onto T1 stack */
887 goto Unexpected_OtherSubr
;
889 top
[0] += top
[1]; /* XXX (over|under)flow */
891 known_othersubr_result_cnt
= 1;
895 /* <arg1> <arg2> 2 21 callothersubr pop */
896 /* ==> push <arg1> - <arg2> onto T1 stack */
898 goto Unexpected_OtherSubr
;
900 top
[0] -= top
[1]; /* XXX (over|under)flow */
902 known_othersubr_result_cnt
= 1;
906 /* <arg1> <arg2> 2 22 callothersubr pop */
907 /* ==> push <arg1> * <arg2> onto T1 stack */
909 goto Unexpected_OtherSubr
;
911 top
[0] = FT_MulFix( top
[0], top
[1] );
913 known_othersubr_result_cnt
= 1;
917 /* <arg1> <arg2> 2 23 callothersubr pop */
918 /* ==> push <arg1> / <arg2> onto T1 stack */
919 if ( arg_cnt
!= 2 || top
[1] == 0 )
920 goto Unexpected_OtherSubr
;
922 top
[0] = FT_DivFix( top
[0], top
[1] );
924 known_othersubr_result_cnt
= 1;
928 /* <val> <idx> 2 24 callothersubr */
929 /* ==> set BuildCharArray[cvi( <idx> )] = <val> */
932 PS_Blend blend
= decoder
->blend
;
935 if ( arg_cnt
!= 2 || blend
== NULL
)
936 goto Unexpected_OtherSubr
;
938 idx
= (FT_Int
)( top
[1] >> 16 );
940 if ( idx
< 0 || (FT_UInt
) idx
>= decoder
->len_buildchar
)
941 goto Unexpected_OtherSubr
;
943 decoder
->buildchar
[idx
] = top
[0];
948 /* <idx> 1 25 callothersubr pop */
949 /* ==> push BuildCharArray[cvi( idx )] */
953 PS_Blend blend
= decoder
->blend
;
956 if ( arg_cnt
!= 1 || blend
== NULL
)
957 goto Unexpected_OtherSubr
;
959 idx
= (FT_Int
)( top
[0] >> 16 );
961 if ( idx
< 0 || (FT_UInt
) idx
>= decoder
->len_buildchar
)
962 goto Unexpected_OtherSubr
;
964 top
[0] = decoder
->buildchar
[idx
];
967 known_othersubr_result_cnt
= 1;
972 /* <val> mark <idx> ==> set BuildCharArray[cvi( <idx> )] = <val>, */
973 /* leave mark on T1 stack */
974 /* <val> <idx> ==> set BuildCharArray[cvi( <idx> )] = <val> */
975 XXX which routine has left its mark on
the (PostScript
) stack
?;
980 /* <res1> <res2> <val1> <val2> 4 27 callothersubr pop */
981 /* ==> push <res1> onto T1 stack if <val1> <= <val2>, */
982 /* otherwise push <res2> */
984 goto Unexpected_OtherSubr
;
986 if ( top
[2] > top
[3] )
989 known_othersubr_result_cnt
= 1;
993 /* 0 28 callothersubr pop */
994 /* => push random value from interval [0, 1) onto stack */
996 goto Unexpected_OtherSubr
;
1003 if ( Rand
>= 0x8000L
)
1008 seed
= FT_MulFix( seed
, 0x10000L
- seed
);
1013 known_othersubr_result_cnt
= 1;
1017 FT_ERROR(( "t1_decoder_parse_charstrings:"
1018 " unknown othersubr [%d %d], wish me luck\n",
1019 arg_cnt
, subr_no
));
1020 unknown_othersubr_result_cnt
= arg_cnt
;
1023 Unexpected_OtherSubr
:
1024 FT_ERROR(( "t1_decoder_parse_charstrings:"
1025 " invalid othersubr [%d %d]\n", arg_cnt
, subr_no
));
1029 top
+= known_othersubr_result_cnt
;
1033 else /* general operator */
1035 FT_Int num_args
= t1_args_count
[op
];
1038 FT_ASSERT( num_args
>= 0 );
1040 if ( top
- decoder
->stack
< num_args
)
1041 goto Stack_Underflow
;
1043 /* XXX Operators usually take their operands from the */
1044 /* bottom of the stack, i.e., the operands are */
1045 /* decoder->stack[0], ..., decoder->stack[num_args - 1]; */
1046 /* only div, callsubr, and callothersubr are different. */
1047 /* In practice it doesn't matter (?). */
1049 #ifdef FT_DEBUG_LEVEL_TRACE
1055 case op_callothersubr
:
1061 if ( top
- decoder
->stack
!= num_args
)
1062 FT_TRACE0(( "t1_decoder_parse_charstrings:"
1063 " too much operands on the stack"
1064 " (seen %d, expected %d)\n",
1065 top
- decoder
->stack
, num_args
));
1069 #endif /* FT_DEBUG_LEVEL_TRACE */
1076 FT_TRACE4(( " endchar\n" ));
1078 close_contour( builder
);
1080 /* close hints recording session */
1083 if ( hinter
->close( hinter
->hints
, builder
->current
->n_points
) )
1086 /* apply hints to the loaded glyph outline now */
1087 hinter
->apply( hinter
->hints
,
1089 (PSH_Globals
)builder
->hints_globals
,
1090 decoder
->hint_mode
);
1093 /* add current outline to the glyph slot */
1094 FT_GlyphLoader_Add( builder
->loader
);
1096 /* the compiler should optimize away this empty loop but ... */
1098 #ifdef FT_DEBUG_LEVEL_TRACE
1100 if ( decoder
->len_buildchar
> 0 )
1105 FT_TRACE4(( "BuildCharArray = [ " ));
1107 for ( i
= 0; i
< decoder
->len_buildchar
; ++i
)
1108 FT_TRACE4(( "%d ", decoder
->buildchar
[ i
] ));
1110 FT_TRACE4(( "]\n" ));
1113 #endif /* FT_DEBUG_LEVEL_TRACE */
1115 FT_TRACE4(( "\n" ));
1118 return PSaux_Err_Ok
;
1121 FT_TRACE4(( " hsbw" ));
1123 builder
->parse_state
= T1_Parse_Have_Width
;
1125 builder
->left_bearing
.x
+= top
[0];
1126 builder
->advance
.x
= top
[1];
1127 builder
->advance
.y
= 0;
1129 orig_x
= x
= builder
->pos_x
+ top
[0];
1130 orig_y
= y
= builder
->pos_y
;
1132 FT_UNUSED( orig_y
);
1134 /* the `metrics_only' indicates that we only want to compute */
1135 /* the glyph's metrics (lsb + advance width), not load the */
1136 /* rest of it; so exit immediately */
1137 if ( builder
->metrics_only
)
1138 return PSaux_Err_Ok
;
1143 return t1operator_seac( decoder
,
1147 (FT_Int
)( top
[3] >> 16 ),
1148 (FT_Int
)( top
[4] >> 16 ) );
1151 FT_TRACE4(( " sbw" ));
1153 builder
->parse_state
= T1_Parse_Have_Width
;
1155 builder
->left_bearing
.x
+= top
[0];
1156 builder
->left_bearing
.y
+= top
[1];
1157 builder
->advance
.x
= top
[2];
1158 builder
->advance
.y
= top
[3];
1160 x
= builder
->pos_x
+ top
[0];
1161 y
= builder
->pos_y
+ top
[1];
1163 /* the `metrics_only' indicates that we only want to compute */
1164 /* the glyph's metrics (lsb + advance width), not load the */
1165 /* rest of it; so exit immediately */
1166 if ( builder
->metrics_only
)
1167 return PSaux_Err_Ok
;
1172 FT_TRACE4(( " closepath" ));
1174 /* if there is no path, `closepath' is a no-op */
1175 if ( builder
->parse_state
== T1_Parse_Have_Path
||
1176 builder
->parse_state
== T1_Parse_Have_Moveto
)
1177 close_contour( builder
);
1179 builder
->parse_state
= T1_Parse_Have_Width
;
1183 FT_TRACE4(( " hlineto" ));
1185 if ( start_point( builder
, x
, y
) )
1192 FT_TRACE4(( " hmoveto" ));
1195 if ( !decoder
->flex_state
)
1197 if ( builder
->parse_state
== T1_Parse_Start
)
1199 builder
->parse_state
= T1_Parse_Have_Moveto
;
1204 FT_TRACE4(( " hvcurveto" ));
1206 if ( start_point( builder
, x
, y
) ||
1207 check_points( builder
, 3 ) )
1211 add_point( builder
, x
, y
, 0 );
1214 add_point( builder
, x
, y
, 0 );
1216 add_point( builder
, x
, y
, 1 );
1220 FT_TRACE4(( " rlineto" ));
1222 if ( start_point( builder
, x
, y
) )
1229 if ( add_point1( builder
, x
, y
) )
1234 FT_TRACE4(( " rmoveto" ));
1238 if ( !decoder
->flex_state
)
1240 if ( builder
->parse_state
== T1_Parse_Start
)
1242 builder
->parse_state
= T1_Parse_Have_Moveto
;
1247 FT_TRACE4(( " rrcurveto" ));
1249 if ( start_point( builder
, x
, y
) ||
1250 check_points( builder
, 3 ) )
1255 add_point( builder
, x
, y
, 0 );
1259 add_point( builder
, x
, y
, 0 );
1263 add_point( builder
, x
, y
, 1 );
1267 FT_TRACE4(( " vhcurveto" ));
1269 if ( start_point( builder
, x
, y
) ||
1270 check_points( builder
, 3 ) )
1274 add_point( builder
, x
, y
, 0 );
1277 add_point( builder
, x
, y
, 0 );
1279 add_point( builder
, x
, y
, 1 );
1283 FT_TRACE4(( " vlineto" ));
1285 if ( start_point( builder
, x
, y
) )
1292 FT_TRACE4(( " vmoveto" ));
1295 if ( !decoder
->flex_state
)
1297 if ( builder
->parse_state
== T1_Parse_Start
)
1299 builder
->parse_state
= T1_Parse_Have_Moveto
;
1304 FT_TRACE4(( " div" ));
1306 /* if `large_int' is set, we divide unscaled numbers; */
1307 /* otherwise, we divide numbers in 16.16 format -- */
1308 /* in both cases, it is the same operation */
1309 *top
= FT_DivFix( top
[0], top
[1] );
1320 FT_TRACE4(( " callsubr" ));
1322 idx
= (FT_Int
)( top
[0] >> 16 );
1323 if ( idx
< 0 || idx
>= (FT_Int
)decoder
->num_subrs
)
1325 FT_ERROR(( "t1_decoder_parse_charstrings:"
1326 " invalid subrs index\n" ));
1330 if ( zone
- decoder
->zones
>= T1_MAX_SUBRS_CALLS
)
1332 FT_ERROR(( "t1_decoder_parse_charstrings:"
1333 " too many nested subrs\n" ));
1337 zone
->cursor
= ip
; /* save current instruction pointer */
1341 /* The Type 1 driver stores subroutines without the seed bytes. */
1342 /* The CID driver stores subroutines with seed bytes. This */
1343 /* case is taken care of when decoder->subrs_len == 0. */
1344 zone
->base
= decoder
->subrs
[idx
];
1346 if ( decoder
->subrs_len
)
1347 zone
->limit
= zone
->base
+ decoder
->subrs_len
[idx
];
1350 /* We are using subroutines from a CID font. We must adjust */
1351 /* for the seed bytes. */
1352 zone
->base
+= ( decoder
->lenIV
>= 0 ? decoder
->lenIV
: 0 );
1353 zone
->limit
= decoder
->subrs
[idx
+ 1];
1356 zone
->cursor
= zone
->base
;
1360 FT_ERROR(( "t1_decoder_parse_charstrings:"
1361 " invoking empty subrs\n" ));
1365 decoder
->zone
= zone
;
1367 limit
= zone
->limit
;
1372 FT_TRACE4(( " pop" ));
1374 if ( known_othersubr_result_cnt
> 0 )
1376 known_othersubr_result_cnt
--;
1377 /* ignore, we pushed the operands ourselves */
1381 if ( unknown_othersubr_result_cnt
== 0 )
1383 FT_ERROR(( "t1_decoder_parse_charstrings:"
1384 " no more operands for othersubr\n" ));
1388 unknown_othersubr_result_cnt
--;
1389 top
++; /* `push' the operand to callothersubr onto the stack */
1393 FT_TRACE4(( " return" ));
1395 if ( zone
<= decoder
->zones
)
1397 FT_ERROR(( "t1_decoder_parse_charstrings:"
1398 " unexpected return\n" ));
1404 limit
= zone
->limit
;
1405 decoder
->zone
= zone
;
1409 FT_TRACE4(( " dotsection" ));
1414 FT_TRACE4(( " hstem" ));
1416 /* record horizontal hint */
1419 /* top[0] += builder->left_bearing.y; */
1420 hinter
->stem( hinter
->hints
, 1, top
);
1425 FT_TRACE4(( " hstem3" ));
1427 /* record horizontal counter-controlled hints */
1429 hinter
->stem3( hinter
->hints
, 1, top
);
1433 FT_TRACE4(( " vstem" ));
1435 /* record vertical hint */
1439 hinter
->stem( hinter
->hints
, 0, top
);
1444 FT_TRACE4(( " vstem3" ));
1446 /* record vertical counter-controlled hints */
1455 hinter
->stem3( hinter
->hints
, 0, top
);
1459 case op_setcurrentpoint
:
1460 FT_TRACE4(( " setcurrentpoint" ));
1462 /* From the T1 specification, section 6.4: */
1464 /* The setcurrentpoint command is used only in */
1465 /* conjunction with results from OtherSubrs procedures. */
1467 /* known_othersubr_result_cnt != 0 is already handled */
1470 /* Note, however, that both Ghostscript and Adobe */
1471 /* Distiller handle this situation by silently ignoring */
1472 /* the inappropriate `setcurrentpoint' instruction. So */
1473 /* we do the same. */
1476 if ( decoder
->flex_state
!= 1 )
1478 FT_ERROR(( "t1_decoder_parse_charstrings:"
1479 " unexpected `setcurrentpoint'\n" ));
1484 decoder
->flex_state
= 0;
1488 FT_TRACE4(( " opcode_15" ));
1489 /* nothing to do except to pop the two arguments */
1493 FT_ERROR(( "t1_decoder_parse_charstrings:"
1494 " unhandled opcode %d\n", op
));
1498 /* XXX Operators usually clear the operand stack; */
1499 /* only div, callsubr, callothersubr, pop, and */
1500 /* return are different. */
1501 /* In practice it doesn't matter (?). */
1505 #ifdef FT_DEBUG_LEVEL_TRACE
1506 FT_TRACE4(( "\n" ));
1510 } /* general operator processing */
1512 } /* while ip < limit */
1514 FT_TRACE4(( "..end..\n\n" ));
1520 return PSaux_Err_Syntax_Error
;
1523 return PSaux_Err_Stack_Underflow
;
1527 /* parse a single Type 1 glyph */
1528 FT_LOCAL_DEF( FT_Error
)
1529 t1_decoder_parse_glyph( T1_Decoder decoder
,
1532 return decoder
->parse_callback( decoder
, glyph
);
1536 /* initialize T1 decoder */
1537 FT_LOCAL_DEF( FT_Error
)
1538 t1_decoder_init( T1_Decoder decoder
,
1542 FT_Byte
** glyph_names
,
1545 FT_Render_Mode hint_mode
,
1546 T1_Decoder_Callback parse_callback
)
1548 FT_MEM_ZERO( decoder
, sizeof ( *decoder
) );
1550 /* retrieve PSNames interface from list of current modules */
1552 FT_Service_PsCMaps psnames
= 0;
1555 FT_FACE_FIND_GLOBAL_SERVICE( face
, psnames
, POSTSCRIPT_CMAPS
);
1558 FT_ERROR(( "t1_decoder_init:"
1559 " the `psnames' module is not available\n" ));
1560 return PSaux_Err_Unimplemented_Feature
;
1563 decoder
->psnames
= psnames
;
1566 t1_builder_init( &decoder
->builder
, face
, size
, slot
, hinting
);
1568 /* decoder->buildchar and decoder->len_buildchar have to be */
1569 /* initialized by the caller since we cannot know the length */
1570 /* of the BuildCharArray */
1572 decoder
->num_glyphs
= (FT_UInt
)face
->num_glyphs
;
1573 decoder
->glyph_names
= glyph_names
;
1574 decoder
->hint_mode
= hint_mode
;
1575 decoder
->blend
= blend
;
1576 decoder
->parse_callback
= parse_callback
;
1578 decoder
->funcs
= t1_decoder_funcs
;
1580 return PSaux_Err_Ok
;
1584 /* finalize T1 decoder */
1585 FT_LOCAL_DEF( void )
1586 t1_decoder_done( T1_Decoder decoder
)
1588 t1_builder_done( &decoder
->builder
);