2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 #ifdef VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermPrimRenderFontSet.c /main/1 1996/04/21 19:18:53 drk $";
26 #endif /* VERBOSE_REV_INFO */
30 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
31 * (c) Copyright 1993, 1994 International Business Machines Corp. *
32 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
33 * (c) Copyright 1993, 1994 Novell, Inc. *
36 #include "TermHeader.h"
37 #include "TermPrimP.h"
38 #include "TermPrimDebug.h"
39 #include "TermPrimRenderP.h"
40 #include "TermPrimRenderFontSet.h"
42 typedef struct _TermFontSetRec {
47 } TermFontSetRec, *TermFontSet;
50 FontSetRenderFunction(
58 unsigned char *string,
62 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
63 struct termData *tpd = tw->term.tpd;
65 unsigned long valueMask;
66 TermFontSet termFontSet = (TermFontSet) font->fontInfo;
68 /* set the renderGC... */
69 valueMask = (unsigned long) 0;
71 /* set the foreground... */
72 if (TermIS_SECURE(flags)) {
73 if (tpd->renderGC.foreground != bg) {
74 tpd->renderGC.foreground = bg;
75 values.foreground = bg;
76 valueMask |= GCForeground;
79 if (tpd->renderGC.foreground != fg) {
80 tpd->renderGC.foreground = fg;
81 values.foreground = fg;
82 valueMask |= GCForeground;
86 /* set background... */
87 if (tpd->renderGC.background != bg) {
88 tpd->renderGC.background = bg;
89 values.background = bg;
90 valueMask |= GCBackground;
93 /* since Xlib will be mucking with the GC's font under us, we need to
94 * make sure we trash the cached value...
96 tpd->renderGC.fid = (Font) 0;
99 (void) XChangeGC(XtDisplay(w), tpd->renderGC.gc, valueMask,
103 /* draw image string a line of text... */
104 if (isDebugFSet('t', 1)) {
108 /* Fill in the text area so we can see what is going to
111 (void) XFillRectangle(XtDisplay(w),
116 (tpd->mbCurMax == 1) ?
117 XmbTextEscapement(termFontSet->fontSet, (char *) string, len) :
118 XwcTextEscapement(termFontSet->fontSet, (wchar_t *) string,
121 (void) XSync(XtDisplay(w), False);
122 (void) shortSleep(100000);
125 if (tpd->mbCurMax == 1)
127 (void) XmbDrawImageString(XtDisplay(w),/* Display */
128 XtWindow(w), /* Drawable */
129 termFontSet->fontSet, /* XFontSet */
130 tpd->renderGC.gc, /* GC */
132 y + termFontSet->ascent, /* y */
133 (char *)string, /* string */
136 /* handle overstrike... */
137 if (TermIS_OVERSTRIKE(flags)) {
138 (void) XmbDrawString(XtDisplay(w), /* Display */
139 XtWindow(w), /* Drawable */
140 termFontSet->fontSet, /* XFontSet */
141 tpd->renderGC.gc, /* GC */
143 y + termFontSet->ascent, /* y */
144 (char *)string, /* string */
147 /* handle the underline enhancement... */
148 /* draw the underline... */
149 if (TermIS_UNDERLINE(flags)) {
150 XDrawLine(XtDisplay(w), /* Display */
151 XtWindow(w), /* Window */
152 tpd->renderGC.gc, /* GC */
154 y + tpd->cellHeight - 1, /* Y1 */
155 x - 1 + XmbTextEscapement(termFontSet->fontSet,
156 (char *) string, len), /* X2 */
157 y + tpd->cellHeight - 1);/* Y2 */
162 (void) XwcDrawImageString(XtDisplay(w), /* Display */
163 XtWindow(w), /* Drawable */
164 termFontSet->fontSet, /* XFontSet */
165 tpd->renderGC.gc, /* GC */
167 y + termFontSet->ascent, /* y */
168 (wchar_t *) string, /* string */
171 /* handle overstrike... */
172 if (TermIS_OVERSTRIKE(flags)) {
173 (void) XwcDrawString(XtDisplay(w), /* Display */
174 XtWindow(w), /* Drawable */
175 termFontSet->fontSet, /* XFontSet */
176 tpd->renderGC.gc, /* GC */
178 y + termFontSet->ascent, /* y */
179 (wchar_t *) string, /* string */
182 /* handle the underline enhancement... */
183 /* draw the underline... */
184 if (TermIS_UNDERLINE(flags)) {
185 XDrawLine(XtDisplay(w), /* Display */
186 XtWindow(w), /* Window */
187 tpd->renderGC.gc, /* GC */
189 y + tpd->cellHeight - 1, /* Y1 */
190 x - 1 + XwcTextEscapement(termFontSet->fontSet,
191 (wchar_t *) string, len), /* X2 */
192 y + tpd->cellHeight - 1); /* Y2 */
198 FontSetDestroyFunction(
203 (void) XtFree((char *) font->fontInfo);
204 (void) XtFree((char *) font);
208 FontSetExtentsFunction(
211 unsigned char *string,
218 TermFontSet termFontSet = (TermFontSet) font->fontInfo;
221 *widthReturn = len * termFontSet->width;
224 *heightReturn = termFontSet->height;
227 *ascentReturn = termFontSet->ascent;
233 _DtTermPrimRenderFontSetCreate(
239 TermFontSet termFontSet;
240 XFontSetExtents *fontSetExtents;
242 termFont = (TermFont) XtMalloc(sizeof(TermFontRec));
243 termFont->renderFunction = FontSetRenderFunction;
244 termFont->destroyFunction = FontSetDestroyFunction;
245 termFont->extentsFunction = FontSetExtentsFunction;
247 termFontSet = (TermFontSet) XtMalloc(sizeof(TermFontSetRec));
248 termFontSet->fontSet = fontSet;
249 fontSetExtents = XExtentsOfFontSet(fontSet);
250 termFontSet->width = fontSetExtents->max_logical_extent.width;
251 termFontSet->height = fontSetExtents->max_logical_extent.height;
252 termFontSet->ascent = -fontSetExtents->max_logical_extent.y;
253 termFont->fontInfo = (XtPointer) termFontSet;