• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSViews that are scaled (-1,-1) to (1,1) do not print well
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSViews that are scaled (-1,-1) to (1,1) do not print well


  • Subject: Re: NSViews that are scaled (-1,-1) to (1,1) do not print well
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Sat, 22 Dec 2001 13:14:56 +0100

Le samedi 22 dicembre 2001, ` 06:30 , Simson Garfinkel a icrit :

Anybody familiar with my NeXTSTEP Programming book will recall that many of
the examples have an NSView that is scaled (-1,-1) to (1,1).

Turns out that this doesn't work well on OSX. Specifically:

* PDF generation doesn't work well at all. You get a 1 pixel PDF that
represents the area (0,0) to (1,1)
* EPS generation doesn't work well either. You get an EPS that has all of
the data inside, but which doesn't print properly on a PostScript printer
and is not readable by Adobe Illustrator on Windows. (Haven't checked it ont
he Mac version yet.)


I got this problem some months ago, asked here and in macosxdev, and didn'
t get useful advice.
After a lot of experiment, I was able to get a correct PDF generation (not EPS) by using the following:
1/ detect in drawRect that I'm not drawing on screen; in my case, I used a internal variable named 'renderingport', which is usually nil, but is the [self graphicsPort] in PDF representation. (There is probably simpler ways)
.
2/ drawRect in the FRAME rect for PDF rep, and use an affine transform here;
3/ now the drawRect looks like that:

- (void)drawRect:(NSRect)rect {
CmdGraphicsPort *port = renderingPort;
float dlw = 0.0f;
if (renderingPort) {// rendering pdf or ps
NSRect bounds = [self bounds], frame = [self frame];
NSAffineTransform *t =[NSAffineTransform transform];
[t translateXBy:-bounds.origin.x yBy:-bounds.origin.y];
[t concat];// translate to have the origin where it should be
rect.origin = NSZeroPoint;
rect.size = bounds.size;
dlw = (bounds.size.width + bounds.size.height)/(frame.size.width + frame.size.height);
}
if (!port) port = [self graphicsPort];
[NSBezierPath setDefaultLineWidth: dlw];
[port drawAllInRect: rect];
}

It is just crazy, but it works. Note the trick with the value dlw. NSBezierPath is bogus, too, with respect to default line width. The value 0 should be the thiner width displayable on the current device, but that doesn't work on PDF: you must give a > 0 value.

Finally drawAtPoint doesn't work for strings if the ratio bound-
size/frame-size is small with respect to 1. I have submitted a bug for that two months ago and it is still 'unresolved'.

If you want to get the whole view, fell free to download 'the commandant proect' at http://lachand.free.fr; look at CmdGraphicsView.


Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.


References: 
 >NSViews that are scaled (-1,-1) to (1,1) do not print well (From: "Simson Garfinkel" <email@hidden>)

  • Prev by Date: Re: Cross platform Cocoa/Obj-C
  • Next by Date: Re: black
  • Previous by thread: NSViews that are scaled (-1,-1) to (1,1) do not print well
  • Next by thread: Re: NSViews that are scaled (-1,-1) to (1,1) do not print well
  • Index(es):
    • Date
    • Thread