/src/ghostpdl/base/wrfont.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2024 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., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, 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 | | #include "stdint_.h" |
26 | | |
27 | 66.2k | #define EEXEC_KEY 55665 |
28 | 17.4M | #define EEXEC_FACTOR 52845 |
29 | 17.4M | #define EEXEC_OFFSET 22719 |
30 | | |
31 | | void |
32 | | WRF_init(WRF_output * a_output, unsigned char *a_buffer, long a_buffer_size) |
33 | 66.2k | { |
34 | 66.2k | a_output->m_pos = a_buffer; |
35 | 66.2k | a_output->m_limit = a_buffer_size; |
36 | 66.2k | a_output->m_count = 0; |
37 | 66.2k | a_output->m_encrypt = false; |
38 | 66.2k | a_output->m_key = EEXEC_KEY; |
39 | 66.2k | } |
40 | | |
41 | | void |
42 | | WRF_wbyte(const gs_memory_t *memory, WRF_output * a_output, unsigned char a_byte) |
43 | 46.7M | { |
44 | 46.7M | if (a_output->m_count < a_output->m_limit && a_output->m_pos != NULL) { |
45 | 24.3M | if (a_output->m_encrypt) { |
46 | 17.4M | a_byte ^= (a_output->m_key >> 8); |
47 | 17.4M | a_output->m_key = |
48 | 17.4M | (unsigned short)((((uint64_t)a_output->m_key + a_byte) * EEXEC_FACTOR + |
49 | 17.4M | EEXEC_OFFSET) & 0xffff); |
50 | 17.4M | } |
51 | 24.3M | *a_output->m_pos++ = a_byte; |
52 | 24.3M | } |
53 | 46.7M | a_output->m_count++; |
54 | 46.7M | } |
55 | | |
56 | | void |
57 | | WRF_wtext(const gs_memory_t *memory, WRF_output * a_output, const unsigned char *a_string, long a_length) |
58 | 233k | { |
59 | 2.35M | while (a_length > 0) { |
60 | 2.12M | WRF_wbyte(memory, a_output, *a_string++); |
61 | 2.12M | a_length--; |
62 | 2.12M | } |
63 | 233k | } |
64 | | |
65 | | void |
66 | | WRF_wstring(const gs_memory_t *memory, WRF_output * a_output, const char *a_string) |
67 | 7.75M | { |
68 | 48.1M | while (*a_string) |
69 | 40.3M | WRF_wbyte(memory, a_output, *a_string++); |
70 | 7.75M | } |
71 | | |
72 | | void |
73 | | WRF_wfloat(const gs_memory_t *memory, WRF_output * a_output, double a_float) |
74 | 454k | { |
75 | 454k | char buffer[32]; |
76 | 454k | int l; |
77 | | |
78 | 454k | l = gs_snprintf(buffer, sizeof (buffer), "%f", a_float); |
79 | 454k | if (l > sizeof (buffer)) { |
80 | 0 | emprintf(memory, "Warning: Font real number value truncated\n"); |
81 | 0 | } |
82 | 454k | WRF_wstring(memory, a_output, buffer); |
83 | 454k | } |
84 | | |
85 | | void |
86 | | WRF_wint(const gs_memory_t *memory, WRF_output * a_output, long a_int) |
87 | 3.54M | { |
88 | 3.54M | char buffer[32]; |
89 | 3.54M | int l; |
90 | | |
91 | 3.54M | l = gs_snprintf(buffer, sizeof(buffer), "%ld", a_int); |
92 | 3.54M | if (l > sizeof (buffer)) { |
93 | 0 | emprintf(memory, "Warning: Font integer number value truncated\n"); |
94 | 0 | } |
95 | 3.54M | WRF_wstring(memory, a_output, buffer); |
96 | 3.54M | } |