[cairo] dimensionally accurate drawings on screen ?

Axel Simon A.Simon at kent.ac.uk
Fri Jan 20 12:45:04 PST 2006

On Fri, 2006-01-20 at 14:57 -0500, John Ellson wrote:
> This isn't a cairo problem, I'm sure, but I'm hoping that someone here will
> know how to solve it.
> I'm trying to create dimensionally accurate drawings using cairo on a 
> GdkDrawable using
> 	GdkDrawable *drawable;
> 	cairo_t *cr;
> 	drawable = gtk_drawing_area_new();
>         cr = gdk_cairo_create  (drawable);
> I can generate the drawings ok.  Its the dimensionally accurate part I'm having difficultly with.
> I'd like to scale according to accurate xy resolution values.  With Xlib I know I can obtain the
> resolution with:
> 	resolution.x = DisplayWidth(dpy, scr) / DisplayWidthMM(dpy, scr);
> 	resolution.y = DisplayHeight(dpy, scr) / DisplayHeightMM(dpy, scr);
> but how can I get from "GdkDrawable *display"  to the "Display* dpy" and the "int scr" ?

 gdk_screen_get_width_mm and  gdk_screen_get_width are your friends,
similarly for height. Note that

a) you need to specify this scaling factor for all text rendering, too,
since Gtk (and Cairo) have a built-in, fixed DPI setting for fonts.

b) what your monitor reports is often wrong, e.g. my 18" TFT reports the
size of its 17" predecessor.


More information about the cairo mailing list