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
24 Page p;24 Page p;
25 25
26 pageinit(&p, page);26 pageinit(&p, page);
27 ret = pagerender(&p);27 if((ret = pagerender(&p)) == 0){
28 if(ret){28 if(!text)
29 if(text){
30 if(p.buf.sz != 0)
31 fprint(1, "%s", (char*)p.buf.b);
32 }else
33 writememimage(1, p.image);29 writememimage(1, p.image);
30 else if(p.buf.sz != 0)
31 print("%s", (char*)p.buf.b);
34 }32 }
35 pagefree(&p);33 pagefree(&p);
36 34
op.c+216−190
@@ -71,33 +71,34 @@ static int · 70 unmodified lines
71flagless(Op *op)71flagless(Op *op)
72{72{
73 if(op->flags != 0){73 if(op->flags != 0){
74 fprint(2, "Op '%s' expected no flags\n", op->s);74 werrstr("op %q: expected no flags", op->s);
75 return 0;75 return -1;
76 }76 }
77 return 1;77 return 0;
78}78}
79 79
80static int80static int
81cobegin(Op *op, Page *p)81cobegin(Op *op, Page *p)
82{82{
83 USED(op, p);83 USED(op, p);
84 return 0;84 return -1;
85}85}
86 86
87static int87static int
88coend(Op *op, Page *p)88coend(Op *op, Page *p)
89{89{
90 USED(op, p);90 USED(op, p);
91 return 0;91 return -1;
92}92}
93 93
94static int94static int
95gspush(Op *op, Page *p)95gspush(Op *op, Page *p)
96{96{
97 GS *r;
98
97 USED(op);99 USED(op);
98 GS *r = realloc(p->GS, sizeof(GS) * (p->nGS + 1));100 if((r = realloc(p->GS, sizeof(GS) * (p->nGS + 1))) == nil)
99 if(r == nil)101 return -1;
100 return 0;
101 p->GS = r;102 p->GS = r;
102 p->nGS++;103 p->nGS++;
103 p->GSactive = &p->GS[p->nGS - 1];104 p->GSactive = &p->GS[p->nGS - 1];
@@ -106,11 +107,11 @@ gspush(Op *op, Page *p) · 2 unmodified lines
106 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));107 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
107 if(p->GSactive->Font.widths == nil){108 if(p->GSactive->Font.widths == nil){
108 werrstr("gspush: out of memory allocating space for glyph widths");109 werrstr("gspush: out of memory allocating space for glyph widths");
109 return 0;110 return -1;
110 }111 }
111 memcpy(p->GSactive->Font.widths, p->GS[p->nGS - 2].Font.widths, sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));112 memcpy(p->GSactive->Font.widths, p->GS[p->nGS - 2].Font.widths, sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
112 }113 }
113 return 1;114 return 0;
114}115}
115 116
116static int117static int
@@ -120,11 +121,11 @@ gspop(Op *op, Page *p) · 3 unmodified lines
120 free(p->GSactive->Font.widths);121 free(p->GSactive->Font.widths);
121 GS *r = realloc(p->GS, sizeof(GS) * (p->nGS - 1));122 GS *r = realloc(p->GS, sizeof(GS) * (p->nGS - 1));
122 if(r == nil)123 if(r == nil)
123 return 0;124 return -1;
124 p->GS = r;125 p->GS = r;
125 p->nGS--;126 p->nGS--;
126 p->GSactive = &p->GS[p->nGS - 1];127 p->GSactive = &p->GS[p->nGS - 1];
127 return 1;128 return 0;
128}129}
129 130
130/* six parameters give the inputs a,b,c,d,e,f for the matrix131/* 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
140{141{
141 double input[6];142 double input[6];
142 int i;143 int i;
144
143 for(i = 0; i < 6; i++)145 for(i = 0; i < 6; i++)
144 input[i] = arrayget(p->stack, i)->num.d;146 input[i] = arrayget(p->stack, i)->num.d;
145 matmult(input, p->GSactive->CTM, p->GSactive->CTM);147 matmult(input, p->GSactive->CTM, p->GSactive->CTM);
@@ -151,8 +153,8 @@ gswidth(Op *op, Page *p) · 5 unmodified lines
151{153{
152 p->GSactive->LW = arrayget(p->stack, 0)->num.d;154 p->GSactive->LW = arrayget(p->stack, 0)->num.d;
153 if(p->GSactive->LW < 0){155 if(p->GSactive->LW < 0){
154 werrstr("line width cannot be negative: %f", p->GSactive->LW);156 werrstr("gswidth: invalid line width: %f", p->GSactive->LW);
155 return 0;157 return -1;
156 }158 }
157 return flagless(op);159 return flagless(op);
158}160}
@@ -162,8 +164,8 @@ gscap(Op *op, Page *p) · 3 unmodified lines
162{164{
163 p->GSactive->LC = arrayget(p->stack, 0)->num.d;165 p->GSactive->LC = arrayget(p->stack, 0)->num.d;
164 if(p->GSactive->LC > CapEND){166 if(p->GSactive->LC > CapEND){
165 werrstr("invalid line cap: %d", p->GSactive->LC);167 werrstr("gscap: invalid line cap: %d", p->GSactive->LC);
166 return 0;168 return -1;
167 }169 }
168 return flagless(op);170 return flagless(op);
169}171}
@@ -173,8 +175,8 @@ gsjoin(Op *op, Page *p) · 3 unmodified lines
173{175{
174 p->GSactive->LJ = arrayget(p->stack, 0)->num.d;176 p->GSactive->LJ = arrayget(p->stack, 0)->num.d;
175 if(p->GSactive->LJ > JoinEND){177 if(p->GSactive->LJ > JoinEND){
176 werrstr("invalid line join: %d", p->GSactive->LJ);178 werrstr("gsjoin: invalid line join: %d", p->GSactive->LJ);
177 return 0;179 return -1;
178 }180 }
179 return flagless(op);181 return flagless(op);
180}182}
@@ -184,8 +186,8 @@ gsmiterlim(Op *op, Page *p) · 3 unmodified lines
184{186{
185 p->GSactive->ML = arrayget(p->stack, 0)->num.d;187 p->GSactive->ML = arrayget(p->stack, 0)->num.d;
186 if(p->GSactive->ML < 0){188 if(p->GSactive->ML < 0){
187 werrstr("miter limit cannot be negative: %f", p->GSactive->ML);189 werrstr("gsmiterlim: invalidmiter limit: %f", p->GSactive->ML);
188 return 0;190 return -1;
189 }191 }
190 return flagless(op);192 return flagless(op);
191}193}
@@ -194,14 +196,14 @@ static int · 2 unmodified lines
194gsdash(Op *op, Page *p)196gsdash(Op *op, Page *p)
195{197{
196 USED(op, p);198 USED(op, p);
197 return 0;199 return -1;
198}200}
199 201
200static int202static int
201gsintent(Op *op, Page *p)203gsintent(Op *op, Page *p)
202{204{
203 USED(op, p);205 USED(op, p);
204 return 0;206 return -1;
205}207}
206 208
207static int209static int
@@ -218,129 +220,132 @@ gsstate(Op *op, Page *p) · 10 unmodified lines
218 Object *gs, *o;220 Object *gs, *o;
219 if((gs = dictget(dictget(dictget(p->obj, "Resources"), "ExtGState"), name)) == &null){221 if((gs = dictget(dictget(dictget(p->obj, "Resources"), "ExtGState"), name)) == &null){
220 werrstr("extgstate dictionary not found: %s", name);222 werrstr("extgstate dictionary not found: %s", name);
221 return 0;223 goto err;
222 }224 }
223 if((o = dictget(gs, "Type")) != &null && strcmp(o->name, "ExtGState") != 0){225 if((o = dictget(gs, "Type")) != &null && strcmp(o->name, "ExtGState") != 0){
224 werrstr("invalid type on ExtGState object: %s", o->name);226 werrstr("invalid type on ExtGState object: %s", o->name);
225 return 0;227 goto err;
226 }228 }
227 if((o = dictget(gs, "LW")) != &null){229 if((o = dictget(gs, "LW")) != &null){
228 if(o->type != Onum){230 if(o->type != Onum){
229 werrstr("line width must be a number, %d", o->type);231 werrstr("line width is not a number");
230 return 0;232 goto err;
231 }233 }
232 p->GSactive->LW = o->num.d;234 p->GSactive->LW = o->num.d;
233 }235 }
234 if((o = dictget(gs, "LC")) != &null){236 if((o = dictget(gs, "LC")) != &null){
235 if(o->type != Onum){237 if(o->type != Onum){
236 werrstr("line cap must be a number");238 werrstr("line cap is not a number");
237 return 0;239 goto err;
238 }240 }
239 p->GSactive->LC = o->num.i;241 p->GSactive->LC = o->num.i;
240 }242 }
241 if((o = dictget(gs, "LJ")) != &null){243 if((o = dictget(gs, "LJ")) != &null){
242 if(o->type != Onum){244 if(o->type != Onum){
243 werrstr("line join must be a number");245 werrstr("line join is not a number");
244 return 0;246 goto err;
245 }247 }
246 p->GSactive->LJ = o->num.i;248 p->GSactive->LJ = o->num.i;
247 }249 }
248 if((o = dictget(gs, "ML")) != &null){250 if((o = dictget(gs, "ML")) != &null){
249 if(o->type != Onum){251 if(o->type != Onum){
250 werrstr("miter limit must be a number");252 werrstr("miter limit is not a number");
251 return 0;253 goto err;
252 }254 }
253 p->GSactive->ML = o->num.d;255 p->GSactive->ML = o->num.d;
254 }256 }
255 return flagless(op);257 return flagless(op);
258err:
259 werrstr("gsstate: %r");
260 return -1;
256}261}
257 262
258static int263static int
259pcmove(Op *op, Page *p)264pcmove(Op *op, Page *p)
260{265{
261 USED(op, p);266 USED(op, p);
262 return 0;267 return -1;
263}268}
264 269
265static int270static int
266pcline(Op *op, Page *p)271pcline(Op *op, Page *p)
267{272{
268 USED(op, p);273 USED(op, p);
269 return 0;274 return -1;
270}275}
271 276
272static int277static int
273pccurve(Op *op, Page *p)278pccurve(Op *op, Page *p)
274{279{
275 USED(op, p);280 USED(op, p);
276 return 0;281 return -1;
277}282}
278 283
279static int284static int
280pcsubpath(Op *op, Page *p)285pcsubpath(Op *op, Page *p)
281{286{
282 USED(op, p);287 USED(op, p);
283 return 0;288 return -1;
284}289}
285 290
286static int291static int
287pcrect(Op *op, Page *p)292pcrect(Op *op, Page *p)
288{293{
289 USED(op, p);294 USED(op, p);
290 return 0;295 return -1;
291}296}
292 297
293static int298static int
294ppstroke(Op *op, Page *p)299ppstroke(Op *op, Page *p)
295{300{
296 USED(op, p);301 USED(op, p);
297 return 0;302 return -1;
298}303}
299 304
300static int305static int
301ppstrokec(Op *op, Page *p)306ppstrokec(Op *op, Page *p)
302{307{
303 USED(op, p);308 USED(op, p);
304 return 0;309 return -1;
305}310}
306 311
307static int312static int
308ppfill(Op *op, Page *p)313ppfill(Op *op, Page *p)
309{314{
310 USED(op, p);315 USED(op, p);
311 return 0;316 return -1;
312}317}
313 318
314static int319static int
315ppfills(Op *op, Page *p)320ppfills(Op *op, Page *p)
316{321{
317 USED(op, p);322 USED(op, p);
318 return 0;323 return -1;
319}324}
320 325
321static int326static int
322ppfillcfs(Op *op, Page *p)327ppfillcfs(Op *op, Page *p)
323{328{
324 USED(op, p);329 USED(op, p);
325 return 0;330 return -1;
326}331}
327 332
328static int333static int
329ppc(Op *op, Page *p)334ppc(Op *op, Page *p)
330{335{
331 USED(op, p);336 USED(op, p);
332 return 0;337 return -1;
333}338}
334 339
335static int340static int
336cpclip(Op *op, Page *p)341cpclip(Op *op, Page *p)
337{342{
338 USED(op, p);343 USED(op, p);
339 return 0;344 return -1;
340}345}
341 346
342char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"};347static char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"};
343ColorSpace colorspacechans[] = {348static ColorSpace colorspacechans[] = {
344 [1] = DeviceGray,349 [1] = DeviceGray,
345 [3] = DeviceRGB,350 [3] = DeviceRGB,
346 [4] = DeviceCMYK,351 [4] = DeviceCMYK,
@@ -350,14 +355,15 @@ static int · 3 unmodified lines
350iccbasedcspace(Object *icc, ColorSpace *c)355iccbasedcspace(Object *icc, ColorSpace *c)
351{356{
352 Object *o;357 Object *o;
358
353 *c = colorspacechans[dictint(icc, "N")];359 *c = colorspacechans[dictint(icc, "N")];
354 if((o = dictget(icc, "Alternate")) != &null){360 if((o = dictget(icc, "Alternate")) != &null){
355 if(*c > 2 || strcmp(colorspacedevices[*c], o->name) != 0){361 if(*c > 2 || strcmp(colorspacedevices[*c], o->name) != 0){
356 werrstr("ICCBased cspace: TODO: handle non-device alternate '%s'", o->name);362 werrstr("iccbasedcspace: TODO: handle non-device alternate %q", o->name);
357 return 0;363 return -1;
358 }364 }
359 }365 }
360 return 1;366 return 0;
361}367}
362 368
363static int369static int
@@ -368,27 +374,29 @@ cspace(Op *op, Page *p) · 4 unmodified lines
368 char *s = arrayget(p->stack, 0)->name;374 char *s = arrayget(p->stack, 0)->name;
369 Object *o;375 Object *o;
370 int i;376 int i;
371 for(i = 0; i < 3; i++)377
378 for(i = 0; i < nelem(colorspacedevices); i++){
372 if(strcmp(s, colorspacedevices[i]) == 0){379 if(strcmp(s, colorspacedevices[i]) == 0){
373 *c = i;380 *c = i;
374 *color = i == 2 ? 0xFF : 0;381 *color = i == 2 ? 0xFF : 0;
375 return 1;382 return 0;
376 }383 }
384 }
377 if((o = dictget(dictget(p->obj, "Resources"), "ColorSpace")) == &null385 if((o = dictget(dictget(p->obj, "Resources"), "ColorSpace")) == &null
378 || (o = dictget(o, s)) == &null){386 || (o = dictget(o, s)) == &null){
379 werrstr("colorspace '%s' not found", s);387 werrstr("colorspace not found: %q", s);
380 return 0;388 return -1;
381 }389 }
382 if(strcmp(arrayget(o, 0)->name, "ICCBased") == 0){390 if(strcmp(arrayget(o, 0)->name, "ICCBased") == 0){
383 /* Don't support ICC; fall back to Alternate or default */391 /* Don't support ICC; fall back to Alternate or default */
384 o = arrayget(o, 1);392 o = arrayget(o, 1);
385 if(!iccbasedcspace(o, c))393 if(!iccbasedcspace(o, c))
386 return 0;394 return -1;
387 *color = *c == 2 ? 0xFF : 0;395 *color = *c == 2 ? 0xFF : 0;
388 return 1;396 return 0;
389 }397 }
390 werrstr("cspace: TODO: %s color space", arrayget(o, 0)->name);398 werrstr("cspace: TODO: color space %q", arrayget(o, 0)->name);
391 return 0;399 return -1;
392}400}
393 401
394static int402static int
@@ -396,11 +404,12 @@ ccolour(Op *op, Page *p) · 1 unmodified line
396{404{
397 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;405 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
398 u32int *color = op->flags & Nonstroking ? &p->GSactive->NSC : &p->GSactive->SC;406 u32int *color = op->flags & Nonstroking ? &p->GSactive->NSC : &p->GSactive->SC;
407
399 if(c == DeviceRGB){408 if(c == DeviceRGB){
400 *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;409 *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;
402 }411 }
403 return 0;412 return -1;
404}413}
405 414
406static int415static int
@@ -409,19 +418,20 @@ ccolour2(Op *op, Page *p) · 2 unmodified lines
409 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;418 ColorSpace c = op->flags & Nonstroking ? p->GSactive->NSCS : p->GSactive->SCS;
410 if(c < 3)419 if(c < 3)
411 return ccolour(op, p);420 return ccolour(op, p);
412 return 0;421 return -1;
413}422}
414 423
415static int424static int
416cgray(Op *op, Page *p)425cgray(Op *op, Page *p)
417{426{
418 int value = 255 * arrayget(p->stack, 0)->num.d;427 int value = 255 * arrayget(p->stack, 0)->num.d;
419 int i;
420 u32int *color;428 u32int *color;
429 int i;
430
421 if(op->flags & Nonstroking){431 if(op->flags & Nonstroking){
422 color = &p->GSactive->NSC;432 color = &p->GSactive->NSC;
423 p->GSactive->NSCS = DeviceGray;433 p->GSactive->NSCS = DeviceGray;
424 } else{434 }else{
425 color = &p->GSactive->SC;435 color = &p->GSactive->SC;
426 p->GSactive->SCS = DeviceGray;436 p->GSactive->SCS = DeviceGray;
427 }437 }
@@ -429,56 +439,56 @@ cgray(Op *op, Page *p) · 1 unmodified line
429 for(i = 0; i < 3; i++)439 for(i = 0; i < 3; i++)
430 *color = (*color | value) << 8;440 *color = (*color | value) << 8;
431 *color |= 255;441 *color |= 255;
432 return 1;442 return 0;
433}443}
434 444
435static int445static int
436crgb(Op *op, Page *p)446crgb(Op *op, Page *p)
437{447{
438 USED(op, p);448 USED(op, p);
439 return 0;449 return -1;
440}450}
441 451
442static int452static int
443ccmyk(Op *op, Page *p)453ccmyk(Op *op, Page *p)
444{454{
445 USED(op, p);455 USED(op, p);
446 return 0;456 return -1;
447}457}
448 458
449static int459static int
450sshade(Op *op, Page *p)460sshade(Op *op, Page *p)
451{461{
452 USED(op, p);462 USED(op, p);
453 return 0;463 return -1;
454}464}
455 465
456static int466static int
457eoobject(Op *op, Page *p)467eoobject(Op *op, Page *p)
458{468{
459 USED(op, p);469 USED(op, p);
460 return 0;470 return -1;
461}471}
462 472
463static int473static int
464iibegin(Op *op, Page *p)474iibegin(Op *op, Page *p)
465{475{
466 USED(op, p);476 USED(op, p);
467 return 0;477 return -1;
468}478}
469 479
470static int480static int
471iidata(Op *op, Page *p)481iidata(Op *op, Page *p)
472{482{
473 USED(op, p);483 USED(op, p);
474 return 0;484 return -1;
475}485}
476 486
477static int487static int
478iiend(Op *op, Page *p)488iiend(Op *op, Page *p)
479{489{
480 USED(op, p);490 USED(op, p);
481 return 0;491 return -1;
482}492}
483 493
484static int494static int
@@ -486,7 +496,7 @@ tsspace(Op *op, Page *p) · 1 unmodified line
486{496{
487 USED(op);497 USED(op);
488 p->TS.Tc = arrayget(p->stack, 0)->num.d;498 p->TS.Tc = arrayget(p->stack, 0)->num.d;
489 return 1;499 return 0;
490}500}
491 501
492static int502static int
@@ -494,14 +504,14 @@ tswspace(Op *op, Page *p) · 1 unmodified line
494{504{
495 USED(op);505 USED(op);
496 p->TS.Tw = arrayget(p->stack, 0)->num.d;506 p->TS.Tw = arrayget(p->stack, 0)->num.d;
497 return 1;507 return 0;
498}508}
499 509
500static int510static int
501tshscale(Op *op, Page *p)511tshscale(Op *op, Page *p)
502{512{
503 USED(op, p);513 USED(op, p);
504 return 0;514 return -1;
505}515}
506 516
507static int517static int
@@ -516,26 +526,30 @@ fontwidths(Page *p) · 8 unmodified lines
516{526{
517 Object *o;527 Object *o;
518 int i;528 int i;
529
519 if(p->GSactive->Font.widths != nil)530 if(p->GSactive->Font.widths != nil)
520 free(p->GSactive->Font.widths);531 free(p->GSactive->Font.widths);
532 p->GSactive->Font.widths = nil;
533 p->GSactive->Font.first = -1;
534 p->GSactive->Font.last = -1;
521 o = dictget(p->GSactive->Font.font, "FirstChar");535 o = dictget(p->GSactive->Font.font, "FirstChar");
522 if(o == nil)536 if(o == nil)
523 return 1;537 return -1;
524 p->GSactive->Font.first = o->num.i;538 p->GSactive->Font.first = o->num.i;
525 p->GSactive->Font.last = dictget(p->GSactive->Font.font, "LastChar")->num.i;539 p->GSactive->Font.last = dictget(p->GSactive->Font.font, "LastChar")->num.i;
526 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));540 p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
527 if(p->GSactive->Font.widths == nil){541 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);542 werrstr("memory");
529 return 1;543 return -1;
530 }544 }
531 o = dictget(p->GSactive->Font.font, "Widths");545 o = dictget(p->GSactive->Font.font, "Widths");
532 if(o == nil)546 if(o == nil)
533 return 0;547 return -1;
534 for(i = 0; i < arraylen(o); i++)548 for(i = 0; i < arraylen(o); i++)
535 p->GSactive->Font.widths[i] = arrayget(o, i)->num.i;549 p->GSactive->Font.widths[i] = arrayget(o, i)->num.i;
536 o = dictget(p->GSactive->Font.font, "FontDescriptor");550 o = dictget(p->GSactive->Font.font, "FontDescriptor");
537 p->GSactive->Font.defwidth = dictget(o, "MissingWidth")->num.i;551 p->GSactive->Font.defwidth = dictget(o, "MissingWidth")->num.i;
538 return 1;552 return 0;
539}553}
540 554
541static int555static int
@@ -544,36 +558,36 @@ tsfontsz(Op *op, Page *p) · 2 unmodified lines
544 char *name = arrayget(p->stack, 0)->name;558 char *name = arrayget(p->stack, 0)->name;
545 p->GSactive->Font.font = dictget(dictget(dictget(p->obj, "Resources"), "Font"), name);559 p->GSactive->Font.font = dictget(dictget(dictget(p->obj, "Resources"), "Font"), name);
546 if(p->GSactive->Font.font == nil){560 if(p->GSactive->Font.font == nil){
547 werrstr("Font not found: '%s'", name);561 werrstr("font not found: %q", name);
548 return 0;562 return -1;
549 }563 }
550 p->GSactive->Font.enc = dictget(p->GSactive->Font.font, "Encoding");564 p->GSactive->Font.enc = dictget(p->GSactive->Font.font, "Encoding");
551 if(p->GSactive->Font.enc)565 if(p->GSactive->Font.enc)
552 p->GSactive->Font.enc = dictget(p->GSactive->Font.enc, "Differences");566 p->GSactive->Font.enc = dictget(p->GSactive->Font.enc, "Differences");
553 p->GSactive->Font.size = arrayget(p->stack, 1)->num.d;567 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;
555}569}
556 570
557static int571static int
558tsrendmode(Op *op, Page *p)572tsrendmode(Op *op, Page *p)
559{573{
560 USED(op, p);574 USED(op, p);
561 return 0;575 return -1;
562}576}
563 577
564static int578static int
565tsrise(Op *op, Page *p)579tsrise(Op *op, Page *p)
566{580{
567 USED(op, p);581 USED(op, p);
568 return 0;582 return -1;
569}583}
570 584
571static int585static int
572tobegin(Op *op, Page *p)586tobegin(Op *op, Page *p)
573{587{
574 if(p->TS.inobj){588 if(p->TS.inobj){
575 werrstr("Text objects must not be nested");589 werrstr("tobegin: text objects must not be nested");
576 return 0;590 return -1;
577 }591 }
578 p->TS.inobj = 1;592 p->TS.inobj = 1;
579 p->GSactive->Font.font = nil;593 p->GSactive->Font.font = nil;
@@ -586,8 +600,8 @@ static int · 6 unmodified lines
586toend(Op *op, Page *p)600toend(Op *op, Page *p)
587{601{
588 if(!p->TS.inobj){602 if(!p->TS.inobj){
589 werrstr("ET found without BT");603 werrstr("toend: ET without BT");
590 return 0;604 return -1;
591 }605 }
592 p->TS.inobj = 0;606 p->TS.inobj = 0;
593 return flagless(op);607 return flagless(op);
@@ -597,6 +611,7 @@ static void · 3 unmodified lines
597tmove(Page *p, double x, double y, int tlm)611tmove(Page *p, double x, double y, int tlm)
598{612{
599 double *mat = tlm ? p->TS.Tlm : p->TS.Tm;613 double *mat = tlm ? p->TS.Tlm : p->TS.Tm;
614
600 mattrans(mat, x, y, mat);615 mattrans(mat, x, y, mat);
601 if(tlm)616 if(tlm)
602 memcpy(p->TS.Tm, p->TS.Tlm, sizeof(double) * 6);617 memcpy(p->TS.Tm, p->TS.Tlm, sizeof(double) * 6);
@@ -606,18 +621,20 @@ static int · 3 unmodified lines
606tpmove(Op *op, Page *p)621tpmove(Op *op, Page *p)
607{622{
608 Object *x, *y;623 Object *x, *y;
624
609 x = arrayget(p->stack, 0);625 x = arrayget(p->stack, 0);
610 y = arrayget(p->stack, 1);626 y = arrayget(p->stack, 1);
611 if(op->flags & Leading)627 if(op->flags & Leading)
612 p->TS.TL = -y->num.d;628 p->TS.TL = -y->num.d;
613 tmove(p, x->num.d, y->num.d, 1);629 tmove(p, x->num.d, y->num.d, 1);
614 return 1;630 return 0;
615}631}
616 632
617static int633static int
618tpmatrix(Op *op, Page *p)634tpmatrix(Op *op, Page *p)
619{635{
620 int i;636 int i;
637
621 for(i = 0; i < 6; i++){638 for(i = 0; i < 6; i++){
622 p->TS.Tm[i] = arrayget(p->stack, i)->num.d;639 p->TS.Tm[i] = arrayget(p->stack, i)->num.d;
623 p->TS.Tlm[i] = p->TS.Tm[i];640 p->TS.Tlm[i] = p->TS.Tm[i];
@@ -638,6 +655,7 @@ writepatched(Page *p, uchar c) · 14 unmodified lines
638{655{
639 int i, len, d = 0;656 int i, len, d = 0;
640 Object *o;657 Object *o;
658
641 if(p->GSactive->Font.enc != nil){659 if(p->GSactive->Font.enc != nil){
642 len = arraylen(p->GSactive->Font.enc);660 len = arraylen(p->GSactive->Font.enc);
643 for(i = 0; i < len; i++){661 for(i = 0; i < len; i++){
@@ -714,11 +732,11 @@ writepatched(Page *p, uchar c) · 70 unmodified lines
714 if(strcmp(o->name, "arrowright") == 0)732 if(strcmp(o->name, "arrowright") == 0)
715 return bufput(&p->buf, (uchar*)"→", strlen("→")) == strlen("→");733 return bufput(&p->buf, (uchar*)"→", strlen("→")) == strlen("→");
716 break;734 break;
717 } else735 }else
718 d++;736 d++;
719 }737 }
720 }738 }
721 return bufput(&p->buf, (uchar*)&c, 1) == 1;739 return bufput(&p->buf, (uchar*)&c, 1);
722}740}
723 741
724// Returns glyph width in TEXT SPACE units.742// Returns glyph width in TEXT SPACE units.
@@ -753,6 +771,7 @@ tchar(Page *p, ulong c) · 28 unmodified lines
753 Memimage *ink;771 Memimage *ink;
754 double tx;772 double tx;
755 int i;773 int i;
774
756 /* Text rendering matrix converts coordinates from font space to device space */775 /* Text rendering matrix converts coordinates from font space to device space */
757 matscale(p->TS.Tm, Tfs, Tfs, Trm);776 matscale(p->TS.Tm, Tfs, Tfs, Trm);
758 matmult(Trm, p->GSactive->CTM, Trm);777 matmult(Trm, p->GSactive->CTM, Trm);
@@ -761,22 +780,22 @@ tchar(Page *p, ulong c) · 2 unmodified lines
761 if(p->TS.y != Trm[5]){780 if(p->TS.y != Trm[5]){
762 for(i = 0; i < (int)((Trm[5] - p->TS.y) / p->GSactive->Font.size / 1.5) && i < 2; i++)781 for(i = 0; i < (int)((Trm[5] - p->TS.y) / p->GSactive->Font.size / 1.5) && i < 2; i++)
763 if(bufput(&p->buf, (uchar*)"\n", 1) != 1)782 if(bufput(&p->buf, (uchar*)"\n", 1) != 1)
764 return 0;783 return -1;
765 } else if(Trm[4] - p->TS.x > 5) {784 }else if(Trm[4] - p->TS.x > 5){
766 if(bufput(&p->buf, (uchar*)" ", 1) != 1)785 if(bufput(&p->buf, (uchar*)" ", 1) != 1)
767 return 0;786 return -1;
768 }787 }
769 }788 }
770 usize oend = p->buf.sz;789 usize oend = p->buf.sz;
771 if(!writepatched(p, c)){790 if(!writepatched(p, c)){
772 werrstr("tchar: failed to write character: %r");791 werrstr("tchar: failed to write character: %r");
773 return 0;792 return -1;
774 }793 }
775 if(p->buf.b != nil){794 if(p->buf.b != nil){
776 ink = allocmemimage(Rect(0,0,1,1),RGB24);795 ink = allocmemimage(Rect(0,0,1,1),RGB24);
777 if(ink == nil){796 if(ink == nil){
778 werrstr("failed to allocate ink");797 werrstr("failed to allocate ink");
779 return 0;798 return -1;
780 }799 }
781 ink->flags |= Frepl;800 ink->flags |= Frepl;
782 ink->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);801 ink->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
@@ -788,7 +807,7 @@ tchar(Page *p, ulong c) · 5 unmodified lines
788 mattrans(p->TS.Tm, tx, 0, p->TS.Tm);807 mattrans(p->TS.Tm, tx, 0, p->TS.Tm);
789 p->TS.x = Trm[4] + tx;808 p->TS.x = Trm[4] + tx;
790 p->TS.y = Trm[5];809 p->TS.y = Trm[5];
791 return 1;810 return 0;
792}811}
793 812
794static int813static int
@@ -797,8 +816,8 @@ tstr(Page *p, char *str, ulong len) · 2 unmodified lines
797 ulong i;816 ulong i;
798 for(i = 0; i < len; i++)817 for(i = 0; i < len; i++)
799 if(!tchar(p, str[i]))818 if(!tchar(p, str[i]))
800 return 0;819 return -1;
801 return 1;820 return 0;
802}821}
803 822
804static int823static int
@@ -806,14 +825,14 @@ thshow(Op *op, Page *p) · 1 unmodified line
806{825{
807 if(op->flags & TwTc){826 if(op->flags & TwTc){
808 werrstr("TODO thshow TwTc");827 werrstr("TODO thshow TwTc");
809 return 0;828 return -1;
810 }829 }
811 if(op->flags & Nextline)830 if(op->flags & Nextline)
812 tmove(p, 0, 0 - p->TS.TL, 1);831 tmove(p, 0, 0 - p->TS.TL, 1);
813 Object *o = arrayget(p->stack, 0);832 Object *o = arrayget(p->stack, 0);
814 if(!tstr(p, o->str, o->len))833 if(!tstr(p, o->str, o->len))
815 return 0;834 return -1;
816 return 1;835 return 0;
817}836}
818 837
819static int838static int
@@ -821,13 +840,13 @@ thshowarr(Op *op, Page *p) · 1 unmodified line
821{840{
822 Object *o, *arr = arrayget(p->stack, 0);841 Object *o, *arr = arrayget(p->stack, 0);
823 int i;842 int i;
843
824 for(i = 0; i < arraylen(arr); i++){844 for(i = 0; i < arraylen(arr); i++){
825 o = arrayget(arr, i);845 o = arrayget(arr, i);
826 if(o->type == Ostr){846 if(o->type == Ostr){
827 if(!tstr(p, o->str, o->len))847 if(!tstr(p, o->str, o->len))
828 return 0;848 return 0;
829 }849 }else{
830 else {
831 mattrans(p->TS.Tm, 0 - (p->GSactive->Font.size * o->num.d / 1000), 0, p->TS.Tm);850 mattrans(p->TS.Tm, 0 - (p->GSactive->Font.size * o->num.d / 1000), 0, p->TS.Tm);
832 }851 }
833 }852 }
@@ -838,14 +857,14 @@ static int · 4 unmodified lines
838t3width(Op *op, Page *p)857t3width(Op *op, Page *p)
839{858{
840 USED(op, p);859 USED(op, p);
841 return 0;860 return -1;
842}861}
843 862
844static int863static int
845t3widthbb(Op *op, Page *p)864t3widthbb(Op *op, Page *p)
846{865{
847 USED(op, p);866 USED(op, p);
848 return 0;867 return -1;
849}868}
850 869
851static int870static int
@@ -859,7 +878,7 @@ t4add(Op *op, Page *p) · 7 unmodified lines
859 s->num.d = x;878 s->num.d = x;
860 s->num.i = x;879 s->num.i = x;
861*/880*/
862 return 0;881 return -1;
863}882}
864 883
865static int884static int
@@ -873,7 +892,7 @@ t4sub(Op *op, Page *p) · 7 unmodified lines
873 s->num.d = x;892 s->num.d = x;
874 s->num.i = x;893 s->num.i = x;
875*/894*/
876 return 0;895 return -1;
877}896}
878 897
879static int898static int
@@ -888,7 +907,7 @@ t4mul(Op *op, Page *p) · 8 unmodified lines
888 s->num.d = x;907 s->num.d = x;
889 s->num.i = x;908 s->num.i = x;
890*/909*/
891 return 0;910 return -1;
892}911}
893 912
894static int913static int
@@ -903,280 +922,280 @@ t4div(Op *op, Page *p) · 8 unmodified lines
903 s->num.d = x;922 s->num.d = x;
904 s->num.i = x;923 s->num.i = x;
905*/924*/
906 return 0;925 return -1;
907}926}
908 927
909static int928static int
910t4idiv(Op *op, Page *p)929t4idiv(Op *op, Page *p)
911{930{
912 USED(op, p);931 USED(op, p);
913 return 0;932 return -1;
914}933}
915 934
916static int935static int
917t4mod(Op *op, Page *p)936t4mod(Op *op, Page *p)
918{937{
919 USED(op, p);938 USED(op, p);
920 return 0;939 return -1;
921}940}
922 941
923static int942static int
924t4neg(Op *op, Page *p)943t4neg(Op *op, Page *p)
925{944{
926 USED(op, p);945 USED(op, p);
927 return 0;946 return -1;
928}947}
929 948
930static int949static int
931t4abs(Op *op, Page *p)950t4abs(Op *op, Page *p)
932{951{
933 USED(op, p);952 USED(op, p);
934 return 0;953 return -1;
935}954}
936 955
937static int956static int
938t4ceiling(Op *op, Page *p)957t4ceiling(Op *op, Page *p)
939{958{
940 USED(op, p);959 USED(op, p);
941 return 0;960 return -1;
942}961}
943 962
944static int963static int
945t4floor(Op *op, Page *p)964t4floor(Op *op, Page *p)
946{965{
947 USED(op, p);966 USED(op, p);
948 return 0;967 return -1;
949}968}
950 969
951static int970static int
952t4round(Op *op, Page *p)971t4round(Op *op, Page *p)
953{972{
954 USED(op, p);973 USED(op, p);
955 return 0;974 return -1;
956}975}
957 976
958static int977static int
959t4truncate(Op *op, Page *p)978t4truncate(Op *op, Page *p)
960{979{
961 USED(op, p);980 USED(op, p);
962 return 0;981 return -1;
963}982}
964 983
965static int984static int
966t4sqrt(Op *op, Page *p)985t4sqrt(Op *op, Page *p)
967{986{
968 USED(op, p);987 USED(op, p);
969 return 0;988 return -1;
970}989}
971 990
972static int991static int
973t4sin(Op *op, Page *p)992t4sin(Op *op, Page *p)
974{993{
975 USED(op, p);994 USED(op, p);
976 return 0;995 return -1;
977}996}
978 997
979static int998static int
980t4cos(Op *op, Page *p)999t4cos(Op *op, Page *p)
981{1000{
982 USED(op, p);1001 USED(op, p);
983 return 0;1002 return -1;
984}1003}
985 1004
986static int1005static int
987t4atan(Op *op, Page *p)1006t4atan(Op *op, Page *p)
988{1007{
989 USED(op, p);1008 USED(op, p);
990 return 0;1009 return -1;
991}1010}
992 1011
993static int1012static int
994t4exp(Op *op, Page *p)1013t4exp(Op *op, Page *p)
995{1014{
996 USED(op, p);1015 USED(op, p);
997 return 0;1016 return -1;
998}1017}
999 1018
1000static int1019static int
1001t4ln(Op *op, Page *p)1020t4ln(Op *op, Page *p)
1002{1021{
1003 USED(op, p);1022 USED(op, p);
1004 return 0;1023 return -1;
1005}1024}
1006 1025
1007static int1026static int
1008t4log(Op *op, Page *p)1027t4log(Op *op, Page *p)
1009{1028{
1010 USED(op, p);1029 USED(op, p);
1011 return 0;1030 return -1;
1012}1031}
1013 1032
1014static int1033static int
1015t4cvi(Op *op, Page *p)1034t4cvi(Op *op, Page *p)
1016{1035{
1017 USED(op, p);1036 USED(op, p);
1018 return 0;1037 return -1;
1019}1038}
1020 1039
1021static int1040static int
1022t4cvr(Op *op, Page *p)1041t4cvr(Op *op, Page *p)
1023{1042{
1024 USED(op, p);1043 USED(op, p);
1025 return 0;1044 return -1;
1026}1045}
1027 1046
1028static int1047static int
1029t4eq(Op *op, Page *p)1048t4eq(Op *op, Page *p)
1030{1049{
1031 USED(op, p);1050 USED(op, p);
1032 return 0;1051 return -1;
1033}1052}
1034 1053
1035static int1054static int
1036t4ne(Op *op, Page *p)1055t4ne(Op *op, Page *p)
1037{1056{
1038 USED(op, p);1057 USED(op, p);
1039 return 0;1058 return -1;
1040}1059}
1041 1060
1042static int1061static int
1043t4gt(Op *op, Page *p)1062t4gt(Op *op, Page *p)
1044{1063{
1045 USED(op, p);1064 USED(op, p);
1046 return 0;1065 return -1;
1047}1066}
1048 1067
1049static int1068static int
1050t4ge(Op *op, Page *p)1069t4ge(Op *op, Page *p)
1051{1070{
1052 USED(op, p);1071 USED(op, p);
1053 return 0;1072 return -1;
1054}1073}
1055 1074
1056static int1075static int
1057t4lt(Op *op, Page *p)1076t4lt(Op *op, Page *p)
1058{1077{
1059 USED(op, p);1078 USED(op, p);
1060 return 0;1079 return -1;
1061}1080}
1062 1081
1063static int1082static int
1064t4le(Op *op, Page *p)1083t4le(Op *op, Page *p)
1065{1084{
1066 USED(op, p);1085 USED(op, p);
1067 return 0;1086 return -1;
1068}1087}
1069 1088
1070static int1089static int
1071t4and(Op *op, Page *p)1090t4and(Op *op, Page *p)
1072{1091{
1073 USED(op, p);1092 USED(op, p);
1074 return 0;1093 return -1;
1075}1094}
1076 1095
1077static int1096static int
1078t4or(Op *op, Page *p)1097t4or(Op *op, Page *p)
1079{1098{
1080 USED(op, p);1099 USED(op, p);
1081 return 0;1100 return -1;
1082}1101}
1083 1102
1084static int1103static int
1085t4xor(Op *op, Page *p)1104t4xor(Op *op, Page *p)
1086{1105{
1087 USED(op, p);1106 USED(op, p);
1088 return 0;1107 return -1;
1089}1108}
1090 1109
1091static int1110static int
1092t4not(Op *op, Page *p)1111t4not(Op *op, Page *p)
1093{1112{
1094 USED(op, p);1113 USED(op, p);
1095 return 0;1114 return -1;
1096}1115}
1097 1116
1098static int1117static int
1099t4bitshift(Op *op, Page *p)1118t4bitshift(Op *op, Page *p)
1100{1119{
1101 USED(op, p);1120 USED(op, p);
1102 return 0;1121 return -1;
1103}1122}
1104 1123
1105static int1124static int
1106t4true(Op *op, Page *p)1125t4true(Op *op, Page *p)
1107{1126{
1108 USED(op, p);1127 USED(op, p);
1109 return 0;1128 return -1;
1110}1129}
1111 1130
1112static int1131static int
1113t4false(Op *op, Page *p)1132t4false(Op *op, Page *p)
1114{1133{
1115 USED(op, p);1134 USED(op, p);
1116 return 0;1135 return -1;
1117}1136}
1118 1137
1119static int1138static int
1120t4if(Op *op, Page *p)1139t4if(Op *op, Page *p)
1121{1140{
1122 USED(op, p);1141 USED(op, p);
1123 return 0;1142 return -1;
1124}1143}
1125 1144
1126static int1145static int
1127t4ifelse(Op *op, Page *p)1146t4ifelse(Op *op, Page *p)
1128{1147{
1129 USED(op, p);1148 USED(op, p);
1130 return 0;1149 return -1;
1131}1150}
1132 1151
1133static int1152static int
1134t4pop(Op *op, Page *p)1153t4pop(Op *op, Page *p)
1135{1154{
1136 USED(op, p);1155 USED(op, p);
1137 return 0;1156 return -1;
1138}1157}
1139 1158
1140static int1159static int
1141t4exch(Op *op, Page *p)1160t4exch(Op *op, Page *p)
1142{1161{
1143 USED(op, p);1162 USED(op, p);
1144 return 0;1163 return -1;
1145}1164}
1146 1165
1147static int1166static int
1148t4dup(Op *op, Page *p)1167t4dup(Op *op, Page *p)
1149{1168{
1150 USED(op, p);1169 USED(op, p);
1151 return 0;1170 return -1;
1152}1171}
1153 1172
1154static int1173static int
1155t4copy(Op *op, Page *p)1174t4copy(Op *op, Page *p)
1156{1175{
1157 USED(op, p);1176 USED(op, p);
1158 return 0;1177 return -1;
1159}1178}
1160 1179
1161static int1180static int
1162t4index(Op *op, Page *p)1181t4index(Op *op, Page *p)
1163{1182{
1164 USED(op, p);1183 USED(op, p);
1165 return 0;1184 return -1;
1166}1185}
1167 1186
1168static int1187static int
1169t4roll(Op *op, Page *p)1188t4roll(Op *op, Page *p)
1170{1189{
1171 USED(op, p);1190 USED(op, p);
1172 return 0;1191 return -1;
1173}1192}
1174 1193
1175static int1194static int
1176opignore(Op *op, Page *p)1195opignore(Op *op, Page *p)
1177{1196{
1178 USED(op, p);1197 USED(op, p);
1179 return 0;1198 return -1;
1180}1199}
1181 1200
1182static Op ops[] = {1201static Op ops[] = {
@@ -1426,6 +1445,7 @@ void · 243 unmodified lines
1426pagegsclean(Page *p)1445pagegsclean(Page *p)
1427{1446{
1428 int i;1447 int i;
1448
1429 if(p->GSactive != nil){1449 if(p->GSactive != nil){
1430 p->GSactive = nil;1450 p->GSactive = nil;
1431 for(i = 0; i < p->nGS; i++)1451 for(i = 0; i < p->nGS; i++)
@@ -1441,7 +1461,7 @@ stackreset(Page *p) · 9 unmodified lines
1441{1461{
1442 pdfobjfree(p->stack);1462 pdfobjfree(p->stack);
1443 p->stack = arraynew(p->obj->pdf);1463 p->stack = arraynew(p->obj->pdf);
1444 return p->stack != nil;1464 return p->stack != nil ? 0 : -1;
1445}1465}
1446 1466
1447void1467void
@@ -1458,14 +1478,15 @@ pagerendercontent(Page *p, Object *content) · 10 unmodified lines
1458 Stream *s;1478 Stream *s;
1459 Object *o;1479 Object *o;
1460 Op *op;1480 Op *op;
1461 s = Sopen(content);1481
1462 if(s == nil){1482 o = nil;
1463 fprint(2, "%O\n", content);1483 if((s = Sopen(content)) == nil){
1464 sysfatal("%r");1484 werrstr("content: %O", content);
1485 goto err;
1465 }1486 }
1466 p->stack = arraynew(content->pdf);1487 p->stack = arraynew(content->pdf);
1467 if(p->stack == nil)1488 if(p->stack == nil)
1468 return 0;1489 goto err;
1469 while(s->buf.off != s->buf.sz){1490 while(s->buf.off != s->buf.sz){
1470 while(isws(s->buf.b[s->buf.off]) && s->buf.off != s->buf.sz)1491 while(isws(s->buf.b[s->buf.off]) && s->buf.off != s->buf.sz)
1471 s->buf.off++;1492 s->buf.off++;
@@ -1473,36 +1494,38 @@ pagerendercontent(Page *p, Object *content) · 1 unmodified line
1473 break;1494 break;
1474 o = pdfobj(content->pdf, s, 0);1495 o = pdfobj(content->pdf, s, 0);
1475 if(o == nil){1496 if(o == nil){
1476 werrstr("pagerendercontent: failed to parse op: %r");1497 werrstr("failed to parse op: %r");
1477 return 0;1498 goto err;
1478 }1499 }
1479 if(o->type == Oop){1500 if(o->type == Oop){
1480 op = opfind(o->str);1501 op = opfind(o->str);
1481 if(op == nil){
1482 fprint(2, "Unknown op: %s\n", o->str);
1483 pdfobjfree(o);
1484 return 0;
1485 }
1486 pdfobjfree(o);1502 pdfobjfree(o);
1487 werrstr("unimplemented or error not reported properly");1503 o = nil;
1488 if(!op->f(op, p)){1504 if(op == nil){
1489 werrstr("renderer: %s failed: %r", op->s);1505 werrstr("unknown op: %s\n", o->str);
1490 fprint(2, "%r\n");1506 goto err;
1491 // return 0;
1492 }1507 }
1493 if(!stackreset(p))1508 if(op->f(op, p) != 0){
1494 return 0;1509 werrstr("%s failed: %r", op->s);
1495 } else{1510 goto err;
1496 if(!arrayadd(p->stack, o)){
1497 fprint(2, "Failed to push operand to stack: %r\n");
1498 return 0;
1499 }1511 }
1512 if(stackreset(p) != 0)
1513 goto err;
1514 }else{
1515 if(arrayadd(p->stack, o) != 0)
1516 goto err;
1500 }1517 }
1501 }1518 }
1502 if(bufput(&p->buf, (uchar*)"\n\0", 2) != 2)1519 if(bufput(&p->buf, (uchar*)"\n", 2) != 2)
1503 return 0;1520 goto err;
1504 Sclose(s);1521 Sclose(s);
1505 return 1;1522
1523 return 0;
1524err:
1525 werrstr("pagerendercontent: %r");
1526 pdfobjfree(o);
1527 Sclose(s);
1528 return -1;
1506}1529}
1507 1530
1508int1531int
@@ -1510,29 +1533,32 @@ pagerender(Page *p) · 1 unmodified line
1510{1533{
1511 Object *content;1534 Object *content;
1512 int i;1535 int i;
1536
1513 p->nGS = 1;1537 p->nGS = 1;
1514 p->GS = malloc(sizeof(GS));1538 p->GS = malloc(sizeof(*p->GS));
1515 if(p->GS == nil){1539 if(p->GS == nil){
1516 werrstr("Out of memory");1540 werrstr("memory");
1517 return 0;1541 goto err;
1518 }1542 }
1519 p->GSactive = p->GS;1543 p->GSactive = p->GS;
1520 gsinit(p, p->GS);1544 gsinit(p, p->GS);
1521 if((p->image = allocmemimage(Rect(0,0,1100,1300), strtochan("r8g8b8"))) == nil){1545 if((p->image = allocmemimage(Rect(0,0,1100,1300), strtochan("r8g8b8"))) == nil){
1522 werrstr("unable to allocate image: %r");1546 werrstr("allocmemimage: %r");
1523 pagegsclean(p);1547 goto err;
1524 return 0;
1525 }1548 }
1526 memfillcolor(p->image, 0xFFFFFFFF);1549 memfillcolor(p->image, DWhite);
1527 content = dictget(p->obj, "Contents");1550 content = dictget(p->obj, "Contents");
1528 if(content->type == Oarray){1551 if(content->type == Oarray){
1529 for(i = 0; i < arraylen(content); i++)1552 for(i = 0; i < arraylen(content); i++){
1530 if(!pagerendercontent(p, arrayget(content, i)))1553 if(pagerendercontent(p, arrayget(content, i)) != 0)
1531 return 0;1554 goto err;
1532 }1555 }
1533 else if(content->type != Onull)1556 }else if(content->type != Onull && pagerendercontent(p, content) != 0)
1534 if(!pagerendercontent(p, content))1557 goto err;
1535 return 0;1558 pagegsclean(p);
1559
1560 return 0;
1561err:
1536 pagegsclean(p);1562 pagegsclean(p);
1537 return 1;1563 return -1;
1538}1564}

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