2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
35 #include "glxserver.h"
38 #include "g_disptab.h"
39 #include "glapitable.h"
43 #include "indirect_dispatch.h"
45 #include <pixmapstr.h>
46 #include <windowstr.h>
47 #include <dixfontstr.h>
50 ** Make a single GL bitmap from a single X glyph
52 static int __glXMakeBitmapFromGlyph(FontPtr font, CharInfoPtr pci)
55 int widthPadded; /* width of glyph in bytes, as padded by X */
56 int allocBytes; /* bytes to allocate to store bitmap */
57 int w; /* width of glyph in bits */
58 int h; /* height of glyph */
59 register unsigned char *pglyph;
60 register unsigned char *p;
61 unsigned char *allocbuf;
62 #define __GL_CHAR_BUF_SIZE 2048
63 unsigned char buf[__GL_CHAR_BUF_SIZE];
65 w = GLYPHWIDTHPIXELS(pci);
66 h = GLYPHHEIGHTPIXELS(pci);
67 widthPadded = GLYPHWIDTHBYTESPADDED(pci);
70 ** Use the local buf if possible, otherwise malloc.
72 allocBytes = widthPadded * h;
73 if (allocBytes <= __GL_CHAR_BUF_SIZE) {
77 p = (unsigned char *) malloc(allocBytes);
84 ** We have to reverse the picture, top to bottom
87 pglyph = FONTGLYPHBITS(FONTGLYPHS(font), pci) + (h-1)*widthPadded;
88 for (j=0; j < h; j++) {
89 for (i=0; i < widthPadded; i++) {
92 pglyph -= widthPadded;
95 CALL_Bitmap( GET_DISPATCH(), (w, h, -pci->metrics.leftSideBearing,
97 pci->metrics.characterWidth, 0,
98 allocbuf ? allocbuf : buf) );
102 #undef __GL_CHAR_BUF_SIZE
106 ** Create a GL bitmap for each character in the X font. The bitmap is stored
107 ** in a display list.
111 MakeBitmapsFromFont(FontPtr pFont, int first, int count, int list_base)
113 unsigned long i, nglyphs;
114 CARD8 chs[2]; /* the font index we are going after */
116 int rv; /* return value */
117 int encoding = (FONTLASTROW(pFont) == 0) ? Linear16Bit : TwoD16Bit;
119 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES, FALSE) );
120 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST, BITMAP_BIT_ORDER == LSBFirst) );
121 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH, 0) );
122 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, 0) );
123 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, 0) );
124 CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT, GLYPHPADBYTES) );
125 for (i=0; i < count; i++) {
126 chs[0] = (first + i) >> 8; /* high byte is first byte */
129 (*pFont->get_glyphs)(pFont, 1, chs, (FontEncoding)encoding,
133 ** Define a display list containing just a glBitmap() call.
135 CALL_NewList( GET_DISPATCH(), (list_base + i, GL_COMPILE) );
137 rv = __glXMakeBitmapFromGlyph(pFont, pci);
142 CALL_EndList( GET_DISPATCH(), () );
147 /************************************************************************/
149 int __glXDisp_UseXFont(__GLXclientState *cl, GLbyte *pc)
151 ClientPtr client = cl->client;
152 xGLXUseXFontReq *req;
154 GLuint currentListIndex;
158 req = (xGLXUseXFontReq *) pc;
159 cx = __glXForceCurrent(cl, req->contextTag, &error);
164 CALL_GetIntegerv( GET_DISPATCH(), (GL_LIST_INDEX, (GLint*) ¤tListIndex) );
165 if (currentListIndex != 0) {
167 ** A display list is currently being made. It is an error
168 ** to try to make a font during another lists construction.
170 client->errorValue = cx->id;
171 return __glXError(GLXBadContextState);
175 ** Font can actually be either the ID of a font or the ID of a GC
176 ** containing a font.
179 error = dixLookupFontable(&pFont, req->font, client, DixReadAccess);
180 if (error != Success)
183 return MakeBitmapsFromFont(pFont, req->first, req->count,