Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 156c76d

Browse files
committed
Merge pull request matplotlib#1209 from dmcdougall/mac_lw
Pass linewidth to Mac context properly
2 parents 634f02d + 51611c8 commit 156c76d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, dpi, width, height):
4242
self.width = width
4343
self.height = height
4444
self.gc = GraphicsContextMac()
45+
self.gc.set_dpi(self.dpi)
4546
self.mathtext_parser = MathTextParser('MacOSX')
4647

4748
def set_width_height (self, width, height):

src/_macosx.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ - (int)index;
425425
NSSize size;
426426
int level;
427427
CGFloat color[4];
428+
float dpi;
428429
} GraphicsContext;
429430

430431
static CGMutablePathRef _create_path(void* iterator)
@@ -849,6 +850,15 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
849850
return Py_None;
850851
}
851852

853+
static PyObject*
854+
GraphicsContext_set_dpi (GraphicsContext* self, PyObject* args)
855+
{
856+
if (!PyArg_ParseTuple(args, "f", &(self->dpi))) return NULL;
857+
858+
Py_INCREF(Py_None);
859+
return Py_None;
860+
}
861+
852862
static PyObject*
853863
GraphicsContext_set_linewidth (GraphicsContext* self, PyObject* args)
854864
{
@@ -862,6 +872,8 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
862872
return NULL;
863873
}
864874

875+
// Convert points to pixels
876+
width *= self->dpi / 72.0;
865877
CGContextSetLineWidth(cr, width);
866878

867879
Py_INCREF(Py_None);
@@ -3202,6 +3214,11 @@ static void _data_provider_release(void* info, const void* data, size_t size)
32023214
METH_VARARGS,
32033215
"Sets the current stroke and fill color to a value in the DeviceGray color space."
32043216
},
3217+
{"set_dpi",
3218+
(PyCFunction)GraphicsContext_set_dpi,
3219+
METH_VARARGS,
3220+
"Sets the dpi for a graphics context."
3221+
},
32053222
{"set_linewidth",
32063223
(PyCFunction)GraphicsContext_set_linewidth,
32073224
METH_VARARGS,

0 commit comments

Comments
 (0)