wineps.drv: Calculate the font size directly from the logfont.
[wine/hramrach.git] / dlls / wineps.drv / encode.c
blobede5cbd6644bcf4e55b5a9e3a49f765b7507e5de
1 /*
2 * PostScript filter functions
4 * Copyright 2003 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include "psdrv.h"
26 DWORD RLE_encode(BYTE *in_buf, DWORD len, BYTE *out_buf)
28 BYTE *next_in = in_buf, *next_out = out_buf;
29 DWORD rl;
31 while(next_in < in_buf + len) {
32 if(next_in + 1 < in_buf + len) {
33 if(*next_in == *(next_in + 1)) {
34 next_in += 2;
35 rl = 2;
36 while(next_in < in_buf + len && *next_in == *(next_in - 1) && rl < 128) {
37 next_in++;
38 rl++;
40 *next_out++ = 257 - rl;
41 *next_out++ = *(next_in - 1);
42 } else {
43 rl = 0;
44 next_out++;
45 while(next_in < in_buf + len && rl < 128) {
46 if(next_in + 2 < in_buf + len && *next_in == *(next_in + 1)) {
47 if(rl == 127 || *next_in == *(next_in + 2))
48 break;
50 *next_out++ = *next_in++;
51 rl++;
53 *(next_out - rl - 1) = rl - 1;
55 } else { /* special case: begin of run on last byte */
56 *next_out++ = 0;
57 *next_out++ = *next_in;
58 break;
61 *next_out++ = 128;
62 return next_out - out_buf;
65 DWORD ASCII85_encode(BYTE *in_buf, DWORD len, BYTE *out_buf)
67 DWORD number;
68 BYTE *next_in = in_buf, *next_out = out_buf;
69 int i;
71 while(next_in + 3 < in_buf + len) {
72 number = (next_in[0] << 24) |
73 (next_in[1] << 16) |
74 (next_in[2] << 8) |
75 (next_in[3] );
76 next_in += 4;
77 if(number == 0)
78 *next_out++ = 'z';
79 else {
80 for(i = 4; i >= 0; i--) {
81 next_out[i] = number % 85 + '!';
82 number /= 85;
84 next_out += 5;
88 if(next_in != in_buf + len) {
89 number = (*next_in++ << 24) & 0xff000000;
90 if(next_in < in_buf + len)
91 number |= ((*next_in++ << 16) & 0x00ff0000);
92 if(next_in < in_buf + len)
93 number |= ((*next_in++ << 8) & 0x0000ff00);
95 for(i = len % 4 + 1; i < 5; i++)
96 number /= 85;
98 for(i = len % 4; i >= 0; i--) {
99 next_out[i] = number % 85 + '!';
100 number /= 85;
102 next_out += len % 4 + 1;
105 return next_out - out_buf;