/src/ghostpdl/base/wrfont.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2021 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, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | /* |
17 | | Support functions to serialize fonts as PostScript code that can |
18 | | then be passed to FreeType via the FAPI FreeType bridge. |
19 | | Started by Graham Asher, 9th August 2002. |
20 | | */ |
21 | | |
22 | | #include "wrfont.h" |
23 | | #include "stdio_.h" |
24 | | #include "assert_.h" |
25 | | |
26 | 472k | #define EEXEC_KEY 55665 |
27 | 107M | #define EEXEC_FACTOR 52845 |
28 | 107M | #define EEXEC_OFFSET 22719 |
29 | | |
30 | | void |
31 | | WRF_init(WRF_output * a_output, unsigned char *a_buffer, long a_buffer_size) |
32 | 472k | { |
33 | 472k | a_output->m_pos = a_buffer; |
34 | 472k | a_output->m_limit = a_buffer_size; |
35 | 472k | a_output->m_count = 0; |
36 | 472k | a_output->m_encrypt = false; |
37 | 472k | a_output->m_key = EEXEC_KEY; |
38 | 472k | } |
39 | | |
40 | | void |
41 | | WRF_wbyte(const gs_memory_t *memory, WRF_output * a_output, unsigned char a_byte) |
42 | 304M | { |
43 | 304M | if (a_output->m_count < a_output->m_limit && a_output->m_pos != NULL) { |
44 | 158M | if (a_output->m_encrypt) { |
45 | 107M | a_byte ^= (a_output->m_key >> 8); |
46 | 107M | a_output->m_key = |
47 | 107M | (unsigned short)((a_output->m_key + a_byte) * EEXEC_FACTOR + |
48 | 107M | EEXEC_OFFSET); |
49 | 107M | } |
50 | 158M | *a_output->m_pos++ = a_byte; |
51 | 158M | } |
52 | 304M | a_output->m_count++; |
53 | 304M | } |
54 | | |
55 | | void |
56 | | WRF_wtext(const gs_memory_t *memory, WRF_output * a_output, const unsigned char *a_string, long a_length) |
57 | 1.84M | { |
58 | 16.0M | while (a_length > 0) { |
59 | 14.2M | WRF_wbyte(memory, a_output, *a_string++); |
60 | 14.2M | a_length--; |
61 | 14.2M | } |
62 | 1.84M | } |
63 | | |
64 | | void |
65 | | WRF_wstring(const gs_memory_t *memory, WRF_output * a_output, const char *a_string) |
66 | 47.1M | { |
67 | 313M | while (*a_string) |
68 | 266M | WRF_wbyte(memory, a_output, *a_string++); |
69 | 47.1M | } |
70 | | |
71 | | void |
72 | | WRF_wfloat(const gs_memory_t *memory, WRF_output * a_output, double a_float) |
73 | 3.26M | { |
74 | 3.26M | char buffer[32]; |
75 | 3.26M | int l; |
76 | | |
77 | 3.26M | l = gs_snprintf(buffer, sizeof (buffer), "%f", a_float); |
78 | 3.26M | if (l > sizeof (buffer)) { |
79 | 0 | emprintf(memory, "Warning: Font real number value truncated\n"); |
80 | 0 | } |
81 | 3.26M | WRF_wstring(memory, a_output, buffer); |
82 | 3.26M | } |
83 | | |
84 | | void |
85 | | WRF_wint(const gs_memory_t *memory, WRF_output * a_output, long a_int) |
86 | 18.7M | { |
87 | 18.7M | char buffer[32]; |
88 | 18.7M | int l; |
89 | | |
90 | 18.7M | l = gs_snprintf(buffer, sizeof(buffer), "%ld", a_int); |
91 | 18.7M | if (l > sizeof (buffer)) { |
92 | 0 | emprintf(memory, "Warning: Font integer number value truncated\n"); |
93 | 0 | } |
94 | 18.7M | WRF_wstring(memory, a_output, buffer); |
95 | 18.7M | } |