1 /****************************************************************************
2 *
3 * psobjs.c
4 *
5 * Auxiliary functions for PostScript fonts (body).
6 *
7 * Copyright (C) 1996-2019 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
19 #include <ft2build.h>
20 #include FT_INTERNAL_POSTSCRIPT_AUX_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_CALC_H
23 #include FT_DRIVER_H
24
25 #include "psobjs.h"
26 #include "psconv.h"
27
197 if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
198 in_offset = -1;
199
200 while ( new_size < table->cursor + length )
201 {
202 /* increase size by 25% and round up to the nearest multiple
203 of 1024 */
204 new_size += ( new_size >> 2 ) + 1;
205 new_size = FT_PAD_CEIL( new_size, 1024 );
206 }
207
208 error = reallocate_t1_table( table, new_size );
209 if ( error )
210 return error;
211
212 if ( in_offset >= 0 )
213 object = table->block + in_offset;
214 }
215
216 /* add the object to the base block and adjust offset */
217 table->elements[idx] = table->block + table->cursor;
218 table->lengths [idx] = length;
219 FT_MEM_COPY( table->block + table->cursor, object, length );
220
221 table->cursor += length;
222 return FT_Err_Ok;
223 }
224
225
226 /**************************************************************************
227 *
228 * @Function:
229 * ps_table_done
230 *
231 * @Description:
232 * Finalizes a PS_TableRec (i.e., reallocate it to its current
233 * cursor).
234 *
235 * @InOut:
236 * table ::
237 * The target table.
2560
2561 /* compute random seed from some memory addresses */
2562 seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^
2563 (FT_Offset)(char*)&face ^
2564 (FT_Offset)(char*)&subfont );
2565 seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 );
2566 if ( seed == 0 )
2567 seed = 0x7384;
2568
2569 subfont->random = seed;
2570 }
2571 }
2572
2573
2574 FT_LOCAL_DEF( void )
2575 t1_decrypt( FT_Byte* buffer,
2576 FT_Offset length,
2577 FT_UShort seed )
2578 {
2579 PS_Conv_EexecDecode( &buffer,
2580 buffer + length,
2581 buffer,
2582 length,
2583 &seed );
2584 }
2585
2586
2587 FT_LOCAL_DEF( FT_UInt32 )
2588 cff_random( FT_UInt32 r )
2589 {
2590 /* a 32bit version of the `xorshift' algorithm */
2591 r ^= r << 13;
2592 r ^= r >> 17;
2593 r ^= r << 5;
2594
2595 return r;
2596 }
2597
2598
2599 /* END */
|
1 /****************************************************************************
2 *
3 * psobjs.c
4 *
5 * Auxiliary functions for PostScript fonts (body).
6 *
7 * Copyright (C) 1996-2020 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
19 #include <ft2build.h>
20 #include FT_INTERNAL_POSTSCRIPT_AUX_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_CALC_H
23 #include FT_DRIVER_H
24
25 #include "psobjs.h"
26 #include "psconv.h"
27
197 if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
198 in_offset = -1;
199
200 while ( new_size < table->cursor + length )
201 {
202 /* increase size by 25% and round up to the nearest multiple
203 of 1024 */
204 new_size += ( new_size >> 2 ) + 1;
205 new_size = FT_PAD_CEIL( new_size, 1024 );
206 }
207
208 error = reallocate_t1_table( table, new_size );
209 if ( error )
210 return error;
211
212 if ( in_offset >= 0 )
213 object = table->block + in_offset;
214 }
215
216 /* add the object to the base block and adjust offset */
217 table->elements[idx] = FT_OFFSET( table->block, table->cursor );
218 table->lengths [idx] = length;
219 FT_MEM_COPY( table->block + table->cursor, object, length );
220
221 table->cursor += length;
222 return FT_Err_Ok;
223 }
224
225
226 /**************************************************************************
227 *
228 * @Function:
229 * ps_table_done
230 *
231 * @Description:
232 * Finalizes a PS_TableRec (i.e., reallocate it to its current
233 * cursor).
234 *
235 * @InOut:
236 * table ::
237 * The target table.
2560
2561 /* compute random seed from some memory addresses */
2562 seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^
2563 (FT_Offset)(char*)&face ^
2564 (FT_Offset)(char*)&subfont );
2565 seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 );
2566 if ( seed == 0 )
2567 seed = 0x7384;
2568
2569 subfont->random = seed;
2570 }
2571 }
2572
2573
2574 FT_LOCAL_DEF( void )
2575 t1_decrypt( FT_Byte* buffer,
2576 FT_Offset length,
2577 FT_UShort seed )
2578 {
2579 PS_Conv_EexecDecode( &buffer,
2580 FT_OFFSET( buffer, length ),
2581 buffer,
2582 length,
2583 &seed );
2584 }
2585
2586
2587 FT_LOCAL_DEF( FT_UInt32 )
2588 cff_random( FT_UInt32 r )
2589 {
2590 /* a 32bit version of the `xorshift' algorithm */
2591 r ^= r << 13;
2592 r ^= r >> 17;
2593 r ^= r << 5;
2594
2595 return r;
2596 }
2597
2598
2599 /* END */
|