ReactOS 0.4.16-dev-2332-g4cba65d
psconv.c File Reference
#include <freetype/internal/psaux.h>
#include <freetype/internal/ftdebug.h>
#include "psconv.h"
#include "psauxerr.h"
Include dependency graph for psconv.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   psconv
 
#define OP   >=
 

Functions

 PS_Conv_Strtol (FT_Byte **cursor, FT_Byte *limit, FT_Long base)
 
 PS_Conv_ToInt (FT_Byte **cursor, FT_Byte *limit)
 
 PS_Conv_ToFixed (FT_Byte **cursor, FT_Byte *limit, FT_Long power_ten)
 
 PS_Conv_ASCIIHexDecode (FT_Byte **cursor, FT_Byte *limit, FT_Byte *buffer, FT_Offset n)
 
 PS_Conv_EexecDecode (FT_Byte **cursor, FT_Byte *limit, FT_Byte *buffer, FT_Offset n, FT_UShort *seed)
 

Variables

static const FT_Char ft_char_table [128]
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   psconv

Definition at line 33 of file psconv.c.

◆ OP

#define OP   >=

Definition at line 56 of file psconv.c.

Function Documentation

◆ PS_Conv_ASCIIHexDecode()

PS_Conv_ASCIIHexDecode ( FT_Byte **  cursor,
FT_Byte limit,
FT_Byte buffer,
FT_Offset  n 
)

Definition at line 464 of file psconv.c.

468 {
469 FT_Byte* p;
470 FT_UInt r = 0;
471 FT_UInt w = 0;
472 FT_UInt pad = 0x01;
473
474
475 n *= 2;
476
477#if 1
478
479 p = *cursor;
480
481 if ( p >= limit )
482 return 0;
483
484 if ( n > (FT_UInt)( limit - p ) )
485 n = (FT_UInt)( limit - p );
486
487 /* we try to process two nibbles at a time to be as fast as possible */
488 for ( ; r < n; r++ )
489 {
490 FT_UInt c = p[r];
491
492
493 if ( IS_PS_SPACE( c ) )
494 continue;
495
496 if ( c OP 0x80 )
497 break;
498
499 c = (FT_UInt)ft_char_table[c & 0x7F];
500 if ( c >= 16 )
501 break;
502
503 pad = ( pad << 4 ) | c;
504 if ( pad & 0x100 )
505 {
506 buffer[w++] = (FT_Byte)pad;
507 pad = 0x01;
508 }
509 }
510
511 if ( pad != 0x01 )
512 buffer[w++] = (FT_Byte)( pad << 4 );
513
514 *cursor = p + r;
515
516 return w;
517
518#else /* 0 */
519
520 for ( r = 0; r < n; r++ )
521 {
522 FT_Char c;
523
524
525 if ( IS_PS_SPACE( *p ) )
526 continue;
527
528 if ( *p OP 0x80 )
529 break;
530
531 c = ft_char_table[*p & 0x7F];
532
533 if ( (unsigned)c >= 16 )
534 break;
535
536 if ( r & 1 )
537 {
538 *buffer = (FT_Byte)(*buffer + c);
539 buffer++;
540 }
541 else
542 *buffer = (FT_Byte)(c << 4);
543
544 r++;
545 }
546
547 *cursor = p;
548
549 return ( r + 1 ) / 2;
550
551#endif /* 0 */
552
553 }
OP
Definition: DragDrop.cpp:27
signed char FT_Char
Definition: fttypes.h:143
unsigned char FT_Byte
Definition: fttypes.h:154
unsigned int FT_UInt
Definition: fttypes.h:231
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLint limit
Definition: glext.h:10326
GLfloat GLfloat p
Definition: glext.h:8902
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
const char cursor[]
Definition: icontest.c:13
#define c
Definition: ke_i.h:80
#define IS_PS_SPACE(ch)
Definition: psaux.h:1395
static const FT_Char ft_char_table[128]
Definition: psconv.c:42

Referenced by ps_parser_to_bytes().

◆ PS_Conv_EexecDecode()

PS_Conv_EexecDecode ( FT_Byte **  cursor,
FT_Byte limit,
FT_Byte buffer,
FT_Offset  n,
FT_UShort seed 
)

Definition at line 557 of file psconv.c.

562 {
563 FT_Byte* p;
564 FT_UInt r;
565 FT_UInt s = *seed;
566
567
568#if 1
569
570 p = *cursor;
571
572 if ( p >= limit )
573 return 0;
574
575 if ( n > (FT_UInt)(limit - p) )
576 n = (FT_UInt)(limit - p);
577
578 for ( r = 0; r < n; r++ )
579 {
580 FT_UInt val = p[r];
581 FT_UInt b = ( val ^ ( s >> 8 ) );
582
583
584 s = ( (val + s)*52845U + 22719 ) & 0xFFFFU;
585 buffer[r] = (FT_Byte) b;
586 }
587
588 *cursor = p + n;
589 *seed = (FT_UShort)s;
590
591#else /* 0 */
592
593 for ( r = 0, p = *cursor; r < n && p < limit; r++, p++ )
594 {
595 FT_Byte b = (FT_Byte)( *p ^ ( s >> 8 ) );
596
597
598 s = (FT_UShort)( ( *p + s ) * 52845U + 22719 );
599 *buffer++ = b;
600 }
601 *cursor = p;
602 *seed = s;
603
604#endif /* 0 */
605
606 return r;
607 }
unsigned short FT_UShort
Definition: fttypes.h:209
GLdouble s
Definition: gl.h:2039
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint GLfloat * val
Definition: glext.h:7180
#define b
Definition: ke_i.h:79

Referenced by t1_decrypt().

◆ PS_Conv_Strtol()

PS_Conv_Strtol ( FT_Byte **  cursor,
FT_Byte limit,
FT_Long  base 
)

Definition at line 83 of file psconv.c.

86 {
87 FT_Byte* p = *cursor;
88
89 FT_Long num = 0;
90 FT_Bool sign = 0;
91 FT_Bool have_overflow = 0;
92
93 FT_Long num_limit;
95
96
97 if ( p >= limit )
98 goto Bad;
99
100 if ( base < 2 || base > 36 )
101 {
102 FT_TRACE4(( "!!!INVALID BASE:!!!" ));
103 return 0;
104 }
105
106 if ( *p == '-' || *p == '+' )
107 {
108 sign = FT_BOOL( *p == '-' );
109
110 p++;
111 if ( p == limit )
112 goto Bad;
113
114 /* only a single sign is allowed */
115 if ( *p == '-' || *p == '+' )
116 return 0;
117 }
118
119 num_limit = 0x7FFFFFFFL / base;
120 c_limit = (FT_Char)( 0x7FFFFFFFL % base );
121
122 for ( ; p < limit; p++ )
123 {
124 FT_Char c;
125
126
127 if ( IS_PS_SPACE( *p ) || *p OP 0x80 )
128 break;
129
130 c = ft_char_table[*p & 0x7F];
131
132 if ( c < 0 || c >= base )
133 break;
134
135 if ( num > num_limit || ( num == num_limit && c > c_limit ) )
136 have_overflow = 1;
137 else
138 num = num * base + c;
139 }
140
141 *cursor = p;
142
143 if ( have_overflow )
144 {
145 num = 0x7FFFFFFFL;
146 FT_TRACE4(( "!!!OVERFLOW:!!!" ));
147 }
148
149 if ( sign )
150 num = -num;
151
152 return num;
153
154 Bad:
155 FT_TRACE4(( "!!!END OF DATA:!!!" ));
156 return 0;
157 }
#define FT_TRACE4(varformat)
Definition: ftdebug.h:191
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
signed long FT_Long
Definition: fttypes.h:242
#define FT_BOOL(x)
Definition: fttypes.h:591
GLuint GLuint num
Definition: glext.h:9618
#define sign(x)
Definition: mapdesc.cc:613
@ c_limit
Definition: synths.h:13

Referenced by PS_Conv_ToInt().

◆ PS_Conv_ToFixed()

PS_Conv_ToFixed ( FT_Byte **  cursor,
FT_Byte limit,
FT_Long  power_ten 
)

Definition at line 195 of file psconv.c.

198 {
199 FT_Byte* p = *cursor;
200 FT_Byte* curp;
201
202 FT_Fixed integral = 0;
203 FT_Long decimal = 0;
204 FT_Long divider = 1;
205
206 FT_Bool sign = 0;
207 FT_Bool have_overflow = 0;
208 FT_Bool have_underflow = 0;
209
210
211 if ( p >= limit )
212 goto Bad;
213
214 if ( *p == '-' || *p == '+' )
215 {
216 sign = FT_BOOL( *p == '-' );
217
218 p++;
219 if ( p == limit )
220 goto Bad;
221
222 /* only a single sign is allowed */
223 if ( *p == '-' || *p == '+' )
224 return 0;
225 }
226
227 /* read the integer part */
228 if ( *p != '.' )
229 {
230 curp = p;
231 integral = PS_Conv_ToInt( &p, limit );
232
233 if ( p == curp )
234 return 0;
235
236 if ( integral > 0x7FFF )
237 have_overflow = 1;
238 else
239 integral = (FT_Fixed)( (FT_UInt32)integral << 16 );
240 }
241
242 /* read the decimal part */
243 if ( p < limit && *p == '.' )
244 {
245 p++;
246
247 for ( ; p < limit; p++ )
248 {
249 FT_Char c;
250
251
252 if ( IS_PS_SPACE( *p ) || *p OP 0x80 )
253 break;
254
255 c = ft_char_table[*p & 0x7F];
256
257 if ( c < 0 || c >= 10 )
258 break;
259
260 /* only add digit if we don't overflow */
261 if ( divider < 0xCCCCCCCL && decimal < 0xCCCCCCCL )
262 {
263 decimal = decimal * 10 + c;
264
265 if ( !integral && power_ten > 0 )
266 power_ten--;
267 else
268 divider *= 10;
269 }
270 }
271 }
272
273 /* read exponent, if any */
274 if ( p + 1 < limit && ( *p == 'e' || *p == 'E' ) )
275 {
277
278
279 p++;
280
281 curp = p;
283
284 if ( curp == p )
285 return 0;
286
287 /* arbitrarily limit exponent */
288 if ( exponent > 1000 )
289 have_overflow = 1;
290 else if ( exponent < -1000 )
291 have_underflow = 1;
292 else
293 power_ten += exponent;
294 }
295
296 *cursor = p;
297
298 if ( !integral && !decimal )
299 return 0;
300
301 if ( have_overflow )
302 goto Overflow;
303 if ( have_underflow )
304 goto Underflow;
305
306 while ( power_ten > 0 )
307 {
308 if ( integral >= 0xCCCCCCCL )
309 goto Overflow;
310 integral *= 10;
311
312 if ( decimal >= 0xCCCCCCCL )
313 {
314 if ( divider == 1 )
315 goto Overflow;
316 divider /= 10;
317 }
318 else
319 decimal *= 10;
320
321 power_ten--;
322 }
323
324 while ( power_ten < 0 )
325 {
326 integral /= 10;
327 if ( divider < 0xCCCCCCCL )
328 divider *= 10;
329 else
330 decimal /= 10;
331
332 if ( !integral && !decimal )
333 goto Underflow;
334
335 power_ten++;
336 }
337
338 if ( decimal )
339 {
340 decimal = FT_DivFix( decimal, divider );
341 /* it's not necessary to check this addition for overflow */
342 /* due to the structure of the real number representation */
343 integral += decimal;
344 }
345
346 Exit:
347 if ( sign )
348 integral = -integral;
349
350 return integral;
351
352 Bad:
353 FT_TRACE4(( "!!!END OF DATA:!!!" ));
354 return 0;
355
356 Overflow:
357 integral = 0x7FFFFFFFL;
358 FT_TRACE4(( "!!!OVERFLOW:!!!" ));
359 goto Exit;
360
361 Underflow:
362 FT_TRACE4(( "!!!UNDERFLOW:!!!" ));
363 return 0;
364 }
__int64 exponent
Definition: cvt.cpp:529
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:607
signed long FT_Fixed
Definition: fttypes.h:287
PS_Conv_ToInt(FT_Byte **cursor, FT_Byte *limit)
Definition: psconv.c:161
static void Exit(void)
Definition: sock.c:1330

Referenced by afm_parser_read_vals(), ps_parser_load_field(), ps_parser_to_fixed(), ps_tocoordarray(), and ps_tofixedarray().

◆ PS_Conv_ToInt()

PS_Conv_ToInt ( FT_Byte **  cursor,
FT_Byte limit 
)

Definition at line 161 of file psconv.c.

164 {
165 FT_Byte* p = *cursor;
166 FT_Byte* curp;
167
168 FT_Long num;
169
170
171 curp = p;
172 num = PS_Conv_Strtol( &p, limit, 10 );
173
174 if ( p == curp )
175 return 0;
176
177 if ( p < limit && *p == '#' )
178 {
179 p++;
180
181 curp = p;
182 num = PS_Conv_Strtol( &p, limit, num );
183
184 if ( p == curp )
185 return 0;
186 }
187
188 *cursor = p;
189
190 return num;
191 }
PS_Conv_Strtol(FT_Byte **cursor, FT_Byte *limit, FT_Long base)
Definition: psconv.c:83

Referenced by afm_parser_read_vals(), PS_Conv_ToFixed(), ps_parser_load_field(), and ps_parser_to_int().

Variable Documentation

◆ ft_char_table

const FT_Char ft_char_table[128]
static
Initial value:
=
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 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, -1, -1, -1, -1, -1,
-1, 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, -1, -1, -1, -1, -1,
}

Definition at line 42 of file psconv.c.

Referenced by PS_Conv_ASCIIHexDecode(), PS_Conv_Strtol(), and PS_Conv_ToFixed().