@@ -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