2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
37 #ifdef HAVE_DIX_CONFIG_H
38 #include <dix-config.h>
41 #include "glxserver.h"
44 #include "g_disptab.h"
45 #include "glapitable.h"
49 #include "indirect_dispatch.h"
51 #include <pixmapstr.h>
52 #include <windowstr.h>
53 #include <dixfontstr.h>
55 extern XID clientErrorValue
; /* imported kludge from dix layer */
58 ** Make a single GL bitmap from a single X glyph
60 static int __glXMakeBitmapFromGlyph(FontPtr font
, CharInfoPtr pci
)
63 int widthPadded
; /* width of glyph in bytes, as padded by X */
64 int allocBytes
; /* bytes to allocate to store bitmap */
65 int w
; /* width of glyph in bits */
66 int h
; /* height of glyph */
67 register unsigned char *pglyph
;
68 register unsigned char *p
;
69 unsigned char *allocbuf
;
70 #define __GL_CHAR_BUF_SIZE 2048
71 unsigned char buf
[__GL_CHAR_BUF_SIZE
];
73 w
= GLYPHWIDTHPIXELS(pci
);
74 h
= GLYPHHEIGHTPIXELS(pci
);
75 widthPadded
= GLYPHWIDTHBYTESPADDED(pci
);
78 ** Use the local buf if possible, otherwise malloc.
80 allocBytes
= widthPadded
* h
;
81 if (allocBytes
<= __GL_CHAR_BUF_SIZE
) {
85 p
= (unsigned char *) xalloc(allocBytes
);
92 ** We have to reverse the picture, top to bottom
95 pglyph
= FONTGLYPHBITS(FONTGLYPHS(font
), pci
) + (h
-1)*widthPadded
;
96 for (j
=0; j
< h
; j
++) {
97 for (i
=0; i
< widthPadded
; i
++) {
100 pglyph
-= widthPadded
;
103 CALL_Bitmap( GET_DISPATCH(), (w
, h
, -pci
->metrics
.leftSideBearing
,
104 pci
->metrics
.descent
,
105 pci
->metrics
.characterWidth
, 0,
106 allocbuf
? allocbuf
: buf
) );
112 #undef __GL_CHAR_BUF_SIZE
116 ** Create a GL bitmap for each character in the X font. The bitmap is stored
117 ** in a display list.
121 MakeBitmapsFromFont(FontPtr pFont
, int first
, int count
, int list_base
)
123 unsigned long i
, nglyphs
;
124 CARD8 chs
[2]; /* the font index we are going after */
126 int rv
; /* return value */
127 int encoding
= (FONTLASTROW(pFont
) == 0) ? Linear16Bit
: TwoD16Bit
;
129 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES
, FALSE
) );
130 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST
, BITMAP_BIT_ORDER
== LSBFirst
) );
131 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH
, 0) );
132 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS
, 0) );
133 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS
, 0) );
134 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT
, GLYPHPADBYTES
) );
135 for (i
=0; i
< count
; i
++) {
136 chs
[0] = (first
+ i
) >> 8; /* high byte is first byte */
139 (*pFont
->get_glyphs
)(pFont
, 1, chs
, (FontEncoding
)encoding
,
143 ** Define a display list containing just a glBitmap() call.
145 CALL_NewList( GET_DISPATCH(), (list_base
+ i
, GL_COMPILE
) );
147 rv
= __glXMakeBitmapFromGlyph(pFont
, pci
);
152 CALL_EndList( GET_DISPATCH(), () );
157 /************************************************************************/
159 int __glXDisp_UseXFont(__GLXclientState
*cl
, GLbyte
*pc
)
161 ClientPtr client
= cl
->client
;
162 xGLXUseXFontReq
*req
;
165 GLuint currentListIndex
;
169 req
= (xGLXUseXFontReq
*) pc
;
170 cx
= __glXForceCurrent(cl
, req
->contextTag
, &error
);
175 CALL_GetIntegerv( GET_DISPATCH(), (GL_LIST_INDEX
, (GLint
*) ¤tListIndex
) );
176 if (currentListIndex
!= 0) {
178 ** A display list is currently being made. It is an error
179 ** to try to make a font during another lists construction.
181 client
->errorValue
= cx
->id
;
182 return __glXError(GLXBadContextState
);
186 ** Font can actually be either the ID of a font or the ID of a GC
187 ** containing a font.
189 pFont
= (FontPtr
)LookupIDByType(req
->font
, RT_FONT
);
191 pGC
= (GC
*)LookupIDByType(req
->font
, RT_GC
);
193 client
->errorValue
= req
->font
;
199 return MakeBitmapsFromFont(pFont
, req
->first
, req
->count
,