[RQt-devel] qstrWidth() outside the paintFun()

Yihui Xie xieyihui at gmail.com
Fri Oct 15 00:31:35 CEST 2010


And can we just put an approximate solution for qstrHeight() for the time being?

qstrHeight <- function(p, text) {
  extents <- qtextExtents(p, text)
  nlines <- sapply(gregexpr('\\n', text), function(xx) ifelse(any(xx <
0), 0, length(xx)) + 1)
  nlines * (extents[,4] - extents[,2])
}

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Thu, Oct 14, 2010 at 11:49 AM, Yihui Xie <xieyihui at gmail.com> wrote:
> Hi,
>
> We can calculate the width of a string inside the paintFun(layer,
> painter) since qstrWIdth() needs the 'painter' argument. I wonder if
> we can calculate the width when we only have the layer object, e.g.
>
> s <- qscene()
> test_layer <- qlayer(s, function(layer, painter) {
>    qdrawRect(painter, 10, 10, 90, 90, stroke = 'blue')
>    qstrWidth(painter, 'this is a string')
> }, limits=qrect(0,0,100,100))
> ## what if we are outside?
> qstrWidth(??, 'this is a string')
>
> I want to automatically adjust the plot margins according to the width
> and height of axis labels. Is there any way to calculate the height of
> a string?
>
> Thanks!
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>


More information about the Qtinterfaces-devel mailing list