2012-06-07 14:20:23 -06:00
|
|
|
/* $XTermId: doublechr.c,v 1.81 2012/04/15 23:39:53 tom Exp $ */
|
2011-09-17 05:51:57 -06:00
|
|
|
|
|
|
|
/*
|
2012-06-07 14:20:23 -06:00
|
|
|
* Copyright 1997-2011,2012 by Thomas E. Dickey
|
2011-09-17 05:51:57 -06:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the
|
|
|
|
* sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization.
|
|
|
|
*/
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
#include <xterm.h>
|
|
|
|
#include <data.h>
|
|
|
|
#include <fontutils.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2008-02-16 02:34:45 -07:00
|
|
|
#define WhichCgsId(flag) (((flag) & BOLD) ? gcCBold : gcCNorm)
|
2007-06-15 13:29:55 -06:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
/*
|
|
|
|
* The first column is all that matters for double-size characters (since the
|
|
|
|
* controls apply to a whole line). However, it's easier to maintain the
|
|
|
|
* information for special fonts by writing to all cells.
|
|
|
|
*/
|
|
|
|
#if OPT_DEC_CHRSET
|
2008-02-16 02:34:45 -07:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
static void
|
2007-06-15 13:29:55 -06:00
|
|
|
repaint_line(XtermWidget xw, unsigned newChrSet)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2009-09-05 09:58:09 -06:00
|
|
|
LineData *ld;
|
2006-11-26 04:11:12 -07:00
|
|
|
int curcol = screen->cur_col;
|
|
|
|
int currow = screen->cur_row;
|
2009-03-09 16:13:04 -06:00
|
|
|
int width = MaxCols(screen);
|
|
|
|
unsigned len = (unsigned) width;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
assert(width > 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore repetition.
|
|
|
|
*/
|
2012-06-07 14:20:23 -06:00
|
|
|
if (!IsLeftRightMode(xw)
|
|
|
|
&& (ld = getLineData(screen, currow)) != 0) {
|
2009-09-05 09:58:09 -06:00
|
|
|
unsigned oldChrSet = GetLineDblCS(ld);
|
|
|
|
|
|
|
|
if (oldChrSet != newChrSet) {
|
|
|
|
TRACE(("repaint_line(%2d,%2d) (%s -> %s)\n", currow, screen->cur_col,
|
|
|
|
visibleChrsetName(oldChrSet),
|
|
|
|
visibleChrsetName(newChrSet)));
|
|
|
|
HideCursor();
|
|
|
|
|
|
|
|
/* If switching from single-width, keep the cursor in the visible part
|
|
|
|
* of the line.
|
|
|
|
*/
|
|
|
|
if (CSET_DOUBLE(newChrSet)) {
|
|
|
|
width /= 2;
|
|
|
|
if (curcol > width)
|
|
|
|
curcol = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ScrnRefresh won't paint blanks for us if we're switching between a
|
|
|
|
* single-size and double-size font. So we paint our own.
|
|
|
|
*/
|
|
|
|
ClearCurBackground(xw,
|
2012-06-07 14:20:23 -06:00
|
|
|
currow,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
len,
|
|
|
|
(unsigned) LineFontWidth(screen, ld));
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
SetLineDblCS(ld, newChrSet);
|
|
|
|
|
|
|
|
set_cur_col(screen, 0);
|
|
|
|
ScrnUpdate(xw, currow, 0, 1, (int) len, True);
|
|
|
|
set_cur_col(screen, curcol);
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the line to double-height characters. The 'top' flag denotes whether
|
|
|
|
* we'll be using it for the top (true) or bottom (false) of the line.
|
|
|
|
*/
|
|
|
|
void
|
2007-06-15 13:29:55 -06:00
|
|
|
xterm_DECDHL(XtermWidget xw GCC_UNUSED, Bool top)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
#if OPT_DEC_CHRSET
|
2007-06-15 13:29:55 -06:00
|
|
|
repaint_line(xw, (unsigned) (top ? CSET_DHL_TOP : CSET_DHL_BOT));
|
2006-11-26 04:11:12 -07:00
|
|
|
#else
|
|
|
|
(void) top;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the line to single-width characters (the normal state).
|
|
|
|
*/
|
|
|
|
void
|
2007-06-15 13:29:55 -06:00
|
|
|
xterm_DECSWL(XtermWidget xw GCC_UNUSED)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
#if OPT_DEC_CHRSET
|
2007-06-15 13:29:55 -06:00
|
|
|
repaint_line(xw, CSET_SWL);
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the line to double-width characters
|
|
|
|
*/
|
|
|
|
void
|
2007-06-15 13:29:55 -06:00
|
|
|
xterm_DECDWL(XtermWidget xw GCC_UNUSED)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
#if OPT_DEC_CHRSET
|
2007-06-15 13:29:55 -06:00
|
|
|
repaint_line(xw, CSET_DWL);
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-06-07 14:20:23 -06:00
|
|
|
/*
|
|
|
|
* Reset all lines on the screen to single-width/single-height.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xterm_ResetDouble(XtermWidget xw)
|
|
|
|
{
|
|
|
|
#if OPT_DEC_CHRSET
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
Boolean changed = False;
|
|
|
|
LineData *ld;
|
|
|
|
unsigned code;
|
|
|
|
int row;
|
|
|
|
|
|
|
|
for (row = 0; row < screen->max_row; ++row) {
|
|
|
|
if ((ld = getLineData(screen, ROW2INX(screen, row))) != 0) {
|
|
|
|
code = GetLineDblCS(ld);
|
|
|
|
if (code != CSET_SWL) {
|
|
|
|
SetLineDblCS(ld, CSET_SWL);
|
|
|
|
changed = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
xtermRepaint(xw);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
#if OPT_DEC_CHRSET
|
|
|
|
static void
|
2008-02-16 02:34:45 -07:00
|
|
|
discard_font(XtermWidget xw, int n)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2008-02-16 02:34:45 -07:00
|
|
|
XTermFonts *data = &(screen->double_fonts[n]);
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
TRACE(("discard_font chrset=%d %s\n", data->chrset,
|
|
|
|
(data->fn != 0) ? data->fn : "<no-name>"));
|
|
|
|
|
|
|
|
data->chrset = 0;
|
|
|
|
data->flags = 0;
|
|
|
|
if (data->fn != 0) {
|
|
|
|
free(data->fn);
|
|
|
|
data->fn = 0;
|
|
|
|
}
|
2008-02-16 02:34:45 -07:00
|
|
|
(void) xtermCloseFont(xw, data);
|
|
|
|
|
|
|
|
screen->fonts_used -= 1;
|
|
|
|
while (n < screen->fonts_used) {
|
|
|
|
screen->double_fonts[n] = screen->double_fonts[n + 1];
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push back existing fonts and create a new entry */
|
|
|
|
static XTermFonts *
|
|
|
|
pushback_font(XtermWidget xw, XTermFonts * source)
|
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2008-02-16 02:34:45 -07:00
|
|
|
XTermFonts *data = screen->double_fonts;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (screen->fonts_used >= screen->cache_doublesize) {
|
|
|
|
TRACE(("pushback_font: discard oldest\n"));
|
|
|
|
discard_font(xw, screen->fonts_used - 1);
|
|
|
|
} else {
|
|
|
|
screen->fonts_used += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = screen->fonts_used; n > 0; n--)
|
|
|
|
data[n] = data[n - 1];
|
|
|
|
data[0] = *source;
|
|
|
|
|
|
|
|
TRACE(("pushback_font -> (NEW:%d)\n", screen->fonts_used));
|
|
|
|
|
|
|
|
return data;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-06-15 13:29:55 -06:00
|
|
|
xterm_Double_index(XtermWidget xw, unsigned chrset, unsigned flags)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
|
|
|
int n;
|
2008-02-16 02:34:45 -07:00
|
|
|
int result = -1;
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
XTermFonts *data = screen->double_fonts;
|
|
|
|
|
|
|
|
flags &= BOLD;
|
|
|
|
TRACE(("xterm_Double_index chrset=%#x, flags=%#x\n", chrset, flags));
|
|
|
|
|
|
|
|
for (n = 0; n < screen->fonts_used; n++) {
|
|
|
|
if (data[n].chrset == chrset
|
|
|
|
&& data[n].flags == flags) {
|
|
|
|
if (n != 0) {
|
|
|
|
XTermFonts save;
|
|
|
|
TRACE(("...xterm_Double_index -> %d (OLD:%d)\n", n, screen->fonts_used));
|
|
|
|
save = data[n];
|
|
|
|
while (n > 0) {
|
|
|
|
data[n] = data[n - 1];
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
data[n] = save;
|
|
|
|
}
|
2008-02-16 02:34:45 -07:00
|
|
|
result = n;
|
|
|
|
break;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-16 02:34:45 -07:00
|
|
|
return result;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup/cache a GC for the double-size character display. We save up to
|
|
|
|
* NUM_CHRSET values.
|
|
|
|
*/
|
|
|
|
GC
|
2008-02-16 02:34:45 -07:00
|
|
|
xterm_DoubleGC(XtermWidget xw,
|
|
|
|
unsigned chrset,
|
|
|
|
unsigned flags,
|
|
|
|
GC old_gc,
|
|
|
|
int *inxp)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
VTwin *cgsWin = WhichVWin(screen);
|
2006-11-26 04:11:12 -07:00
|
|
|
int n;
|
|
|
|
char *name;
|
2008-02-16 02:34:45 -07:00
|
|
|
XTermFonts *data = 0;
|
2007-06-15 13:29:55 -06:00
|
|
|
GC result = 0;
|
|
|
|
|
|
|
|
if ((name = xtermSpecialFont(screen, flags, chrset)) != 0) {
|
|
|
|
CgsEnum cgsId = WhichCgsId(flags);
|
|
|
|
Boolean found = False;
|
|
|
|
|
2008-02-16 02:34:45 -07:00
|
|
|
if ((n = xterm_Double_index(xw, chrset, flags)) >= 0) {
|
|
|
|
data = &(screen->double_fonts[n]);
|
|
|
|
if (data->fn != 0) {
|
|
|
|
if (!strcmp(data->fn, name)
|
|
|
|
&& data->fs != 0) {
|
|
|
|
found = True;
|
|
|
|
free(name);
|
|
|
|
} else {
|
|
|
|
discard_font(xw, n);
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
if (!found) {
|
2008-02-16 02:34:45 -07:00
|
|
|
XTermFonts temp;
|
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
TRACE(("xterm_DoubleGC %s %d: %s\n",
|
|
|
|
flags & BOLD ? "BOLD" : "NORM", n, name));
|
|
|
|
|
2008-02-16 02:34:45 -07:00
|
|
|
memset(&temp, 0, sizeof(temp));
|
|
|
|
temp.fn = name;
|
|
|
|
temp.chrset = chrset;
|
|
|
|
temp.flags = (flags & BOLD);
|
|
|
|
|
2009-03-09 16:13:04 -06:00
|
|
|
if (!xtermOpenFont(xw, name, &temp, fwAlways, False)) {
|
2007-06-15 13:29:55 -06:00
|
|
|
/* Retry with * in resolutions */
|
|
|
|
char *nname = xtermSpecialFont(screen, flags | NORESOLUTION, chrset);
|
|
|
|
|
|
|
|
if (nname != 0) {
|
2009-03-09 16:13:04 -06:00
|
|
|
found = (Boolean) xtermOpenFont(xw, nname, &temp,
|
|
|
|
fwAlways, False);
|
2008-02-16 02:34:45 -07:00
|
|
|
free(nname);
|
2007-06-15 13:29:55 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
found = True;
|
|
|
|
}
|
2008-02-16 02:34:45 -07:00
|
|
|
free(name);
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
n = 0;
|
|
|
|
data = pushback_font(xw, &temp);
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
TRACE(("-> %s\n", found ? "OK" : "FAIL"));
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
if (found) {
|
|
|
|
setCgsCSet(xw, cgsWin, cgsId, chrset);
|
2008-02-16 02:34:45 -07:00
|
|
|
setCgsFont(xw, cgsWin, cgsId, data);
|
2007-06-15 13:29:55 -06:00
|
|
|
setCgsFore(xw, cgsWin, cgsId, getCgsFore(xw, cgsWin, old_gc));
|
|
|
|
setCgsBack(xw, cgsWin, cgsId, getCgsBack(xw, cgsWin, old_gc));
|
|
|
|
result = getCgsGC(xw, cgsWin, cgsId);
|
2008-02-16 02:34:45 -07:00
|
|
|
*inxp = n;
|
|
|
|
} else if (flags & BOLD) {
|
2010-05-08 06:20:46 -06:00
|
|
|
UIntClr(flags, BOLD);
|
2008-02-16 02:34:45 -07:00
|
|
|
result = xterm_DoubleGC(xw, chrset, flags, old_gc, inxp);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
2008-02-16 02:34:45 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
return result;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
#endif
|