Is there a way to get the dimensions that the results of a Text[]
will occupy within a Graphics[]
? Specifically, if I run something like
Graphics[Text[
Style["how quickly daft jumping zebras vex",
FontFamily -> "Verdana", FontSize -> 20]], PlotRange -> 1]
how can I get the dimensions relative to the coordinate system of the text?
edit: I have the PlotRange->1
in there because I'm using the text on a larger field and manipulating the text and other graphics using transformations that depend on the coordinate system. The text also is likely to change (hence my using sample text), so I'd like to have the transformations depend on measurements derived from the text (taking into account the styling of it).
Answer
Here you go:
t = Text[Style["how quickly daft jumping zebras vex",
FontFamily -> "Verdana", FontSize -> 20]];
{l, h} = d = Rasterize[t, "RasterSize"];
Graphics[{Green, Rectangle[{0, 0}, d], Black,
Inset[t]}, PlotRange -> {{0, l}, {0, h}}, ImageSize -> l]
Comments
Post a Comment