1 /* $XTermId: doublechr.c,v 1.75 2010/06/15 10:58:13 tom Exp $ */
3 /************************************************************
5 Copyright 1997-2009,2010 by Thomas E. Dickey
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 Except as contained in this notice, the name(s) of the above copyright
29 holders shall not be used in advertising or otherwise to promote the
30 sale, use or other dealings in this Software without prior written
33 ********************************************************/
37 #include <fontutils.h>
41 #define WhichCgsId(flag) (((flag) & BOLD) ? gcCBold : gcCNorm)
44 * The first column is all that matters for double-size characters (since the
45 * controls apply to a whole line). However, it's easier to maintain the
46 * information for special fonts by writing to all cells.
51 repaint_line(XtermWidget xw, unsigned newChrSet)
53 TScreen *screen = TScreenOf(xw);
55 int curcol = screen->cur_col;
56 int currow = screen->cur_row;
57 int width = MaxCols(screen);
58 unsigned len = (unsigned) width;
65 if ((ld = getLineData(screen, currow)) != 0) {
66 unsigned oldChrSet = GetLineDblCS(ld);
68 if (oldChrSet != newChrSet) {
69 TRACE(("repaint_line(%2d,%2d) (%s -> %s)\n", currow, screen->cur_col,
70 visibleChrsetName(oldChrSet),
71 visibleChrsetName(newChrSet)));
74 /* If switching from single-width, keep the cursor in the visible part
77 if (CSET_DOUBLE(newChrSet)) {
84 * ScrnRefresh won't paint blanks for us if we're switching between a
85 * single-size and double-size font. So we paint our own.
87 ClearCurBackground(xw,
88 CursorY(screen, currow),
89 LineCursorX(screen, ld, 0),
90 (unsigned) FontHeight(screen),
91 len * (unsigned) LineFontWidth(screen, ld));
93 SetLineDblCS(ld, newChrSet);
95 set_cur_col(screen, 0);
96 ScrnUpdate(xw, currow, 0, 1, (int) len, True);
97 set_cur_col(screen, curcol);
104 * Set the line to double-height characters. The 'top' flag denotes whether
105 * we'll be using it for the top (true) or bottom (false) of the line.
108 xterm_DECDHL(XtermWidget xw GCC_UNUSED, Bool top)
111 repaint_line(xw, (unsigned) (top ? CSET_DHL_TOP : CSET_DHL_BOT));
118 * Set the line to single-width characters (the normal state).
121 xterm_DECSWL(XtermWidget xw GCC_UNUSED)
124 repaint_line(xw, CSET_SWL);
129 * Set the line to double-width characters
132 xterm_DECDWL(XtermWidget xw GCC_UNUSED)
135 repaint_line(xw, CSET_DWL);
141 discard_font(XtermWidget xw, int n)
143 TScreen *screen = TScreenOf(xw);
144 XTermFonts *data = &(screen->double_fonts[n]);
146 TRACE(("discard_font chrset=%d %s\n", data->chrset,
147 (data->fn != 0) ? data->fn : "<no-name>"));
155 (void) xtermCloseFont(xw, data);
157 screen->fonts_used -= 1;
158 while (n < screen->fonts_used) {
159 screen->double_fonts[n] = screen->double_fonts[n + 1];
164 /* push back existing fonts and create a new entry */
166 pushback_font(XtermWidget xw, XTermFonts * source)
168 TScreen *screen = TScreenOf(xw);
169 XTermFonts *data = screen->double_fonts;
172 if (screen->fonts_used >= screen->cache_doublesize) {
173 TRACE(("pushback_font: discard oldest\n"));
174 discard_font(xw, screen->fonts_used - 1);
176 screen->fonts_used += 1;
179 for (n = screen->fonts_used; n > 0; n--)
180 data[n] = data[n - 1];
183 TRACE(("pushback_font -> (NEW:%d)\n", screen->fonts_used));
189 xterm_Double_index(XtermWidget xw, unsigned chrset, unsigned flags)
193 TScreen *screen = TScreenOf(xw);
194 XTermFonts *data = screen->double_fonts;
197 TRACE(("xterm_Double_index chrset=%#x, flags=%#x\n", chrset, flags));
199 for (n = 0; n < screen->fonts_used; n++) {
200 if (data[n].chrset == chrset
201 && data[n].flags == flags) {
204 TRACE(("...xterm_Double_index -> %d (OLD:%d)\n", n, screen->fonts_used));
207 data[n] = data[n - 1];
221 * Lookup/cache a GC for the double-size character display. We save up to
225 xterm_DoubleGC(XtermWidget xw,
231 TScreen *screen = TScreenOf(xw);
232 VTwin *cgsWin = WhichVWin(screen);
235 XTermFonts *data = 0;
238 if ((name = xtermSpecialFont(screen, flags, chrset)) != 0) {
239 CgsEnum cgsId = WhichCgsId(flags);
240 Boolean found = False;
242 if ((n = xterm_Double_index(xw, chrset, flags)) >= 0) {
243 data = &(screen->double_fonts[n]);
245 if (!strcmp(data->fn, name)
258 TRACE(("xterm_DoubleGC %s %d: %s\n",
259 flags & BOLD ? "BOLD" : "NORM", n, name));
261 memset(&temp, 0, sizeof(temp));
263 temp.chrset = chrset;
264 temp.flags = (flags & BOLD);
266 if (!xtermOpenFont(xw, name, &temp, fwAlways, False)) {
267 /* Retry with * in resolutions */
268 char *nname = xtermSpecialFont(screen, flags | NORESOLUTION, chrset);
271 found = (Boolean) xtermOpenFont(xw, nname, &temp,
282 data = pushback_font(xw, &temp);
285 TRACE(("-> %s\n", found ? "OK" : "FAIL"));
289 setCgsCSet(xw, cgsWin, cgsId, chrset);
290 setCgsFont(xw, cgsWin, cgsId, data);
291 setCgsFore(xw, cgsWin, cgsId, getCgsFore(xw, cgsWin, old_gc));
292 setCgsBack(xw, cgsWin, cgsId, getCgsBack(xw, cgsWin, old_gc));
293 result = getCgsGC(xw, cgsWin, cgsId);
295 } else if (flags & BOLD) {
296 UIntClr(flags, BOLD);
297 result = xterm_DoubleGC(xw, chrset, flags, old_gc, inxp);