|
47 | 47 | #ifndef COMPILING_FOR_10_5
|
48 | 48 | static int ngc = 0; /* The number of graphics contexts in use */
|
49 | 49 |
|
| 50 | +#include <Carbon/Carbon.h> |
50 | 51 |
|
51 | 52 | /* For drawing Unicode strings with ATSUI */
|
52 | 53 | static ATSUStyle style = NULL;
|
@@ -2620,7 +2621,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
|
2620 | 2621 | #endif
|
2621 | 2622 | CFRelease(string);
|
2622 | 2623 | }
|
2623 |
| - if (font == NULL) |
| 2624 | + if (!font) |
2624 | 2625 | {
|
2625 | 2626 | PyErr_SetString(PyExc_ValueError, "Could not load font");
|
2626 | 2627 | }
|
@@ -2761,11 +2762,13 @@ static CGFloat _get_device_scale(CGContextRef cr)
|
2761 | 2762 | const UniChar* text;
|
2762 | 2763 | #endif
|
2763 | 2764 |
|
2764 |
| - CGFloat ascent; |
2765 |
| - CGFloat descent; |
2766 |
| - double width; |
| 2765 | + float descent; |
| 2766 | + float width; |
| 2767 | + float height; |
| 2768 | + |
2767 | 2769 | CGRect rect;
|
2768 | 2770 |
|
| 2771 | + CGPoint point; |
2769 | 2772 | CTFontRef font;
|
2770 | 2773 |
|
2771 | 2774 | CGContextRef cr = self->cr;
|
@@ -2830,12 +2833,15 @@ static CGFloat _get_device_scale(CGContextRef cr)
|
2830 | 2833 | return NULL;
|
2831 | 2834 | }
|
2832 | 2835 |
|
2833 |
| - width = CTLineGetTypographicBounds(line, &ascent, &descent, NULL); |
| 2836 | + point = CGContextGetTextPosition(cr); |
2834 | 2837 | rect = CTLineGetImageBounds(line, cr);
|
2835 |
| - |
2836 | 2838 | CFRelease(line);
|
2837 | 2839 |
|
2838 |
| - return Py_BuildValue("fff", width, rect.size.height, descent); |
| 2840 | + width = rect.size.width; |
| 2841 | + height = rect.size.height; |
| 2842 | + descent = point.y - rect.origin.y; |
| 2843 | + |
| 2844 | + return Py_BuildValue("fff", width, height, descent); |
2839 | 2845 | }
|
2840 | 2846 |
|
2841 | 2847 | #else // Text drawing for OSX versions <10.5
|
@@ -2948,6 +2954,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
|
2948 | 2954 | const char* italic;
|
2949 | 2955 |
|
2950 | 2956 | ATSFontRef atsfont;
|
| 2957 | + Rect rect; |
2951 | 2958 |
|
2952 | 2959 | CGContextRef cr = self->cr;
|
2953 | 2960 | if (!cr)
|
@@ -3016,23 +3023,20 @@ static CGFloat _get_device_scale(CGContextRef cr)
|
3016 | 3023 | return NULL;
|
3017 | 3024 | }
|
3018 | 3025 |
|
3019 |
| - ATSUTextMeasurement before; |
3020 |
| - ATSUTextMeasurement after; |
3021 |
| - ATSUTextMeasurement ascent; |
3022 |
| - ATSUTextMeasurement descent; |
3023 |
| - status = ATSUGetUnjustifiedBounds(layout, |
3024 |
| - kATSUFromTextBeginning, kATSUToTextEnd, |
3025 |
| - &before, &after, &ascent, &descent); |
| 3026 | + status = ATSUMeasureTextImage(layout, |
| 3027 | + kATSUFromTextBeginning, kATSUToTextEnd, |
| 3028 | + 0, 0, &rect); |
3026 | 3029 | if (status!=noErr)
|
3027 | 3030 | {
|
3028 |
| - PyErr_SetString(PyExc_RuntimeError, "ATSUGetUnjustifiedBounds failed"); |
| 3031 | + PyErr_SetString(PyExc_RuntimeError, "ATSUMeasureTextImage failed"); |
3029 | 3032 | return NULL;
|
3030 | 3033 | }
|
3031 | 3034 |
|
3032 |
| - const float width = FixedToFloat(after-before); |
3033 |
| - const float height = FixedToFloat(ascent-descent); |
| 3035 | + const float width = rect.right-rect.left; |
| 3036 | + const float height = rect.bottom-rect.top; |
| 3037 | + const float descent = rect.bottom; |
3034 | 3038 |
|
3035 |
| - return Py_BuildValue("fff", width, height, FixedToFloat(descent)); |
| 3039 | + return Py_BuildValue("fff", width, height, descent); |
3036 | 3040 | }
|
3037 | 3041 | #endif
|
3038 | 3042 |
|
|
0 commit comments