The R Project SVN R

Rev

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

Rev 2105 Rev 2122
Line 30... Line 30...
30
static DevDesc *MathDevice;
30
static DevDesc *MathDevice;
31
static unsigned int BoxColor;
31
static unsigned int BoxColor;
32
static unsigned int TextColor;
32
static unsigned int TextColor;
33
static double BaseCex = 1;
33
static double BaseCex = 1;
34
static int MetricUnit = INCHES;
34
static int MetricUnit = INCHES;
35
static double HalfPi  = 1.57079632679489661922;
-
 
36
 
35
 
37
/* Font Definitions */
36
/* Font Definitions */
38
 
37
 
39
typedef enum {
38
typedef enum {
40
    PlainFont      = 1,
39
    PlainFont      = 1,
Line 42... Line 41...
42
    ItalicFont     = 3,
41
    ItalicFont     = 3,
43
    BoldItalicFont = 4,
42
    BoldItalicFont = 4,
44
    SymbolFont     = 5,
43
    SymbolFont     = 5,
45
} FontType;
44
} FontType;
46
 
45
 
47
/* 
46
/*
48
 *  Italic Correction Factor
47
 *  Italic Correction Factor
49
 *
48
 *
50
 *  The correction for a character is computed as ItalicFactor
49
 *  The correction for a character is computed as ItalicFactor
51
 *  times the height (above the baseline) of the character's
50
 *  times the height (above the baseline) of the character's
52
 *  bounding box.
51
 *  bounding box.
Line 198... Line 197...
198
static double MuSpace()
197
static double MuSpace()
199
{
198
{
200
    double height, depth, width;
199
    double height, depth, width;
201
    static double OneEighteenth = 0.05555555555555555555;
200
    static double OneEighteenth = 0.05555555555555555555;
202
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
201
    GMetricInfo('M', &height, &depth, &width, MetricUnit, MathDevice);
203
    return OneEighteenth * width;    
202
    return OneEighteenth * width;
204
}
203
}
205
 
204
 
206
 
205
 
207
/*
206
/*
208
 *  Mathematics Layout Parameters
207
 *  Mathematics Layout Parameters
Line 324... Line 323...
324
    return CurrentStyle;
323
    return CurrentStyle;
325
}
324
}
326
 
325
 
327
static void SetStyle(STYLE newstyle)
326
static void SetStyle(STYLE newstyle)
328
{
327
{
329
    switch (newstyle) {	
328
    switch (newstyle) {
330
    case STYLE_D:
329
    case STYLE_D:
331
    case STYLE_T:
330
    case STYLE_T:
332
    case STYLE_D1:
331
    case STYLE_D1:
333
    case STYLE_T1:
332
    case STYLE_T1:
334
	MathDevice->gp.cex = 1.0 * BaseCex;
333
	MathDevice->gp.cex = 1.0 * BaseCex;
Line 1311... Line 1310...
1311
	    bbox = CombineBBoxes(bbox, RenderSlash(draw));
1310
	    bbox = CombineBBoxes(bbox, RenderSlash(draw));
1312
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
1311
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
1313
	    return CombineBBoxes(bbox, RenderElement(CADDR(expr), draw));
1312
	    return CombineBBoxes(bbox, RenderElement(CADDR(expr), draw));
1314
	}
1313
	}
1315
	else {
1314
	else {
1316
	    gap = (CurrentStyle > STYLE_S) ? MediumSpace() : 0;	    
1315
	    gap = (CurrentStyle > STYLE_S) ? MediumSpace() : 0;
1317
	    bbox = RenderElement(CADR(expr), draw);
1316
	    bbox = RenderElement(CADR(expr), draw);
1318
	    bbox = RenderItalicCorr(bbox, draw);
1317
	    bbox = RenderItalicCorr(bbox, draw);
1319
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
1318
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
1320
	    bbox = CombineBBoxes(bbox, RenderSymbolChar(op, draw));
1319
	    bbox = CombineBBoxes(bbox, RenderSymbolChar(op, draw));
1321
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
1320
	    bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
Line 1584... Line 1583...
1584
    "hat",            94,
1583
    "hat",            94,
1585
    "ring",          176,
1584
    "ring",          176,
1586
    "tilde",         126,
1585
    "tilde",         126,
1587
    NULL,              0,
1586
    NULL,              0,
1588
};
1587
};
1589
    
1588
 
1590
static int AccentCode(SEXP expr)
1589
static int AccentCode(SEXP expr)
1591
{
1590
{
1592
    int i;
1591
    int i;
1593
    for (i = 0; AccentTable[i].code; i++)
1592
    for (i = 0; AccentTable[i].code; i++)
1594
	if (NameMatch(expr, AccentTable[i].name))
1593
	if (NameMatch(expr, AccentTable[i].name))
Line 1899... Line 1898...
1899
    case ']':
1898
    case ']':
1900
	top = 249; ext = 250; bot = 251; mid = 0;
1899
	top = 249; ext = 250; bot = 251; mid = 0;
1901
	break;
1900
	break;
1902
    case '{':
1901
    case '{':
1903
	top = 236; ext = 239; bot = 238; mid = 237;
1902
	top = 236; ext = 239; bot = 238; mid = 237;
1904
	break;	
1903
	break;
1905
    case '}':
1904
    case '}':
1906
	top = 252; ext = 239; bot = 254; mid = 253;
1905
	top = 252; ext = 239; bot = 254; mid = 253;
1907
	break;
1906
	break;
1908
    default:
1907
    default:
1909
	error("group is incomplete\n");
1908
	error("group is incomplete\n");
Line 1935... Line 1934...
1935
	ansBBox = CombineAlignedBBoxes(ansBBox, midBBox);
1934
	ansBBox = CombineAlignedBBoxes(ansBBox, midBBox);
1936
	if (draw) {
1935
	if (draw) {
1937
	    MoveTo(savedX, savedY + topShift);
1936
	    MoveTo(savedX, savedY + topShift);
1938
	    RenderSymbolChar(top, draw);
1937
	    RenderSymbolChar(top, draw);
1939
	    MoveTo(savedX, savedY + midShift);
1938
	    MoveTo(savedX, savedY + midShift);
1940
	    RenderSymbolChar(mid, draw);	    
1939
	    RenderSymbolChar(mid, draw);
1941
	    MoveTo(savedX, savedY - botShift);
1940
	    MoveTo(savedX, savedY - botShift);
1942
	    RenderSymbolChar(bot, draw);
1941
	    RenderSymbolChar(bot, draw);
1943
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
1942
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
1944
	}
1943
	}
1945
    }
1944
    }
Line 1962... Line 1961...
1962
		    MoveTo(savedX, savedY + ybot + (i + 0.5) * delta - extShift);
1961
		    MoveTo(savedX, savedY + ybot + (i + 0.5) * delta - extShift);
1963
		    RenderSymbolChar(ext, draw);
1962
		    RenderSymbolChar(ext, draw);
1964
		}
1963
		}
1965
	    }
1964
	    }
1966
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
1965
	    MoveTo(savedX + bboxWidth(ansBBox), savedY);
1967
	    
1966
 
1968
	}
1967
	}
1969
    }
1968
    }
1970
    SetFont(prev);
1969
    SetFont(prev);
1971
    return ansBBox;
1970
    return ansBBox;
1972
}
1971
}
Line 2397... Line 2396...
2397
 */
2396
 */
2398
 
2397
 
2399
                                /* Binary Relationships */
2398
                                /* Binary Relationships */
2400
 
2399
 
2401
SymTab RelTable[] = {
2400
SymTab RelTable[] = {
2402
    "<",                 60,    /* less */  
2401
    "<",                 60,    /* less */
2403
    "==",                61,    /* equal */
2402
    "==",                61,    /* equal */
2404
    ">",                 62,    /* greater */
2403
    ">",                 62,    /* greater */
2405
    "%=~%",              64,    /* congruent */
2404
    "%=~%",              64,    /* congruent */
2406
    "!=",               185,    /* not equal */
2405
    "!=",               185,    /* not equal */
2407
    "<=",               163,    /* less or equal */
2406
    "<=",               163,    /* less or equal */
Line 2446... Line 2445...
2446
    int nexpr = length(expr);
2445
    int nexpr = length(expr);
2447
    BBOX bbox;
2446
    BBOX bbox;
2448
    double gap;
2447
    double gap;
2449
 
2448
 
2450
    if(nexpr == 3) {
2449
    if(nexpr == 3) {
2451
	gap = (CurrentStyle > STYLE_S) ? ThickSpace() : 0;	    
2450
	gap = (CurrentStyle > STYLE_S) ? ThickSpace() : 0;
2452
	bbox = RenderElement(CADR(expr), draw);
2451
	bbox = RenderElement(CADR(expr), draw);
2453
	bbox = RenderItalicCorr(bbox, draw);
2452
	bbox = RenderItalicCorr(bbox, draw);
2454
	bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
2453
	bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
2455
	bbox = CombineBBoxes(bbox, RenderSymbolChar(op, draw));
2454
	bbox = CombineBBoxes(bbox, RenderSymbolChar(op, draw));
2456
	bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
2455
	bbox = CombineBBoxes(bbox, RenderGap(gap, draw));
Line 2561... Line 2560...
2561
 
2560
 
2562
static BBOX RenderStyle(SEXP expr, int draw)
2561
static BBOX RenderStyle(SEXP expr, int draw)
2563
{
2562
{
2564
    STYLE prevstyle = GetStyle();
2563
    STYLE prevstyle = GetStyle();
2565
    BBOX bbox;
2564
    BBOX bbox;
2566
    if (NameMatch(CAR(expr), "displaystyle"))	
2565
    if (NameMatch(CAR(expr), "displaystyle"))
2567
	SetStyle(STYLE_D);
2566
	SetStyle(STYLE_D);
2568
    else if (NameMatch(CAR(expr), "textstyle"))	
2567
    else if (NameMatch(CAR(expr), "textstyle"))
2569
	SetStyle(STYLE_T);
2568
	SetStyle(STYLE_T);
2570
    else if (NameMatch(CAR(expr), "scriptstyle"))	
2569
    else if (NameMatch(CAR(expr), "scriptstyle"))
2571
	SetStyle(STYLE_S);
2570
	SetStyle(STYLE_S);
2572
    else if (NameMatch(CAR(expr), "scriptscriptstyle"))	
2571
    else if (NameMatch(CAR(expr), "scriptscriptstyle"))
2573
	SetStyle(STYLE_SS);
2572
	SetStyle(STYLE_SS);
2574
    bbox = RenderElement(CADR(expr), draw);
2573
    bbox = RenderElement(CADR(expr), draw);
2575
    SetStyle(prevstyle);
2574
    SetStyle(prevstyle);
2576
    return bbox;
2575
    return bbox;
2577
}
2576
}
Line 2860... Line 2859...
2860
	CurrentY = ReferenceY + bboxDepth(bbox)
2859
	CurrentY = ReferenceY + bboxDepth(bbox)
2861
	    - yc * (bboxHeight(bbox) + bboxDepth(bbox));
2860
	    - yc * (bboxHeight(bbox) + bboxDepth(bbox));
2862
    else
2861
    else
2863
	CurrentY = ReferenceY;
2862
	CurrentY = ReferenceY;
2864
    CurrentAngle = rot;
2863
    CurrentAngle = rot;
-
 
2864
    rot = rot / 90 * M_PI_half;/* radians */
2865
    CosAngle = cos(rot / 90 * HalfPi);
2865
    CosAngle = cos(rot);
2866
    SinAngle = sin(rot / 90 * HalfPi);
2866
    SinAngle = sin(rot);
2867
    RenderElement(expr, 1);
2867
    RenderElement(expr, 1);
2868
}
2868
}
2869
 
2869
 
2870
 
2870
 
2871
void GMMathText(SEXP str, int side, double line, int outer,
2871
void GMMathText(SEXP str, int side, double line, int outer,