Re: how to scale text to a bounding rectangle?
- To: mathgroup at smc.vnet.net
- Subject: [mg110417] Re: how to scale text to a bounding rectangle?
- From: Michael <michael2718 at gmail.com>
- Date: Thu, 17 Jun 2010 02:03:59 -0400 (EDT)
The problem with both of these solutions is that I need the bounding rectangle to be in a Graphics[] expression because I'm creating several of these text filled boxes at arbitrary offsets. I'm trying to create something similar to Graph[] (hopefully using it's embedding functions) but instead of vertexes I want to create collections of boxes containing text. However Mathematica seems to render text independently of the coordinate range of the graphic. For example, these two expressions produce identical output: Graphics[{ Text[Style["Test", 12]], Circle[{0, 0}, 1] } ] Graphics[{ Text[Style["Test", 12]], Circle[{0, 0}, 100] } ] I found something close to what I want to do, but it's ugly because the graphics don't scale nicely: Graphics[{ FaceForm[], EdgeForm[Black], Raster[Reverse[Rasterize["Hello", "Data"]], {{0, 0}, {100, 16}}], Rectangle[{0, 0}, {100, 16}] } ] But I would have to hope that surely there is some way to put Text[] in Graphics[] such that the size of the text is proportional to the visible coordinate range of the Graphics[]. Even if I could only find the size of the text in a given image I could then scale it as needed. I tried using Rasterize[string,"RasterSize"] but I couldn't figure out how to make it work. Any ideas along that line? I'm hoping that I'm just missing something obvious that I've overlooked in Mathematica's big API... Thanks, Michael > On 6/15/2010 2:29 AM, Michael wrote: >> How can I automatically scale Text[] to fit into a bounding rectangle of >> a size that I specify? >> >> For instance, I can get a pretty close result here, but it is not >> perfect (the text doesn't touch the bottom edge of the rectangle), and >> "36", {0,0}, and {-1,-1} are all numbers I had to find through trial and >> error: >> >> Graphics[{ >> FaceForm[], EdgeForm[Black], >> Rectangle[{0, 0}, {100, 10}], >> Text[Style["Hello", 36], {0, 0}, {-1, -1}] >> } >> ] On 6/16/2010 2:41 AM, Alexei Boulbitch wrote: > Hi, Michael, > > try this: > > Manipulate[ > > Framed@Pane[Graphics[Text[Style["ABcdEG", n]]], {m1, m2}, > Alignment -> Center], > > {n, 10, 30}, {m1, 50, 200}, {m2, 20, 200}] > > and play with parameters to chose those fitting your needs. > Have fun, Alexei On 6/16/2010 2:42 AM, Helen Read wrote: > Framed[Text[Style["Hello"]]] > > If you want the 36 point font, that's fine too. > > Framed[Text[Style["Hello", 36]]] > > You can set FrameMargins on any or all sides. > > Framed[Text[Style["Hello", 36]], FrameMargins -> {{10, 200}, {0, 0}}] > > Framed[Text[Style["Hello", 36]], FrameMargins -> 20]