The R Project SVN R

Rev

Rev 2028 | Rev 2122 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2028 Rev 2105
Line 101... Line 101...
101
    CurrentY = y;
101
    CurrentY = y;
102
}
102
}
103
 
103
 
104
/* Basic Font Properties */
104
/* Basic Font Properties */
105
 
105
 
-
 
106
#ifdef OLD
106
static double FontHeight()
107
static double FontHeight()
107
{
108
{
108
    double height, depth, width;
109
    double height, depth, width;
109
    GMetricInfo(0, &height, &depth, &width, MetricUnit, MathDevice);
110
    GMetricInfo(0, &height, &depth, &width, MetricUnit, MathDevice);
110
    return height + depth;
111
    return height + depth;
111
}
112
}
-
 
113
#endif
112
 
114
 
113
static double xHeight()
115
static double xHeight()
114
{
116
{
115
    double height, depth, width;
117
    double height, depth, width;
116
    GMetricInfo('x', &height, &depth, &width, MetricUnit, MathDevice);
118
    GMetricInfo('x', &height, &depth, &width, MetricUnit, MathDevice);
Line 136... Line 138...
136
    double height, depth, width;
138
    double height, depth, width;
137
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
139
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
138
    return width;
140
    return width;
139
}
141
}
140
 
142
 
-
 
143
/* The height of digits */
-
 
144
static double FigHeight()
-
 
145
{
-
 
146
    double height, depth, width;
-
 
147
    GMetricInfo('0', &height, &depth, &width, MetricUnit, MathDevice);
-
 
148
    return height;
-
 
149
}
-
 
150
 
-
 
151
/* Depth of lower case descenders */
-
 
152
static double DescDepth()
-
 
153
{
-
 
154
    double height, depth, width;
-
 
155
    GMetricInfo('g', &height, &depth, &width, MetricUnit, MathDevice);
-
 
156
    return depth;
-
 
157
}
-
 
158
 
-
 
159
static double AscHeight()
-
 
160
{
-
 
161
    double height, depth, width, save;
-
 
162
    GMetricInfo('d', &height, &depth, &width, MetricUnit, MathDevice);
-
 
163
    save = height;
-
 
164
    GMetricInfo('a', &height, &depth, &width, MetricUnit, MathDevice);
-
 
165
    return save - height;
-
 
166
}
-
 
167
 
-
 
168
/* Thickness of rules */
-
 
169
static double RuleThickness()
-
 
170
{
-
 
171
    return 0.015;
-
 
172
}
-
 
173
 
141
static double ThinSpace()
174
static double ThinSpace()
142
{
175
{
143
    double height, depth, width;
176
    double height, depth, width;
144
    static double OneSixth = 0.16666666666666666666;
177
    static double OneSixth = 0.16666666666666666666;
145
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
178
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
Line 174... Line 207...
174
/*
207
/*
175
 *  Mathematics Layout Parameters
208
 *  Mathematics Layout Parameters
176
 *
209
 *
177
 *  The TeXBook, Appendex G, Page 447.
210
 *  The TeXBook, Appendex G, Page 447.
178
 *
211
 *
179
 *  Note : these values are ``optimised'' for PostScript.
212
 *  These values are based on an inspection of TeX metafont files
180
 *  They can look ugly under X11.
213
 *  together with some visual simplification.
-
 
214
 *
-
 
215
 *  Note : The values are ``optimised'' for PostScript.
181
 *
216
 *
182
 */
217
 */
183
 
218
 
184
typedef enum {
219
typedef enum {
185
    sigma2, sigma5, sigma6, sigma8, sigma9, sigma10, sigma11, sigma12,
220
    sigma2,  sigma5,  sigma6,  sigma8,  sigma9,  sigma10, sigma11,
186
    sigma13, sigma14, sigma15, sigma16, sigma17, sigma18, sigma19,
221
    sigma12, sigma13, sigma14, sigma15, sigma16, sigma17, sigma18,
187
    sigma20, sigma21, sigma22, xi8, xi9, xi10, xi11, xi12, xi13
222
    sigma19, sigma20, sigma21, sigma22, xi8, xi9, xi10, xi11, xi12, xi13
188
}
223
}
189
TEXPAR;
224
TEXPAR;
190
 
225
 
191
 
-
 
192
#define LINEWIDTH 0.015
226
#define SUBS           0.7
193
 
227
 
194
static double TeX(TEXPAR which)
228
static double TeX(TEXPAR which)
195
{
229
{
196
    double value;
230
    double value;
197
    switch(which) {
231
    switch(which) {
Line 201... Line 235...
201
 
235
 
202
    case sigma6:  /* quad */
236
    case sigma6:  /* quad */
203
	return Quad();
237
	return Quad();
204
 
238
 
205
    case sigma8:  /* num1 */
239
    case sigma8:  /* num1 */
-
 
240
	return AxisHeight()
-
 
241
	    + 3.51 * RuleThickness()
-
 
242
	    + 0.15 * XHeight()          /* 54/36 * 0.1 */
-
 
243
	    + SUBS * DescDepth();
206
    case sigma9:  /* num2 */
244
    case sigma9:  /* num2 */
-
 
245
	return AxisHeight()
-
 
246
	    + 1.51 * RuleThickness()
-
 
247
	    + 0.08333333 * XHeight();   /* 30/36 * 0.1 */
207
    case sigma10: /* num3 */
248
    case sigma10: /* num3 */
208
	return (0.45 * XHeight() + AxisHeight());
249
	return AxisHeight()
209
 
-
 
-
 
250
	    + 1.51 * RuleThickness()
-
 
251
	    + 0.1333333 * XHeight();    /* 48/36 * 0.1 */
210
    case sigma11: /* denom1 */
252
    case sigma11: /* denom1 */
-
 
253
	return  - AxisHeight()
-
 
254
	    + 3.51 * RuleThickness()
-
 
255
	    + SUBS * FigHeight()
-
 
256
	    + 0.344444 * XHeight();     /* 124/36 * 0.1 */
211
    case sigma12: /* denom2 */
257
    case sigma12: /* denom2 */
212
	return (1.45 * XHeight() - AxisHeight());
258
	return  - AxisHeight()
-
 
259
	    + 1.51 * RuleThickness()
-
 
260
	    + SUBS * FigHeight()
-
 
261
	    + 0.08333333 * XHeight();   /* 30/36 * 0.1 */
213
 
262
 
214
    case sigma13: /* sup1 */
263
    case sigma13: /* sup1 */
-
 
264
	return 0.95 * xHeight();
215
    case sigma14: /* sup2 */
265
    case sigma14: /* sup2 */
-
 
266
	return 0.825 * xHeight();
216
    case sigma15: /* sup3 */
267
    case sigma15: /* sup3 */
217
	return xHeight();
268
	return 0.7 * xHeight();
218
 
269
 
219
    case sigma16: /* sub1 */
270
    case sigma16: /* sub1 */
-
 
271
	return 0.35 * xHeight();
220
    case sigma17: /* sub2 */
272
    case sigma17: /* sub2 */
221
	return 0.5 * xHeight();
273
	return 0.45 * XHeight();
222
 
274
 
223
    case sigma18: /* sup_drop */
275
    case sigma18: /* sup_drop */
224
	return 0.1 * xHeight();
276
	return 0.3861111 * XHeight();
225
 
277
 
226
    case sigma19: /* sub_drop */
278
    case sigma19: /* sub_drop */
227
	return 0.1 * xHeight();
279
	return 0.05 * XHeight();
228
 
280
 
229
    case sigma20: /* delim1 */
281
    case sigma20: /* delim1 */
-
 
282
	return 2.39 * XHeight();
230
    case sigma21: /* delim2 */
283
    case sigma21: /* delim2 */
-
 
284
	return 1.01 *XHeight();
231
 
285
 
232
    case sigma22: /* axis_height */
286
    case sigma22: /* axis_height */
233
	return AxisHeight();
287
	return AxisHeight();
234
 
288
 
235
    case xi8:     /* default_rule_thickness */
289
    case xi8:     /* default_rule_thickness */
236
	return LINEWIDTH;
290
	return RuleThickness();
237
	break;
291
	break;
238
 
292
 
239
    case xi9:     /* big_op_spacing1 */
293
    case xi9:     /* big_op_spacing1 */
240
    case xi10:    /* big_op_spacing2 */
294
    case xi10:    /* big_op_spacing2 */
241
    case xi11:    /* big_op_spacing3 */
295
    case xi11:    /* big_op_spacing3 */
Line 794... Line 848...
794
}
848
}
795
 
849
 
796
static int TranslatedSymbol(SEXP expr)
850
static int TranslatedSymbol(SEXP expr)
797
{
851
{
798
    int code = SymbolCode(expr);
852
    int code = SymbolCode(expr);
799
    if ((65 <= code && code <= 90)  ||   /* Greek */
853
    if ((0101 <= code && code <= 0132)  ||   /* Greek */
800
	(97 <= code && code <= 122) ||
854
	(0141 <= code && code <= 0172)  ||   /* Greek */
801
	code == 161                 ||
855
	code == 0241                    ||   /* Greek */
802
	code == 162                 ||   /* minute */
856
	code == 0242                    ||   /* minute */
803
	code == 165                 ||   /* infinity */
857
	code == 0245                    ||   /* infinity */
804
	code == 176                 ||   /* degree */
858
	code == 0260                    ||   /* degree */
805
	code == 178                 ||   /* second */
859
	code == 0262                    ||   /* second */
806
	0)
860
	0)
807
	return code;
861
	return code;
808
    else
862
    else
809
	return 0;
863
	return 0;
810
}
864
}
Line 1147... Line 1201...
1147
	error("invalid mathematical annotation\n");
1201
	error("invalid mathematical annotation\n");
1148
 
1202
 
1149
}
1203
}
1150
 
1204
 
1151
static SymTab BinTable[] = {
1205
static SymTab BinTable[] = {
1152
    "*",                42,    /* Binary Operators */
1206
    "*",                052,    /* Binary Operators */
1153
    "+",                43,
1207
    "+",                053,
1154
    "-",                45,
1208
    "-",                055,
1155
    "/",                47,
1209
    "/",                057,
1156
    ":",                58,
1210
    ":",                072,
1157
    "%+-%",            177,
1211
    "%+-%",            0261,
1158
    "%*%",             180,
1212
    "%*%",             0264,
1159
    "%/%",             184,
1213
    "%/%",             0270,
-
 
1214
    "%intersection%",  0307,
-
 
1215
    "%union%",         0310,
1160
    NULL,                0
1216
    NULL,                 0
1161
};
1217
};
1162
 
1218
 
1163
static int BinAtom(SEXP expr)
1219
static int BinAtom(SEXP expr)
1164
{
1220
{
1165
    int i;
1221
    int i;
Line 1423... Line 1479...
1423
    double height = bboxHeight(bbox);
1479
    double height = bboxHeight(bbox);
1424
    double width = bboxWidth(bbox);
1480
    double width = bboxWidth(bbox);
1425
    double totalwidth = bboxWidth(bbox) + bboxItalic(bbox);
1481
    double totalwidth = bboxWidth(bbox) + bboxItalic(bbox);
1426
    double delta = totalwidth * (1 - 2 * DELTA) / NTILDE;
1482
    double delta = totalwidth * (1 - 2 * DELTA) / NTILDE;
1427
    double start = DELTA * totalwidth;
1483
    double start = DELTA * totalwidth;
1428
    double accentGap = ACCENT_GAP * FontHeight();
1484
    double accentGap = ACCENT_GAP * XHeight();
1429
    double hatHeight = 0.5 * HAT_HEIGHT * FontHeight();
1485
    double hatHeight = 0.5 * HAT_HEIGHT * XHeight();
1430
    double c = 8 * atan(1.0) / NTILDE;
1486
    double c = 8 * atan(1.0) / NTILDE;
1431
    double x[NTILDE + 3], y[NTILDE + 3];
1487
    double x[NTILDE + 3], y[NTILDE + 3];
1432
    double baseX, baseY, xval, yval;
1488
    double baseX, baseY, xval, yval;
1433
    int i;
1489
    int i;
1434
 
1490
 
Line 1463... Line 1519...
1463
static BBOX RenderWideHat(SEXP expr, int draw)
1519
static BBOX RenderWideHat(SEXP expr, int draw)
1464
{
1520
{
1465
    double savedX = CurrentX;
1521
    double savedX = CurrentX;
1466
    double savedY = CurrentY;
1522
    double savedY = CurrentY;
1467
    BBOX bbox = RenderElement(CADR(expr), draw);
1523
    BBOX bbox = RenderElement(CADR(expr), draw);
1468
    double accentGap = ACCENT_GAP * FontHeight();
1524
    double accentGap = ACCENT_GAP * XHeight();
1469
    double hatHeight = HAT_HEIGHT * FontHeight();
1525
    double hatHeight = HAT_HEIGHT * XHeight();
1470
    double totalwidth = bboxWidth(bbox) + bboxItalic(bbox);
1526
    double totalwidth = bboxWidth(bbox) + bboxItalic(bbox);
1471
    double height = bboxHeight(bbox);
1527
    double height = bboxHeight(bbox);
1472
    double width = bboxWidth(bbox);
1528
    double width = bboxWidth(bbox);
1473
    double x[3], y[3];
1529
    double x[3], y[3];
1474
 
1530
 
Line 1498... Line 1554...
1498
static BBOX RenderBar(SEXP expr, int draw)
1554
static BBOX RenderBar(SEXP expr, int draw)
1499
{
1555
{
1500
    double savedX = CurrentX;
1556
    double savedX = CurrentX;
1501
    double savedY = CurrentY;
1557
    double savedY = CurrentY;
1502
    BBOX bbox = RenderElement(CADR(expr), draw);
1558
    BBOX bbox = RenderElement(CADR(expr), draw);
1503
    double accentGap = ACCENT_GAP * FontHeight();
1559
    double accentGap = ACCENT_GAP * XHeight();
1504
    double hatHeight = HAT_HEIGHT * FontHeight();
1560
    double hatHeight = HAT_HEIGHT * XHeight();
1505
    double totalwidth = bboxWidth(bbox) + bboxItalic(bbox);
-
 
1506
    double height = bboxHeight(bbox);
1561
    double height = bboxHeight(bbox);
1507
    double width = bboxWidth(bbox);
1562
    double width = bboxWidth(bbox);
-
 
1563
    double offset = bboxItalic(bbox);
1508
    double x[2], y[2];
1564
    double x[2], y[2];
1509
 
1565
 
1510
    if (draw) {
1566
    if (draw) {
1511
	MoveTo(savedX, savedY + height + accentGap);
1567
	MoveTo(savedX + offset, savedY + height + accentGap);
1512
	x[0] = ConvertedX();
1568
	x[0] = ConvertedX();
1513
	y[0] = ConvertedY();
1569
	y[0] = ConvertedY();
1514
	MoveAcross(totalwidth);
1570
	MoveAcross(width);
1515
	x[1] = ConvertedX();
1571
	x[1] = ConvertedX();
1516
	y[1] = ConvertedY();
1572
	y[1] = ConvertedY();
1517
	GPolyline(2, x, y, INCHES, MathDevice);
1573
	GPolyline(2, x, y, INCHES, MathDevice);
1518
	MoveTo(savedX + width, savedY);
1574
	MoveTo(savedX + width, savedY);
1519
    }
1575
    }
Line 1524... Line 1580...
1524
    char *name;
1580
    char *name;
1525
    int code;
1581
    int code;
1526
}
1582
}
1527
AccentTable[] = {
1583
AccentTable[] = {
1528
    "hat",            94,
1584
    "hat",            94,
-
 
1585
    "ring",          176,
1529
    "tilde",         126,
1586
    "tilde",         126,
1530
    NULL,              0,
1587
    NULL,              0,
1531
};
1588
};
1532
    
1589
    
1533
static int AccentCode(SEXP expr)
1590
static int AccentCode(SEXP expr)
Line 1539... Line 1596...
1539
    return 0;
1596
    return 0;
1540
}
1597
}
1541
 
1598
 
1542
static int AccentAtom(SEXP expr)
1599
static int AccentAtom(SEXP expr)
1543
{
1600
{
1544
    return NameAtom(expr) && 
1601
    return NameAtom(expr) && (AccentCode(expr) != 0);
1545
	(NameMatch(expr, "hat") || NameMatch(expr, "tilde"));
-
 
1546
}
1602
}
1547
 
1603
 
1548
static void InvalidAccent(SEXP expr)
1604
static void InvalidAccent(SEXP expr)
1549
{
1605
{
1550
    errorcall(expr, "invalid accent\n");
1606
    errorcall(expr, "invalid accent\n");
Line 1554... Line 1610...
1554
{
1610
{
1555
    SEXP body, accent;
1611
    SEXP body, accent;
1556
    double savedX = CurrentX;
1612
    double savedX = CurrentX;
1557
    double savedY = CurrentY;
1613
    double savedY = CurrentY;
1558
    BBOX bodyBBox, accentBBox;
1614
    BBOX bodyBBox, accentBBox;
1559
    double xoffset, yoffset;
1615
    double xoffset, yoffset, width, italic;
1560
    int code;
1616
    int code;
1561
    if (length(expr) != 2)
1617
    if (length(expr) != 2)
1562
	InvalidAccent(expr);
1618
	InvalidAccent(expr);
1563
    accent = CAR(expr);
1619
    accent = CAR(expr);
1564
    body = CADR(expr);
1620
    body = CADR(expr);
1565
    if (NameMatch(accent, "hat"))
1621
    code = AccentCode(accent);
1566
	code = 94;
1622
    if (code == 0)
1567
    else if (NameMatch(accent, "tilde"))
-
 
1568
	code = 126;
-
 
1569
    else
-
 
1570
	InvalidAccent(expr);
1623
	InvalidAccent(expr);
1571
    bodyBBox = RenderElement(body, draw);
1624
    bodyBBox = RenderElement(body, 0);
-
 
1625
    italic = bboxItalic(bodyBBox);
1572
    accentBBox = RenderChar(code, 0);
1626
    accentBBox = RenderChar(code, 0);
1573
    xoffset = 0.5 *(bboxWidth(bodyBBox) - bboxWidth(accentBBox));
1627
    width = max(bboxWidth(bodyBBox) + bboxItalic(bodyBBox),
-
 
1628
		bboxWidth(accentBBox));
1574
    yoffset = bboxHeight(bodyBBox);
1629
    xoffset = 0.5 *(width - bboxWidth(bodyBBox));
-
 
1630
    bodyBBox = RenderGap(xoffset, draw);
-
 
1631
    bodyBBox = CombineBBoxes(bodyBBox, RenderElement(body, draw));
-
 
1632
    bodyBBox = CombineBBoxes(bodyBBox, RenderGap(xoffset, draw));
-
 
1633
    MoveTo(savedX, savedY);
-
 
1634
    xoffset = 0.5 *(width - bboxWidth(accentBBox))
-
 
1635
	+ 0.9 * italic;
-
 
1636
    yoffset = bboxHeight(bodyBBox) + bboxDepth(accentBBox) + 0.1 * XHeight();
1575
    if (draw) {
1637
    if (draw) {
1576
	MoveTo(savedX + xoffset, savedY + yoffset);
1638
	MoveTo(savedX + xoffset, savedY + yoffset);
1577
	RenderChar(code, draw);
1639
	RenderChar(code, draw);
1578
    }
1640
    }
1579
    bodyBBox = CombineOffsetBBoxes(bodyBBox, 0, accentBBox, 0,
1641
    bodyBBox = CombineOffsetBBoxes(bodyBBox, 0, accentBBox, 0,
1580
				   xoffset, yoffset);
1642
				   xoffset, yoffset);
1581
    MoveTo(savedX + bboxWidth(bodyBBox), savedY);
1643
    MoveTo(savedX + width, savedY);
1582
    return bodyBBox;
1644
    return bodyBBox;
1583
}
1645
}
1584
 
1646
 
1585
 
1647
 
1586
/*----------------------------------------------------------------------
1648
/*----------------------------------------------------------------------
Line 1607... Line 1669...
1607
	*v = TeX(sigma12);
1669
	*v = TeX(sigma12);
1608
	phi = theta;
1670
	phi = theta;
1609
    }
1671
    }
1610
    delta = (*u - bboxDepth(numBBox)) - (a + 0.5 * theta);
1672
    delta = (*u - bboxDepth(numBBox)) - (a + 0.5 * theta);
1611
    if (delta < phi)
1673
    if (delta < phi)
1612
	*u += (phi - delta);
1674
	*u += (phi - delta) + theta;
1613
    delta = (a + 0.5 * theta) - (bboxHeight(denomBBox) - *v);
1675
    delta = (a + 0.5 * theta) - (bboxHeight(denomBBox) - *v);
1614
    if (delta < phi)
1676
    if (delta < phi)
1615
	*v += (phi - delta);
1677
	*v += (phi - delta) + theta;
1616
}
1678
}
1617
 
1679
 
1618
static void NumDenomHShift(BBOX numBBox, BBOX denomBBox,
1680
static void NumDenomHShift(BBOX numBBox, BBOX denomBBox,
1619
			   double *numShift, double *denomShift)
1681
			   double *numShift, double *denomShift)
1620
{
1682
{
Line 1683... Line 1745...
1683
    return CombineAlignedBBoxes(numBBox, denomBBox);
1745
    return CombineAlignedBBoxes(numBBox, denomBBox);
1684
}
1746
}
1685
 
1747
 
1686
static int OverAtom(SEXP expr)
1748
static int OverAtom(SEXP expr)
1687
{
1749
{
-
 
1750
    return NameAtom(expr) &&
1688
    return NameAtom(expr) && NameMatch(expr, "over");
1751
        (NameMatch(expr, "over") || NameMatch(expr, "frac"));
1689
}
1752
}
1690
 
1753
 
1691
static BBOX RenderOver(SEXP expr, int draw)
1754
static BBOX RenderOver(SEXP expr, int draw)
1692
{
1755
{
1693
    return RenderFraction(expr, 1, draw);
1756
    return RenderFraction(expr, 1, draw);
Line 1700... Line 1763...
1700
 
1763
 
1701
static BBOX RenderAtop(SEXP expr, int draw)
1764
static BBOX RenderAtop(SEXP expr, int draw)
1702
{
1765
{
1703
    return RenderFraction(expr, 0, draw);
1766
    return RenderFraction(expr, 0, draw);
1704
}
1767
}
-
 
1768
 
1705
/*----------------------------------------------------------------------
1769
/*----------------------------------------------------------------------
1706
 *
1770
 *
1707
 *  Code for Grouped Expressions  (e.g. ( ... ))
1771
 *  Code for Grouped Expressions  (e.g. ( ... ))
1708
 *
1772
 *
1709
 *    group(ldelim, body, rdelim)
1773
 *    group(ldelim, body, rdelim)
1710
 *
1774
 *
1711
 *    bgroup(ldelim, body, rdelim)
1775
 *    bgroup(ldelim, body, rdelim)
1712
 *
1776
 *
1713
 */
1777
 */
1714
 
1778
 
-
 
1779
#define DelimSymbolMag 1.25
-
 
1780
 
1715
static int DelimCode(SEXP expr, SEXP head)
1781
static int DelimCode(SEXP expr, SEXP head)
1716
{
1782
{
1717
    int code = 0;
1783
    int code = 0;
1718
    if (NameAtom(head)) {
1784
    if (NameAtom(head)) {
1719
	if (NameMatch(head, "lfloor"))
1785
	if (NameMatch(head, "lfloor"))
Line 1748... Line 1814...
1748
    if (code == 0)
1814
    if (code == 0)
1749
	errorcall(expr, "invalid group delimiter\n");
1815
	errorcall(expr, "invalid group delimiter\n");
1750
    return code;
1816
    return code;
1751
}
1817
}
1752
 
1818
 
-
 
1819
static BBOX RenderDelimiter(int delim, int draw)
-
 
1820
{
-
 
1821
    BBOX bbox;
-
 
1822
    double savecex = MathDevice->gp.cex;
-
 
1823
    MathDevice->gp.cex = DelimSymbolMag * MathDevice->gp.cex;
-
 
1824
    bbox = RenderSymbolChar(delim, draw);
-
 
1825
    MathDevice->gp.cex = savecex;
-
 
1826
    return bbox;
-
 
1827
}
-
 
1828
 
1753
static int GroupAtom(SEXP expr)
1829
static int GroupAtom(SEXP expr)
1754
{
1830
{
1755
    return NameAtom(expr) && NameMatch(expr, "group");
1831
    return NameAtom(expr) && NameMatch(expr, "group");
1756
}
1832
}
1757
 
1833
 
1758
static BBOX RenderGroup(SEXP expr, int draw)
1834
static BBOX RenderGroup(SEXP expr, int draw)
1759
{
1835
{
-
 
1836
    double cexSaved = MathDevice->gp.cex;
1760
    BBOX bbox;
1837
    BBOX bbox;
1761
    int code;
1838
    int code;
1762
    if (length(expr) != 4)
1839
    if (length(expr) != 4)
1763
	errorcall(expr, "invalid group specification\n");
1840
	errorcall(expr, "invalid group specification\n");
1764
    bbox = NullBBox();
1841
    bbox = NullBBox();
1765
    code = DelimCode(expr, CADR(expr));
1842
    code = DelimCode(expr, CADR(expr));
-
 
1843
    MathDevice->gp.cex = DelimSymbolMag * MathDevice->gp.cex;
1766
    if (code == 2) {
1844
    if (code == 2) {
1767
	bbox = RenderSymbolChar('|', draw);
1845
	bbox = RenderSymbolChar('|', draw);
1768
	bbox = RenderSymbolChar('|', draw);
1846
	bbox = RenderSymbolChar('|', draw);
1769
    }
1847
    }
1770
    else if (code != '.')
1848
    else if (code != '.')
1771
	bbox = RenderSymbolChar(code, draw);
1849
	bbox = RenderSymbolChar(code, draw);
-
 
1850
    MathDevice->gp.cex = cexSaved;
1772
    bbox = CombineBBoxes(bbox, RenderElement(CADDR(expr), draw));
1851
    bbox = CombineBBoxes(bbox, RenderElement(CADDR(expr), draw));
1773
    bbox = RenderItalicCorr(bbox, draw);
1852
    bbox = RenderItalicCorr(bbox, draw);
1774
    code = DelimCode(expr, CADDDR(expr));
1853
    code = DelimCode(expr, CADDDR(expr));
-
 
1854
    MathDevice->gp.cex = DelimSymbolMag * MathDevice->gp.cex;
1775
    if (code == 2) {
1855
    if (code == 2) {
1776
	bbox = RenderSymbolChar('|', draw);
1856
	bbox = RenderSymbolChar('|', draw);
1777
	bbox = RenderSymbolChar('|', draw);
1857
	bbox = RenderSymbolChar('|', draw);
1778
    }
1858
    }
1779
    else if (code != '.')
1859
    else if (code != '.')
1780
	bbox = RenderSymbolChar(code, draw);
1860
	bbox = RenderSymbolChar(code, draw);
-
 
1861
    MathDevice->gp.cex = cexSaved;
1781
    return bbox;
1862
    return bbox;
1782
}
1863
}
1783
 
1864
 
1784
static int BGroupAtom(SEXP expr)
1865
static int BGroupAtom(SEXP expr)
1785
{
1866
{
Line 1791... Line 1872...
1791
    double savedX = CurrentX;
1872
    double savedX = CurrentX;
1792
    double savedY = CurrentY;
1873
    double savedY = CurrentY;
1793
    FontType prev = SetFont(SymbolFont);
1874
    FontType prev = SetFont(SymbolFont);
1794
    BBOX ansBBox, topBBox, botBBox, extBBox, midBBox;
1875
    BBOX ansBBox, topBBox, botBBox, extBBox, midBBox;
1795
    int top, bot, ext, mid;
1876
    int top, bot, ext, mid;
-
 
1877
    int i, n;
1796
    double topShift, botShift;
1878
    double topShift, botShift, extShift, midShift;
-
 
1879
    double ytop, ybot, extHeight, delta;
1797
    double axisHeight = TeX(sigma22);
1880
    double axisHeight = TeX(sigma22);
1798
 
1881
 
1799
    switch(which) {
1882
    switch(which) {
1800
    case '.':
1883
    case '.':
1801
	return NullBBox();
1884
	return NullBBox();
Line 1827... Line 1910...
1827
	break;
1910
	break;
1828
    }
1911
    }
1829
    topBBox = GlyphBBox(top);
1912
    topBBox = GlyphBBox(top);
1830
    extBBox = GlyphBBox(ext);
1913
    extBBox = GlyphBBox(ext);
1831
    botBBox = GlyphBBox(bot);
1914
    botBBox = GlyphBBox(bot);
-
 
1915
    if (which == '{' || which == '}') {
-
 
1916
	if (1.2 * (bboxHeight(topBBox) + bboxDepth(topBBox)) > dist)
-
 
1917
	    dist = 1.2 * (bboxHeight(topBBox) + bboxDepth(botBBox));
-
 
1918
    }
-
 
1919
    else {
-
 
1920
	if (0.8 * (bboxHeight(topBBox) + bboxDepth(topBBox)) > dist)
-
 
1921
	    dist = 0.8 * (bboxHeight(topBBox) + bboxDepth(topBBox));
-
 
1922
    }
-
 
1923
    extHeight = bboxHeight(extBBox) + bboxDepth(extBBox);
1832
    topShift = dist - bboxHeight(topBBox) + axisHeight;
1924
    topShift = dist - bboxHeight(topBBox) + axisHeight;
1833
    botShift = dist - bboxDepth(botBBox) - axisHeight;
1925
    botShift = dist - bboxDepth(botBBox) - axisHeight;
-
 
1926
    extShift = 0.5 * (bboxHeight(extBBox) - bboxDepth(extBBox));
1834
    topBBox = ShiftBBox(topBBox, topShift);
1927
    topBBox = ShiftBBox(topBBox, topShift);
1835
    botBBox = ShiftBBox(botBBox, -botShift);
1928
    botBBox = ShiftBBox(botBBox, -botShift);
1836
    ansBBox = CombineAlignedBBoxes(topBBox, botBBox);
1929
    ansBBox = CombineAlignedBBoxes(topBBox, botBBox);
-
 
1930
    if (which == '{' || which == '}') {
-
 
1931
	midBBox = GlyphBBox(mid);
-
 
1932
	midShift = axisHeight
-
 
1933
	    - 0.5 * (bboxHeight(midBBox) - bboxDepth(midBBox));
-
 
1934
	midBBox = ShiftBBox(midBBox, midShift);
-
 
1935
	ansBBox = CombineAlignedBBoxes(ansBBox, midBBox);
1837
    if (draw) {
1936
	if (draw) {
1838
	MoveUp(topShift);
1937
	    MoveTo(savedX, savedY + topShift);
1839
	RenderSymbolChar(top, draw);
1938
	    RenderSymbolChar(top, draw);
-
 
1939
	    MoveTo(savedX, savedY + midShift);
-
 
1940
	    RenderSymbolChar(mid, draw);	    
-
 
1941
	    MoveTo(savedX, savedY - botShift);
-
 
1942
	    RenderSymbolChar(bot, draw);
-
 
1943
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
-
 
1944
	}
-
 
1945
    }
-
 
1946
    else {
-
 
1947
	if (draw) {
-
 
1948
	    /* draw the top and bottom elements */
1840
	MoveTo(savedX, savedY);
1949
	    MoveTo(savedX, savedY + topShift);
-
 
1950
	    RenderSymbolChar(top, draw);
1841
	MoveUp(-botShift);
1951
	    MoveTo(savedX, savedY - botShift);
1842
	RenderSymbolChar(bot, draw);
1952
	    RenderSymbolChar(bot, draw);
-
 
1953
	    /* now join with extenders */
-
 
1954
	    ytop = axisHeight + dist
-
 
1955
		- (bboxHeight(topBBox) + bboxDepth(topBBox));
-
 
1956
	    ybot = axisHeight - dist
-
 
1957
		+ (bboxHeight(botBBox) + bboxDepth(botBBox));
-
 
1958
	    n = ceil((ytop - ybot) / (0.99 * extHeight));
-
 
1959
	    if (n > 0) {
-
 
1960
		delta = (ytop - ybot) / n;
-
 
1961
		for (i = 0; i < n; i++) {
-
 
1962
		    MoveTo(savedX, savedY + ybot + (i + 0.5) * delta - extShift);
-
 
1963
		    RenderSymbolChar(ext, draw);
-
 
1964
		}
-
 
1965
	    }
1843
	MoveTo(savedX + bboxWidth(ansBBox), savedY);
1966
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
-
 
1967
	    
-
 
1968
	}
1844
    }
1969
    }
1845
    SetFont(prev);
1970
    SetFont(prev);
1846
    return ansBBox;
1971
    return ansBBox;
1847
}
1972
}
1848
 
1973
 
Line 1859... Line 1984...
1859
    delim1 = DelimCode(expr, CADR(expr));
1984
    delim1 = DelimCode(expr, CADR(expr));
1860
    delim2 = DelimCode(expr, CADDDR(expr));
1985
    delim2 = DelimCode(expr, CADDDR(expr));
1861
    bbox = RenderElement(CADDR(expr), 0);
1986
    bbox = RenderElement(CADDR(expr), 0);
1862
    dist = max(bboxHeight(bbox) - axisHeight, bboxDepth(bbox) + axisHeight);
1987
    dist = max(bboxHeight(bbox) - axisHeight, bboxDepth(bbox) + axisHeight);
1863
    bbox = RenderDelim(delim1, dist + extra, draw);
1988
    bbox = RenderDelim(delim1, dist + extra, draw);
1864
    bbox = CombineBBoxes(bbox,  RenderGap(ThinSpace(), draw));
-
 
1865
    bbox = CombineBBoxes(bbox,  RenderElement(CADDR(expr), draw));
1989
    bbox = CombineBBoxes(bbox,  RenderElement(CADDR(expr), draw));
1866
    bbox = RenderItalicCorr(bbox, draw);
1990
    bbox = RenderItalicCorr(bbox, draw);
1867
    bbox = CombineBBoxes(bbox,  RenderDelim(delim2, dist + extra, draw));
1991
    bbox = CombineBBoxes(bbox,  RenderDelim(delim2, dist + extra, draw));
1868
    bbox = CombineBBoxes(bbox,  RenderGap(ThinSpace(), draw));
-
 
1869
    return bbox;
1992
    return bbox;
1870
}
1993
}
1871
 
1994
 
1872
/*----------------------------------------------------------------------
1995
/*----------------------------------------------------------------------
1873
 *
1996
 *
Line 1881... Line 2004...
1881
}
2004
}
1882
 
2005
 
1883
static BBOX RenderParen(SEXP expr, int draw)
2006
static BBOX RenderParen(SEXP expr, int draw)
1884
{
2007
{
1885
    BBOX bbox;
2008
    BBOX bbox;
1886
    bbox = RenderSymbolChar(S_PARENLEFT, draw);
2009
    bbox = RenderDelimiter(S_PARENLEFT, draw);
1887
    bbox = CombineBBoxes(bbox, RenderElement(CADR(expr), draw));
2010
    bbox = CombineBBoxes(bbox, RenderElement(CADR(expr), draw));
1888
    bbox = RenderItalicCorr(bbox, draw);
2011
    bbox = RenderItalicCorr(bbox, draw);
1889
    return CombineBBoxes(bbox, RenderSymbolChar(S_PARENRIGHT, draw));
2012
    return CombineBBoxes(bbox, RenderDelimiter(S_PARENRIGHT, draw));
1890
}
2013
}
1891
 
2014
 
1892
/*----------------------------------------------------------------------
2015
/*----------------------------------------------------------------------
1893
 *
2016
 *
1894
 *  Code for Integral Operators.
2017
 *  Code for Integral Operators.
Line 1903... Line 2026...
1903
 
2026
 
1904
static BBOX RenderIntSymbol(int draw)
2027
static BBOX RenderIntSymbol(int draw)
1905
{
2028
{
1906
    double savedX = CurrentX;
2029
    double savedX = CurrentX;
1907
    double savedY = CurrentY;
2030
    double savedY = CurrentY;
-
 
2031
    if (GetStyle() > STYLE_T) {
1908
    BBOX bbox1 = RenderSymbolChar(243, 0);
2032
	BBOX bbox1 = RenderSymbolChar(243, 0);
1909
    BBOX bbox2 = RenderSymbolChar(245, 0);
2033
	BBOX bbox2 = RenderSymbolChar(245, 0);
1910
    double shift;
2034
	double shift;
1911
    shift = TeX(sigma22) + 0.99 * bboxDepth(bbox1);
2035
	shift = TeX(sigma22) + 0.99 * bboxDepth(bbox1);
1912
    MoveUp(shift);
2036
	MoveUp(shift);
1913
    bbox1 = ShiftBBox(RenderSymbolChar(243, draw), shift);
2037
	bbox1 = ShiftBBox(RenderSymbolChar(243, draw), shift);
1914
    CurrentX = savedX;
2038
	CurrentX = savedX;
1915
    CurrentY = savedY;
2039
	CurrentY = savedY;
1916
    shift = TeX(sigma22) - 0.99 * bboxHeight(bbox2);
2040
	shift = TeX(sigma22) - 0.99 * bboxHeight(bbox2);
1917
    MoveUp(shift);
2041
	MoveUp(shift);
1918
    bbox2 = ShiftBBox(RenderSymbolChar(245, draw), shift);
2042
	bbox2 = ShiftBBox(RenderSymbolChar(245, draw), shift);
1919
    if (draw)
2043
	if (draw)
1920
	MoveTo(savedX + max(bboxWidth(bbox1), bboxWidth(bbox2)), savedY);
2044
	    MoveTo(savedX + max(bboxWidth(bbox1), bboxWidth(bbox2)), savedY);
1921
    else
2045
	else
1922
	MoveTo(savedX, savedY);
2046
	    MoveTo(savedX, savedY);
1923
    return CombineAlignedBBoxes(bbox1, bbox2);
2047
	return CombineAlignedBBoxes(bbox1, bbox2);
-
 
2048
    }
-
 
2049
    else {
-
 
2050
	return RenderSymbolChar(0362, draw);
-
 
2051
    }
1924
}
2052
}
1925
 
2053
 
1926
static BBOX RenderInt(SEXP expr, int draw)
2054
static BBOX RenderInt(SEXP expr, int draw)
1927
{
2055
{
1928
    BBOX opBBox, lowerBBox, upperBBox, bodyBBox;
2056
    BBOX opBBox, lowerBBox, upperBBox, bodyBBox;
Line 2004... Line 2132...
2004
    BBOX bbox;
2132
    BBOX bbox;
2005
    double cexSaved = MathDevice->gp.cex;
2133
    double cexSaved = MathDevice->gp.cex;
2006
    double savedX = CurrentX;
2134
    double savedX = CurrentX;
2007
    double savedY = CurrentY;
2135
    double savedY = CurrentY;
2008
    double shift;
2136
    double shift;
-
 
2137
    int display = (GetStyle() > STYLE_T);
2009
    int opId = OpAtom(op);
2138
    int opId = OpAtom(op);
2010
 
2139
 
2011
    if (opId == S_SUM || opId == S_PRODUCT) {
2140
    if (opId == S_SUM || opId == S_PRODUCT) {
-
 
2141
	if (display) {
2012
	MathDevice->gp.cex = OperatorSymbolMag * MathDevice->gp.cex;
2142
	    MathDevice->gp.cex = OperatorSymbolMag * MathDevice->gp.cex;
2013
	bbox = RenderSymbolChar(OpAtom(op), 0);
2143
	    bbox = RenderSymbolChar(OpAtom(op), 0);
2014
	shift = 0.5 * (bboxHeight(bbox) - bboxDepth(bbox)) - TeX(sigma22);
2144
	    shift = 0.5 * (bboxHeight(bbox) - bboxDepth(bbox)) - TeX(sigma22);
2015
	if (draw) {
2145
	    if (draw) {
2016
	    MoveUp(-shift);
2146
		MoveUp(-shift);
2017
	    bbox = RenderSymbolChar(OpAtom(op), 1);
2147
		bbox = RenderSymbolChar(opId, 1);
2018
	    MoveUp(shift);
2148
		MoveUp(shift);
-
 
2149
	    }
-
 
2150
	    MathDevice->gp.cex = cexSaved;
-
 
2151
	    return ShiftBBox(bbox, -shift);
2019
	}
2152
	}
2020
	MathDevice->gp.cex = cexSaved;
-
 
2021
	return ShiftBBox(bbox, -shift);
2153
	else return RenderSymbolChar(opId, draw);
2022
    }
2154
    }
2023
    else {
2155
    else {
2024
	FontType prevfont = SetFont(PlainFont);
2156
	FontType prevfont = SetFont(PlainFont);
2025
	bbox = RenderStr(CHAR(PRINTNAME(op)), draw);
2157
	bbox = RenderStr(CHAR(PRINTNAME(op)), draw);
2026
	SetFont(prevfont);
2158
	SetFont(prevfont);
Line 2545... Line 2677...
2545
    if (NameAtom(CAR(expr)))
2677
    if (NameAtom(CAR(expr)))
2546
	bbox = RenderSymbolString(CAR(expr), draw);
2678
	bbox = RenderSymbolString(CAR(expr), draw);
2547
    else
2679
    else
2548
	bbox = RenderElement(CAR(expr), draw);
2680
	bbox = RenderElement(CAR(expr), draw);
2549
    bbox = RenderItalicCorr(bbox, draw);
2681
    bbox = RenderItalicCorr(bbox, draw);
2550
    bbox = CombineBBoxes(bbox, RenderSymbolChar(S_PARENLEFT, draw));
2682
    bbox = CombineBBoxes(bbox, RenderDelimiter(S_PARENLEFT, draw));
2551
    bbox = CombineBBoxes(bbox, RenderCommaList(CDR(expr), draw));
2683
    bbox = CombineBBoxes(bbox, RenderCommaList(CDR(expr), draw));
2552
    bbox = RenderItalicCorr(bbox, draw);
2684
    bbox = RenderItalicCorr(bbox, draw);
2553
    bbox = CombineBBoxes(bbox, RenderSymbolChar(S_PARENRIGHT, draw));
2685
    bbox = CombineBBoxes(bbox, RenderDelimiter(S_PARENRIGHT, draw));
2554
    return bbox;
2686
    return bbox;
2555
}
2687
}
2556
 
2688
 
2557
/*----------------------------------------------------------------------
2689
/*----------------------------------------------------------------------
2558
 *
2690
 *
Line 2713... Line 2845...
2713
    MathDevice = dd;
2845
    MathDevice = dd;
2714
    BaseCex = MathDevice->gp.cex;
2846
    BaseCex = MathDevice->gp.cex;
2715
    BoxColor = name2col("pink");
2847
    BoxColor = name2col("pink");
2716
    TextColor = MathDevice->gp.col;
2848
    TextColor = MathDevice->gp.col;
2717
    CurrentStyle = STYLE_D;
2849
    CurrentStyle = STYLE_D;
2718
#ifdef OLD
-
 
2719
    /* SetFont(ItalicFont); */
2850
    SetFont(PlainFont);
2720
#endif
-
 
2721
    bbox = RenderElement(expr, 0);
2851
    bbox = RenderElement(expr, 0);
2722
    ReferenceX = x;
2852
    ReferenceX = x;
2723
    ReferenceY = y;
2853
    ReferenceY = y;
2724
    GConvert(&ReferenceX, &ReferenceY, coords, INCHES, dd);
2854
    GConvert(&ReferenceX, &ReferenceY, coords, INCHES, dd);
2725
    if (FINITE(xc))
2855
    if (FINITE(xc))