The R Project SVN R

Rev

Rev 30776 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30776 Rev 31031
Line 159... Line 159...
159
    rgb   outcolor;		/* Outside canvas color */
159
    rgb   outcolor;		/* Outside canvas color */
160
    rect  clip;			/* The clipping rectangle */
160
    rect  clip;			/* The clipping rectangle */
161
    Rboolean usefixed;
161
    Rboolean usefixed;
162
    font  fixedfont;
162
    font  fixedfont;
163
    font  font;
163
    font  font;
-
 
164
    char fontfamily[50];
-
 
165
 
164
    Rboolean locator;
166
    Rboolean locator;
165
    int clicked; /* {0,1,2} */
167
    int clicked; /* {0,1,2} */
166
    int	px, py, lty, lwd;
168
    int	px, py, lty, lwd;
167
    int resizing; /* {1,2,3} */
169
    int resizing; /* {1,2,3} */
168
    double rescale_factor;
170
    double rescale_factor;
Line 275... Line 277...
275
	/* Support Routines */
277
	/* Support Routines */
276
 
278
 
277
static double pixelHeight(drawing  d);
279
static double pixelHeight(drawing  d);
278
static double pixelWidth(drawing d);
280
static double pixelWidth(drawing d);
279
static void SetColor(int, double, NewDevDesc *);
281
static void SetColor(int, double, NewDevDesc *);
280
static void SetFont(int, int, double, NewDevDesc *);
282
static void SetFont(char*, int, int, double, NewDevDesc *);
281
static void SetLinetype(int, double, NewDevDesc *);
283
static void SetLinetype(int, double, NewDevDesc *);
282
static int Load_Rbitmap_Dll();
284
static int Load_Rbitmap_Dll();
283
void UnLoad_Rbitmap_Dll();
285
void UnLoad_Rbitmap_Dll();
284
static void SaveAsPng(NewDevDesc *dd, char *fn);
286
static void SaveAsPng(NewDevDesc *dd, char *fn);
285
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
287
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
Line 555... Line 557...
555
{
557
{
556
    xd->fontface = 1;
558
    xd->fontface = 1;
557
    xd->fontsize = xd->basefontsize;
559
    xd->fontsize = xd->basefontsize;
558
    xd->fontangle = 0.0;
560
    xd->fontangle = 0.0;
559
    xd->usefixed = FALSE;
561
    xd->usefixed = FALSE;
-
 
562
    xd->fontfamily[0] = '\0';
560
    xd->font = gnewfont(xd->gawin, fontname[0], fontstyle[0],
563
    xd->font = gnewfont(xd->gawin, fontname[0], fontstyle[0],
561
			MulDiv(xd->fontsize, xd->wanteddpi, xd->truedpi), 0.0);
564
			MulDiv(xd->fontsize, xd->wanteddpi, xd->truedpi), 0.0);
562
    if (!xd->font) {
565
    if (!xd->font) {
563
	xd->usefixed= TRUE;
566
	xd->usefixed= TRUE;
564
	xd->font = xd->fixedfont = FixedFont;
567
	xd->font = xd->fixedfont = FixedFont;
Line 566... Line 569...
566
	    return 0;
569
	    return 0;
567
    }
570
    }
568
    return 1;
571
    return 1;
569
}
572
}
570
 
573
 
-
 
574
/* Return a non-relocatable copy of a string */
-
 
575
 
-
 
576
static char *SaveFontSpec(SEXP sxp, int offset)
-
 
577
{
-
 
578
    char *s;
-
 
579
    if(!isString(sxp) || length(sxp) <= offset)
-
 
580
	error("Invalid font specification");
-
 
581
    s = R_alloc(strlen(CHAR(STRING_ELT(sxp, offset)))+1, sizeof(char));
-
 
582
    strcpy(s, CHAR(STRING_ELT(sxp, offset)));
-
 
583
    return s;
-
 
584
}
571
 
585
 
-
 
586
/*
-
 
587
 * Take the fontfamily from a gcontext (which is device-independent)
-
 
588
 * and convert it into a Windows-specific font description using
-
 
589
 * the Windows font database (see src/library/graphics/R/unix/windows.R)
-
 
590
 *
-
 
591
 * IF gcontext fontfamily is empty ("") 
-
 
592
 * OR IF can't find gcontext fontfamily in font database 
-
 
593
 * THEN return NULL
-
 
594
 */
-
 
595
static char* translateFontFamily(char* family) {
-
 
596
    SEXP graphicsNS, windowsenv, fontdb, fontnames;
-
 
597
    int i, nfonts;
-
 
598
    char* result = NULL;
-
 
599
    PROTECT_INDEX xpi;
-
 
600
 
-
 
601
    PROTECT(graphicsNS = R_FindNamespace(ScalarString(mkChar("grDevices"))));
-
 
602
    PROTECT_WITH_INDEX(windowsenv = findVar(install(".Windowsenv"), 
-
 
603
					   graphicsNS), &xpi);
-
 
604
    if(TYPEOF(windowsenv) == PROMSXP)
-
 
605
	REPROTECT(windowsenv = eval(windowsenv, graphicsNS), xpi);
-
 
606
    PROTECT(fontdb = findVar(install(".Windows.Fonts"), windowsenv));
-
 
607
    PROTECT(fontnames = getAttrib(fontdb, R_NamesSymbol));
-
 
608
    nfonts = LENGTH(fontdb);
-
 
609
    if (strlen(family) > 0) {
-
 
610
	int found = 0;
-
 
611
	for (i=0; i<nfonts && !found; i++) {
-
 
612
	    char* fontFamily = CHAR(STRING_ELT(fontnames, i));
-
 
613
	    if (strcmp(family, fontFamily) == 0) {
-
 
614
		found = 1;
-
 
615
		result = SaveFontSpec(VECTOR_ELT(fontdb, i), 0);
-
 
616
	    }
-
 
617
	}
-
 
618
	if (!found)
-
 
619
	    warning("Font family not found in Windows font database");
-
 
620
    }
-
 
621
    UNPROTECT(4);
-
 
622
    return result;
-
 
623
}
572
 
624
 
573
/* Set the font size and face */
625
/* Set the font size and face */
574
/* If the font of this size and at that the specified */
626
/* If the font of this size and at that the specified */
575
/* rotation is not present it is loaded. */
627
/* rotation is not present it is loaded. */
576
/* 0 = plain text, 1 = bold */
628
/* 0 = plain text, 1 = bold */
577
/* 2 = oblique, 3 = bold-oblique */
629
/* 2 = oblique, 3 = bold-oblique */
578
 
630
 
579
#define SMALLEST 2
631
#define SMALLEST 2
580
#define LARGEST 100
632
#define LARGEST 100
581
 
633
 
582
static void SetFont(int face, int size, double rot, NewDevDesc *dd)
634
static void SetFont(char *family, int face, int size, double rot, 
-
 
635
		    NewDevDesc *dd)
583
{
636
{
584
    gadesc *xd = (gadesc *) dd->deviceSpecific;
637
    gadesc *xd = (gadesc *) dd->deviceSpecific;
-
 
638
    char* fontfamily;
585
 
639
 
586
    if (face < 1 || face > fontnum)
640
    if (face < 1 || face > fontnum)
587
	face = 1;
641
	face = 1;
588
    if (size < SMALLEST) size = SMALLEST;
642
    if (size < SMALLEST) size = SMALLEST;
589
    if (size > LARGEST) size = LARGEST;
643
    if (size > LARGEST) size = LARGEST;
590
    size = MulDiv(size, xd->wanteddpi, xd->truedpi);
644
    size = MulDiv(size, xd->wanteddpi, xd->truedpi);
591
    if (!xd->usefixed &&
645
    if (!xd->usefixed &&
592
	(size != xd->fontsize || face != xd->fontface ||
646
	(size != xd->fontsize || face != xd->fontface ||
593
	 rot != xd->fontangle)) {
647
	 rot != xd->fontangle || strcmp(family, xd->fontfamily))) {
594
	 del(xd->font); doevent();
648
        del(xd->font); doevent();
-
 
649
	/*
-
 
650
	 * If specify family = "", get family from face via Rdevga
-
 
651
	 *
-
 
652
	 * If specify a family and a face in 1 to 4 then get
-
 
653
	 * that family (mapped through WindowsFonts()) and face.
-
 
654
	 *
-
 
655
	 * If specify face > 4 then get font from face via Rdevga
-
 
656
	 * (whether specifed family or not).
-
 
657
	 */
-
 
658
	fontfamily = translateFontFamily(family);
-
 
659
	if (fontfamily && face <= 4) {
595
	 xd->font = gnewfont(xd->gawin,
660
	    xd->font = gnewfont(xd->gawin,
-
 
661
				fontfamily, fontstyle[face - 1],
-
 
662
				size, rot);
-
 
663
	    if (xd->font)
-
 
664
                strcpy(xd->fontfamily, family);
-
 
665
	} else {
-
 
666
            xd->font = gnewfont(xd->gawin,
596
			    fontname[face - 1], fontstyle[face - 1],
667
				fontname[face - 1], fontstyle[face - 1],
597
			    size, rot);
668
				size, rot);
-
 
669
	}
598
	if (xd->font) {
670
	if (xd->font) {
599
	    xd->fontface = face;
671
	    xd->fontface = face;
600
	    xd->fontsize = size;
672
	    xd->fontsize = size;
601
	    xd->fontangle = rot;
673
	    xd->fontangle = rot;
602
	} else {
674
	} else {
Line 1643... Line 1715...
1643
{
1715
{
1644
    gadesc *xd = (gadesc *) dd->deviceSpecific;
1716
    gadesc *xd = (gadesc *) dd->deviceSpecific;
1645
    double a;
1717
    double a;
1646
    int   size = gc->cex * gc->ps + 0.5;
1718
    int   size = gc->cex * gc->ps + 0.5;
1647
 
1719
 
1648
    SetFont(gc->fontface, size, 0.0, dd);
1720
    SetFont(gc->fontfamily, gc->fontface, size, 0.0, dd);
1649
    a = (double) gstrwidth(xd->gawin, xd->font, str);
1721
    a = (double) gstrwidth(xd->gawin, xd->font, str);
1650
    return a;
1722
    return a;
1651
}
1723
}
1652
 
1724
 
1653
 
1725
 
Line 1668... Line 1740...
1668
{
1740
{
1669
    int   a, d, w;
1741
    int   a, d, w;
1670
    int   size = gc->cex * gc->ps + 0.5;
1742
    int   size = gc->cex * gc->ps + 0.5;
1671
    gadesc *xd = (gadesc *) dd->deviceSpecific;
1743
    gadesc *xd = (gadesc *) dd->deviceSpecific;
1672
 
1744
 
1673
    SetFont(gc->fontface, size, 0.0, dd);
1745
    SetFont(gc->fontfamily, gc->fontface, size, 0.0, dd);
1674
    gcharmetric(xd->gawin, xd->font, c, &a, &d, &w);
1746
    gcharmetric(xd->gawin, xd->font, c, &a, &d, &w);
1675
    /* Some Windows systems report that space has height and depth,
1747
    /* Some Windows systems report that space has height and depth,
1676
       so we have a kludge.  Note that 32 is space in symbol font too */
1748
       so we have a kludge.  Note that 32 is space in symbol font too */
1677
    if(c == 32) {
1749
    if(c == 32) {
1678
	*ascent  = 0.0;
1750
	*ascent  = 0.0;
Line 2199... Line 2271...
2199
    xl = 0.0;
2271
    xl = 0.0;
2200
    yl = -pixs;
2272
    yl = -pixs;
2201
    rot1 = rot * DEG2RAD;
2273
    rot1 = rot * DEG2RAD;
2202
    x += -xl * cos(rot1) + yl * sin(rot1);
2274
    x += -xl * cos(rot1) + yl * sin(rot1);
2203
    y -= -xl * sin(rot1) - yl * cos(rot1);
2275
    y -= -xl * sin(rot1) - yl * cos(rot1);
2204
    SetFont(gc->fontface, size, rot, dd);
2276
    SetFont(gc->fontfamily, gc->fontface, size, rot, dd);
2205
    SetColor(gc->col, gc->gamma, dd);
2277
    SetColor(gc->col, gc->gamma, dd);
2206
    if (R_OPAQUE(gc->col)) {
2278
    if (R_OPAQUE(gc->col)) {
2207
#ifdef NOCLIPTEXT
2279
#ifdef NOCLIPTEXT
2208
	gsetcliprect(xd->gawin, getrect(xd->gawin));
2280
	gsetcliprect(xd->gawin, getrect(xd->gawin));
2209
	gdrawstr1(xd->gawin, xd->font, xd->fgcolor, pt(x, y), str, hadj);
2281
	gdrawstr1(xd->gawin, xd->font, xd->fgcolor, pt(x, y), str, hadj);