1 /*******************************************************************
3 ** *********************************************************
8 ** * Send Soft Font Download data to the specified
13 ** *********************************************************
15 ********************************************************************/
17 (c) Copyright 1996 Hewlett-Packard Company
18 (c) Copyright 1996 International Business Machines Corp.
19 (c) Copyright 1996 Sun Microsystems, Inc.
20 (c) Copyright 1996 Novell, Inc.
21 (c) Copyright 1996 Digital Equipment Corp.
22 (c) Copyright 1996 Fujitsu Limited
23 (c) Copyright 1996 Hitachi, Ltd.
25 Permission is hereby granted, free of charge, to any person obtaining a copy
26 of this software and associated documentation files (the "Software"), to deal
27 in the Software without restriction, including without limitation the rights
28 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 copies of the Software, and to permit persons to whom the Software is
30 furnished to do so, subject to the following conditions:
32 The above copyright notice and this permission notice shall be included in
33 all copies or substantial portions of the Software.
35 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 Except as contained in this notice, the names of the copyright holders shall
43 not be used in advertising or otherwise to promote the sale, use or other
44 dealings in this Software without prior written authorization from said
49 #ifdef HAVE_DIX_CONFIG_H
50 #include <dix-config.h>
58 #define Put1byte(fp, x) tmp1=x; fwrite((char *)&tmp1, 1, 1, fp)
59 #define Put2bytes(fp, x) tmp2=x; fwrite((char *)&tmp2, 2, 1, fp)
62 #define SYMBOL_SET 277
64 static unsigned int PclDownloadChar(FILE *,PclCharDataPtr
,unsigned short,unsigned char);
65 static unsigned int PclDownloadHeader(FILE *, PclFontDescPtr
, unsigned short);
67 #ifdef PCL_FONT_COMPRESS
68 static unsigned char *compress_bitmap_data(PclCharDataPtr
, unsigned int *);
69 #endif /* PCL_FONT_COMPRESS */
71 /* -*- PclDownloadSoftFont8 -*-
72 * Send the Character Definition Command for 8-bit font
73 * **************************************************************************/
77 PclSoftFontInfoPtr pSoftFontInfo
,
84 * Check whether the font header has already been downloaded.
85 * If not, download it.
89 pfh
->fid
= pSoftFontInfo
->cur_max_fid
++;
90 PclDownloadHeader(fp
, &(pfh
->fd
), pfh
->fid
);
92 pfh
->index
[*code
] = *code
;
93 PclDownloadChar(fp
, pcd
, pfh
->fid
, pfh
->index
[*code
]);
97 /* -*- PclDownloadSoftFont16 -*-
98 * Send the Character Definition Command for 16 bit font
99 * **************************************************************************/
101 PclDownloadSoftFont16(
103 PclSoftFontInfoPtr pSoftFontInfo
,
104 PclFontHead16Ptr pfh
,
111 * Check whether the font header is already downloaded.
112 * If not, download it.
115 if ( !pfh
->cur_cindex
) {
116 pfh
->cur_fid
= pSoftFontInfo
->cur_max_fid
++;
117 PclDownloadHeader(fp
, &(pfh
->fd
), pfh
->cur_fid
);
119 pfh
->index
[row
][col
].fid
= pfh
->cur_fid
;
120 pfh
->index
[row
][col
].cindex
= pfh
->cur_cindex
++;
122 PclDownloadChar(fp
, pcd
, pfh
->index
[row
][col
].fid
, pfh
->index
[row
][col
].cindex
);
125 /* -*- PclCreateSoftFontInfo -*-
126 * Create and Initialize the structure for storing the information
127 * of the downloaded soft font.
128 * **************************************************************************/
130 PclCreateSoftFontInfo(void)
132 PclSoftFontInfoPtr pSoftFontInfo
;
134 pSoftFontInfo
= (PclSoftFontInfoPtr
)xalloc(sizeof(PclSoftFontInfoRec
));
135 if ( pSoftFontInfo
== (PclSoftFontInfoPtr
) NULL
)
136 return (PclSoftFontInfoPtr
) NULL
;
137 pSoftFontInfo
->phead8
= (PclFontHead8Ptr
)NULL
;
138 pSoftFontInfo
->phead16
= (PclFontHead16Ptr
)NULL
;
139 pSoftFontInfo
->pinfont
= (PclInternalFontPtr
)NULL
;
140 pSoftFontInfo
->cur_max_fid
= 1;
141 return pSoftFontInfo
;
144 /* -*- PclDestroySoftFontInfo -*-
145 * Destroy the soft font information structure
146 * **************************************************************************/
148 PclDestroySoftFontInfo( PclSoftFontInfoPtr pSoftFontInfo
)
150 PclFontHead8Ptr pfh8
, pfh8_next
;
151 PclFontHead16Ptr pfh16
, pfh16_next
;
152 PclInternalFontPtr pin
, pin_next
;
153 unsigned char nindex_row
;
156 if ( pSoftFontInfo
== (PclSoftFontInfoPtr
) NULL
)
159 pfh8
= pSoftFontInfo
->phead8
;
160 while (pfh8
!= (PclFontHead8Ptr
) NULL
) {
161 xfree(pfh8
->fontname
);
163 pfh8_next
= pfh8
->next
;
168 pfh16
= pSoftFontInfo
->phead16
;
169 while (pfh16
!= (PclFontHead16Ptr
) NULL
) {
170 xfree(pfh16
->fontname
);
171 nindex_row
= pfh16
->lastRow
- pfh16
->firstRow
+ 1;
172 for (i
=0; i
<nindex_row
; i
++)
173 xfree(pfh16
->index
[i
]);
175 pfh16_next
= pfh16
->next
;
180 pin
= pSoftFontInfo
->pinfont
;
181 while (pin
!= (PclInternalFontPtr
) NULL
) {
182 xfree(pin
->fontname
);
183 pin_next
= pin
->next
;
188 xfree(pSoftFontInfo
);
191 /* -*- PclDownloadHeader -*-
192 * Send the Font Header Commnad.
193 * Format 0 : Font Header for Pcl Bitmapped Fonts
194 * Format 20 : Font Header for Resolution Specified Bitmapped Fonts
195 * **************************************************************************/
209 #endif /* XP_PCL_LJ3 */
211 * Font ID Command : Esc *c#D
212 * (Default = 0, Range = 0 - 32767)
214 fprintf(fp
, "%c*c%dD", ESC
, fid
);
217 * Font Header Commnad : Esc )s#W[font header data]
218 * (Default = 0, Range = 0 - 32767)
220 fprintf(fp
, "%c)s%dW", ESC
, nbytes
);
222 Put2bytes(fp
, nbytes
); /* Font Description Size */
224 Put1byte(fp
, 0); /* Header Format */
226 Put1byte(fp
, 20); /* Header Format */
227 #endif /* XP_PCL_LJ3 */
228 Put1byte(fp
, 2); /* Font Type */
229 Put2bytes(fp
, 0); /* Style MSB */
230 Put2bytes(fp
, fd
->ascent
); /* BaseLine Position */
231 Put2bytes(fp
, fd
->cellwidth
); /* Cell Width */
232 Put2bytes(fp
, fd
->cellheight
); /* Cell Height */
233 Put1byte(fp
, 0); /* Orienation */
234 Put1byte(fp
, fd
->spacing
); /* Spacing */
235 Put2bytes(fp
, SYMBOL_SET
); /* Symbol Set */
236 Put2bytes(fp
, fd
->pitch
*4); /* font pitch */
237 Put2bytes(fp
, fd
->cellheight
* 4); /* Height */
238 Put2bytes(fp
, 0); /* x-Height */
239 Put1byte(fp
, 0); /* width type (normal) */
240 Put1byte(fp
, 0); /* Style LSB */
241 Put1byte(fp
, 0); /* Stroke Weight */
242 Put1byte(fp
, 5); /* Typeface LSB */
243 Put1byte(fp
, 0); /* Typeface MSB */
244 Put1byte(fp
, 0); /* Serif Style */
245 Put1byte(fp
, 0); /* Quality */
246 Put1byte(fp
, 0); /* Placement */
247 Put1byte(fp
, 0); /* Underline Position */
248 Put1byte(fp
, 0); /* Underline Thickness */
249 Put2bytes(fp
, fd
->cellheight
*1.2); /* Text Height */
250 Put2bytes(fp
, fd
->cellwidth
* 4); /* Text Width */
251 Put2bytes(fp
, 0); /* First Code */
252 Put2bytes(fp
, 255); /* Last Code */
253 Put1byte(fp
, 0); /* Pitch Extend */
254 Put1byte(fp
, 0); /* Height Extend */
255 Put2bytes(fp
, 0); /* Cap Height */
256 Put2bytes(fp
, 0); /* Font Number 1 */
257 Put2bytes(fp
, 0); /* Font Number 2 */
258 Put2bytes(fp
, 0); /* Font Name */
259 Put2bytes(fp
, 0); /* Font Name */
260 Put2bytes(fp
, 0); /* Font Name */
261 Put2bytes(fp
, 0); /* Font Name */
262 Put2bytes(fp
, 0); /* Font Name */
263 Put2bytes(fp
, 0); /* Font Name */
264 Put2bytes(fp
, 0); /* Font Name */
265 Put2bytes(fp
, 0); /* Font Name */
270 Put2bytes(fp
, 300); /* X Resolution */
271 Put2bytes(fp
, 300); /* Y Resolution */
273 #endif /* XP_PCL_LJ3 */
277 /* -*- PclDownloadCharacter -*-
278 * Send the Character Definition Command.
279 * **************************************************************************/
288 unsigned int nbytes
, n
;
289 unsigned char *raster
;
292 * Font ID Command : Esc *c#D
293 * (Default = 0, Range = 0 - 32767)
294 * Character Code Command : Esc *c#E
295 * (Default = 0, Range = 0 - 65535)
297 fprintf(fp
, "%c*c%dd%dE", ESC
, fid
, code
);
300 * Character Definition Command : Esc (s#W[character descriptor and data]
301 * (Default = N/A, Range = 0 - 32767)
304 nbytes
= n
= cd
->height
* ((cd
->width
+ 7) / 8);
305 #ifdef PCL_FONT_COMPRESS
306 raster
= compress_bitmap_data(cd
, &nbytes
);
308 raster
= (unsigned char *)NULL
;
309 #endif /* PCL_FONT_COMPRESS */
310 fprintf(fp
, "%c(s%dW", ESC
, nbytes
+ 16);
312 Put1byte(fp
, 4); /* Format */
313 Put1byte(fp
, 0); /* Continuation */
314 Put1byte(fp
, 14); /* Descriptor Size */
315 if (raster
) { /* Class */
318 Put1byte(fp
, 1); /* Class */
320 Put2bytes(fp
, 0); /* Orientation */
321 Put2bytes(fp
, cd
->h_offset
); /* left offset */
322 Put2bytes(fp
, cd
->v_offset
); /* top offset */
323 Put2bytes(fp
, cd
->width
); /* character width */
324 Put2bytes(fp
, cd
->height
); /* character height */
325 Put2bytes(fp
, cd
->font_pitch
*4); /* delta X */
328 * Raster Character Data
331 fwrite(raster
, nbytes
, 1, fp
);
334 fwrite(cd
->raster_top
, nbytes
, 1, fp
);
340 #ifdef PCL_FONT_COMPRESS
341 /* -*- compress_bitmap_data -*-
342 * Compress Bitmap data
343 * **************************************************************************/
344 static unsigned char *
345 compress_bitmap_data(
350 unsigned int byte_width
;
351 unsigned char *raster
, *rptr_s
, *rptr_e
, *rptr_end
;
352 unsigned char *tmp_s
, *tmp_ptr
;
354 unsigned char cur
, pixel
;
359 byte_width
= (cd
->width
+ 7) / 8;
360 *nbytes
= cd
->height
* byte_width
;
362 /* Create buffer for storing compress bitmap glyph */
363 raster
= (unsigned char *)xalloc(*nbytes
);
366 rptr_end
= raster
+ *nbytes
;
368 tmp_s
= (unsigned char *)xalloc(cd
->width
* 8 + 2);
371 for (i
=0; i
<cd
->height
; i
++) {
374 if ( (*p
>>7)&0x1 == 1 ) {
381 for (j
=0, w
=0; j
<byte_width
; j
++, p
++) {
382 for (k
=0; k
<8 && w
<cd
->width
; k
++, w
++) {
383 pixel
= (*p
>>(7-k
))&0x1;
384 if ( pixel
== cur
) {
398 if ( pixel
== cur
) {
404 *tmp_ptr
++ = num
&0xff;
408 if ( ((rptr_e
- rptr_s
) == (tmp_ptr
- tmp_s
)) &&
409 !memcmp(rptr_s
+1, tmp_s
+1, (tmp_ptr
- tmp_s
) - 1) )
412 if ( rptr_e
+ (tmp_ptr
- tmp_s
) > rptr_end
) {
415 return (unsigned char *)NULL
;
417 memcpy (rptr_e
, tmp_s
, tmp_ptr
- tmp_s
);
419 rptr_e
= rptr_s
+ (tmp_ptr
- tmp_s
);
423 *nbytes
= rptr_e
- raster
;
427 #endif /* PCL_FONT_COMPRESS */