The R Project SVN R

Rev

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

Rev 33419 Rev 34864
Line 981... Line 981...
981
    if (draw)
981
    if (draw)
982
	PMoveAcross(gap, mc);
982
	PMoveAcross(gap, mc);
983
    return MakeBBox(0, 0, gap);
983
    return MakeBBox(0, 0, gap);
984
}
984
}
985
 
985
 
986
/* Draw a Symbol from the Special Font */
986
/* Draw a Symbol from the Special Font:
-
 
987
   this is assumed to be 8-bit encoded in Adobe Symbol.
-
 
988
 */
987
 
989
 
988
static BBOX RenderSymbolChar(int ascii, int draw, mathContext *mc,
990
static BBOX RenderSymbolChar(int ascii, int draw, mathContext *mc,
989
			     R_GE_gcontext *gc, GEDevDesc *dd)
991
			     R_GE_gcontext *gc, GEDevDesc *dd)
990
{
992
{
991
    FontType prev;
993
    FontType prev;
Line 995... Line 997...
995
	prev = SetFont(PlainFont, gc);
997
	prev = SetFont(PlainFont, gc);
996
    else
998
    else
997
	prev = SetFont(SymbolFont, gc);
999
	prev = SetFont(SymbolFont, gc);
998
    bbox = GlyphBBox(ascii, gc, dd);
1000
    bbox = GlyphBBox(ascii, gc, dd);
999
    if (draw) {
1001
    if (draw) {
1000
	/* <UTF8-FIXME> */
-
 
1001
	asciiStr[0] = ascii;
1002
	asciiStr[0] = ascii;
1002
	asciiStr[1] = '\0';
1003
	asciiStr[1] = '\0';
1003
	GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), asciiStr,
1004
	GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), asciiStr,
1004
	       0.0, 0.0, mc->CurrentAngle, gc,
1005
	       0.0, 0.0, mc->CurrentAngle, gc,
1005
	       dd);
1006
	       dd);
Line 1007... Line 1008...
1007
    }
1008
    }
1008
    SetFont(prev, gc);
1009
    SetFont(prev, gc);
1009
    return bbox;
1010
    return bbox;
1010
}
1011
}
1011
 
1012
 
1012
/* Draw a Symbol String in "Math Mode */
1013
/* Draw a Symbol String in "Math Mode" */
1013
/* This code inserts italic corrections after */
1014
/* This code inserts italic corrections after */
1014
/* every character. */
1015
/* every character. */
1015
 
1016
 
1016
static BBOX RenderSymbolStr(char *str, int draw, mathContext *mc,
1017
static BBOX RenderSymbolStr(char *str, int draw, mathContext *mc,
1017
			    R_GE_gcontext *gc, GEDevDesc *dd)
1018
			    R_GE_gcontext *gc, GEDevDesc *dd)
1018
{
1019
{
1019
    char chr[2];
1020
    char chr[7] = "", *s = str;
1020
    BBOX glyphBBox;
1021
    BBOX glyphBBox;
1021
    BBOX resultBBox = NullBBox();
1022
    BBOX resultBBox = NullBBox();
1022
    double lastItalicCorr = 0;
1023
    double lastItalicCorr = 0;
1023
    FontType prevfont = GetFont(gc);
1024
    FontType prevfont = GetFont(gc);
1024
    FontType font = prevfont;
1025
    FontType font = prevfont;
1025
    chr[1] = '\0';
-
 
-
 
1026
 
1026
    if (str) {
1027
    if (str) {
-
 
1028
#ifdef SUPPORT_MBCS
-
 
1029
	if(mbcslocale) {  /* need to advance by character, not byte */
-
 
1030
	    wchar_t wc;
1027
	/* <UTF8-FIXME> perhaps */
1031
	    mbstate_t mb_st;
1028
	char *s = str;
1032
	    size_t res;
-
 
1033
	    
-
 
1034
	    memset(&mb_st, 0, sizeof(mb_st));
1029
	while (*s) {
1035
	    while (*s) {
-
 
1036
		wc = 0;
-
 
1037
		res = mbrtowc(&wc, s, MB_LEN_MAX, &mb_st);
1030
	    if (isdigit((int)*s) && font != PlainFont) {
1038
		if (iswdigit(wc) && font != PlainFont) {
1031
		font = PlainFont;
1039
		    font = PlainFont;
1032
		SetFont(PlainFont, gc);
1040
		    SetFont(PlainFont, gc);
1033
	    }
1041
		}
1034
	    else if (font != prevfont) {
1042
		else if (font != prevfont) {
1035
		font = prevfont;
1043
		    font = prevfont;
1036
		SetFont(prevfont, gc);
1044
		    SetFont(prevfont, gc);
-
 
1045
		}
-
 
1046
		glyphBBox = GlyphBBox((int)wc, gc, dd);
-
 
1047
		if (UsingItalics(gc))
-
 
1048
		    bboxItalic(glyphBBox) =
-
 
1049
			ItalicFactor * bboxHeight(glyphBBox);
-
 
1050
		else
-
 
1051
		    bboxItalic(glyphBBox) = 0;
-
 
1052
		if (draw) {
-
 
1053
		    memset(chr, 0, sizeof(chr));
-
 
1054
		    wcrtomb(chr,wc,&mb_st);
-
 
1055
		    PMoveAcross(lastItalicCorr, mc);
-
 
1056
		    GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), chr,
-
 
1057
			   0.0, 0.0, mc->CurrentAngle, gc,
-
 
1058
			   dd);
-
 
1059
		    PMoveAcross(bboxWidth(glyphBBox), mc);
-
 
1060
		}
-
 
1061
		bboxWidth(resultBBox) += lastItalicCorr;
-
 
1062
		resultBBox = CombineBBoxes(resultBBox, glyphBBox);
-
 
1063
		lastItalicCorr = bboxItalic(glyphBBox);
-
 
1064
		s += res;
1037
	    }
1065
	    }
-
 
1066
	} else
-
 
1067
#endif
-
 
1068
	{
-
 
1069
	    while (*s) {
-
 
1070
		if (isdigit((int)*s) && font != PlainFont) {
-
 
1071
		    font = PlainFont;
-
 
1072
		    SetFont(PlainFont, gc);
-
 
1073
		}
-
 
1074
		else if (font != prevfont) {
-
 
1075
		    font = prevfont;
-
 
1076
		    SetFont(prevfont, gc);
-
 
1077
		}
1038
	    glyphBBox = GlyphBBox(*s, gc, dd);
1078
		glyphBBox = GlyphBBox(*s, gc, dd);
1039
	    if (UsingItalics(gc))
1079
		if (UsingItalics(gc))
-
 
1080
		    bboxItalic(glyphBBox) =
1040
		bboxItalic(glyphBBox) = ItalicFactor * bboxHeight(glyphBBox);
1081
			ItalicFactor * bboxHeight(glyphBBox);
1041
	    else
1082
		else
1042
		bboxItalic(glyphBBox) = 0;
1083
		    bboxItalic(glyphBBox) = 0;
1043
	    if (draw) {
1084
		if (draw) {
1044
		chr[0] = *s;
1085
		    chr[0] = *s;
1045
		PMoveAcross(lastItalicCorr, mc);
1086
		    PMoveAcross(lastItalicCorr, mc);
1046
		GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), chr,
1087
		    GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), chr,
1047
		       0.0, 0.0, mc->CurrentAngle, gc,
1088
			   0.0, 0.0, mc->CurrentAngle, gc,
1048
		       dd);
1089
			   dd);
1049
		PMoveAcross(bboxWidth(glyphBBox), mc);
1090
		    PMoveAcross(bboxWidth(glyphBBox), mc);
-
 
1091
		}
-
 
1092
		bboxWidth(resultBBox) += lastItalicCorr;
-
 
1093
		resultBBox = CombineBBoxes(resultBBox, glyphBBox);
-
 
1094
		lastItalicCorr = bboxItalic(glyphBBox);
-
 
1095
		s++;
1050
	    }
1096
	    }
1051
	    bboxWidth(resultBBox) += lastItalicCorr;
-
 
1052
	    resultBBox = CombineBBoxes(resultBBox, glyphBBox);
-
 
1053
	    lastItalicCorr = bboxItalic(glyphBBox);
-
 
1054
	    s++;
-
 
1055
	}
1097
	}
1056
	if (font != prevfont)
1098
	if (font != prevfont)
1057
	    SetFont(prevfont, gc);
1099
	    SetFont(prevfont, gc);
1058
    }
1100
    }
1059
    bboxSimple(resultBBox) = 1;
1101
    bboxSimple(resultBBox) = 1;
Line 1065... Line 1107...
1065
/* This only gets called from RenderAccent */
1107
/* This only gets called from RenderAccent */
1066
static BBOX RenderChar(int ascii, int draw, mathContext *mc,
1108
static BBOX RenderChar(int ascii, int draw, mathContext *mc,
1067
		       R_GE_gcontext *gc, GEDevDesc *dd)
1109
		       R_GE_gcontext *gc, GEDevDesc *dd)
1068
{
1110
{
1069
    BBOX bbox;
1111
    BBOX bbox;
1070
    char asciiStr[2];
1112
    char asciiStr[7];
-
 
1113
 
1071
    bbox = GlyphBBox(ascii, gc, dd);
1114
    bbox = GlyphBBox(ascii, gc, dd);
1072
    if (draw) {
1115
    if (draw) {
1073
	/* <UTF8-FIXME> This appears only to get called with values
1116
        memset(asciiStr, 0, sizeof(asciiStr));
-
 
1117
#ifdef SUPPORT_MBCS
-
 
1118
	if(mbcslocale) {
1074
	   for hat, tilde and ring.  The latter appears to be hardcoded
1119
	    wcrtomb(asciiStr, ascii, NULL);
1075
	   in Latin-1.
1120
	} else
1076
	 */
1121
#endif
1077
	asciiStr[0] = ascii;
1122
	    asciiStr[0] = ascii;
1078
	asciiStr[1] = '\0';
-
 
1079
	GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), asciiStr,
1123
	GEText(ConvertedX(mc ,dd), ConvertedY(mc, dd), asciiStr,
1080
	       0.0, 0.0, mc->CurrentAngle, gc,
1124
	       0.0, 0.0, mc->CurrentAngle, gc,
1081
	       dd);
1125
	       dd);
1082
	PMoveAcross(bboxWidth(bbox), mc);
1126
	PMoveAcross(bboxWidth(bbox), mc);
1083
    }
1127
    }
Line 1727... Line 1771...
1727
    code = AccentCode(accent);
1771
    code = AccentCode(accent);
1728
    if (code == 0)
1772
    if (code == 0)
1729
	InvalidAccent(expr);
1773
	InvalidAccent(expr);
1730
    bodyBBox = RenderElement(body, 0, mc, gc, dd);
1774
    bodyBBox = RenderElement(body, 0, mc, gc, dd);
1731
    italic = bboxItalic(bodyBBox);
1775
    italic = bboxItalic(bodyBBox);
-
 
1776
    if (code == 176 || /* ring (as degree) */
1732
    if (code == 215) /* dotmath */
1777
	code == 215)   /* dotmath */
1733
	accentBBox = RenderSymbolChar(code, 0, mc, gc, dd);
1778
	accentBBox = RenderSymbolChar(code, 0, mc, gc, dd);
1734
    else
1779
    else
1735
	accentBBox = RenderChar(code, 0, mc, gc, dd);
1780
	accentBBox = RenderChar(code, 0, mc, gc, dd);
1736
    width = max(bboxWidth(bodyBBox) + bboxItalic(bodyBBox),
1781
    width = max(bboxWidth(bodyBBox) + bboxItalic(bodyBBox),
1737
		bboxWidth(accentBBox));
1782
		bboxWidth(accentBBox));
Line 1744... Line 1789...
1744
	+ 0.9 * italic;
1789
	+ 0.9 * italic;
1745
    yoffset = bboxHeight(bodyBBox) + bboxDepth(accentBBox) +
1790
    yoffset = bboxHeight(bodyBBox) + bboxDepth(accentBBox) +
1746
	0.1 * XHeight(gc, dd);
1791
	0.1 * XHeight(gc, dd);
1747
    if (draw) {
1792
    if (draw) {
1748
	PMoveTo(savedX + xoffset, savedY + yoffset, mc);
1793
	PMoveTo(savedX + xoffset, savedY + yoffset, mc);
-
 
1794
	if (code == 176 || /* ring (as degree) */
1749
	if (code == 215) /* dotmath */
1795
	    code == 215) /* dotmath */
1750
	    RenderSymbolChar(code, draw, mc, gc, dd);
1796
	    RenderSymbolChar(code, draw, mc, gc, dd);
1751
	else
1797
	else
1752
	    RenderChar(code, draw, mc, gc, dd);
1798
	    RenderChar(code, draw, mc, gc, dd);
1753
    }
1799
    }
1754
    bodyBBox = CombineOffsetBBoxes(bodyBBox, 0, accentBBox, 0,
1800
    bodyBBox = CombineOffsetBBoxes(bodyBBox, 0, accentBBox, 0,