Rev 68 | Blame | Compare with Previous | Last modification | View Log | RSS feed
### bdopen
### Used to open a graphics driver with BDplot.
### In X11, height and width are scaled to get a nicer window on the screen.
### This hack is ugly. At least there should be a scaling factor in stead so that all measures are scaled (fonts, etc).
bdopen <- function(file=bdp()$file,paper=bdp()$paper,mfrow=bdp()$mfrow,scale=TRUE,quality=NULL,scaleheight=1,height=NULL)
{
.bdcalcsizes(paper=paper,mfrow=mfrow,scaleheight=scaleheight,height=height)
prm <- .bdgetpars()
if(!is.null(height)){
prm$height <- height
}
if(prm$debug)
print(prm$height)
if( !is.na(file) )
{
## If figdir is supplied, prepending it to filename. It would be great only to do this if the path given in file is not absolute, ie starting by eather / or ~.
if(!is.null(prm$figdir)&&!is.na(prm$figdir) && (substring(bdp()$figdir,1,1)!="~"&&substring(bdp()$figdir,1,1)!="/") )
{
file <- paste(prm$figdir,file,sep="/")
}
cat("Writing to",file,"\n")
## determining device driver from filename
nchars <- nchar(file)
##### should switch be used here?
if( any( substr(file,nchars-2,nchars)==".ps",substr(file,nchars-3,nchars)==".eps")){
m <- {
cat("B/D plotting writing to postscript file\n")
postscript(file=file, width=prm$width, height=prm$height, paper="special", family = "Helvetica", horizontal=FALSE)
}
} else if ( substr(file,nchars-3,nchars)==".pdf")
{
pdf(file=file, width=prm$width, height=prm$height, paper="special",family = "Helvetica")
} else if (any(substr(file,nchars-3,nchars)==".jpg", substr(file,nchars-4,nchars)==".jpeg")) {
cat("Writing to jpeg file\n")
if(is.null(quality))
quality=prm$jpeg.quality
jpeg(filename=file,width=prm$width,height=prm$height,units=prm$size.unit,quality=quality,res=prm$jpeg.res,type="cairo")
### bitmap(file=file,type="jpeg",width=prm$width,height=prm$height,units=prm$size.unit,res=prm$jpeg.res,pointsize=.3)
} else if ( substr(file,nchars-3,nchars)==".tex"){
require(tikzDevice)
cat("Writing to tikz file\n")
tikz(file=file)
}
} else {
if(scale){
prm$height <- prm$height*2
prm$width <- prm$width*2
}
## to X. Note that this doesn't work on win and osx.
X11(height=prm$height,width=prm$width)
}
par(mfrow=mfrow)
}