3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996 Sun Microsystems, Inc.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
66 ** * Contents: Character-drawing routines for the PS DDX
68 ** * Created By: Roger Helmendach (Liberty Systems)
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
72 ** *********************************************************
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
82 #include "windowstr.h"
83 #include <X11/fonts/fntfil.h>
84 #include <X11/fonts/fntfilst.h>
89 DrawablePtr pDrawable
,
96 if( pDrawable
->type
==DRAWABLE_PIXMAP
)
99 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
100 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
104 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return x
;
106 disp
= PsGetFreeDisplayBlock(priv
);
108 elm
= &disp
->elms
[disp
->nelms
];
109 elm
->type
= Text8Cmd
;
113 elm
->c
.text8
.count
= count
;
114 elm
->c
.text8
.string
= (char *)xalloc(count
);
115 memcpy(elm
->c
.text8
.string
, string
, count
);
122 PsFontInfoRec
*firec
;
124 /* We need a context for rendering... */
125 if (PsGetPsContextPriv(pDrawable
) == NULL
)
128 firec
= PsGetFontInfoRec(pDrawable
, pGC
->font
);
132 #ifdef XP_USE_FREETYPE
133 if (firec
->ftir
->downloadableFont
&&
134 (firec
->ftir
->font_type
== PSFTI_FONT_TYPE_FREETYPE
))
139 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
)
142 if (firec
->ftir
->alreadyDownloaded
[0] == False
)
144 PsOut_DownloadFreeType(psOut
,
145 firec
->ftir
->ft_download_font_type
,
146 firec
->ftir
->download_ps_name
, pGC
->font
, 0);
147 firec
->ftir
->alreadyDownloaded
[0] = True
;
150 PsOut_Offset(psOut
, pDrawable
->x
, pDrawable
->y
);
151 PsOut_Color(psOut
, PsGetPixelColor(cMap
, pGC
->fgPixel
));
153 PsOut_TextAttrsMtx(psOut
, firec
->ftir
->download_ps_name
, firec
->mtx
, firec
->ftir
->is_iso_encoding
);
155 PsOut_TextAttrs(psOut
, firec
->ftir
->download_ps_name
, firec
->size
, firec
->ftir
->is_iso_encoding
);
156 PsOut_FreeType_Text(pGC
->font
, psOut
, x
, y
, string
, count
);
161 #endif /* XP_USE_FREETYPE */
162 if (firec
->ftir
->downloadableFont
&&
163 (firec
->ftir
->font_type
!= PSFTI_FONT_TYPE_FREETYPE
))
168 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
)
171 if (firec
->ftir
->alreadyDownloaded
[0] == False
)
173 PsOut_DownloadType1(psOut
, "PsPolyText8",
174 firec
->ftir
->download_ps_name
, firec
->ftir
->filename
);
175 firec
->ftir
->alreadyDownloaded
[0] = True
;
178 PsOut_Offset(psOut
, pDrawable
->x
, pDrawable
->y
);
179 PsOut_Color(psOut
, PsGetPixelColor(cMap
, pGC
->fgPixel
));
181 PsOut_TextAttrsMtx(psOut
, firec
->ftir
->download_ps_name
, firec
->mtx
, firec
->ftir
->is_iso_encoding
);
183 PsOut_TextAttrs(psOut
, firec
->ftir
->download_ps_name
, firec
->size
, firec
->ftir
->is_iso_encoding
);
184 PsOut_Text(psOut
, x
, y
, string
, count
, -1);
189 /* Render glyphs as bitmaps */
193 CharInfoPtr charinfo
[255];
195 GetGlyphs(pGC
->font
, (unsigned long)count
,
196 (unsigned char *)string
, Linear8Bit
, &n
, charinfo
);
198 for (i
=0; i
< n
; i
++)
199 w
+= charinfo
[i
]->metrics
.characterWidth
;
202 PsPolyGlyphBlt(pDrawable
, pGC
, x
, y
, n
,
203 charinfo
, FONTGLYPHS(pGC
->font
));
214 DrawablePtr pDrawable
,
219 unsigned short *string
)
221 if( pDrawable
->type
==DRAWABLE_PIXMAP
)
224 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
225 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
229 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return x
;
231 disp
= PsGetFreeDisplayBlock(priv
);
233 elm
= &disp
->elms
[disp
->nelms
];
234 elm
->type
= Text16Cmd
;
238 elm
->c
.text16
.count
= count
;
239 elm
->c
.text16
.string
=
240 (unsigned short *)xalloc(count
*sizeof(unsigned short));
241 memcpy(elm
->c
.text16
.string
, string
, count
*sizeof(unsigned short));
248 PsFontInfoRec
*firec
;
250 /* We need a context for rendering... */
251 if (PsGetPsContextPriv(pDrawable
) == NULL
)
254 firec
= PsGetFontInfoRec(pDrawable
, pGC
->font
);
258 #ifdef XP_USE_FREETYPE
259 if (firec
->ftir
->downloadableFont
&&
260 (firec
->ftir
->font_type
== PSFTI_FONT_TYPE_FREETYPE
))
270 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
)
273 /* Scan the string we want to render and download all neccesary parts
274 * of the font (one part(="font page") has 256 glyphs)
276 for( i
= 0 ; i
< count
; i
++ )
279 #if IMAGE_BYTE_ORDER == LSBFirst
280 c_hiByte
= c
& 0x00FF;
281 c_lowByte
= (c
>> 8) & 0x00FF;
282 #elif IMAGE_BYTE_ORDER == MSBFirst
283 c_hiByte
= (c
>> 8) & 0x00FF;
284 c_lowByte
= c
& 0x00FF;
286 #error Unsupported byte order
290 if (firec
->ftir
->alreadyDownloaded
[fontPage
] == False
)
297 sprintf(buffer
, "%s_%x", firec
->ftir
->download_ps_name
, (int)fontPage
);
302 ps_name
= firec
->ftir
->download_ps_name
;
305 PsOut_DownloadFreeType(psOut
,
306 firec
->ftir
->ft_download_font_type
,
307 ps_name
, pGC
->font
, (fontPage
* 0x100)); /* same as (fontPage << 8) */
309 firec
->ftir
->alreadyDownloaded
[fontPage
] = True
;
314 PsOut_Offset(psOut
, pDrawable
->x
, pDrawable
->y
);
315 PsOut_Color(psOut
, PsGetPixelColor(cMap
, pGC
->fgPixel
));
317 PsOut_FreeType_TextAttrsMtx16(psOut
, firec
->ftir
->download_ps_name
, firec
->mtx
, firec
->ftir
->is_iso_encoding
);
319 PsOut_FreeType_TextAttrs16(psOut
, firec
->ftir
->download_ps_name
, firec
->size
, firec
->ftir
->is_iso_encoding
);
320 PsOut_FreeType_Text16(pGC
->font
, psOut
, x
, y
, string
, count
);
325 #endif /* XP_USE_FREETYPE */
326 if (firec
->ftir
->downloadableFont
&&
327 (firec
->ftir
->font_type
!= PSFTI_FONT_TYPE_FREETYPE
))
331 unsigned short fontPage
;
333 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
)
336 PsOut_DownloadType1(psOut
, "PsPolyText16",
337 firec
->ftir
->download_ps_name
, firec
->ftir
->filename
);
338 firec
->ftir
->alreadyDownloaded
[fontPage
] = True
;
340 PsOut_Offset(psOut
, pDrawable
->x
, pDrawable
->y
);
341 PsOut_Color(psOut
, PsGetPixelColor(cMap
, pGC
->fgPixel
));
343 PsOut_TextAttrsMtx(psOut
, firec
->ftir
->download_ps_name
, firec
->mtx
, firec
->ftir
->is_iso_encoding
);
345 PsOut_TextAttrs(psOut
, firec
->ftir
->download_ps_name
, firec
->size
, firec
->ftir
->is_iso_encoding
);
346 PsOut_Text16(psOut
, x
, y
, string
, count
, -1);
351 /* Render glyphs as bitmaps */
355 CharInfoPtr charinfo
[255]; /* encoding only has 1 byte for count */
357 GetGlyphs(pGC
->font
, (unsigned long)count
, (unsigned char *)string
,
358 (FONTLASTROW(pGC
->font
) == 0) ? Linear16Bit
: TwoD16Bit
,
361 for (i
=0; i
< n
; i
++)
362 w
+= charinfo
[i
]->metrics
.characterWidth
;
364 PsPolyGlyphBlt(pDrawable
, pGC
, x
, y
, n
, charinfo
, FONTGLYPHS(pGC
->font
));
375 DrawablePtr pDrawable
,
382 if( pDrawable
->type
==DRAWABLE_PIXMAP
)
385 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
386 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
390 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return;
392 disp
= PsGetFreeDisplayBlock(priv
);
394 elm
= &disp
->elms
[disp
->nelms
];
395 elm
->type
= TextI8Cmd
;
399 elm
->c
.text8
.count
= count
;
400 elm
->c
.text8
.string
= (char *)xalloc(count
);
401 memcpy(elm
->c
.text8
.string
, string
, count
);
413 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
) return;
414 PsOut_Offset(psOut
, pDrawable
->x
, pDrawable
->y
);
415 PsOut_Color(psOut
, PsGetPixelColor(cMap
, pGC
->fgPixel
));
416 fnam
= PsGetPSFontName(pGC
->font
);
417 if( !fnam
) fnam
= "Times-Roman";
418 siz
= PsGetFontSize(pGC
->font
, mtx
);
419 iso
= PsIsISOLatin1Encoding(pGC
->font
);
420 if( !siz
) PsOut_TextAttrsMtx(psOut
, fnam
, mtx
, iso
);
421 else PsOut_TextAttrs(psOut
, fnam
, siz
, iso
);
422 PsOut_Text(psOut
, x
, y
, string
, count
, PsGetPixelColor(cMap
, pGC
->bgPixel
));
428 DrawablePtr pDrawable
,
433 unsigned short *string
)
435 if( pDrawable
->type
==DRAWABLE_PIXMAP
)
438 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
439 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
443 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return;
445 disp
= PsGetFreeDisplayBlock(priv
);
447 elm
= &disp
->elms
[disp
->nelms
];
448 elm
->type
= TextI16Cmd
;
452 elm
->c
.text16
.count
= count
;
453 elm
->c
.text16
.string
=
454 (unsigned short *)xalloc(count
*sizeof(unsigned short));
455 memcpy(elm
->c
.text16
.string
, string
, count
*sizeof(unsigned short));
463 str
= (char *)xalloc(count
);
464 for( i
=0 ; i
<count
; i
++ ) str
[i
] = string
[i
];
465 PsImageText8(pDrawable
, pGC
, x
, y
, count
, str
);
472 DrawablePtr pDrawable
,
476 unsigned int nGlyphs
,
477 CharInfoPtr
*pCharInfo
,
480 /* NOT TO BE IMPLEMENTED */
485 DrawablePtr pDrawable
,
489 unsigned int nGlyphs
,
490 CharInfoPtr
*pCharInfo
,
495 int nbyLine
; /* bytes per line of padded pixmap */
500 unsigned char *pbits
; /* buffer for PutImage */
501 register unsigned char *pb
; /* temp pointer into buffer */
502 register CharInfoPtr pci
; /* currect char info */
503 register unsigned char *pglyph
; /* pointer bits in glyph */
504 int gWidth
, gHeight
; /* width and height of glyph */
505 register int nbyGlyphWidth
; /* bytes per scanline of glyph */
506 int nbyPadGlyph
; /* server padded line of glyph */
511 width
= FONTMAXBOUNDS(pfont
,rightSideBearing
) -
512 FONTMINBOUNDS(pfont
,leftSideBearing
);
513 height
= FONTMAXBOUNDS(pfont
,ascent
) +
514 FONTMAXBOUNDS(pfont
,descent
);
516 if ((width
== 0) || (height
== 0) )
521 for (i
=0; i
< nGlyphs
; i
++) w
+= pCharInfo
[i
]->metrics
.characterWidth
;
523 pGCtmp
= GetScratchGC(1, pDrawable
->pScreen
);
526 (*pDrawable
->pScreen
->DestroyPixmap
)(pPixmap
);
531 gcvals
[1] = pGC
->fgPixel
;
532 gcvals
[2] = pGC
->bgPixel
;
534 DoChangeGC(pGCtmp
, GCFunction
|GCForeground
|GCBackground
, gcvals
, 0);
537 nbyLine
= BitmapBytePad(width
);
538 pbits
= (unsigned char *)ALLOCATE_LOCAL(height
*nbyLine
);
540 PsDestroyPixmap(pPixmap
);
547 pglyph
= FONTGLYPHBITS(pGlyphBase
, pci
);
548 gWidth
= GLYPHWIDTHPIXELS(pci
);
549 gHeight
= GLYPHHEIGHTPIXELS(pci
);
550 if (gWidth
&& gHeight
)
552 nbyGlyphWidth
= GLYPHWIDTHBYTESPADDED(pci
);
553 nbyPadGlyph
= BitmapBytePad(gWidth
);
555 if (nbyGlyphWidth
== nbyPadGlyph
556 #if GLYPHPADBYTES != 4
557 && (((int) pglyph
) & 3) == 0
565 for (i
=0, pb
= pbits
; i
<gHeight
; i
++, pb
= pbits
+(i
*nbyPadGlyph
))
566 for (j
= 0; j
< nbyGlyphWidth
; j
++)
571 PsPutImageMask((DrawablePtr
)pDrawable
, pGCtmp
,
572 1, x
+ pci
->metrics
.leftSideBearing
,
573 y
- pci
->metrics
.ascent
, gWidth
, gHeight
,
574 0, XYBitmap
, (char *)pb
);
577 x
+= pci
->metrics
.characterWidth
;
579 DEALLOCATE_LOCAL(pbits
);
580 FreeScratchGC(pGCtmp
);