History

properly handle font loading errors

Sigrid Solveig Haflínudóttir committed 5 years agomaster

Commit 07102961 parent e771f322 files · +10 −2Browse files

Unified · Split

2 files
  1. pt.c +8 −1
  2. test.c +2 −1
pt.c+8−1
@@ -102,8 +102,10 @@ pt_font(uchar *data, float height) · 101 unmodified lines
102 Sfont *f;102 Sfont *f;
103 103
104 f = mallocz(sizeof(*f), 1);104 f = mallocz(sizeof(*f), 1);
105 if(stbtt_InitFont(&f->fi, data, stbtt_GetFontOffsetForIndex(data, 0)) == 0)105 if(stbtt_InitFont(&f->fi, data, stbtt_GetFontOffsetForIndex(data, 0)) == 0){
106 werrstr("stbtt_InitFont: %r");
106 goto err;107 goto err;
108 }
107 109
108 f->scale = stbtt_ScaleForPixelHeight(&f->fi, height);110 f->scale = stbtt_ScaleForPixelHeight(&f->fi, height);
109 f->height = height;111 f->height = height;
@@ -119,6 +121,10 @@ pt_font(uchar *data, float height) · 9 unmodified lines
119 f->bb.max.x = (f->bb.max.x + 3) & ~3;121 f->bb.max.x = (f->bb.max.x + 3) & ~3;
120 f->bb.max.y = (f->bb.max.y + 3) & ~3;122 f->bb.max.y = (f->bb.max.y + 3) & ~3;
121 123
124 if(badrect(f->bb)){
125 werrstr("invalid glyph bbox: %R", f->bb);
126 goto err;
127 }
122 if((f->g = allocmemimage(f->bb, GREY8)) == nil)128 if((f->g = allocmemimage(f->bb, GREY8)) == nil)
123 goto err;129 goto err;
124 if((f->b = allocmemimage(f->bb, GREY8)) == nil)130 if((f->b = allocmemimage(f->bb, GREY8)) == nil)
@@ -127,6 +133,7 @@ pt_font(uchar *data, float height) · 2 unmodified lines
127 133
128 return f;134 return f;
129err:135err:
136 werrstr("pt_font: %r");
130 pt_freefont(f);137 pt_freefont(f);
131 return nil;138 return nil;
132}139}
test.c+2−1
@@ -193,7 +193,8 @@ threadmain(int argc, char **argv) · 192 unmodified lines
193 193
194changed:194changed:
195 pt_freefont(fo);195 pt_freefont(fo);
196 fo = pt_font(data, height);196 if((fo = pt_font(data, height)) == nil)
197 sysfatal("%r");
197 rect = pt_textrect(fo, s);198 rect = pt_textrect(fo, s);
198 freeimage(image);199 freeimage(image);
199 image = pt_textdraw(fo, s, rect, &opts);200 image = pt_textdraw(fo, s, rect, &opts);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t