The R Project SVN R

Rev

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

Rev 18657 Rev 18784
Line 2566... Line 2566...
2566
	rcolor fill;	         /* fill color */
2566
	rcolor fill;	         /* fill color */
2567
	rcolor bg;		 /* color */
2567
	rcolor bg;		 /* color */
2568
    } current;
2568
    } current;
2569
 
2569
 
2570
    int nobjs;  /* number of objects */
2570
    int nobjs;  /* number of objects */
2571
    int pos[1100]; /* object positions */
2571
    int *pos; /* object positions */
2572
    int pageobj[500]; /* page object numbers */
2572
    int *pageobj; /* page object numbers */
-
 
2573
    int pagemax;
2573
    int startstream; /* position of start of current stream */
2574
    int startstream; /* position of start of current stream */
2574
    Rboolean inText;
2575
    Rboolean inText;
2575
}
2576
}
2576
PDFDesc;
2577
PDFDesc;
2577
 
2578
 
Line 2636... Line 2637...
2636
    }
2637
    }
2637
 
2638
 
2638
    /* allocate new PDF device description */
2639
    /* allocate new PDF device description */
2639
    if (!(pd = (PDFDesc *) malloc(sizeof(PDFDesc))))
2640
    if (!(pd = (PDFDesc *) malloc(sizeof(PDFDesc))))
2640
	return 0;
2641
	return 0;
2641
 
-
 
2642
    /* from here on, if need to bail out with "error", must also */
2642
    /* from here on, if need to bail out with "error", must also */
2643
    /* free(pd) */
2643
    /* free(pd) */
2644
 
2644
 
-
 
2645
    pd->pos = (int *) calloc(350, sizeof(int));
-
 
2646
    if(!pd->pos) {
-
 
2647
	free(pd); free(dd);
-
 
2648
	error("cannot allocate pd->pos");
-
 
2649
    }
-
 
2650
    pd->pageobj = (int *) calloc(100, sizeof(int));
-
 
2651
    if(!pd->pageobj) {
-
 
2652
	free(pd->pos);free(pd); free(dd);
-
 
2653
	error("cannot allocate pd->pageobj");
-
 
2654
    }
-
 
2655
    pd->pagemax = 100;
-
 
2656
 
-
 
2657
 
2645
    /* initialize PDF device description */
2658
    /* initialize PDF device description */
2646
    strcpy(pd->filename, file);
2659
    strcpy(pd->filename, file);
2647
    pd->fontfamily = MatchFamily(family);
2660
    pd->fontfamily = MatchFamily(family);
2648
    if(strlen(encoding) > PATH_MAX - 1) {
2661
    if(strlen(encoding) > PATH_MAX - 1) {
2649
	free(dd);
2662
	free(dd);
2650
	free(pd);
2663
	free(pd->pos); free(pd->pageobj); free(pd);
2651
	error("encoding path is too long");
2664
	error("encoding path is too long");
2652
    }
2665
    }
2653
    strcpy(pd->encpath, encoding);
2666
    strcpy(pd->encpath, encoding);
2654
    setbg = str2col(bg);
2667
    setbg = str2col(bg);
2655
    setfg = str2col(fg);
2668
    setfg = str2col(fg);
Line 2657... Line 2670...
2657
    pd->width = width;
2670
    pd->width = width;
2658
    pd->height = height;
2671
    pd->height = height;
2659
    pointsize = floor(ps);
2672
    pointsize = floor(ps);
2660
    if(setbg == NA_INTEGER && setfg  == NA_INTEGER) {
2673
    if(setbg == NA_INTEGER && setfg  == NA_INTEGER) {
2661
	free(dd);
2674
	free(dd);
2662
	free(pd);
2675
	free(pd->pos); free(pd->pageobj); free(pd);
2663
	error("invalid foreground/background color (pdf)");
2676
	error("invalid foreground/background color (pdf)");
2664
    }
2677
    }
2665
 
2678
 
2666
    pd->onefile = onefile;
2679
    pd->onefile = onefile;
2667
    pd->maxpointsize = 72.0 * ((height > width) ? height : width);
2680
    pd->maxpointsize = 72.0 * ((height > width) ? height : width);
Line 2714... Line 2727...
2714
    dd->canChangeGamma = FALSE;
2727
    dd->canChangeGamma = FALSE;
2715
 
2728
 
2716
    /*	Start the driver */
2729
    /*	Start the driver */
2717
 
2730
 
2718
    if(!PDF_Open(dd, pd)) {
2731
    if(!PDF_Open(dd, pd)) {
2719
	free(pd);
2732
	free(pd->pos); free(pd->pageobj); free(pd);
2720
	return 0;
2733
	return 0;
2721
    }
2734
    }
2722
 
2735
 
2723
    dd->newDevStruct = 1;
2736
    dd->newDevStruct = 1;
2724
 
2737
 
Line 3023... Line 3036...
3023
static void PDF_NewPage(int fill, double gamma, NewDevDesc *dd)
3036
static void PDF_NewPage(int fill, double gamma, NewDevDesc *dd)
3024
{
3037
{
3025
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
3038
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
3026
    char buf[512];
3039
    char buf[512];
3027
 
3040
 
3028
    if(pd->pageno > 499 || pd->nobjs > 1099)
3041
    if(pd->pageno >= pd->pagemax || pd->nobjs >= 3*pd->pagemax) {
-
 
3042
	pd->pageobj = (int *) 
-
 
3043
	    realloc(pd->pageobj, 2*pd->pagemax * sizeof(int));
-
 
3044
	pd->pos = (int *) realloc(pd->pos, 
-
 
3045
				  (6*pd->pagemax + 50) * sizeof(int));
-
 
3046
	if(!pd->pos || !pd->pageobj)
3029
	error("limit on pages or objects exceeded:please shut down the PDFdevice");
3047
	    error("unable to increase page limit: please shutdown the pdf device");
-
 
3048
	pd->pagemax *= 2;
-
 
3049
    }
-
 
3050
    
3030
 
3051
 
3031
    if(pd->pageno > 0) {
3052
    if(pd->pageno > 0) {
3032
	PDF_endpage(pd);
3053
	PDF_endpage(pd);
3033
	if(!pd->onefile) {
3054
	if(!pd->onefile) {
3034
	    PDF_endfile(pd);
3055
	    PDF_endfile(pd);
Line 3063... Line 3084...
3063
{
3084
{
3064
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
3085
    PDFDesc *pd = (PDFDesc *) dd->deviceSpecific;
3065
 
3086
 
3066
    if(pd->pageno > 0) PDF_endpage(pd);
3087
    if(pd->pageno > 0) PDF_endpage(pd);
3067
    PDF_endfile(pd);
3088
    PDF_endfile(pd);
3068
    free(pd);
3089
    free(pd->pos); free(pd->pageobj); free(pd);
3069
}
3090
}
3070
 
3091
 
3071
static void PDF_Activate(NewDevDesc *dd) {}
3092
static void PDF_Activate(NewDevDesc *dd) {}
3072
static void PDF_Deactivate(NewDevDesc *dd) {}
3093
static void PDF_Deactivate(NewDevDesc *dd) {}
3073
 
3094