[Rd] strwidth does not take font into account (PR#776)

plummer@iarc.fr plummer@iarc.fr
Tue, 19 Dec 2000 14:53:42 +0100 (MET)


One for the wishlist.

The text() function permits the use of different fonts with the arguments
"font" or "vfont".  These create text strings of the same height as the
default font, but of different widths: bold face is slightly wider; vector
fonts are usually much wider.  I think the strwidth() function needs to
take the font into account by also having "font" and "vfont" arguments.
Currently it reports the string width using the default font, which can
be quite different.

Here is a little test function you can use to see how far off the
reported string width is.

test.strwidth <-
function(text, vfont=NULL, cex=NULL, ...)
{
 plot(0,0,xlim=c(-1,1),ylim=c(-1,1), type="n")
 text(0,0, text, adj=c(0,0), offset=0, cex=cex, vfont=vfont, ...)
 abline(h=c(0, strheight(text, cex=cex)), lty=2)
 abline(v=c(0, strwidth(text, cex=cex)), lty=2)
}

e.g.

test.strwidth("This is some text", cex=2)
test.strwidth("This is some text", cex=2, font=2)
test.strwidth("This is some text", vfont=c("sans serif", "plain"))

Martyn

Please do not edit the information below--

Version:
 platform = i686-pc-linux-gnu
 arch = i686
 os = linux-gnu
 system = i686, linux-gnu
 status =
 major = 1
 minor = 2.0
 year = 2000
 month = 12
 day = 15
 language = R

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._