Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01ce972

Browse filesBrowse files
committed
Better error handling with font can not be loaded by macosx backend
1 parent 71e41e9 commit 01ce972
Copy full SHA for 01ce972

File tree

Expand file treeCollapse file tree

1 file changed

+22
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-4
lines changed

‎src/_macosx.m

Copy file name to clipboardExpand all lines: src/_macosx.m
+22-4Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,10 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
25672567
#endif
25682568
CFRelease(string);
25692569
}
2570+
if (font == NULL)
2571+
{
2572+
PyErr_SetString(PyExc_ValueError, "Could not load font");
2573+
}
25702574
#ifndef COMPILING_FOR_10_5
25712575
CGContextSelectFont(cr, name, size, kCGEncodingMacRoman);
25722576
#endif
@@ -2632,7 +2636,11 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
26322636
CFStringRef s = CFStringCreateWithCharacters(kCFAllocatorDefault, text, n);
26332637
#endif
26342638

2635-
font = setfont(cr, family, size, weight, italic);
2639+
if (!(font = setfont(cr, family, size, weight, italic)))
2640+
{
2641+
CFRelease(s);
2642+
return NULL;
2643+
}
26362644

26372645
color = CGColorCreateGenericRGB(self->color[0],
26382646
self->color[1],
@@ -2739,7 +2747,11 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
27392747
CFStringRef s = CFStringCreateWithCharacters(kCFAllocatorDefault, text, n);
27402748
#endif
27412749

2742-
font = setfont(cr, family, size, weight, italic);
2750+
if (!(font = setfont(cr, family, size, weight, italic)))
2751+
{
2752+
CFRelease(s);
2753+
return NULL;
2754+
};
27432755

27442756
CFStringRef keys[1];
27452757
CFTypeRef values[1];
@@ -2810,7 +2822,10 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
28102822
&italic,
28112823
&angle)) return NULL;
28122824

2813-
atsfont = setfont(cr, family, size, weight, italic);
2825+
if (!(atsfont = setfont(cr, family, size, weight, italic))
2826+
{
2827+
return NULL;
2828+
}
28142829

28152830
OSStatus status;
28162831

@@ -2895,7 +2910,10 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
28952910

28962911
if(!PyArg_ParseTuple(args, "u#Ofss", &text, &n, &family, &size, &weight, &italic)) return NULL;
28972912

2898-
atsfont = setfont(cr, family, size, weight, italic);
2913+
if (!(atsfont = setfont(cr, family, size, weight, italic)))
2914+
{
2915+
return NULL;
2916+
}
28992917

29002918
OSStatus status = noErr;
29012919
ATSUAttributeTag tags[] = {kATSUFontTag,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.