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