summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/tkUnixFont.c40
-rw-r--r--unix/tkUnixRFont.c62
2 files changed, 100 insertions, 2 deletions
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index 9174f8e..0ab8fb5 100644
--- a/unix/tkUnixFont.c
+++ b/unix/tkUnixFont.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixFont.c,v 1.29 2006/10/05 21:27:43 hobbs Exp $
+ * RCS: @(#) $Id: tkUnixFont.c,v 1.30 2006/12/01 20:14:23 kennykb Exp $
*/
#include "tkUnixInt.h"
@@ -930,6 +930,44 @@ TkpGetSubFonts(
}
/*
+ *----------------------------------------------------------------------
+ *
+ * TkpGetFontAttrsForChar --
+ *
+ * Retrieve the font attributes of the actual font used to render
+ * a given character.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The font attributes are stored in *faPtr.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TkpGetFontAttrsForChar(
+ Tk_Window tkwin, /* Window on the font's display */
+ Tk_Font tkfont, /* Font to query */
+ Tcl_UniChar c, /* Character of interest */
+ TkFontAttributes* faPtr) /* Output: Font attributes */
+{
+ FontAttributes atts;
+ UnixFont *fontPtr = (UnixFont *) tkfont;
+ /* Structure describing the logical font */
+ SubFont *lastSubFontPtr = &fontPtr->subFontArray[0];
+ /* Pointer to subfont array in case
+ * FindSubFontForChar needs to fix up the
+ * memory allocation */
+ SubFont *thisSubFontPtr = FindSubFontForChar(fontPtr, c, &lastSubFontPtr);
+ /* Pointer to the subfont to use for the
+ * given character */
+ GetFontAttributes(Tk_Display(tkwin), thisSubFontPtr->fontStructPtr, &atts);
+ *faPtr = atts.fa;
+}
+
+/*
*---------------------------------------------------------------------------
*
* Tk_MeasureChars --
diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c
index 407bcf6..285ac8e 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.13 2006/03/23 22:08:51 rmax Exp $
+ * RCS: @(#) $Id: tkUnixRFont.c,v 1.14 2006/12/01 20:14:23 kennykb Exp $
*/
#include "tkUnixInt.h"
@@ -469,6 +469,66 @@ TkpGetSubFonts(
Tcl_SetObjResult(interp, resultPtr);
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * TkpGetFontAttrsForChar --
+ *
+ * Retrieve the font attributes of the actual font used to render
+ * a given character.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The font attributes are stored in *faPtr.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TkpGetFontAttrsForChar(
+ Tk_Window tkwin, /* Window on the font's display */
+ Tk_Font tkfont, /* Font to query */
+ Tcl_UniChar c, /* Character of interest */
+ TkFontAttributes* faPtr) /* Output: Font attributes */
+{
+ UnixFtFont *fontPtr = (UnixFtFont*) tkfont;
+ /* Structure describing the logical font */
+ FcChar32 ucs4 = (FcChar32) c;
+ /* UCS-4 character to map */
+ XftFont *xftFontPtr = GetFont(fontPtr, ucs4);
+ /* Actual font used to render the character */
+ const char* family; /* Font family name */
+ double size; /* Font size */
+ int weight; /* Font weight */
+ int slant; /* Font slant */
+
+ if (XftPatternGetString(xftFontPtr->pattern, XFT_FAMILY, 0,
+ &family) != XftResultMatch) {
+ family = "Unknown";
+ }
+ if (XftPatternGetDouble(xftFontPtr->pattern, XFT_SIZE, 0,
+ &size) != XftResultMatch) {
+ size = 12.0;
+ }
+ if (XftPatternGetInteger(xftFontPtr->pattern, XFT_WEIGHT, 0,
+ &weight) != XftResultMatch) {
+ weight = XFT_WEIGHT_MEDIUM;
+ }
+ if (XftPatternGetInteger(xftFontPtr->pattern, XFT_SLANT, 0,
+ &slant) != XftResultMatch) {
+ slant = XFT_SLANT_ROMAN;
+ }
+ faPtr->family = Tk_GetUid(family);
+ faPtr->size = (int) size;
+ faPtr->weight = (weight > XFT_WEIGHT_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
+ faPtr->slant = (slant > XFT_SLANT_ROMAN) ? TK_FS_ITALIC : TK_FS_ROMAN;
+ faPtr->underline = fontPtr->font.fa.underline;
+ faPtr->overstrike = fontPtr->font.fa.overstrike;
+
+}
+
int
Tk_MeasureChars(
Tk_Font tkfont, /* Font in which characters will be drawn. */