EVOLUTION-MANAGER
Edit File: calcStringMetric.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Calculate Metric Information for Text</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for calcStringMetric {grid}"><tr><td>calcStringMetric {grid}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Calculate Metric Information for Text </h2> <h3>Description</h3> <p>This function returns the ascent, descent, and width metric information for a character or expression vector. </p> <h3>Usage</h3> <pre> calcStringMetric(text) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>text</code></td> <td> <p> A character or expression vector. </p> </td></tr> </table> <h3>Value</h3> <p>A list with three numeric components named ascent, descent, and width. All values are in inches. </p> <h3>WARNING </h3> <p> The metric information from this function is based on the font settings that are in effect when this function is called. It will not necessarily correspond to the metric information of any text that is drawn on the page. </p> <h3>Author(s)</h3> <p> Paul Murrell </p> <h3>See Also</h3> <p><code><a href="stringWidth.html">stringAscent</a></code>, <code><a href="stringWidth.html">stringDescent</a></code>, <code><a href="grobWidth.html">grobAscent</a></code>, and <code><a href="grobWidth.html">grobDescent</a></code>.</p> <h3>Examples</h3> <pre> grid.newpage() grid.segments(.01, .5, .99, .5, gp=gpar(col="grey")) metrics <- calcStringMetric(letters) grid.rect(x=1:26/27, width=unit(metrics$width, "inches"), height=unit(metrics$ascent, "inches"), just="bottom", gp=gpar(col="red")) grid.rect(x=1:26/27, width=unit(metrics$width, "inches"), height=unit(metrics$descent, "inches"), just="top", gp=gpar(col="red")) grid.text(letters, x=1:26/27, just="bottom") test <- function(x) { grid.text(x, just="bottom") metric <- calcStringMetric(x) if (is.character(x)) { grid.rect(width=unit(metric$width, "inches"), height=unit(metric$ascent, "inches"), just="bottom", gp=gpar(col=rgb(1,0,0,.5))) grid.rect(width=unit(metric$width, "inches"), height=unit(metric$descent, "inches"), just="top", gp=gpar(col=rgb(1,0,0,.5))) } else { grid.rect(width=unit(metric$width, "inches"), y=unit(.5, "npc") + unit(metric[2], "inches"), height=unit(metric$ascent, "inches"), just="bottom", gp=gpar(col=rgb(1,0,0,.5))) grid.rect(width=unit(metric$width, "inches"), height=unit(metric$descent, "inches"), just="bottom", gp=gpar(col=rgb(1,0,0,.5))) } } tests <- list("t", "test", "testy", "test\ntwo", expression(x), expression(y), expression(x + y), expression(a + b), expression(atop(x + y, 2))) grid.newpage() nrowcol <- n2mfrow(length(tests)) pushViewport(viewport(layout=grid.layout(nrowcol[1], nrowcol[2]), gp=gpar(cex=5, lwd=.5))) for (i in 1:length(tests)) { col <- (i - 1) %% nrowcol[2] + 1 row <- (i - 1) %/% nrowcol[2] + 1 pushViewport(viewport(layout.pos.row=row, layout.pos.col=col)) test(tests[[i]]) popViewport() } </pre> <hr /><div style="text-align: center;">[Package <em>grid</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>