1 /* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: wrfont.c,v 1.3 2003/05/05 12:57:13 igor Exp $ */
18 /*
19 Support functions to serialize fonts as PostScript code that can
20 then be passed to FreeType via the FAPI FreeType bridge.
21 Started by Graham Asher, 9th August 2002.
22 */
23
24 #include "wrfont.h"
25 #include "stdio_.h"
26
27 #define EEXEC_KEY 55665
28 #define EEXEC_FACTOR 52845
29 #define EEXEC_OFFSET 22719
30
WRF_init(WRF_output * a_output,unsigned char * a_buffer,long a_buffer_size)31 void WRF_init(WRF_output* a_output,unsigned char* a_buffer,long a_buffer_size)
32 {
33 a_output->m_pos = a_buffer;
34 a_output->m_limit = a_buffer_size;
35 a_output->m_count = 0;
36 a_output->m_encrypt = false;
37 a_output->m_key = EEXEC_KEY;
38 }
39
WRF_wbyte(WRF_output * a_output,unsigned char a_byte)40 void WRF_wbyte(WRF_output* a_output,unsigned char a_byte)
41 {
42 if (a_output->m_count < a_output->m_limit)
43 {
44 if (a_output->m_encrypt)
45 {
46 a_byte ^= (a_output->m_key >> 8);
47 a_output->m_key = (unsigned short)((a_output->m_key + a_byte) * EEXEC_FACTOR + EEXEC_OFFSET);
48 }
49 *a_output->m_pos++ = a_byte;
50 }
51 a_output->m_count++;
52 }
53
WRF_wtext(WRF_output * a_output,const unsigned char * a_string,long a_length)54 void WRF_wtext(WRF_output* a_output,const unsigned char* a_string,long a_length)
55 {
56 while (a_length > 0)
57 {
58 WRF_wbyte(a_output,*a_string++);
59 a_length--;
60 }
61 }
62
WRF_wstring(WRF_output * a_output,const char * a_string)63 void WRF_wstring(WRF_output* a_output,const char* a_string)
64 {
65 while (*a_string)
66 WRF_wbyte(a_output,*a_string++);
67 }
68
WRF_wfloat(WRF_output * a_output,double a_float)69 void WRF_wfloat(WRF_output* a_output,double a_float)
70 {
71 char buffer[32];
72 sprintf(buffer,"%f",a_float);
73 WRF_wstring(a_output,buffer);
74 }
75
WRF_wint(WRF_output * a_output,long a_int)76 void WRF_wint(WRF_output* a_output,long a_int)
77 {
78 char buffer[32];
79 sprintf(buffer,"%ld",a_int);
80 WRF_wstring(a_output,buffer);
81 }
82