Cairo.jl icon indicating copy to clipboard operation
Cairo.jl copied to clipboard

HiDPI / Retina Display Support

Open dognotdog opened this issue 10 years ago • 7 comments

It seems like creating a simple Cairo surface in a Tk window (as in the Tk examples) doesn't use native pixels on a scaled display (in my case a Retina MacBook with OS X 10.10).

Is there some way to a) query the native pixel size, and b) to set the surface to have native resolution instead of scaled?

dognotdog avatar Nov 21 '15 20:11 dognotdog

afaiu Cairo on OSX, it asks for a Quartz surface and uses this. I'd guess the resolution is already decided in the initilisation of the Tk window.

lobingera avatar Nov 22 '15 07:11 lobingera

The reason I think it's something to do with surface creation is that a TreeView, for example, does use native size pixels. I've tried looking through the Canvas creation sequence in Tk.jl and Cairo.jl as well as digging a bit in the Tk sources, but it's all convoluted enough that I failed to find out where things go awry, so far.

In the meantime, I'm trying to bring up a native window with a Quartz drawable via Julia's FFI to figure out how to do it, but that's still in progress.

dognotdog avatar Nov 22 '15 09:11 dognotdog

So, drawing into a plain NSView via overriding -drawRect: with the Julia FFI and objc runtime yields correct drawing results, eg. the drawable has a HiDPI resolution without having to do any special setup to get that.

So where in the setup process of the Cairo Canvas is the error?

dognotdog avatar Nov 22 '15 12:11 dognotdog

Could you please spend a few lines, what you want to do and how this looks in code? I had no time to look into the details. but it could be that Cairo is somehow put into the mode to render to a bitmap which is copied to screen and the window size isn't reported correctly as there are many layers of indirection (OSX, TK, Quartz 2D, libcairo).

lobingera avatar Nov 23 '15 08:11 lobingera

I would try with a GTK or Qt window and see whether the issue persists. Tk isn't the most actively developed toolkit around.

nalimilan avatar Nov 23 '15 11:11 nalimilan

The Gtk.jl Canvas provides double-buffering via drawing to an image (pixel) surface by default and i fear we see the same problem. But this default can be bypassed and the underlying rendering stage can be accessed.

lobingera avatar Nov 23 '15 12:11 lobingera

Unfortunately, I haven't done anything with Tk/Gtk/Qt outside of Julia, so I've not the faintest clue how a HiDPI option should be passed. I know Tk is the old dog of the bunch, but it was the only one I could get working mostly right on short notice.

dognotdog avatar Nov 23 '15 20:11 dognotdog