Finding the top left corner in the Quartz plugin

I have a Mac plugin to view images. It was originally written in Quickdraw and I am trying to move it to Quartz.

My current problem is the origin. In QD, the origin is (reasonably) at the top left of the plugin rectangle. In Quartz, it appears to be one screen height below the top of the plugin rectangle (not including Firefox buttons, etc.). It's effectively somewhere in the middle of my plugin rectangle.

This also means that I need to know the size of the part of the drawing in the browser window. I'm sure I can figure out how big the window is, but how can I figure out how much space a tab is taking, etc.? Mac doesn't know about this, does it?

In this regard, does anyone know why Apple decided to put the origin in the lower left corner? seems dumb to me.

0


a source to share


1 answer


If you are using NSView, you can create a -isFlipped

YES return function implementation that will allow you to draw based on an inverted coordinate system.

Alternatively, if you are not using NSView, but using a rough CoreGraphics drawing, you can change the CTM like so:

CGContextScaleCTM( context, 1.0, -1.0 );

      

It comes from this Apple Q&A document .



If you do it with a CGContextRef you got something else, save the existing CTM first and restore it when done:

CGContextSaveGState( context );

// do your stuff here ...

CGContextRestoreGState( context );

      

Oh, and the origin is in the lower left corner because the quartz rendering system is based on the PDF graphics system, which is PostScript based and has its origin in the lower left corner.

+1


a source







All Articles