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