diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index a12079618b73..411cebbc8a60 100755 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -172,7 +172,7 @@ def get_text_width_height_descent(self, s, prop, ismath): size = self.points_to_pixels(points) width, height, descent = self.gc.get_text_width_height_descent( six.text_type(s), family, size, weight, style) - return width, height, 0.0*descent + return width, height, descent def flipy(self): return False diff --git a/src/_macosx.m b/src/_macosx.m index 97f60432c2a8..ee9933138d86 100644 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -47,6 +47,7 @@ #ifndef COMPILING_FOR_10_5 static int ngc = 0; /* The number of graphics contexts in use */ +#include /* For drawing Unicode strings with ATSUI */ static ATSUStyle style = NULL; @@ -2620,7 +2621,7 @@ static CGFloat _get_device_scale(CGContextRef cr) #endif CFRelease(string); } - if (font == NULL) + if (!font) { PyErr_SetString(PyExc_ValueError, "Could not load font"); } @@ -2761,11 +2762,13 @@ static CGFloat _get_device_scale(CGContextRef cr) const UniChar* text; #endif - CGFloat ascent; - CGFloat descent; - double width; + float descent; + float width; + float height; + CGRect rect; + CGPoint point; CTFontRef font; CGContextRef cr = self->cr; @@ -2830,12 +2833,15 @@ static CGFloat _get_device_scale(CGContextRef cr) return NULL; } - width = CTLineGetTypographicBounds(line, &ascent, &descent, NULL); + point = CGContextGetTextPosition(cr); rect = CTLineGetImageBounds(line, cr); - CFRelease(line); - return Py_BuildValue("fff", width, rect.size.height, descent); + width = rect.size.width; + height = rect.size.height; + descent = point.y - rect.origin.y; + + return Py_BuildValue("fff", width, height, descent); } #else // Text drawing for OSX versions <10.5 @@ -2948,6 +2954,7 @@ static CGFloat _get_device_scale(CGContextRef cr) const char* italic; ATSFontRef atsfont; + Rect rect; CGContextRef cr = self->cr; if (!cr) @@ -3016,23 +3023,20 @@ static CGFloat _get_device_scale(CGContextRef cr) return NULL; } - ATSUTextMeasurement before; - ATSUTextMeasurement after; - ATSUTextMeasurement ascent; - ATSUTextMeasurement descent; - status = ATSUGetUnjustifiedBounds(layout, - kATSUFromTextBeginning, kATSUToTextEnd, - &before, &after, &ascent, &descent); + status = ATSUMeasureTextImage(layout, + kATSUFromTextBeginning, kATSUToTextEnd, + 0, 0, &rect); if (status!=noErr) { - PyErr_SetString(PyExc_RuntimeError, "ATSUGetUnjustifiedBounds failed"); + PyErr_SetString(PyExc_RuntimeError, "ATSUMeasureTextImage failed"); return NULL; } - const float width = FixedToFloat(after-before); - const float height = FixedToFloat(ascent-descent); + const float width = rect.right-rect.left; + const float height = rect.bottom-rect.top; + const float descent = rect.bottom; - return Py_BuildValue("fff", width, height, FixedToFloat(descent)); + return Py_BuildValue("fff", width, height, descent); } #endif pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy