1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
$NetBSD: patch-ae,v 1.5 2010/02/03 21:14:22 is Exp $
--- tkStripchart.c.orig 1996-03-16 21:14:00.000000000 +0000
+++ tkStripchart.c
@@ -148,7 +148,7 @@ struct strip_struct {
int scrollrequired;
int guarantee_draw;
int grow_up;
- XFontStruct *fontPtr; /* Information about text font, or NULL. */
+ Tk_Font tkfont; /* Information about text font, or NULL. */
XColor *textColorPtr; /* Color for drawing text. */
GC textGC; /* GC for drawing text. */
XColor *tickColorPtr; /* Color for drawing ticks. */
@@ -257,7 +257,7 @@ static Tk_ConfigSpec configSpecs[] =
{TK_CONFIG_SYNONYM, "-fg", "stripcolor", 0,
0, 0, 0},
{TK_CONFIG_FONT, "-font", "font", "Font",
- DEF_STRIPCHART_FONT, Tk_Offset(Stripchart, fontPtr),
+ DEF_STRIPCHART_FONT, Tk_Offset(Stripchart, tkfont),
0},
{TK_CONFIG_BOOLEAN, "-guaranteedrawing", "guaranteedrawing",
"Guaranteedrawing", DEF_GUARANTEE_DRAW,
@@ -570,8 +570,8 @@ DestroyStripchart(ClientData clientData)
if (StripchartPtr->value != NULL)
free(StripchartPtr->value);
- if (StripchartPtr->fontPtr != NULL)
- Tk_FreeFontStruct(StripchartPtr->fontPtr);
+ if (StripchartPtr->tkfont != NULL)
+ Tk_FreeFont(StripchartPtr->tkfont);
if (StripchartPtr->textColorPtr != NULL)
Tk_FreeColor(StripchartPtr->textColorPtr);
@@ -631,7 +631,7 @@ ConfigureStripchart(Tcl_Interp *interp,
Tk_SetBackgroundFromBorder(StripchartPtr->tkwin, StripchartPtr->border);
- gcValues.font = StripchartPtr->fontPtr->fid;
+ gcValues.font = Tk_FontId(StripchartPtr->tkfont);
gcValues.foreground = StripchartPtr->textColorPtr->pixel;
newGC = Tk_GetGC(StripchartPtr->tkwin, GCForeground|GCFont, &gcValues);
if (StripchartPtr->textGC != None && StripchartPtr->tkwin) {
@@ -692,8 +692,11 @@ ComputeStripchartGeometry(Stripchart* St
{
int tt = hasatitle(StripchartPtr);
int bd = StripchartPtr->borderWidth;
- int lineHeight = StripchartPtr->fontPtr->ascent +
- StripchartPtr->fontPtr->descent;
+ Tk_FontMetrics fm;
+ int lineHeight;
+
+ Tk_GetFontMetrics(StripchartPtr->tkfont, &fm);
+ lineHeight = fm.ascent + fm.descent;
Tk_GeometryRequest(StripchartPtr->tkwin,
2 * (bd + PADDING) + StripchartPtr->num_strips *
@@ -726,11 +729,13 @@ DisplayStripchart(ClientData clientData)
/*
* Variable declarations used in the title drawing routines
*/
- XFontStruct *fp = StripchartPtr->fontPtr;
- XCharStruct bbox;
- int x, dummy;
- int lineHeight = StripchartPtr->fontPtr->ascent +
- StripchartPtr->fontPtr->descent;
+ Tk_Font tkf = StripchartPtr->tkfont;
+ int x;
+ Tk_FontMetrics fm;
+ int lineHeight;
+
+ Tk_GetFontMetrics(tkf, &fm);
+ lineHeight = fm.ascent + fm.descent;
StripchartPtr->displaybits &= ~REDRAW_PENDING;
if ((StripchartPtr->tkwin == NULL) || !Tk_IsMapped(tkwin))
@@ -747,18 +752,17 @@ DisplayStripchart(ClientData clientData)
* space. Otherwise left justified and clipped on the right.
*/
if (tt && StripchartPtr->displaybits & DISPLAY_TITLE) {
- XTextExtents(fp, StripchartPtr->title,
- strlen(StripchartPtr->title),
- &dummy, &dummy, &dummy, &bbox);
- if (bbox.lbearing + bbox.rbearing < Tk_Width(tkwin) - 2 * bd)
- x = (Tk_Width(tkwin) - bbox.lbearing - bbox.rbearing)/2;
+ int width = Tk_TextWidth(tkf, StripchartPtr->title,
+ strlen(StripchartPtr->title));
+ if (width < Tk_Width(tkwin) - 2 * bd)
+ x = (Tk_Width(tkwin) - width)/2;
else
x = bd + PADDING;
XClearArea(Tk_Display(tkwin), Tk_WindowId(tkwin), bd, bd,
Tk_Width(tkwin) - 2 * bd, lineHeight + PADDING, False);
XDrawString(Tk_Display(tkwin), Tk_WindowId(tkwin),
- StripchartPtr->textGC, x, fp->max_bounds.ascent + bd,
+ StripchartPtr->textGC, x, fm.ascent + bd, /*XXX no max_bounds */
StripchartPtr->title, strlen(StripchartPtr->title));
}
/*
@@ -1057,7 +1061,8 @@ static void
DrawStripi(Stripchart* SPtr, int i)
{
Tk_Window tkwin = SPtr->tkwin;
- int lineHeight = SPtr->fontPtr->ascent + SPtr->fontPtr->descent;
+ Tk_FontMetrics fm;
+ int lineHeight;
int x = SPtr->borderWidth + PADDING + (i - 1) * SPtr->strip_width;
int y = SPtr->borderWidth + PADDING +
hasatitle(SPtr) * (lineHeight + PADDING);
@@ -1066,6 +1071,9 @@ DrawStripi(Stripchart* SPtr, int i)
double maxv = SPtr->max_value;
double minv = SPtr->min_value;
+ Tk_GetFontMetrics(SPtr->tkfont, &fm);
+ lineHeight = fm.ascent + fm.descent;
+
if (i < 1 || i > SPtr->num_strips)
return;
@@ -1136,7 +1144,8 @@ static void
ScrollStrips(Stripchart* SPtr)
{
Tk_Window tkwin = SPtr->tkwin;
- int lineHeight = SPtr->fontPtr->ascent + SPtr->fontPtr->descent;
+ Tk_FontMetrics fm;
+ int lineHeight;
int src_x = SPtr->borderWidth + PADDING + SPtr->strip_width;
int src_y = SPtr->borderWidth + PADDING +
hasatitle(SPtr) * (lineHeight + PADDING);
@@ -1145,6 +1154,8 @@ ScrollStrips(Stripchart* SPtr)
int w = (SPtr->num_strips - 1) * SPtr->strip_width;
int h = SPtr->max_height;
+ Tk_GetFontMetrics(SPtr->tkfont, &fm);
+
XCopyArea(Tk_Display(tkwin), Tk_WindowId(tkwin), Tk_WindowId(tkwin),
Tk_GetGC(tkwin, 0, NULL), src_x, src_y, w, h, dest_x, dest_y);
}
|