The R Project SVN R

Rev

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

Rev 1009 Rev 1016
Line 88... Line 88...
88
{
88
{
89
  if (section == 1)
89
  if (section == 1)
90
    return 243;
90
    return 243;
91
  else if (section == 2)
91
  else if (section == 2)
92
    return 244;
92
    return 244;
93
  else 
93
  else
94
    return 245;
94
    return 245;
95
}
95
}
96
 
96
 
97
static int groupOpenAscii()
97
static int groupOpenAscii()
98
{
98
{
Line 326... Line 326...
326
}
326
}
327
 
327
 
328
static int radicalAtom(SEXP expr)
328
static int radicalAtom(SEXP expr)
329
{
329
{
330
	return symbolAtom(expr) &&
330
	return symbolAtom(expr) &&
331
	    (symbolMatch(expr, "root") || 
331
	    (symbolMatch(expr, "root") ||
332
	     symbolMatch(expr, "sqrt"));
332
	     symbolMatch(expr, "sqrt"));
333
}
333
}
334
 
334
 
335
static int absAtom(SEXP expr)
335
static int absAtom(SEXP expr)
336
{
336
{
Line 401... Line 401...
401
 
401
 
402
static void boldFont() { setFont(2); }
402
static void boldFont() { setFont(2); }
403
static void italicFont() { setFont(3); }
403
static void italicFont() { setFont(3); }
404
static void plainFont() { setFont(1); }
404
static void plainFont() { setFont(1); }
405
static void boldItalicFont() { setFont(4); }
405
static void boldItalicFont() { setFont(4); }
406
  
406
 
407
static int isItalic() { return (getFont() == 3 || getFont() == 4); }
407
static int isItalic() { return (getFont() == 3 || getFont() == 4); }
408
  
408
 
409
static int atomFontFace(SEXP expr)
409
static int atomFontFace(SEXP expr)
410
{
410
{
411
	int fontFace = 1;
411
	int fontFace = 1;
412
	if (symbolAtom(expr)) {
412
	if (symbolAtom(expr)) {
413
		if (greekSymbol(expr) ||
413
		if (greekSymbol(expr) ||
Line 949... Line 949...
949
static double currentY;
949
static double currentY;
950
static double currentAngle;
950
static double currentAngle;
951
static double cosAngle;
951
static double cosAngle;
952
static double sinAngle;
952
static double sinAngle;
953
 
953
 
954
		/* 
954
		/*
955
		   // convert currentX and currentY from 0 angle
955
		   // convert currentX and currentY from 0 angle
956
		   // to and currentAngle
956
		   // to and currentAngle
957
		 */
957
		 */
958
static double convertedX()
958
static double convertedX()
959
{
959
{
Line 1009... Line 1009...
1009
		mathDevice->gp.font = 1;
1009
		mathDevice->gp.font = 1;
1010
	else
1010
	else
1011
		mathDevice->gp.font = 5;
1011
		mathDevice->gp.font = 5;
1012
	asciiStr[0] = ascii;
1012
	asciiStr[0] = ascii;
1013
	asciiStr[1] = '\0';
1013
	asciiStr[1] = '\0';
1014
	GText(convertedX(), convertedY(), INCHES, asciiStr, 
1014
	GText(convertedX(), convertedY(), INCHES, asciiStr,
1015
	      0.0, 0.0, currentAngle, mathDevice);
1015
	      0.0, 0.0, currentAngle, mathDevice);
1016
	moveAcross(GStrWidth(asciiStr, metricUnit, mathDevice));
1016
	moveAcross(GStrWidth(asciiStr, metricUnit, mathDevice));
1017
}
1017
}
1018
 
1018
 
1019
/* code for character atoms */
1019
/* code for character atoms */
Line 1031... Line 1031...
1031
}
1031
}
1032
 
1032
 
1033
static void drawChar(char *str, SEXP expr)
1033
static void drawChar(char *str, SEXP expr)
1034
{
1034
{
1035
	mathDevice->gp.font = atomFontFace(expr);
1035
	mathDevice->gp.font = atomFontFace(expr);
1036
	GText(convertedX(), convertedY(), INCHES, str, 
1036
	GText(convertedX(), convertedY(), INCHES, str,
1037
	      0.0, 0.0, currentAngle, mathDevice);
1037
	      0.0, 0.0, currentAngle, mathDevice);
1038
	moveAcross(GStrWidth(str, metricUnit, mathDevice));
1038
	moveAcross(GStrWidth(str, metricUnit, mathDevice));
1039
}
1039
}
1040
 
1040
 
1041
/* code for symbol atoms */
1041
/* code for symbol atoms */
Line 1124... Line 1124...
1124
 
1124
 
1125
static void drawCorrectionWithin(SEXP expr)
1125
static void drawCorrectionWithin(SEXP expr)
1126
{
1126
{
1127
  if (isItalic() && !nonItalicExpression(expr))
1127
  if (isItalic() && !nonItalicExpression(expr))
1128
    moveAcross(italicCorrection(expr));
1128
    moveAcross(italicCorrection(expr));
1129
}    
1129
}
1130
 
1130
 
1131
	/* correction between expressions checks current font and font */
1131
	/* correction between expressions checks current font and font */
1132
	/* of each expression */
1132
	/* of each expression */
1133
 
1133
 
1134
static BBOX correctionBetweenBBox(SEXP expr1, SEXP expr2)
1134
static BBOX correctionBetweenBBox(SEXP expr1, SEXP expr2)
Line 1230... Line 1230...
1230
	operand1 = CADR(expr);
1230
	operand1 = CADR(expr);
1231
        setGapCEX();
1231
        setGapCEX();
1232
	if(length(expr) == 3) {
1232
	if(length(expr) == 3) {
1233
		operand2 = CADDR(expr);
1233
		operand2 = CADDR(expr);
1234
		if (multiplicationOperator(operator))
1234
		if (multiplicationOperator(operator))
1235
			middleBBox = 
1235
			middleBBox =
1236
			  correctionBetweenBBox(operand1, operand2);
1236
			  correctionBetweenBBox(operand1, operand2);
1237
		else 
1237
		else
1238
			middleBBox = 
1238
			middleBBox =
1239
                          combineBBoxes(
1239
                          combineBBoxes(
1240
                            gapBBox(binGapBefore(operand1)),
1240
                            gapBBox(binGapBefore(operand1)),
1241
			    combineBBoxes(atomBBox(operator),
1241
			    combineBBoxes(atomBBox(operator),
1242
					  gapBBox(binGapAfter(operand2))));
1242
					  gapBBox(binGapAfter(operand2))));
1243
 
1243
 
Line 1261... Line 1261...
1261
	operand1 = CADR(expr);
1261
	operand1 = CADR(expr);
1262
	setGapCEX();
1262
	setGapCEX();
1263
	if(length(expr) == 3) {
1263
	if(length(expr) == 3) {
1264
		operand2 = CADDR(expr);
1264
		operand2 = CADDR(expr);
1265
		drawElement(operand1);
1265
		drawElement(operand1);
1266
		if (multiplicationOperator(operator)) 
1266
		if (multiplicationOperator(operator))
1267
		  drawGap(binGapBetween(operand1, operand2));
1267
		  drawGap(binGapBetween(operand1, operand2));
1268
		else {
1268
		else {
1269
			drawGap(binGapBefore(operand1));
1269
			drawGap(binGapBefore(operand1));
1270
			drawAtom(operator);
1270
			drawAtom(operator);
1271
			drawGap(binGapAfter(operand2));
1271
			drawGap(binGapAfter(operand2));
Line 1623... Line 1623...
1623
  if (integralOperator(operator))
1623
  if (integralOperator(operator))
1624
    return combineAlignedBBoxes(
1624
    return combineAlignedBBoxes(
1625
	     shiftBBox(asciiBBox(integralAscii(1)), integralTopShift()),
1625
	     shiftBBox(asciiBBox(integralAscii(1)), integralTopShift()),
1626
	     combineAlignedBBoxes(asciiBBox(integralAscii(2)),
1626
	     combineAlignedBBoxes(asciiBBox(integralAscii(2)),
1627
				  shiftBBox(asciiBBox(integralAscii(3)),
1627
				  shiftBBox(asciiBBox(integralAscii(3)),
1628
					    integralBottomShift())));	
1628
					    integralBottomShift())));
1629
  else
1629
  else
1630
    return asciiBBox(operatorAscii(operator));
1630
    return asciiBBox(operatorAscii(operator));
1631
}
1631
}
1632
 
1632
 
1633
static int useRelGap = 1;
1633
static int useRelGap = 1;
1634
  
1634
 
1635
static BBOX operatorLimitBBox(SEXP limit)
1635
static BBOX operatorLimitBBox(SEXP limit)
1636
{
1636
{
1637
  float cexSaved = mathDevice->gp.cex;
1637
  float cexSaved = mathDevice->gp.cex;
1638
  BBOX limitBBox;
1638
  BBOX limitBBox;
1639
 
1639
 
Line 1655... Line 1655...
1655
  setGapCEX();
1655
  setGapCEX();
1656
 
1656
 
1657
  if (length(expr) > 1) {
1657
  if (length(expr) > 1) {
1658
    body = CADR(expr);
1658
    body = CADR(expr);
1659
    bodyBBox = combineBBoxes(opBBox,
1659
    bodyBBox = combineBBoxes(opBBox,
1660
                             combineBBoxes(gapBBox(operatorGap(body)), 
1660
                             combineBBoxes(gapBBox(operatorGap(body)),
1661
					   elementBBox(body)));
1661
					   elementBBox(body)));
1662
    
1662
 
1663
    if (length(expr) > 2) {
1663
    if (length(expr) > 2) {
1664
      lower = CADDR(expr);
1664
      lower = CADDR(expr);
1665
      lowerBBox = operatorLimitBBox(lower);
1665
      lowerBBox = operatorLimitBBox(lower);
1666
 
1666
 
1667
      if (length(expr) > 3) {
1667
      if (length(expr) > 3) {
Line 1698... Line 1698...
1698
		   operatorLowerShift(operator, lower)));
1698
		   operatorLowerShift(operator, lower)));
1699
    }
1699
    }
1700
    else
1700
    else
1701
      return bodyBBox;
1701
      return bodyBBox;
1702
  }
1702
  }
1703
  else 
1703
  else
1704
    error("Invalid Formula\n");
1704
    error("Invalid Formula\n");
1705
    
1705
 
1706
}
1706
}
1707
 
1707
 
1708
static void drawTheOperator(SEXP operator)
1708
static void drawTheOperator(SEXP operator)
1709
{
1709
{
1710
  if (integralOperator(operator)) {
1710
  if (integralOperator(operator)) {
Line 1719... Line 1719...
1719
    drawAscii(integralAscii(2));
1719
    drawAscii(integralAscii(2));
1720
  }
1720
  }
1721
  else
1721
  else
1722
    drawAscii(operatorAscii(operator));
1722
    drawAscii(operatorAscii(operator));
1723
}
1723
}
1724
    
1724
 
1725
static void drawOperatorLimit(SEXP limit)
1725
static void drawOperatorLimit(SEXP limit)
1726
{
1726
{
1727
  useRelGap = 0;
1727
  useRelGap = 0;
1728
  drawScriptElement(limit);
1728
  drawScriptElement(limit);
1729
  useRelGap = 1;
1729
  useRelGap = 1;
Line 1736... Line 1736...
1736
  SEXP lower, upper;
1736
  SEXP lower, upper;
1737
  double savedX = currentX;
1737
  double savedX = currentX;
1738
  double savedY = currentY;
1738
  double savedY = currentY;
1739
 
1739
 
1740
  setGapCEX();
1740
  setGapCEX();
1741
  
1741
 
1742
  if (length(expr) > 2) {
1742
  if (length(expr) > 2) {
1743
    lower = CADDR(expr);
1743
    lower = CADDR(expr);
1744
 
1744
 
1745
    if (length(expr) > 3) {
1745
    if (length(expr) > 3) {
1746
      upper = CADDDR(expr);
1746
      upper = CADDDR(expr);
Line 1877... Line 1877...
1877
		if (i < numParams - 1)
1877
		if (i < numParams - 1)
1878
			resultBBox = combineBBoxes(resultBBox,
1878
			resultBBox = combineBBoxes(resultBBox,
1879
				   combineBBoxes(asciiBBox(commaAscii()),
1879
				   combineBBoxes(asciiBBox(commaAscii()),
1880
					       asciiBBox(spaceAscii())));
1880
					       asciiBBox(spaceAscii())));
1881
	}
1881
	}
1882
	return combineBBoxes(resultBBox, 
1882
	return combineBBoxes(resultBBox,
1883
			     combineBBoxes(correctionWithinBBox(lastTerm),
1883
			     combineBBoxes(correctionWithinBBox(lastTerm),
1884
					   asciiBBox(groupCloseAscii())));
1884
					   asciiBBox(groupCloseAscii())));
1885
}
1885
}
1886
 
1886
 
1887
static void drawExpression(SEXP expr)
1887
static void drawExpression(SEXP expr)
Line 2068... Line 2068...
2068
  lastArg = CAR(args);
2068
  lastArg = CAR(args);
2069
  args = CDR(args);
2069
  args = CDR(args);
2070
 
2070
 
2071
  for (i=1; i<numArgs; i++) {
2071
  for (i=1; i<numArgs; i++) {
2072
    result = combineBBoxes(
2072
    result = combineBBoxes(
2073
	       result, 
2073
	       result,
2074
	       combineBBoxes(correctionBetweenBBox(lastArg, CAR(args)),
2074
	       combineBBoxes(correctionBetweenBBox(lastArg, CAR(args)),
2075
			     elementBBox(CAR(args))));
2075
			     elementBBox(CAR(args))));
2076
    lastArg = CAR(args);
2076
    lastArg = CAR(args);
2077
    args = CDR(args);
2077
    args = CDR(args);
2078
  }
2078
  }
Line 2207... Line 2207...
2207
{
2207
{
2208
        BBOX exprBBox = elementBBox(expr);
2208
        BBOX exprBBox = elementBBox(expr);
2209
        double w  = exprBBox.width;
2209
        double w  = exprBBox.width;
2210
	if (units == INCHES)
2210
	if (units == INCHES)
2211
		return w;
2211
		return w;
2212
	else 
2212
	else
2213
		return GConvertXUnits(w, INCHES, units, dd);
2213
		return GConvertXUnits(w, INCHES, units, dd);
2214
}
2214
}
2215
 
2215
 
2216
#define ABS(a)  ((a)>=0 ? (a) : -(a))
2216
#define ABS(a)  ((a)>=0 ? (a) : -(a))
2217
 
2217
 
Line 2225... Line 2225...
2225
		return GConvertYUnits(h, INCHES, units, dd);
2225
		return GConvertYUnits(h, INCHES, units, dd);
2226
}
2226
}
2227
 
2227
 
2228
		/* functions forming the API */
2228
		/* functions forming the API */
2229
 
2229
 
2230
void GMathText(double x, double y, int coords, SEXP expr, 
2230
void GMathText(double x, double y, int coords, SEXP expr,
2231
	       double xc, double yc, double rot, DevDesc *dd)
2231
	       double xc, double yc, double rot, DevDesc *dd)
2232
{
2232
{
2233
	BBOX expressionBBox;
2233
	BBOX expressionBBox;
2234
 
2234
 
2235
	mathDevice = dd;
2235
	mathDevice = dd;