History

this is not Go

Sigrid Solveig Haflínudóttir committed 3 years ago

Commit 5949d531 parent 5de3c662 files · +220 −196Browse files

Unified · Split

2 files
  1. main.c +4 −6
  2. op.c +216 −190
main.c+4−6
@@ -24,13 +24,11 @@ dumppage(Object *page, int text) · 23 unmodified lines
2424 Page p;
2525
2626 pageinit(&p, page);
27− ret = pagerender(&p);
28− if(ret){
29− if(text){
30− if(p.buf.sz != 0)
31− fprint(1, "%s", (char*)p.buf.b);
32− }else
27+ if((ret = pagerender(&p)) == 0){
28+ if(!text)
3329 writememimage(1, p.image);
30+ else if(p.buf.sz != 0)
31+ print("%s", (char*)p.buf.b);
3432 }
3533 pagefree(&p);
3634
op.c+216−190
@@ -71,33 +71,34 @@ static int · 70 unmodified lines
7171 flagless(Op *op)
7272 {
7373 if(op->flags != 0){
74− fprint(2, "Op '%s' expected no flags\n", op->s);
75− return 0;
74+ werrstr("op %q: expected no flags", op->s);
75+ return -1;
7676 }
77− return 1;
77+ return 0;
7878 }
7979
8080 static int
8181 cobegin(Op *op, Page *p)
8282 {
8383 USED(op, p);
84− return 0;
84+ return -1;
8585 }
8686
8787 static int
8888 coend(Op *op, Page *p)
8989 {
9090 USED(op, p);
91− return 0;
91+ return -1;
9292 }
9393
9494 static int
9595 gspush(Op *op, Page *p)
9696 {
97+ GS *r;
98+
9799 USED(op);
98− GS *r = realloc(p->GS, sizeof(GS) * (p->nGS + 1));
99− if(r == nil)
100− return 0;
100+ if((r = realloc(p->GS, sizeof(GS) * (p->nGS + 1))) == nil)
101+ return -1;
101102 p->GS = r;
102103 p->nGS++;
103104 p->GSactive = &p->GS[p->nGS - 1];
@@ -106,11 +107,11 @@ gspush(Op *op, Page *p) · 2 unmodified lines
106107 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
107108 if(p->GSactive->Font.widths == nil){
108109 werrstr("gspush: out of memory allocating space for glyph widths");
109− return 0;
110+ return -1;
110111 }
111112 memcpy(p->GSactive->Font.widths, p->GS[p->nGS - 2].Font.widths, sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
112113 }
113− return 1;
114+ return 0;
114115 }
115116
116117 static int
@@ -120,11 +121,11 @@ gspop(Op *op, Page *p) · 3 unmodified lines
120121 free(p->GSactive->Font.widths);
121122 GS *r = realloc(p->GS, sizeof(GS) * (p->nGS - 1));
122123 if(r == nil)
123− return 0;
124+ return -1;
124125 p->GS = r;
125126 p->nGS--;
126127 p->GSactive = &p->GS[p->nGS - 1];
127− return 1;
128+ return 0;
128129 }
129130
130131 /* six parameters give the inputs a,b,c,d,e,f for the matrix
@@ -140,6 +141,7 @@ gsctm(Op *op, Page *p) · 9 unmodified lines
140141 {
141142 double input[6];
142143 int i;
144+
143145 for(i = 0; i < 6; i++)
144146 input[i] = arrayget(p->stack, i)->num.d;
145147 matmult(input, p->GSactive->CTM, p->GSactive->CTM);
@@ -151,8 +153,8 @@ gswidth(Op *op, Page *p) · 5 unmodified lines
151153 {
152154 p->GSactive->LW = arrayget(p->stack, 0)->num.d;
153155 if(p->GSactive->LW < 0){
154− werrstr("line width cannot be negative: %f", p->GSactive->LW);
155− return 0;
156+ werrstr("gswidth: invalid line width: %f", p->GSactive->LW);
157+ return -1;
156158 }
157159 return flagless(op);
158160 }
@@ -162,8 +164,8 @@ gscap(Op *op, Page *p) · 3 unmodified lines
162164 {
163165 p->GSactive->LC = arrayget(p->stack, 0)->num.d;
164166 if(p->GSactive->LC > CapEND){
165− werrstr("invalid line cap: %d", p->GSactive->LC);
166− return 0;
167+ werrstr("gscap: invalid line cap: %d", p->GSactive->LC);
168+ return -1;
167169 }
168170 return flagless(op);
169171 }
@@ -173,8 +175,8 @@ gsjoin(Op *op, Page *p) · 3 unmodified lines
173175 {
174176 p->GSactive->LJ = arrayget(p->stack, 0)->num.d;
175177 if(p->GSactive->LJ > JoinEND){
176− werrstr("invalid line join: %d", p->GSactive->LJ);
177− return 0;
178+ werrstr("gsjoin: invalid line join: %d", p->GSactive->LJ);
179+ return -1;
178180 }
179181 return flagless(op);
180182 }
@@ -184,8 +186,8 @@ gsmiterlim(Op *op, Page *p) · 3 unmodified lines
184186 {
185187 p->GSactive->ML = arrayget(p->stack, 0)->num.d;
186188 if(p->GSactive->ML < 0){
187− werrstr("miter limit cannot be negative: %f", p->GSactive->ML);
188− return 0;
189+ werrstr("gsmiterlim: invalidmiter limit: %f", p->GSactive->ML);
190+ return -1;
189191 }
190192 return flagless(op);
191193 }
@@ -194,14 +196,14 @@ static int · 2 unmodified lines
194196 gsdash(Op *op, Page *p)
195197 {
196198 USED(op, p);
197− return 0;
199+ return -1;
198200 }
199201
200202 static int
201203 gsintent(Op *op, Page *p)
202204 {
203205 USED(op, p);
204− return 0;
206+ return -1;
205207 }
206208
207209 static int
@@ -218,129 +220,132 @@ gsstate(Op *op, Page *p) · 10 unmodified lines
218220 Object *gs, *o;
219221 if((gs = dictget(dictget(dictget(p->obj, "Resources"), "ExtGState"), name)) == &null){
220222 werrstr("extgstate dictionary not found: %s", name);
221− return 0;
223+ goto err;
222224 }
223225 if((o = dictget(gs, "Type")) != &null && strcmp(o->name, "ExtGState") != 0){
224226 werrstr("invalid type on ExtGState object: %s", o->name);
225− return 0;
227+ goto err;
226228 }
227229 if((o = dictget(gs, "LW")) != &null){
228230 if(o->type != Onum){
229− werrstr("line width must be a number, %d", o->type);
230− return 0;
231+ werrstr("line width is not a number");
232+ goto err;
231233 }
232234 p->GSactive->LW = o->num.d;
233235 }
234236 if((o = dictget(gs, "LC")) != &null){
235237 if(o->type != Onum){
236− werrstr("line cap must be a number");
237− return 0;
238+ werrstr("line cap is not a number");
239+ goto err;
238240 }
239241 p->GSactive->LC = o->num.i;
240242 }
241243 if((o = dictget(gs, "LJ")) != &null){
242244 if(o->type != Onum){
243− werrstr("line join must be a number");
244− return 0;
245+ werrstr("line join is not a number");
246+ goto err;
245247 }
246248 p->GSactive->LJ = o->num.i;
247249 }
248250 if((o = dictget(gs, "ML")) != &null){
249251 if(o->type != Onum){
250− werrstr("miter limit must be a number");
251− return 0;
252+ werrstr("miter limit is not a number");
253+ goto err;
252254 }
253255 p->GSactive->ML = o->num.d;
254256 }
255257 return flagless(op);
258+err:
259+ werrstr("gsstate: %r");
260+ return -1;
256261 }
257262
258263 static int
259264 pcmove(Op *op, Page *p)
260265 {
261266 USED(op, p);
262− return 0;
267+ return -1;
263268 }
264269
265270 static int
266271 pcline(Op *op, Page *p)
267272 {
268273 USED(op, p);
269− return 0;
274+ return -1;
270275 }
271276
272277 static int
273278 pccurve(Op *op, Page *p)
274279 {
275280 USED(op, p);
276− return 0;
281+ return -1;
277282 }
278283
279284 static int
280285 pcsubpath(Op *op, Page *p)
281286 {
282287 USED(op, p);
283− return 0;
288+ return -1;
284289 }
285290
286291 static int
287292 pcrect(Op *op, Page *p)
288293 {
289294 USED(op, p);
290− return 0;
295+ return -1;
291296 }
292297
293298 static int
294299 ppstroke(Op *op, Page *p)
295300 {
296301 USED(op, p);
297− return 0;
302+ return -1;
298303 }
299304
300305 static int
301306 ppstrokec(Op *op, Page *p)
302307 {
303308 USED(op, p);
304− return 0;
309+ return -1;
305310 }
306311
307312 static int
308313 ppfill(Op *op, Page *p)
309314 {
310315 USED(op, p);
311− return 0;
316+ return -1;
312317 }
313318
314319 static int
315320 ppfills(Op *op, Page *p)
316321 {
317322 USED(op, p);
318− return 0;
323+ return -1;
319324 }
320325
321326 static int
322327 ppfillcfs(Op *op, Page *p)
323328 {
324329 USED(op, p);
325− return 0;
330+ return -1;
326331 }
327332
328333 static int
329334 ppc(Op *op, Page *p)
330335 {
331336 USED(op, p);
332− return 0;
337+ return -1;
333338 }
334339
335340 static int
336341 cpclip(Op *op, Page *p)
337342 {
338343 USED(op, p);
339− return 0;
344+ return -1;
340345 }
341346
342−char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"};
343−ColorSpace colorspacechans[] = {
347+static char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"};
348+static ColorSpace colorspacechans[] = {
344349 [1] = DeviceGray,
345350 [3] = DeviceRGB,
346351 [4] = DeviceCMYK,
@@ -350,14 +355,15 @@ static int · 3 unmodified lines
350355 iccbasedcspace(Object *icc, ColorSpace *c)
351356 {
352357 Object *o;
358+
353359 *c = colorspacechans[dictint(icc, "N")];
354360 if((o = dictget(icc, "Alternate")) != &null){
355361 if(*c > 2 || strcmp(colorspacedevices[*c], o->name) != 0){
356− werrstr("ICCBased cspace: TODO: handle non-device alternate '%s'", o->name);
357− return 0;
362+ werrstr("iccbasedcspace: TODO: handle non-device alternate %q", o->name);
363+ return -1;
358364 }
359365 }
360− return 1;
366+ return 0;
361367 }
362368
363369 static int
@@ -368,27 +374,29 @@ cspace(Op *op, Page *p) · 4 unmodified lines
368374 char *s = arrayget(p->stack, 0)->name;
369375 Object *o;
370376 int i;
371− for(i = 0; i < 3; i++)
377+
378+ for(i = 0; i < nelem(colorspacedevices); i++){
372379 if(strcmp(s, colorspacedevices[i]) == 0){
373380 *c = i;
374381 *color = i == 2 ? 0xFF : 0;
375− return 1;
382+ return 0;
376383 }
384+ }
377385 if((o = dictget(dictget(p->obj, "Resources"), "ColorSpace")) == &null
378386 || (o = dictget(o, s)) == &null){
379− werrstr("colorspace '%s' not found", s);
380− return 0;
387+ werrstr("colorspace not found: %q", s);
388+ return -1;
381389 }
382390 if(strcmp(arrayget(o, 0)->name, "ICCBased") == 0){
383391 /* Don't support ICC; fall back to Alternate or default */
384392 o = arrayget(o, 1);
385393 if(!iccbasedcspace(o, c))
386− return 0;
394+ return -1;
387395 *color = *c == 2 ? 0xFF : 0;
388− return 1;
396+ return 0;
389397 }
390− werrstr("cspace: TODO: %s color space", arrayget(o, 0)->name);
391− return 0;
398+ werrstr("cspace: TODO: color space %q", arrayget(o, 0)->name);
399+ return -1;
392400 }
393401
394402 static int
@@ -396,11 +404,12 @@ ccolour(Op *op, Page *p) · 1 unmodified line
396404 {
397405 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
398406 u32int *color = op->flags & Nonstroking ? &p->GSactive->NSC : &p->GSactive->SC;
407+
399408 if(c == DeviceRGB){
400409 *color = ((u8int)(255 * arrayget(p->stack, 0)->num.d)) << 24 | ((u8int)(255 * arrayget(p->stack, 1)->num.d)) << 16 | ((u8int)(255 * arrayget(p->stack, 2)->num.d)) << 8 | 0xff;
401− return 1;
410+ return 0;
402411 }
403− return 0;
412+ return -1;
404413 }
405414
406415 static int
@@ -409,19 +418,20 @@ ccolour2(Op *op, Page *p) · 2 unmodified lines
409418 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
410419 if(c < 3)
411420 return ccolour(op, p);
412− return 0;
421+ return -1;
413422 }
414423
415424 static int
416425 cgray(Op *op, Page *p)
417426 {
418427 int value = 255 * arrayget(p->stack, 0)->num.d;
419− int i;
420428 u32int *color;
429+ int i;
430+
421431 if(op->flags & Nonstroking){
422432 color = &p->GSactive->NSC;
423433 p->GSactive->NSCS = DeviceGray;
424− } else{
434+ }else{
425435 color = &p->GSactive->SC;
426436 p->GSactive->SCS = DeviceGray;
427437 }
@@ -429,56 +439,56 @@ cgray(Op *op, Page *p) · 1 unmodified line
429439 for(i = 0; i < 3; i++)
430440 *color = (*color | value) << 8;
431441 *color |= 255;
432− return 1;
442+ return 0;
433443 }
434444
435445 static int
436446 crgb(Op *op, Page *p)
437447 {
438448 USED(op, p);
439− return 0;
449+ return -1;
440450 }
441451
442452 static int
443453 ccmyk(Op *op, Page *p)
444454 {
445455 USED(op, p);
446− return 0;
456+ return -1;
447457 }
448458
449459 static int
450460 sshade(Op *op, Page *p)
451461 {
452462 USED(op, p);
453− return 0;
463+ return -1;
454464 }
455465
456466 static int
457467 eoobject(Op *op, Page *p)
458468 {
459469 USED(op, p);
460− return 0;
470+ return -1;
461471 }
462472
463473 static int
464474 iibegin(Op *op, Page *p)
465475 {
466476 USED(op, p);
467− return 0;
477+ return -1;
468478 }
469479
470480 static int
471481 iidata(Op *op, Page *p)
472482 {
473483 USED(op, p);
474− return 0;
484+ return -1;
475485 }
476486
477487 static int
478488 iiend(Op *op, Page *p)
479489 {
480490 USED(op, p);
481− return 0;
491+ return -1;
482492 }
483493
484494 static int
@@ -486,7 +496,7 @@ tsspace(Op *op, Page *p) · 1 unmodified line
486496 {
487497 USED(op);
488498 p->TS.Tc = arrayget(p->stack, 0)->num.d;
489− return 1;
499+ return 0;
490500 }
491501
492502 static int
@@ -494,14 +504,14 @@ tswspace(Op *op, Page *p) · 1 unmodified line
494504 {
495505 USED(op);
496506 p->TS.Tw = arrayget(p->stack, 0)->num.d;
497− return 1;
507+ return 0;
498508 }
499509
500510 static int
501511 tshscale(Op *op, Page *p)
502512 {
503513 USED(op, p);
504− return 0;
514+ return -1;
505515 }
506516
507517 static int
@@ -516,26 +526,30 @@ fontwidths(Page *p) · 8 unmodified lines
516526 {
517527 Object *o;
518528 int i;
529+
519530 if(p->GSactive->Font.widths != nil)
520531 free(p->GSactive->Font.widths);
532+ p->GSactive->Font.widths = nil;
533+ p->GSactive->Font.first = -1;
534+ p->GSactive->Font.last = -1;
521535 o = dictget(p->GSactive->Font.font, "FirstChar");
522536 if(o == nil)
523− return 1;
537+ return -1;
524538 p->GSactive->Font.first = o->num.i;
525539 p->GSactive->Font.last = dictget(p->GSactive->Font.font, "LastChar")->num.i;
526540 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
527541 if(p->GSactive->Font.widths == nil){
528− print("Failed to allocate for (%d, %d): %d\n", p->GSactive->Font.first, p->GSactive->Font.last, p->GSactive->Font.last - p->GSactive->Font.first + 1);
529− return 1;
542+ werrstr("memory");
543+ return -1;
530544 }
531545 o = dictget(p->GSactive->Font.font, "Widths");
532546 if(o == nil)
533− return 0;
547+ return -1;
534548 for(i = 0; i < arraylen(o); i++)
535549 p->GSactive->Font.widths[i] = arrayget(o, i)->num.i;
536550 o = dictget(p->GSactive->Font.font, "FontDescriptor");
537551 p->GSactive->Font.defwidth = dictget(o, "MissingWidth")->num.i;
538− return 1;
552+ return 0;
539553 }
540554
541555 static int
@@ -544,36 +558,36 @@ tsfontsz(Op *op, Page *p) · 2 unmodified lines
544558 char *name = arrayget(p->stack, 0)->name;
545559 p->GSactive->Font.font = dictget(dictget(dictget(p->obj, "Resources"), "Font"), name);
546560 if(p->GSactive->Font.font == nil){
547− werrstr("Font not found: '%s'", name);
548− return 0;
561+ werrstr("font not found: %q", name);
562+ return -1;
549563 }
550564 p->GSactive->Font.enc = dictget(p->GSactive->Font.font, "Encoding");
551565 if(p->GSactive->Font.enc)
552566 p->GSactive->Font.enc = dictget(p->GSactive->Font.enc, "Differences");
553567 p->GSactive->Font.size = arrayget(p->stack, 1)->num.d;
554− return fontwidths(p) && flagless(op);
568+ return (fontwidths(p) == 0 && flagless(op) == 0) ? 0 : -1;
555569 }
556570
557571 static int
558572 tsrendmode(Op *op, Page *p)
559573 {
560574 USED(op, p);
561− return 0;
575+ return -1;
562576 }
563577
564578 static int
565579 tsrise(Op *op, Page *p)
566580 {
567581 USED(op, p);
568− return 0;
582+ return -1;
569583 }
570584
571585 static int
572586 tobegin(Op *op, Page *p)
573587 {
574588 if(p->TS.inobj){
575− werrstr("Text objects must not be nested");
576− return 0;
589+ werrstr("tobegin: text objects must not be nested");
590+ return -1;
577591 }
578592 p->TS.inobj = 1;
579593 p->GSactive->Font.font = nil;
@@ -586,8 +600,8 @@ static int · 6 unmodified lines
586600 toend(Op *op, Page *p)
587601 {
588602 if(!p->TS.inobj){
589− werrstr("ET found without BT");
590− return 0;
603+ werrstr("toend: ET without BT");
604+ return -1;
591605 }
592606 p->TS.inobj = 0;
593607 return flagless(op);
@@ -597,6 +611,7 @@ static void · 3 unmodified lines
597611 tmove(Page *p, double x, double y, int tlm)
598612 {
599613 double *mat = tlm ? p->TS.Tlm : p->TS.Tm;
614+
600615 mattrans(mat, x, y, mat);
601616 if(tlm)
602617 memcpy(p->TS.Tm, p->TS.Tlm, sizeof(double) * 6);
@@ -606,18 +621,20 @@ static int · 3 unmodified lines
606621 tpmove(Op *op, Page *p)
607622 {
608623 Object *x, *y;
624+
609625 x = arrayget(p->stack, 0);
610626 y = arrayget(p->stack, 1);
611627 if(op->flags & Leading)
612628 p->TS.TL = -y->num.d;
613629 tmove(p, x->num.d, y->num.d, 1);
614− return 1;
630+ return 0;
615631 }
616632
617633 static int
618634 tpmatrix(Op *op, Page *p)
619635 {
620636 int i;
637+
621638 for(i = 0; i < 6; i++){
622639 p->TS.Tm[i] = arrayget(p->stack, i)->num.d;
623640 p->TS.Tlm[i] = p->TS.Tm[i];
@@ -638,6 +655,7 @@ writepatched(Page *p, uchar c) · 14 unmodified lines
638655 {
639656 int i, len, d = 0;
640657 Object *o;
658+
641659 if(p->GSactive->Font.enc != nil){
642660 len = arraylen(p->GSactive->Font.enc);
643661 for(i = 0; i < len; i++){
@@ -714,11 +732,11 @@ writepatched(Page *p, uchar c) · 70 unmodified lines
714732 if(strcmp(o->name, "arrowright") == 0)
715733 return bufput(&p->buf, (uchar*)"→", strlen("→")) == strlen("→");
716734 break;
717− } else
735+ }else
718736 d++;
719737 }
720738 }
721− return bufput(&p->buf, (uchar*)&c, 1) == 1;
739+ return bufput(&p->buf, (uchar*)&c, 1);
722740 }
723741
724742 // Returns glyph width in TEXT SPACE units.
@@ -753,6 +771,7 @@ tchar(Page *p, ulong c) · 28 unmodified lines
753771 Memimage *ink;
754772 double tx;
755773 int i;
774+
756775 /* Text rendering matrix converts coordinates from font space to device space */
757776 matscale(p->TS.Tm, Tfs, Tfs, Trm);
758777 matmult(Trm, p->GSactive->CTM, Trm);
@@ -761,22 +780,22 @@ tchar(Page *p, ulong c) · 2 unmodified lines
761780 if(p->TS.y != Trm[5]){
762781 for(i = 0; i < (int)((Trm[5] - p->TS.y) / p->GSactive->Font.size / 1.5) && i < 2; i++)
763782 if(bufput(&p->buf, (uchar*)"\n", 1) != 1)
764− return 0;
765− } else if(Trm[4] - p->TS.x > 5) {
783+ return -1;
784+ }else if(Trm[4] - p->TS.x > 5){
766785 if(bufput(&p->buf, (uchar*)" ", 1) != 1)
767− return 0;
786+ return -1;
768787 }
769788 }
770789 usize oend = p->buf.sz;
771790 if(!writepatched(p, c)){
772791 werrstr("tchar: failed to write character: %r");
773− return 0;
792+ return -1;
774793 }
775794 if(p->buf.b != nil){
776795 ink = allocmemimage(Rect(0,0,1,1),RGB24);
777796 if(ink == nil){
778797 werrstr("failed to allocate ink");
779− return 0;
798+ return -1;
780799 }
781800 ink->flags |= Frepl;
782801 ink->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
@@ -788,7 +807,7 @@ tchar(Page *p, ulong c) · 5 unmodified lines
788807 mattrans(p->TS.Tm, tx, 0, p->TS.Tm);
789808 p->TS.x = Trm[4] + tx;
790809 p->TS.y = Trm[5];
791− return 1;
810+ return 0;
792811 }
793812
794813 static int
@@ -797,8 +816,8 @@ tstr(Page *p, char *str, ulong len) · 2 unmodified lines
797816 ulong i;
798817 for(i = 0; i < len; i++)
799818 if(!tchar(p, str[i]))
800− return 0;
801− return 1;
819+ return -1;
820+ return 0;
802821 }
803822
804823 static int
@@ -806,14 +825,14 @@ thshow(Op *op, Page *p) · 1 unmodified line
806825 {
807826 if(op->flags & TwTc){
808827 werrstr("TODO thshow TwTc");
809− return 0;
828+ return -1;
810829 }
811830 if(op->flags & Nextline)
812831 tmove(p, 0, 0 - p->TS.TL, 1);
813832 Object *o = arrayget(p->stack, 0);
814833 if(!tstr(p, o->str, o->len))
815− return 0;
816− return 1;
834+ return -1;
835+ return 0;
817836 }
818837
819838 static int
@@ -821,13 +840,13 @@ thshowarr(Op *op, Page *p) · 1 unmodified line
821840 {
822841 Object *o, *arr = arrayget(p->stack, 0);
823842 int i;
843+
824844 for(i = 0; i < arraylen(arr); i++){
825845 o = arrayget(arr, i);
826846 if(o->type == Ostr){
827847 if(!tstr(p, o->str, o->len))
828848 return 0;
829− }
830− else {
849+ }else{
831850 mattrans(p->TS.Tm, 0 - (p->GSactive->Font.size * o->num.d / 1000), 0, p->TS.Tm);
832851 }
833852 }
@@ -838,14 +857,14 @@ static int · 4 unmodified lines
838857 t3width(Op *op, Page *p)
839858 {
840859 USED(op, p);
841− return 0;
860+ return -1;
842861 }
843862
844863 static int
845864 t3widthbb(Op *op, Page *p)
846865 {
847866 USED(op, p);
848− return 0;
867+ return -1;
849868 }
850869
851870 static int
@@ -859,7 +878,7 @@ t4add(Op *op, Page *p) · 7 unmodified lines
859878 s->num.d = x;
860879 s->num.i = x;
861880 */
862− return 0;
881+ return -1;
863882 }
864883
865884 static int
@@ -873,7 +892,7 @@ t4sub(Op *op, Page *p) · 7 unmodified lines
873892 s->num.d = x;
874893 s->num.i = x;
875894 */
876− return 0;
895+ return -1;
877896 }
878897
879898 static int
@@ -888,7 +907,7 @@ t4mul(Op *op, Page *p) · 8 unmodified lines
888907 s->num.d = x;
889908 s->num.i = x;
890909 */
891− return 0;
910+ return -1;
892911 }
893912
894913 static int
@@ -903,280 +922,280 @@ t4div(Op *op, Page *p) · 8 unmodified lines
903922 s->num.d = x;
904923 s->num.i = x;
905924 */
906− return 0;
925+ return -1;
907926 }
908927
909928 static int
910929 t4idiv(Op *op, Page *p)
911930 {
912931 USED(op, p);
913− return 0;
932+ return -1;
914933 }
915934
916935 static int
917936 t4mod(Op *op, Page *p)
918937 {
919938 USED(op, p);
920− return 0;
939+ return -1;
921940 }
922941
923942 static int
924943 t4neg(Op *op, Page *p)
925944 {
926945 USED(op, p);
927− return 0;
946+ return -1;
928947 }
929948
930949 static int
931950 t4abs(Op *op, Page *p)
932951 {
933952 USED(op, p);
934− return 0;
953+ return -1;
935954 }
936955
937956 static int
938957 t4ceiling(Op *op, Page *p)
939958 {
940959 USED(op, p);
941− return 0;
960+ return -1;
942961 }
943962
944963 static int
945964 t4floor(Op *op, Page *p)
946965 {
947966 USED(op, p);
948− return 0;
967+ return -1;
949968 }
950969
951970 static int
952971 t4round(Op *op, Page *p)
953972 {
954973 USED(op, p);
955− return 0;
974+ return -1;
956975 }
957976
958977 static int
959978 t4truncate(Op *op, Page *p)
960979 {
961980 USED(op, p);
962− return 0;
981+ return -1;
963982 }
964983
965984 static int
966985 t4sqrt(Op *op, Page *p)
967986 {
968987 USED(op, p);
969− return 0;
988+ return -1;
970989 }
971990
972991 static int
973992 t4sin(Op *op, Page *p)
974993 {
975994 USED(op, p);
976− return 0;
995+ return -1;
977996 }
978997
979998 static int
980999 t4cos(Op *op, Page *p)
9811000 {
9821001 USED(op, p);
983− return 0;
1002+ return -1;
9841003 }
9851004
9861005 static int
9871006 t4atan(Op *op, Page *p)
9881007 {
9891008 USED(op, p);
990− return 0;
1009+ return -1;
9911010 }
9921011
9931012 static int
9941013 t4exp(Op *op, Page *p)
9951014 {
9961015 USED(op, p);
997− return 0;
1016+ return -1;
9981017 }
9991018
10001019 static int
10011020 t4ln(Op *op, Page *p)
10021021 {
10031022 USED(op, p);
1004− return 0;
1023+ return -1;
10051024 }
10061025
10071026 static int
10081027 t4log(Op *op, Page *p)
10091028 {
10101029 USED(op, p);
1011− return 0;
1030+ return -1;
10121031 }
10131032
10141033 static int
10151034 t4cvi(Op *op, Page *p)
10161035 {
10171036 USED(op, p);
1018− return 0;
1037+ return -1;
10191038 }
10201039
10211040 static int
10221041 t4cvr(Op *op, Page *p)
10231042 {
10241043 USED(op, p);
1025− return 0;
1044+ return -1;
10261045 }
10271046
10281047 static int
10291048 t4eq(Op *op, Page *p)
10301049 {
10311050 USED(op, p);
1032− return 0;
1051+ return -1;
10331052 }
10341053
10351054 static int
10361055 t4ne(Op *op, Page *p)
10371056 {
10381057 USED(op, p);
1039− return 0;
1058+ return -1;
10401059 }
10411060
10421061 static int
10431062 t4gt(Op *op, Page *p)
10441063 {
10451064 USED(op, p);
1046− return 0;
1065+ return -1;
10471066 }
10481067
10491068 static int
10501069 t4ge(Op *op, Page *p)
10511070 {
10521071 USED(op, p);
1053− return 0;
1072+ return -1;
10541073 }
10551074
10561075 static int
10571076 t4lt(Op *op, Page *p)
10581077 {
10591078 USED(op, p);
1060− return 0;
1079+ return -1;
10611080 }
10621081
10631082 static int
10641083 t4le(Op *op, Page *p)
10651084 {
10661085 USED(op, p);
1067− return 0;
1086+ return -1;
10681087 }
10691088
10701089 static int
10711090 t4and(Op *op, Page *p)
10721091 {
10731092 USED(op, p);
1074− return 0;
1093+ return -1;
10751094 }
10761095
10771096 static int
10781097 t4or(Op *op, Page *p)
10791098 {
10801099 USED(op, p);
1081− return 0;
1100+ return -1;
10821101 }
10831102
10841103 static int
10851104 t4xor(Op *op, Page *p)
10861105 {
10871106 USED(op, p);
1088− return 0;
1107+ return -1;
10891108 }
10901109
10911110 static int
10921111 t4not(Op *op, Page *p)
10931112 {
10941113 USED(op, p);
1095− return 0;
1114+ return -1;
10961115 }
10971116
10981117 static int
10991118 t4bitshift(Op *op, Page *p)
11001119 {
11011120 USED(op, p);
1102− return 0;
1121+ return -1;
11031122 }
11041123
11051124 static int
11061125 t4true(Op *op, Page *p)
11071126 {
11081127 USED(op, p);
1109− return 0;
1128+ return -1;
11101129 }
11111130
11121131 static int
11131132 t4false(Op *op, Page *p)
11141133 {
11151134 USED(op, p);
1116− return 0;
1135+ return -1;
11171136 }
11181137
11191138 static int
11201139 t4if(Op *op, Page *p)
11211140 {
11221141 USED(op, p);
1123− return 0;
1142+ return -1;
11241143 }
11251144
11261145 static int
11271146 t4ifelse(Op *op, Page *p)
11281147 {
11291148 USED(op, p);
1130− return 0;
1149+ return -1;
11311150 }
11321151
11331152 static int
11341153 t4pop(Op *op, Page *p)
11351154 {
11361155 USED(op, p);
1137− return 0;
1156+ return -1;
11381157 }
11391158
11401159 static int
11411160 t4exch(Op *op, Page *p)
11421161 {
11431162 USED(op, p);
1144− return 0;
1163+ return -1;
11451164 }
11461165
11471166 static int
11481167 t4dup(Op *op, Page *p)
11491168 {
11501169 USED(op, p);
1151− return 0;
1170+ return -1;
11521171 }
11531172
11541173 static int
11551174 t4copy(Op *op, Page *p)
11561175 {
11571176 USED(op, p);
1158− return 0;
1177+ return -1;
11591178 }
11601179
11611180 static int
11621181 t4index(Op *op, Page *p)
11631182 {
11641183 USED(op, p);
1165− return 0;
1184+ return -1;
11661185 }
11671186
11681187 static int
11691188 t4roll(Op *op, Page *p)
11701189 {
11711190 USED(op, p);
1172− return 0;
1191+ return -1;
11731192 }
11741193
11751194 static int
11761195 opignore(Op *op, Page *p)
11771196 {
11781197 USED(op, p);
1179− return 0;
1198+ return -1;
11801199 }
11811200
11821201 static Op ops[] = {
@@ -1426,6 +1445,7 @@ void · 243 unmodified lines
14261445 pagegsclean(Page *p)
14271446 {
14281447 int i;
1448+
14291449 if(p->GSactive != nil){
14301450 p->GSactive = nil;
14311451 for(i = 0; i < p->nGS; i++)
@@ -1441,7 +1461,7 @@ stackreset(Page *p) · 9 unmodified lines
14411461 {
14421462 pdfobjfree(p->stack);
14431463 p->stack = arraynew(p->obj->pdf);
1444− return p->stack != nil;
1464+ return p->stack != nil ? 0 : -1;
14451465 }
14461466
14471467 void
@@ -1458,14 +1478,15 @@ pagerendercontent(Page *p, Object *content) · 10 unmodified lines
14581478 Stream *s;
14591479 Object *o;
14601480 Op *op;
1461− s = Sopen(content);
1462− if(s == nil){
1463− fprint(2, "%O\n", content);
1464− sysfatal("%r");
1481+
1482+ o = nil;
1483+ if((s = Sopen(content)) == nil){
1484+ werrstr("content: %O", content);
1485+ goto err;
14651486 }
14661487 p->stack = arraynew(content->pdf);
14671488 if(p->stack == nil)
1468− return 0;
1489+ goto err;
14691490 while(s->buf.off != s->buf.sz){
14701491 while(isws(s->buf.b[s->buf.off]) && s->buf.off != s->buf.sz)
14711492 s->buf.off++;
@@ -1473,36 +1494,38 @@ pagerendercontent(Page *p, Object *content) · 1 unmodified line
14731494 break;
14741495 o = pdfobj(content->pdf, s, 0);
14751496 if(o == nil){
1476− werrstr("pagerendercontent: failed to parse op: %r");
1477− return 0;
1497+ werrstr("failed to parse op: %r");
1498+ goto err;
14781499 }
14791500 if(o->type == Oop){
14801501 op = opfind(o->str);
1481− if(op == nil){
1482− fprint(2, "Unknown op: %s\n", o->str);
1483− pdfobjfree(o);
1484− return 0;
1485− }
14861502 pdfobjfree(o);
1487− werrstr("unimplemented or error not reported properly");
1488− if(!op->f(op, p)){
1489− werrstr("renderer: %s failed: %r", op->s);
1490− fprint(2, "%r\n");
1491− // return 0;
1503+ o = nil;
1504+ if(op == nil){
1505+ werrstr("unknown op: %s\n", o->str);
1506+ goto err;
14921507 }
1493− if(!stackreset(p))
1494− return 0;
1495− } else{
1496− if(!arrayadd(p->stack, o)){
1497− fprint(2, "Failed to push operand to stack: %r\n");
1498− return 0;
1508+ if(op->f(op, p) != 0){
1509+ werrstr("%s failed: %r", op->s);
1510+ goto err;
14991511 }
1512+ if(stackreset(p) != 0)
1513+ goto err;
1514+ }else{
1515+ if(arrayadd(p->stack, o) != 0)
1516+ goto err;
15001517 }
15011518 }
1502− if(bufput(&p->buf, (uchar*)"\n\0", 2) != 2)
1503− return 0;
1519+ if(bufput(&p->buf, (uchar*)"\n", 2) != 2)
1520+ goto err;
15041521 Sclose(s);
1505− return 1;
1522+
1523+ return 0;
1524+err:
1525+ werrstr("pagerendercontent: %r");
1526+ pdfobjfree(o);
1527+ Sclose(s);
1528+ return -1;
15061529 }
15071530
15081531 int
@@ -1510,29 +1533,32 @@ pagerender(Page *p) · 1 unmodified line
15101533 {
15111534 Object *content;
15121535 int i;
1536+
15131537 p->nGS = 1;
1514− p->GS = malloc(sizeof(GS));
1538+ p->GS = malloc(sizeof(*p->GS));
15151539 if(p->GS == nil){
1516− werrstr("Out of memory");
1517− return 0;
1540+ werrstr("memory");
1541+ goto err;
15181542 }
15191543 p->GSactive = p->GS;
15201544 gsinit(p, p->GS);
15211545 if((p->image = allocmemimage(Rect(0,0,1100,1300), strtochan("r8g8b8"))) == nil){
1522− werrstr("unable to allocate image: %r");
1523− pagegsclean(p);
1524− return 0;
1546+ werrstr("allocmemimage: %r");
1547+ goto err;
15251548 }
1526− memfillcolor(p->image, 0xFFFFFFFF);
1549+ memfillcolor(p->image, DWhite);
15271550 content = dictget(p->obj, "Contents");
15281551 if(content->type == Oarray){
1529− for(i = 0; i < arraylen(content); i++)
1530− if(!pagerendercontent(p, arrayget(content, i)))
1531− return 0;
1532− }
1533− else if(content->type != Onull)
1534− if(!pagerendercontent(p, content))
1535− return 0;
1552+ for(i = 0; i < arraylen(content); i++){
1553+ if(pagerendercontent(p, arrayget(content, i)) != 0)
1554+ goto err;
1555+ }
1556+ }else if(content->type != Onull && pagerendercontent(p, content) != 0)
1557+ goto err;
1558+ pagegsclean(p);
1559+
1560+ return 0;
1561+err:
15361562 pagegsclean(p);
1537− return 1;
1563+ return -1;
15381564 }

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