MathGroup Archive 2009

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

Search the Archive

Problem with Rasterize[] on Strings

  • To: mathgroup at
  • Subject: [mg95072] Problem with Rasterize[] on Strings
  • From: "Nathan Myhrvold" <nathanm at>
  • Date: Mon, 5 Jan 2009 03:28:43 -0500 (EST)

I am trying to use Rasterize[] on strings, and I am running into some
strange behavior.

This line works fine

s1 = Style["A medium length string", FontSize-> 10, FontFamily ->

Rasterize[s1,  ImageResolution -> 100]

However, as I increase either the font size, or the image resolution,
the text will wrap into two or more lines:

s2 = Style["A medium length string", FontSize-> 100, FontFamily ->

Rasterize[s2,  ImageResolution -> 300]

The strange thing is that this depends on the window size!  If you make
the window very narrow (or have a low resolution screen) then it will
start wrapping sooner that it will with.  So depending on your monitor
and graphics card, and what size window you use, you can find a
combination that will wrap.

So if I stretch a Mathematica window across my dual-monitor set up, I
can take the string s2 up to ImageResolution-> 192 before it wraps.
With a small window it wraps at ImageResolution-> 90.

I think what is going on here is that the Mathematica front end is doing
the rasterizing and it first lays out the string for the window.    If
it needs to wrap, then it formats the string into two lines before it
rasterizes.  The weird part is that the decision to format depends on
the resolution even though the display does not.

So, even if s2 above displays correctly, and even if the result of
Rasterize[s2,ImageResolution->300]  is displayed correctly (at 100 point
font size) the intermediate calculation of whether there is enough space
to rasterize somehow is done depending on window size.  I think this is
a rather serious bug,  because it defeats the purpose of using
ImageResolution higher than screen resolution.   Note that the same
occurs for RasterSize->num   when num is bigger than your window, it

My question is this - how can I avoid this word wrapping?  There must be
some way to do this!

One approach I have tried is to use Graphics inside Rasterize, i.e.

Rasterize[Graphics[Text[s2,{0,0},{-1,0}],ImageSize->{All, 200}] ,
ImageResolution -> 300]

This has a couple problems:

-        I get lots of padding on both sides of the text.  I can't seem
to control it with ImagePadding-> 0, PlotRangePadding-> 0

-        Yet if I don't make ImageSize very large, I have my string cut

Perhaps I am not making the right incantations to Graphics[] to get this
to work properly.

Here is an additional question.  I am using Rasterize because I need to
send documents to computers that don't have the same fonts I have.
Normally I would use a PDF file.  However Mathematica does not seem to
support the font embedding feature of PDF files.   If there was a way to
enable font embedding do that I wouldn't need to Rasterize the text.


This message and any attachments, may contain confidential and/or
legally privileged information.  If you are not the intended recipient
of the message by the original sender, please destroy it.   Message and
attachments copyright (c) 2008, all rights reserved.  Any unauthorized
dissemination, distribution or copying is strictly forbidden

  • Prev by Date: Re: Re: a LOT of Mathematica bugs (some very old)
  • Next by Date: loading autosaved package using Needs[]
  • Previous by thread: Re: a LOT of Mathematica bugs (some very old)
  • Next by thread: Re: Problem with Rasterize[] on Strings