summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixRFont.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2009-10-10 19:38:27 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2009-10-10 19:38:27 (GMT)
commit8070fad15bc7eae379a988961b59f035032677c4 (patch)
tree0adbc9f0a1118abf68c78f3a75e1832c41eb3dde /unix/tkUnixRFont.c
parent33f53ca7dbbba7afbf10013b82655465ecf09558 (diff)
downloadtk-8070fad15bc7eae379a988961b59f035032677c4.zip
tk-8070fad15bc7eae379a988961b59f035032677c4.tar.gz
tk-8070fad15bc7eae379a988961b59f035032677c4.tar.bz2
[Bug 1961455]: Draw underlines and overstrikes when using Xft for font rendering
Diffstat (limited to 'unix/tkUnixRFont.c')
-rw-r--r--unix/tkUnixRFont.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c
index b3d5ce4..f580b2f 100644
--- a/unix/tkUnixRFont.c
+++ b/unix/tkUnixRFont.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixRFont.c,v 1.24.2.1 2009/09/10 12:47:15 dkf Exp $
+ * RCS: @(#) $Id: tkUnixRFont.c,v 1.24.2.2 2009/10/10 19:38:27 dkf Exp $
*/
#include "tkUnixInt.h"
@@ -35,7 +35,6 @@ typedef struct {
XftDraw *ftDraw;
XftColor color;
} UnixFtFont;
-
/*
* Package initialization:
@@ -261,6 +260,44 @@ InitFont(
GetTkFontAttributes(ftFont, &fontPtr->font.fa);
GetTkFontMetrics(ftFont, &fontPtr->font.fm);
+ /*
+ * Fontconfig can't report any information about the position or thickness
+ * of underlines or overstrikes. Thus, we use some defaults that are
+ * hacked around from backup defaults in tkUnixFont.c, which are in turn
+ * based on recommendations in the X manual. The comments from that file
+ * leading to these computations were:
+ *
+ * If the XA_UNDERLINE_POSITION property does not exist, the X manual
+ * recommends using half the descent.
+ *
+ * If the XA_UNDERLINE_THICKNESS property does not exist, the X
+ * manual recommends using the width of the stem on a capital letter.
+ * I don't know of a way to get the stem width of a letter, so guess
+ * and use 1/3 the width of a capital I.
+ *
+ * Note that nothing corresponding to *either* property is reported by
+ * Fontconfig at all. [Bug 1961455]
+ */
+
+ {
+ TkFont *fPtr = &fontPtr->font;
+ int iWidth;
+
+ fPtr->underlinePos = fPtr->fm.descent / 2;
+ Tk_MeasureChars((Tk_Font) fPtr, "I", 1, -1, 0, &iWidth);
+ fPtr->underlineHeight = iWidth / 3;
+ if (fPtr->underlineHeight == 0) {
+ fPtr->underlineHeight = 1;
+ }
+ if (fPtr->underlineHeight + fPtr->underlinePos > fPtr->fm.descent) {
+ fPtr->underlineHeight = fPtr->fm.descent - fPtr->underlinePos;
+ if (fPtr->underlineHeight == 0) {
+ fPtr->underlinePos--;
+ fPtr->underlineHeight = 1;
+ }
+ }
+ }
+
return fontPtr;
}
@@ -404,6 +441,9 @@ TkpGetFontFromAttributes(
FcPatternDestroy(pattern);
return NULL;
}
+
+ fontPtr->font.fa.underline = faPtr->underline;
+ fontPtr->font.fa.overstrike = faPtr->overstrike;
return &fontPtr->font;
}
@@ -671,7 +711,7 @@ Tk_DrawChars(
UnixFtFont *fontPtr = (UnixFtFont *) tkfont;
XGCValues values;
XColor xcolor;
- int clen, nspec;
+ int clen, nspec, xStart = x;
XftGlyphFontSpec specs[NUM_SPEC];
XGlyphInfo metrics;
@@ -711,7 +751,7 @@ Tk_DrawChars(
* This should not happen, but it can.
*/
- return;
+ goto doUnderlineStrikeout;
}
source += clen;
numBytes -= clen;
@@ -737,4 +777,17 @@ Tk_DrawChars(
if (nspec) {
XftDrawGlyphFontSpec(fontPtr->ftDraw, &fontPtr->color, specs, nspec);
}
+
+ doUnderlineStrikeout:
+ if (fontPtr->font.fa.underline != 0) {
+ XFillRectangle(display, drawable, gc, xStart,
+ y + fontPtr->font.underlinePos, (unsigned) (x - xStart),
+ (unsigned) fontPtr->font.underlineHeight);
+ }
+ if (fontPtr->font.fa.overstrike != 0) {
+ y -= fontPtr->font.fm.descent + (fontPtr->font.fm.ascent) / 10;
+ XFillRectangle(display, drawable, gc, xStart, y,
+ (unsigned) (x - xStart),
+ (unsigned) fontPtr->font.underlineHeight);
+ }
}