Re: Problem with Rasterize[] on Strings
- To: mathgroup at smc.vnet.net
- Subject: [mg95137] Re: Problem with Rasterize[] on Strings
- From: m.r at inbox.ru
- Date: Wed, 7 Jan 2009 04:13:04 -0500 (EST)
- References: <gjsgbg$k2s$1@smc.vnet.net>
Nathan Myhrvold wrote: > 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 -> > "Times"]; > > 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 -> > "Times"]; > > 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 > wraps. > > 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 > off. > > 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. > > Nathan > > 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 Add LineBreakWithin -> False to Style. Maxim Rytin m.r at inbox.ru