1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fixes the bug, which caused dtterm to show stripes of wrong color between text lines when using fontsets that include fonts of slightly different heights.

The cause of the bug was that X*DrawImageString draws background
according to the extents of the given string, not to extents of the font set,
which determine terminal line height.

Now, when such a situation is detected, the background is cleared before
drawing the characters.
This commit is contained in:
Eugene Doudine 2014-05-03 21:02:50 +03:00 committed by Jon Trulson
parent a9dbe60805
commit 4e2adc1f8e

View file

@ -64,10 +64,57 @@ FontSetRenderFunction(
XGCValues values; XGCValues values;
unsigned long valueMask; unsigned long valueMask;
TermFontSet termFontSet = (TermFontSet) font->fontInfo; TermFontSet termFontSet = (TermFontSet) font->fontInfo;
int escapement;
XRectangle extents;
Boolean fixExtents;
/* set the renderGC... */ /* set the renderGC... */
valueMask = (unsigned long) 0; valueMask = (unsigned long) 0;
/* set background... */
if (tpd->renderGC.background != bg) {
tpd->renderGC.background = bg;
values.background = bg;
valueMask |= GCBackground;
}
/* since Xlib will be mucking with the GC's font under us, we need to
* make sure we trash the cached value...
*/
tpd->renderGC.fid = (Font) 0;
escapement = (tpd->mbCurMax == 1) ?
XmbTextExtents(termFontSet->fontSet, (char *) string, len,
NULL, &extents) :
XwcTextExtents(termFontSet->fontSet, (wchar_t*) string, len,
NULL, &extents);
/* Text height may be smaller than cellHeight (happens when using font sets).
In this case we need to fill background manually and then use X*DrawString
instead of X*DrawImageString */
fixExtents = extents.height < tpd->cellHeight;
if (fixExtents) {
/* set background color as foreground if needed*/
if (tpd->renderGC.foreground != bg) {
tpd->renderGC.foreground = bg;
valueMask|= GCForeground ;
values.foreground = bg;
}
if (valueMask) {
(void) XChangeGC(XtDisplay(w), tpd->renderGC.gc, valueMask, &values);
valueMask= (unsigned long) 0;
}
/* paint background manually */
(void) XFillRectangle(XtDisplay(w),
XtWindow(w),
tpd->renderGC.gc,
x,
y,
escapement,
tpd->cellHeight);
}
/* set the foreground... */ /* set the foreground... */
if (TermIS_SECURE(flags)) { if (TermIS_SECURE(flags)) {
if (tpd->renderGC.foreground != bg) { if (tpd->renderGC.foreground != bg) {
@ -82,19 +129,6 @@ FontSetRenderFunction(
valueMask |= GCForeground; valueMask |= GCForeground;
} }
} }
/* set background... */
if (tpd->renderGC.background != bg) {
tpd->renderGC.background = bg;
values.background = bg;
valueMask |= GCBackground;
}
/* since Xlib will be mucking with the GC's font under us, we need to
* make sure we trash the cached value...
*/
tpd->renderGC.fid = (Font) 0;
if (valueMask) { if (valueMask) {
(void) XChangeGC(XtDisplay(w), tpd->renderGC.gc, valueMask, (void) XChangeGC(XtDisplay(w), tpd->renderGC.gc, valueMask,
&values); &values);
@ -102,6 +136,10 @@ FontSetRenderFunction(
/* draw image string a line of text... */ /* draw image string a line of text... */
if (isDebugFSet('t', 1)) { if (isDebugFSet('t', 1)) {
/* we need to clear background after the debug draw and delay,
so this will cause X*DrawImageString to be always used
in debug mode */
fixExtents = 0;
#ifdef BBA #ifdef BBA
#pragma BBA_IGNORE #pragma BBA_IGNORE
#endif /*BBA*/ #endif /*BBA*/
@ -113,18 +151,18 @@ FontSetRenderFunction(
tpd->renderGC.gc, tpd->renderGC.gc,
x, x,
y, y,
(tpd->mbCurMax == 1) ? escapement,
XmbTextEscapement(termFontSet->fontSet, (char *) string, len) : extents.height);
XwcTextEscapement(termFontSet->fontSet, (wchar_t *) string, (void) XSync(XtDisplay(w), False);
len), (void) shortSleep(100000);
tpd->cellHeight);
(void) XSync(XtDisplay(w), False);
(void) shortSleep(100000);
} }
if (tpd->mbCurMax == 1) if (tpd->mbCurMax == 1)
{ {
(void) XmbDrawImageString(XtDisplay(w),/* Display */ /* select right function, we do not want text background be drawn twice */
(void) (fixExtents ? XmbDrawString: XmbDrawImageString)
(XtDisplay(w), /* Display */
XtWindow(w), /* Drawable */ XtWindow(w), /* Drawable */
termFontSet->fontSet, /* XFontSet */ termFontSet->fontSet, /* XFontSet */
tpd->renderGC.gc, /* GC */ tpd->renderGC.gc, /* GC */
@ -133,9 +171,9 @@ FontSetRenderFunction(
(char *)string, /* string */ (char *)string, /* string */
len); /* length */ len); /* length */
/* handle overstrike... */ /* handle overstrike... */
if (TermIS_OVERSTRIKE(flags)) { if (TermIS_OVERSTRIKE(flags)) {
(void) XmbDrawString(XtDisplay(w), /* Display */ (void) XmbDrawString(XtDisplay(w), /* Display */
XtWindow(w), /* Drawable */ XtWindow(w), /* Drawable */
termFontSet->fontSet, /* XFontSet */ termFontSet->fontSet, /* XFontSet */
tpd->renderGC.gc, /* GC */ tpd->renderGC.gc, /* GC */
@ -144,22 +182,12 @@ FontSetRenderFunction(
(char *)string, /* string */ (char *)string, /* string */
len); /* length */ len); /* length */
} }
/* handle the underline enhancement... */
/* draw the underline... */
if (TermIS_UNDERLINE(flags)) {
XDrawLine(XtDisplay(w), /* Display */
XtWindow(w), /* Window */
tpd->renderGC.gc, /* GC */
x, /* X1 */
y + tpd->cellHeight - 1, /* Y1 */
x - 1 + XmbTextEscapement(termFontSet->fontSet,
(char *) string, len), /* X2 */
y + tpd->cellHeight - 1);/* Y2 */
}
} }
else else
{ {
(void) XwcDrawImageString(XtDisplay(w), /* Display */ /* select right function, we do not want text background be drawn twice */
(void) (fixExtents ? XwcDrawString: XwcDrawImageString)
(XtDisplay(w), /* Displa*/
XtWindow(w), /* Drawable */ XtWindow(w), /* Drawable */
termFontSet->fontSet, /* XFontSet */ termFontSet->fontSet, /* XFontSet */
tpd->renderGC.gc, /* GC */ tpd->renderGC.gc, /* GC */
@ -179,18 +207,17 @@ FontSetRenderFunction(
(wchar_t *) string, /* string */ (wchar_t *) string, /* string */
len); /* length */ len); /* length */
} }
/* handle the underline enhancement... */ }
/* draw the underline... */ /* handle the underline enhancement... */
if (TermIS_UNDERLINE(flags)) { /* draw the underline... */
XDrawLine(XtDisplay(w), /* Display */ if (TermIS_UNDERLINE(flags)) {
XtWindow(w), /* Window */ XDrawLine(XtDisplay(w), /* Display */
tpd->renderGC.gc, /* GC */ XtWindow(w), /* Window */
x, /* X1 */ tpd->renderGC.gc, /* GC */
y + tpd->cellHeight - 1, /* Y1 */ x, /* X1 */
x - 1 + XwcTextEscapement(termFontSet->fontSet, y + tpd->cellHeight - 1, /* Y1 */
(wchar_t *) string, len), /* X2 */ x - 1 + escapement, /* X2 */
y + tpd->cellHeight - 1); /* Y2 */ y + tpd->cellHeight - 1); /* Y2 */
}
} }
} }