1 /***************************************************************************/
5 /* PostScript Type 1 decoding routines (body). */
7 /* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_CALC_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
31 /*************************************************************************/
33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35 /* messages during execution. */
38 #define FT_COMPONENT trace_t1decode
41 typedef enum T1_Operator_
71 op_max
/* never remove this one */
77 const FT_Int t1_args_count
[op_max
] =
100 -1, /* callothersubr */
104 2, /* setcurrentpoint */
105 2 /* opcode 15 (undocumented and obsolete) */
109 /*************************************************************************/
112 /* t1_lookup_glyph_by_stdcharcode */
115 /* Looks up a given glyph by its StandardEncoding charcode. Used to */
116 /* implement the SEAC Type 1 operator. */
119 /* face :: The current face object. */
121 /* charcode :: The character code to look for. */
124 /* A glyph index in the font face. Returns -1 if the corresponding */
125 /* glyph wasn't found. */
128 t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder
,
132 const FT_String
* glyph_name
;
133 FT_Service_PsCMaps psnames
= decoder
->psnames
;
136 /* check range of standard char code */
137 if ( charcode
< 0 || charcode
> 255 )
140 glyph_name
= psnames
->adobe_std_strings(
141 psnames
->adobe_std_encoding
[charcode
]);
143 for ( n
= 0; n
< decoder
->num_glyphs
; n
++ )
145 FT_String
* name
= (FT_String
*)decoder
->glyph_names
[n
];
149 name
[0] == glyph_name
[0] &&
150 ft_strcmp( name
, glyph_name
) == 0 )
158 /*************************************************************************/
161 /* t1operator_seac */
164 /* Implements the `seac' Type 1 operator for a Type 1 decoder. */
167 /* decoder :: The current CID decoder. */
169 /* asb :: The accent's side bearing. */
171 /* adx :: The horizontal offset of the accent. */
173 /* ady :: The vertical offset of the accent. */
175 /* bchar :: The base character's StandardEncoding charcode. */
177 /* achar :: The accent character's StandardEncoding charcode. */
180 /* FreeType error code. 0 means success. */
183 t1operator_seac( T1_Decoder decoder
,
191 FT_Int bchar_index
, achar_index
;
193 FT_Int n_base_points
;
194 FT_Outline
* base
= decoder
->builder
.base
;
196 FT_Vector left_bearing
, advance
;
198 #ifdef FT_CONFIG_OPTION_INCREMENTAL
199 T1_Face face
= (T1_Face
)decoder
->builder
.face
;
205 FT_ERROR(( "t1operator_seac: invalid nested seac\n" ));
206 return PSaux_Err_Syntax_Error
;
210 adx
+= decoder
->builder
.left_bearing
.x
;
212 /* `glyph_names' is set to 0 for CID fonts which do not */
213 /* include an encoding. How can we deal with these? */
214 if ( decoder
->glyph_names
== 0 )
216 FT_ERROR(( "t1operator_seac:"
217 " glyph names table not available in this font\n" ));
218 return PSaux_Err_Syntax_Error
;
221 #ifdef FT_CONFIG_OPTION_INCREMENTAL
222 if ( face
->root
.internal
->incremental_interface
)
224 /* the caller must handle the font encoding also */
231 bchar_index
= t1_lookup_glyph_by_stdcharcode( decoder
, bchar
);
232 achar_index
= t1_lookup_glyph_by_stdcharcode( decoder
, achar
);
235 if ( bchar_index
< 0 || achar_index
< 0 )
237 FT_ERROR(( "t1operator_seac:"
238 " invalid seac character code arguments\n" ));
239 return PSaux_Err_Syntax_Error
;
242 /* if we are trying to load a composite glyph, do not load the */
243 /* accent character and return the array of subglyphs. */
244 if ( decoder
->builder
.no_recurse
)
246 FT_GlyphSlot glyph
= (FT_GlyphSlot
)decoder
->builder
.glyph
;
247 FT_GlyphLoader loader
= glyph
->internal
->loader
;
251 /* reallocate subglyph array if necessary */
252 error
= FT_GlyphLoader_CheckSubGlyphs( loader
, 2 );
256 subg
= loader
->current
.subglyphs
;
258 /* subglyph 0 = base character */
259 subg
->index
= bchar_index
;
260 subg
->flags
= FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
|
261 FT_SUBGLYPH_FLAG_USE_MY_METRICS
;
266 /* subglyph 1 = accent character */
267 subg
->index
= achar_index
;
268 subg
->flags
= FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
;
269 subg
->arg1
= (FT_Int
)FIXED_TO_INT( adx
- asb
);
270 subg
->arg2
= (FT_Int
)FIXED_TO_INT( ady
);
272 /* set up remaining glyph fields */
273 glyph
->num_subglyphs
= 2;
274 glyph
->subglyphs
= loader
->base
.subglyphs
;
275 glyph
->format
= FT_GLYPH_FORMAT_COMPOSITE
;
277 loader
->current
.num_subglyphs
= 2;
281 /* First load `bchar' in builder */
282 /* now load the unscaled outline */
284 FT_GlyphLoader_Prepare( decoder
->builder
.loader
); /* prepare loader */
286 /* the seac operator must not be nested */
287 decoder
->seac
= TRUE
;
288 error
= t1_decoder_parse_glyph( decoder
, bchar_index
);
289 decoder
->seac
= FALSE
;
293 /* save the left bearing and width of the base character */
294 /* as they will be erased by the next load. */
296 left_bearing
= decoder
->builder
.left_bearing
;
297 advance
= decoder
->builder
.advance
;
299 decoder
->builder
.left_bearing
.x
= 0;
300 decoder
->builder
.left_bearing
.y
= 0;
302 decoder
->builder
.pos_x
= adx
- asb
;
303 decoder
->builder
.pos_y
= ady
;
305 /* Now load `achar' on top of */
306 /* the base outline */
308 /* the seac operator must not be nested */
309 decoder
->seac
= TRUE
;
310 error
= t1_decoder_parse_glyph( decoder
, achar_index
);
311 decoder
->seac
= FALSE
;
315 /* restore the left side bearing and */
316 /* advance width of the base character */
318 decoder
->builder
.left_bearing
= left_bearing
;
319 decoder
->builder
.advance
= advance
;
321 decoder
->builder
.pos_x
= 0;
322 decoder
->builder
.pos_y
= 0;
329 /*************************************************************************/
332 /* t1_decoder_parse_charstrings */
335 /* Parses a given Type 1 charstrings program. */
338 /* decoder :: The current Type 1 decoder. */
340 /* charstring_base :: The base address of the charstring stream. */
342 /* charstring_len :: The length in bytes of the charstring stream. */
345 /* FreeType error code. 0 means success. */
347 FT_LOCAL_DEF( FT_Error
)
348 t1_decoder_parse_charstrings( T1_Decoder decoder
,
349 FT_Byte
* charstring_base
,
350 FT_UInt charstring_len
)
353 T1_Decoder_Zone zone
;
356 T1_Builder builder
= &decoder
->builder
;
357 FT_Pos x
, y
, orig_x
, orig_y
;
358 FT_Int known_othersubr_result_cnt
= 0;
359 FT_Int unknown_othersubr_result_cnt
= 0;
363 T1_Hints_Funcs hinter
;
365 #ifdef FT_DEBUG_LEVEL_TRACE
370 /* we don't want to touch the source code -- use macro trick */
371 #define start_point t1_builder_start_point
372 #define check_points t1_builder_check_points
373 #define add_point t1_builder_add_point
374 #define add_point1 t1_builder_add_point1
375 #define add_contour t1_builder_add_contour
376 #define close_contour t1_builder_close_contour
379 /* compute random seed from stack address of parameter */
380 seed
= (FT_Fixed
)( ( (FT_PtrDist
)(char*)&seed
^
381 (FT_PtrDist
)(char*)&decoder
^
382 (FT_PtrDist
)(char*)&charstring_base
) &
384 seed
= ( seed
^ ( seed
>> 10 ) ^ ( seed
>> 20 ) ) & 0xFFFFL
;
388 /* First of all, initialize the decoder */
389 decoder
->top
= decoder
->stack
;
390 decoder
->zone
= decoder
->zones
;
391 zone
= decoder
->zones
;
393 builder
->parse_state
= T1_Parse_Start
;
395 hinter
= (T1_Hints_Funcs
)builder
->hints_funcs
;
397 /* a font that reads BuildCharArray without setting */
398 /* its values first is buggy, but ... */
399 FT_ASSERT( ( decoder
->len_buildchar
== 0 ) ==
400 ( decoder
->buildchar
== NULL
) );
402 if ( decoder
->len_buildchar
> 0 )
403 ft_memset( &decoder
->buildchar
[0],
405 sizeof( decoder
->buildchar
[0] ) * decoder
->len_buildchar
);
408 "Start charstring\n" ));
410 zone
->base
= charstring_base
;
411 limit
= zone
->limit
= charstring_base
+ charstring_len
;
412 ip
= zone
->cursor
= zone
->base
;
414 error
= PSaux_Err_Ok
;
416 x
= orig_x
= builder
->pos_x
;
417 y
= orig_y
= builder
->pos_y
;
419 /* begin hints recording session, if any */
421 hinter
->open( hinter
->hints
);
425 /* now, execute loop */
428 FT_Long
* top
= decoder
->top
;
429 T1_Operator op
= op_none
;
433 FT_ASSERT( known_othersubr_result_cnt
== 0 ||
434 unknown_othersubr_result_cnt
== 0 );
436 #ifdef FT_DEBUG_LEVEL_TRACE
439 FT_TRACE5(( " (%d)", decoder
->top
- decoder
->stack
));
444 /*********************************************************************/
446 /* Decode operator or operand */
450 /* first of all, decompress operator or value */
492 case 15: /* undocumented, obsolete operator */
513 FT_ERROR(( "t1_decoder_parse_charstrings:"
514 " invalid escape (12+EOF)\n" ));
539 op
= op_callothersubr
;
545 op
= op_setcurrentpoint
;
549 FT_ERROR(( "t1_decoder_parse_charstrings:"
550 " invalid escape (12+%d)\n",
556 case 255: /* four bytes integer */
557 if ( ip
+ 4 > limit
)
559 FT_ERROR(( "t1_decoder_parse_charstrings:"
560 " unexpected EOF in integer\n" ));
564 value
= (FT_Int32
)( ( (FT_Long
)ip
[0] << 24 ) |
565 ( (FT_Long
)ip
[1] << 16 ) |
566 ( (FT_Long
)ip
[2] << 8 ) |
570 /* According to the specification, values > 32000 or < -32000 must */
571 /* be followed by a `div' operator to make the result be in the */
572 /* range [-32000;32000]. We expect that the second argument of */
573 /* `div' is not a large number. Additionally, we don't handle */
574 /* stuff like `<large1> <large2> <num> div <num> div' or */
575 /* <large1> <large2> <num> div div'. This is probably not allowed */
577 if ( value
> 32000 || value
< -32000 )
581 FT_ERROR(( "t1_decoder_parse_charstrings:"
582 " no `div' after large integer\n" ));
599 value
= (FT_Int32
)ip
[-1] - 139;
604 FT_ERROR(( "t1_decoder_parse_charstrings:"
605 " unexpected EOF in integer\n" ));
610 value
= ( ( (FT_Int32
)ip
[-2] - 247 ) << 8 ) + ip
[-1] + 108;
612 value
= -( ( ( (FT_Int32
)ip
[-2] - 251 ) << 8 ) + ip
[-1] + 108 );
620 FT_ERROR(( "t1_decoder_parse_charstrings:"
621 " invalid byte (%d)\n", ip
[-1] ));
626 if ( unknown_othersubr_result_cnt
> 0 )
637 /* all operands have been transferred by previous pops */
638 unknown_othersubr_result_cnt
= 0;
643 if ( large_int
&& !( op
== op_none
|| op
== op_div
) )
645 FT_ERROR(( "t1_decoder_parse_charstrings:"
646 " no `div' after large integer\n" ));
651 /*********************************************************************/
653 /* Push value on stack, or process operator */
658 if ( top
- decoder
->stack
>= T1_MAX_CHARSTRINGS_OPERANDS
)
660 FT_ERROR(( "t1_decoder_parse_charstrings: stack overflow\n" ));
664 #ifdef FT_DEBUG_LEVEL_TRACE
666 FT_TRACE4(( " %ld", value
));
668 FT_TRACE4(( " %ld", (FT_Int32
)( value
>> 16 ) ));
674 else if ( op
== op_callothersubr
) /* callothersubr */
680 #ifdef FT_DEBUG_LEVEL_TRACE
681 FT_TRACE4(( " callothersubr\n" ));
685 if ( top
- decoder
->stack
< 2 )
686 goto Stack_Underflow
;
690 subr_no
= (FT_Int
)( top
[1] >> 16 );
691 arg_cnt
= (FT_Int
)( top
[0] >> 16 );
693 /***********************************************************/
695 /* remove all operands to callothersubr from the stack */
697 /* for handled othersubrs, where we know the number of */
698 /* arguments, we increase the stack by the value of */
699 /* known_othersubr_result_cnt */
701 /* for unhandled othersubrs the following pops adjust the */
702 /* stack pointer as necessary */
704 if ( arg_cnt
> top
- decoder
->stack
)
705 goto Stack_Underflow
;
709 known_othersubr_result_cnt
= 0;
710 unknown_othersubr_result_cnt
= 0;
712 /* XXX TODO: The checks to `arg_count == <whatever>' */
713 /* might not be correct; an othersubr expects a certain */
714 /* number of operands on the PostScript stack (as opposed */
715 /* to the T1 stack) but it doesn't have to put them there */
716 /* by itself; previous othersubrs might have left the */
717 /* operands there if they were not followed by an */
718 /* appropriate number of pops */
720 /* On the other hand, Adobe Reader 7.0.8 for Linux doesn't */
721 /* accept a font that contains charstrings like */
723 /* 100 200 2 20 callothersubr */
724 /* 300 1 20 callothersubr pop */
726 /* Perhaps this is the reason why BuildCharArray exists. */
730 case 1: /* start flex feature */
732 goto Unexpected_OtherSubr
;
734 decoder
->flex_state
= 1;
735 decoder
->num_flex_vectors
= 0;
736 if ( start_point( builder
, x
, y
) ||
737 check_points( builder
, 6 ) )
741 case 2: /* add flex vectors */
747 goto Unexpected_OtherSubr
;
749 /* note that we should not add a point for index 0; */
750 /* this will move our current position to the flex */
751 /* point without adding any point to the outline */
752 idx
= decoder
->num_flex_vectors
++;
753 if ( idx
> 0 && idx
< 7 )
757 (FT_Byte
)( idx
== 3 || idx
== 6 ) );
761 case 0: /* end flex feature */
763 goto Unexpected_OtherSubr
;
765 if ( decoder
->flex_state
== 0 ||
766 decoder
->num_flex_vectors
!= 7 )
768 FT_ERROR(( "t1_decoder_parse_charstrings:"
769 " unexpected flex end\n" ));
773 /* the two `results' are popped by the following setcurrentpoint */
774 known_othersubr_result_cnt
= 2;
777 case 3: /* change hints */
779 goto Unexpected_OtherSubr
;
781 known_othersubr_result_cnt
= 1;
784 hinter
->reset( hinter
->hints
, builder
->current
->n_points
);
789 /* counter control hints, clear stack */
790 top
= decoder
->stack
;
797 case 18: /* multiple masters */
799 PS_Blend blend
= decoder
->blend
;
800 FT_UInt num_points
, nn
, mm
;
807 FT_ERROR(( "t1_decoder_parse_charstrings:"
808 " unexpected multiple masters operator\n" ));
812 num_points
= (FT_UInt
)subr_no
- 13 + ( subr_no
== 18 );
813 if ( arg_cnt
!= (FT_Int
)( num_points
* blend
->num_designs
) )
815 FT_ERROR(( "t1_decoder_parse_charstrings:"
816 " incorrect number of multiple masters arguments\n" ));
820 /* we want to compute: */
822 /* a0*w0 + a1*w1 + ... + ak*wk */
824 /* but we only have the a0, a1-a0, a2-a0, .. ak-a0 */
825 /* however, given that w0 + w1 + ... + wk == 1, we can */
826 /* rewrite it easily as: */
828 /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + .. + (ak-a0)*wk */
830 /* where k == num_designs-1 */
832 /* I guess that's why it's written in this `compact' */
835 delta
= top
+ num_points
;
837 for ( nn
= 0; nn
< num_points
; nn
++ )
839 FT_Long tmp
= values
[0];
842 for ( mm
= 1; mm
< blend
->num_designs
; mm
++ )
843 tmp
+= FT_MulFix( *delta
++, blend
->weight_vector
[mm
] );
848 known_othersubr_result_cnt
= num_points
;
853 /* <idx> 1 19 callothersubr */
854 /* => replace elements starting from index cvi( <idx> ) */
855 /* of BuildCharArray with WeightVector */
858 PS_Blend blend
= decoder
->blend
;
861 if ( arg_cnt
!= 1 || blend
== NULL
)
862 goto Unexpected_OtherSubr
;
864 idx
= (FT_Int
)( top
[0] >> 16 );
867 idx
+ blend
->num_designs
> decoder
->len_buildchar
)
868 goto Unexpected_OtherSubr
;
870 ft_memcpy( &decoder
->buildchar
[idx
],
871 blend
->weight_vector
,
873 sizeof( blend
->weight_vector
[0] ) );
878 /* <arg1> <arg2> 2 20 callothersubr pop */
879 /* ==> push <arg1> + <arg2> onto T1 stack */
881 goto Unexpected_OtherSubr
;
883 top
[0] += top
[1]; /* XXX (over|under)flow */
885 known_othersubr_result_cnt
= 1;
889 /* <arg1> <arg2> 2 21 callothersubr pop */
890 /* ==> push <arg1> - <arg2> onto T1 stack */
892 goto Unexpected_OtherSubr
;
894 top
[0] -= top
[1]; /* XXX (over|under)flow */
896 known_othersubr_result_cnt
= 1;
900 /* <arg1> <arg2> 2 22 callothersubr pop */
901 /* ==> push <arg1> * <arg2> onto T1 stack */
903 goto Unexpected_OtherSubr
;
905 top
[0] = FT_MulFix( top
[0], top
[1] );
907 known_othersubr_result_cnt
= 1;
911 /* <arg1> <arg2> 2 23 callothersubr pop */
912 /* ==> push <arg1> / <arg2> onto T1 stack */
913 if ( arg_cnt
!= 2 || top
[1] == 0 )
914 goto Unexpected_OtherSubr
;
916 top
[0] = FT_DivFix( top
[0], top
[1] );
918 known_othersubr_result_cnt
= 1;
922 /* <val> <idx> 2 24 callothersubr */
923 /* ==> set BuildCharArray[cvi( <idx> )] = <val> */
926 PS_Blend blend
= decoder
->blend
;
929 if ( arg_cnt
!= 2 || blend
== NULL
)
930 goto Unexpected_OtherSubr
;
932 idx
= (FT_Int
)( top
[1] >> 16 );
934 if ( idx
< 0 || (FT_UInt
) idx
>= decoder
->len_buildchar
)
935 goto Unexpected_OtherSubr
;
937 decoder
->buildchar
[idx
] = top
[0];
942 /* <idx> 1 25 callothersubr pop */
943 /* ==> push BuildCharArray[cvi( idx )] */
947 PS_Blend blend
= decoder
->blend
;
950 if ( arg_cnt
!= 1 || blend
== NULL
)
951 goto Unexpected_OtherSubr
;
953 idx
= (FT_Int
)( top
[0] >> 16 );
955 if ( idx
< 0 || (FT_UInt
) idx
>= decoder
->len_buildchar
)
956 goto Unexpected_OtherSubr
;
958 top
[0] = decoder
->buildchar
[idx
];
961 known_othersubr_result_cnt
= 1;
966 /* <val> mark <idx> ==> set BuildCharArray[cvi( <idx> )] = <val>, */
967 /* leave mark on T1 stack */
968 /* <val> <idx> ==> set BuildCharArray[cvi( <idx> )] = <val> */
969 XXX which routine has left its mark on
the (PostScript
) stack
?;
974 /* <res1> <res2> <val1> <val2> 4 27 callothersubr pop */
975 /* ==> push <res1> onto T1 stack if <val1> <= <val2>, */
976 /* otherwise push <res2> */
978 goto Unexpected_OtherSubr
;
980 if ( top
[2] > top
[3] )
983 known_othersubr_result_cnt
= 1;
987 /* 0 28 callothersubr pop */
988 /* => push random value from interval [0, 1) onto stack */
990 goto Unexpected_OtherSubr
;
997 if ( Rand
>= 0x8000L
)
1002 seed
= FT_MulFix( seed
, 0x10000L
- seed
);
1007 known_othersubr_result_cnt
= 1;
1011 FT_ERROR(( "t1_decoder_parse_charstrings:"
1012 " unknown othersubr [%d %d], wish me luck\n",
1013 arg_cnt
, subr_no
));
1014 unknown_othersubr_result_cnt
= arg_cnt
;
1017 Unexpected_OtherSubr
:
1018 FT_ERROR(( "t1_decoder_parse_charstrings:"
1019 " invalid othersubr [%d %d]\n", arg_cnt
, subr_no
));
1023 top
+= known_othersubr_result_cnt
;
1027 else /* general operator */
1029 FT_Int num_args
= t1_args_count
[op
];
1032 FT_ASSERT( num_args
>= 0 );
1034 if ( top
- decoder
->stack
< num_args
)
1035 goto Stack_Underflow
;
1037 /* XXX Operators usually take their operands from the */
1038 /* bottom of the stack, i.e., the operands are */
1039 /* decoder->stack[0], ..., decoder->stack[num_args - 1]; */
1040 /* only div, callsubr, and callothersubr are different. */
1041 /* In practice it doesn't matter (?). */
1043 #ifdef FT_DEBUG_LEVEL_TRACE
1049 case op_callothersubr
:
1055 if ( top
- decoder
->stack
!= num_args
)
1056 FT_TRACE0(( "t1_decoder_parse_charstrings:"
1057 " too much operands on the stack"
1058 " (seen %d, expected %d)\n",
1059 top
- decoder
->stack
, num_args
));
1063 #endif /* FT_DEBUG_LEVEL_TRACE */
1070 FT_TRACE4(( " endchar\n" ));
1072 close_contour( builder
);
1074 /* close hints recording session */
1077 if ( hinter
->close( hinter
->hints
, builder
->current
->n_points
) )
1080 /* apply hints to the loaded glyph outline now */
1081 hinter
->apply( hinter
->hints
,
1083 (PSH_Globals
)builder
->hints_globals
,
1084 decoder
->hint_mode
);
1087 /* add current outline to the glyph slot */
1088 FT_GlyphLoader_Add( builder
->loader
);
1090 /* the compiler should optimize away this empty loop but ... */
1092 #ifdef FT_DEBUG_LEVEL_TRACE
1094 if ( decoder
->len_buildchar
> 0 )
1099 FT_TRACE4(( "BuildCharArray = [ " ));
1101 for ( i
= 0; i
< decoder
->len_buildchar
; ++i
)
1102 FT_TRACE4(( "%d ", decoder
->buildchar
[ i
] ));
1104 FT_TRACE4(( "]\n" ));
1107 #endif /* FT_DEBUG_LEVEL_TRACE */
1109 FT_TRACE4(( "\n" ));
1112 return PSaux_Err_Ok
;
1115 FT_TRACE4(( " hsbw" ));
1117 builder
->parse_state
= T1_Parse_Have_Width
;
1119 builder
->left_bearing
.x
+= top
[0];
1120 builder
->advance
.x
= top
[1];
1121 builder
->advance
.y
= 0;
1123 orig_x
= x
= builder
->pos_x
+ top
[0];
1124 orig_y
= y
= builder
->pos_y
;
1126 FT_UNUSED( orig_y
);
1128 /* the `metrics_only' indicates that we only want to compute */
1129 /* the glyph's metrics (lsb + advance width), not load the */
1130 /* rest of it; so exit immediately */
1131 if ( builder
->metrics_only
)
1132 return PSaux_Err_Ok
;
1137 return t1operator_seac( decoder
,
1141 (FT_Int
)( top
[3] >> 16 ),
1142 (FT_Int
)( top
[4] >> 16 ) );
1145 FT_TRACE4(( " sbw" ));
1147 builder
->parse_state
= T1_Parse_Have_Width
;
1149 builder
->left_bearing
.x
+= top
[0];
1150 builder
->left_bearing
.y
+= top
[1];
1151 builder
->advance
.x
= top
[2];
1152 builder
->advance
.y
= top
[3];
1154 x
= builder
->pos_x
+ top
[0];
1155 y
= builder
->pos_y
+ top
[1];
1157 /* the `metrics_only' indicates that we only want to compute */
1158 /* the glyph's metrics (lsb + advance width), not load the */
1159 /* rest of it; so exit immediately */
1160 if ( builder
->metrics_only
)
1161 return PSaux_Err_Ok
;
1166 FT_TRACE4(( " closepath" ));
1168 /* if there is no path, `closepath' is a no-op */
1169 if ( builder
->parse_state
== T1_Parse_Have_Path
||
1170 builder
->parse_state
== T1_Parse_Have_Moveto
)
1171 close_contour( builder
);
1173 builder
->parse_state
= T1_Parse_Have_Width
;
1177 FT_TRACE4(( " hlineto" ));
1179 if ( start_point( builder
, x
, y
) )
1186 FT_TRACE4(( " hmoveto" ));
1189 if ( !decoder
->flex_state
)
1191 if ( builder
->parse_state
== T1_Parse_Start
)
1193 builder
->parse_state
= T1_Parse_Have_Moveto
;
1198 FT_TRACE4(( " hvcurveto" ));
1200 if ( start_point( builder
, x
, y
) ||
1201 check_points( builder
, 3 ) )
1205 add_point( builder
, x
, y
, 0 );
1208 add_point( builder
, x
, y
, 0 );
1210 add_point( builder
, x
, y
, 1 );
1214 FT_TRACE4(( " rlineto" ));
1216 if ( start_point( builder
, x
, y
) )
1223 if ( add_point1( builder
, x
, y
) )
1228 FT_TRACE4(( " rmoveto" ));
1232 if ( !decoder
->flex_state
)
1234 if ( builder
->parse_state
== T1_Parse_Start
)
1236 builder
->parse_state
= T1_Parse_Have_Moveto
;
1241 FT_TRACE4(( " rrcurveto" ));
1243 if ( start_point( builder
, x
, y
) ||
1244 check_points( builder
, 3 ) )
1249 add_point( builder
, x
, y
, 0 );
1253 add_point( builder
, x
, y
, 0 );
1257 add_point( builder
, x
, y
, 1 );
1261 FT_TRACE4(( " vhcurveto" ));
1263 if ( start_point( builder
, x
, y
) ||
1264 check_points( builder
, 3 ) )
1268 add_point( builder
, x
, y
, 0 );
1271 add_point( builder
, x
, y
, 0 );
1273 add_point( builder
, x
, y
, 1 );
1277 FT_TRACE4(( " vlineto" ));
1279 if ( start_point( builder
, x
, y
) )
1286 FT_TRACE4(( " vmoveto" ));
1289 if ( !decoder
->flex_state
)
1291 if ( builder
->parse_state
== T1_Parse_Start
)
1293 builder
->parse_state
= T1_Parse_Have_Moveto
;
1298 FT_TRACE4(( " div" ));
1300 /* if `large_int' is set, we divide unscaled numbers; */
1301 /* otherwise, we divide numbers in 16.16 format -- */
1302 /* in both cases, it is the same operation */
1303 *top
= FT_DivFix( top
[0], top
[1] );
1314 FT_TRACE4(( " callsubr" ));
1316 idx
= (FT_Int
)( top
[0] >> 16 );
1317 if ( idx
< 0 || idx
>= (FT_Int
)decoder
->num_subrs
)
1319 FT_ERROR(( "t1_decoder_parse_charstrings:"
1320 " invalid subrs index\n" ));
1324 if ( zone
- decoder
->zones
>= T1_MAX_SUBRS_CALLS
)
1326 FT_ERROR(( "t1_decoder_parse_charstrings:"
1327 " too many nested subrs\n" ));
1331 zone
->cursor
= ip
; /* save current instruction pointer */
1335 /* The Type 1 driver stores subroutines without the seed bytes. */
1336 /* The CID driver stores subroutines with seed bytes. This */
1337 /* case is taken care of when decoder->subrs_len == 0. */
1338 zone
->base
= decoder
->subrs
[idx
];
1340 if ( decoder
->subrs_len
)
1341 zone
->limit
= zone
->base
+ decoder
->subrs_len
[idx
];
1344 /* We are using subroutines from a CID font. We must adjust */
1345 /* for the seed bytes. */
1346 zone
->base
+= ( decoder
->lenIV
>= 0 ? decoder
->lenIV
: 0 );
1347 zone
->limit
= decoder
->subrs
[idx
+ 1];
1350 zone
->cursor
= zone
->base
;
1354 FT_ERROR(( "t1_decoder_parse_charstrings:"
1355 " invoking empty subrs\n" ));
1359 decoder
->zone
= zone
;
1361 limit
= zone
->limit
;
1366 FT_TRACE4(( " pop" ));
1368 if ( known_othersubr_result_cnt
> 0 )
1370 known_othersubr_result_cnt
--;
1371 /* ignore, we pushed the operands ourselves */
1375 if ( unknown_othersubr_result_cnt
== 0 )
1377 FT_ERROR(( "t1_decoder_parse_charstrings:"
1378 " no more operands for othersubr\n" ));
1382 unknown_othersubr_result_cnt
--;
1383 top
++; /* `push' the operand to callothersubr onto the stack */
1387 FT_TRACE4(( " return" ));
1389 if ( zone
<= decoder
->zones
)
1391 FT_ERROR(( "t1_decoder_parse_charstrings:"
1392 " unexpected return\n" ));
1398 limit
= zone
->limit
;
1399 decoder
->zone
= zone
;
1403 FT_TRACE4(( " dotsection" ));
1408 FT_TRACE4(( " hstem" ));
1410 /* record horizontal hint */
1413 /* top[0] += builder->left_bearing.y; */
1414 hinter
->stem( hinter
->hints
, 1, top
);
1419 FT_TRACE4(( " hstem3" ));
1421 /* record horizontal counter-controlled hints */
1423 hinter
->stem3( hinter
->hints
, 1, top
);
1427 FT_TRACE4(( " vstem" ));
1429 /* record vertical hint */
1433 hinter
->stem( hinter
->hints
, 0, top
);
1438 FT_TRACE4(( " vstem3" ));
1440 /* record vertical counter-controlled hints */
1449 hinter
->stem3( hinter
->hints
, 0, top
);
1453 case op_setcurrentpoint
:
1454 FT_TRACE4(( " setcurrentpoint" ));
1456 /* From the T1 specs, section 6.4: */
1458 /* The setcurrentpoint command is used only in */
1459 /* conjunction with results from OtherSubrs procedures. */
1461 /* known_othersubr_result_cnt != 0 is already handled above */
1462 if ( decoder
->flex_state
!= 1 )
1464 FT_ERROR(( "t1_decoder_parse_charstrings:"
1465 " unexpected `setcurrentpoint'\n" ));
1469 decoder
->flex_state
= 0;
1473 FT_TRACE4(( " opcode_15" ));
1474 /* nothing to do except to pop the two arguments */
1478 FT_ERROR(( "t1_decoder_parse_charstrings:"
1479 " unhandled opcode %d\n", op
));
1483 /* XXX Operators usually clear the operand stack; */
1484 /* only div, callsubr, callothersubr, pop, and */
1485 /* return are different. */
1486 /* In practice it doesn't matter (?). */
1490 #ifdef FT_DEBUG_LEVEL_TRACE
1491 FT_TRACE4(( "\n" ));
1495 } /* general operator processing */
1497 } /* while ip < limit */
1499 FT_TRACE4(( "..end..\n\n" ));
1505 return PSaux_Err_Syntax_Error
;
1508 return PSaux_Err_Stack_Underflow
;
1512 /* parse a single Type 1 glyph */
1513 FT_LOCAL_DEF( FT_Error
)
1514 t1_decoder_parse_glyph( T1_Decoder decoder
,
1517 return decoder
->parse_callback( decoder
, glyph
);
1521 /* initialize T1 decoder */
1522 FT_LOCAL_DEF( FT_Error
)
1523 t1_decoder_init( T1_Decoder decoder
,
1527 FT_Byte
** glyph_names
,
1530 FT_Render_Mode hint_mode
,
1531 T1_Decoder_Callback parse_callback
)
1533 FT_MEM_ZERO( decoder
, sizeof ( *decoder
) );
1535 /* retrieve PSNames interface from list of current modules */
1537 FT_Service_PsCMaps psnames
= 0;
1540 FT_FACE_FIND_GLOBAL_SERVICE( face
, psnames
, POSTSCRIPT_CMAPS
);
1543 FT_ERROR(( "t1_decoder_init:"
1544 " the `psnames' module is not available\n" ));
1545 return PSaux_Err_Unimplemented_Feature
;
1548 decoder
->psnames
= psnames
;
1551 t1_builder_init( &decoder
->builder
, face
, size
, slot
, hinting
);
1553 /* decoder->buildchar and decoder->len_buildchar have to be */
1554 /* initialized by the caller since we cannot know the length */
1555 /* of the BuildCharArray */
1557 decoder
->num_glyphs
= (FT_UInt
)face
->num_glyphs
;
1558 decoder
->glyph_names
= glyph_names
;
1559 decoder
->hint_mode
= hint_mode
;
1560 decoder
->blend
= blend
;
1561 decoder
->parse_callback
= parse_callback
;
1563 decoder
->funcs
= t1_decoder_funcs
;
1565 return PSaux_Err_Ok
;
1569 /* finalize T1 decoder */
1570 FT_LOCAL_DEF( void )
1571 t1_decoder_done( T1_Decoder decoder
)
1573 t1_builder_done( &decoder
->builder
);