Permalink
Browse files

Pass dpi to GC for converting points to pixels

  • Loading branch information...
1 parent 1478a1b commit 51611c8028b43bbceb13f77f6b870e9ca1eeed6f @dmcdougall committed Sep 6, 2012
Showing with 18 additions and 0 deletions.
  1. +1 −0 lib/matplotlib/backends/backend_macosx.py
  2. +17 −0 src/_macosx.m
@@ -42,6 +42,7 @@ def __init__(self, dpi, width, height):
self.width = width
self.height = height
self.gc = GraphicsContextMac()
+ self.gc.set_dpi(self.dpi)
self.mathtext_parser = MathTextParser('MacOSX')
def set_width_height (self, width, height):
View
@@ -425,6 +425,7 @@ - (int)index;
NSSize size;
int level;
CGFloat color[4];
+ float dpi;
} GraphicsContext;
static CGMutablePathRef _create_path(void* iterator)
@@ -850,6 +851,15 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
}
static PyObject*
+GraphicsContext_set_dpi (GraphicsContext* self, PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, "f", &(self->dpi))) return NULL;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject*
GraphicsContext_set_linewidth (GraphicsContext* self, PyObject* args)
{
float width;
@@ -862,6 +872,8 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
return NULL;
}
+ // Convert points to pixels
+ width *= self->dpi / 72.0;
CGContextSetLineWidth(cr, width);
Py_INCREF(Py_None);
@@ -3202,6 +3214,11 @@ static void _data_provider_release(void* info, const void* data, size_t size)
METH_VARARGS,
"Sets the current stroke and fill color to a value in the DeviceGray color space."
},
+ {"set_dpi",
+ (PyCFunction)GraphicsContext_set_dpi,
+ METH_VARARGS,
+ "Sets the dpi for a graphics context."
+ },
{"set_linewidth",
(PyCFunction)GraphicsContext_set_linewidth,
METH_VARARGS,

0 comments on commit 51611c8

Please sign in to comment.