MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to scale text to a bounding rectangle?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110430] Re: how to scale text to a bounding rectangle?
  • From: "Alexey Popkov" <lehin.p at gmail.com>
  • Date: Thu, 17 Jun 2010 07:11:30 -0400 (EDT)
  • References: <hvcds8$5h9$1@smc.vnet.net>

Hi, Michael,

You can try to play with text outlines (vector representation of the text):
Graphics[{{FaceForm[], EdgeForm[Black], Rectangle[{0, 0}, {100, 10}]},
Inset[First@ImportString[ExportString[Style["Hello", 36], "PDF"], "PDF"]]}]




"Michael" <michael2718 at gmail.com>  news:hvcds8$5h9$1 at smc.vnet.net...
> 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]
>
>
> 




  • Prev by Date: Re: Automatic update of variables
  • Next by Date: Re: how to scale text to a bounding rectangle?
  • Previous by thread: Re: how to scale text to a bounding rectangle?
  • Next by thread: Re: how to scale text to a bounding rectangle?