| @@ -71,33 +71,34 @@ static int · 70 unmodified lines |
| 71 | flagless(Op *op) | 71 | flagless(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 | |
| 80 | static int | 80 | static int |
| 81 | cobegin(Op *op, Page *p) | 81 | cobegin(Op *op, Page *p) |
| 82 | { | 82 | { |
| 83 | USED(op, p); | 83 | USED(op, p); |
| 84 | return 0; | 84 | return -1; |
| 85 | } | 85 | } |
| 86 | | 86 | |
| 87 | static int | 87 | static int |
| 88 | coend(Op *op, Page *p) | 88 | coend(Op *op, Page *p) |
| 89 | { | 89 | { |
| 90 | USED(op, p); | 90 | USED(op, p); |
| 91 | return 0; | 91 | return -1; |
| 92 | } | 92 | } |
| 93 | | 93 | |
| 94 | static int | 94 | static int |
| 95 | gspush(Op *op, Page *p) | 95 | gspush(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 | |
| 116 | static int | 117 | static 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 matrix | 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 | 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 |
| 194 | gsdash(Op *op, Page *p) | 196 | gsdash(Op *op, Page *p) |
| 195 | { | 197 | { |
| 196 | USED(op, p); | 198 | USED(op, p); |
| 197 | return 0; | 199 | return -1; |
| 198 | } | 200 | } |
| 199 | | 201 | |
| 200 | static int | 202 | static int |
| 201 | gsintent(Op *op, Page *p) | 203 | gsintent(Op *op, Page *p) |
| 202 | { | 204 | { |
| 203 | USED(op, p); | 205 | USED(op, p); |
| 204 | return 0; | 206 | return -1; |
| 205 | } | 207 | } |
| 206 | | 208 | |
| 207 | static int | 209 | static 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); |
| | 258 | err: |
| | 259 | werrstr("gsstate: %r"); |
| | 260 | return -1; |
| 256 | } | 261 | } |
| 257 | | 262 | |
| 258 | static int | 263 | static int |
| 259 | pcmove(Op *op, Page *p) | 264 | pcmove(Op *op, Page *p) |
| 260 | { | 265 | { |
| 261 | USED(op, p); | 266 | USED(op, p); |
| 262 | return 0; | 267 | return -1; |
| 263 | } | 268 | } |
| 264 | | 269 | |
| 265 | static int | 270 | static int |
| 266 | pcline(Op *op, Page *p) | 271 | pcline(Op *op, Page *p) |
| 267 | { | 272 | { |
| 268 | USED(op, p); | 273 | USED(op, p); |
| 269 | return 0; | 274 | return -1; |
| 270 | } | 275 | } |
| 271 | | 276 | |
| 272 | static int | 277 | static int |
| 273 | pccurve(Op *op, Page *p) | 278 | pccurve(Op *op, Page *p) |
| 274 | { | 279 | { |
| 275 | USED(op, p); | 280 | USED(op, p); |
| 276 | return 0; | 281 | return -1; |
| 277 | } | 282 | } |
| 278 | | 283 | |
| 279 | static int | 284 | static int |
| 280 | pcsubpath(Op *op, Page *p) | 285 | pcsubpath(Op *op, Page *p) |
| 281 | { | 286 | { |
| 282 | USED(op, p); | 287 | USED(op, p); |
| 283 | return 0; | 288 | return -1; |
| 284 | } | 289 | } |
| 285 | | 290 | |
| 286 | static int | 291 | static int |
| 287 | pcrect(Op *op, Page *p) | 292 | pcrect(Op *op, Page *p) |
| 288 | { | 293 | { |
| 289 | USED(op, p); | 294 | USED(op, p); |
| 290 | return 0; | 295 | return -1; |
| 291 | } | 296 | } |
| 292 | | 297 | |
| 293 | static int | 298 | static int |
| 294 | ppstroke(Op *op, Page *p) | 299 | ppstroke(Op *op, Page *p) |
| 295 | { | 300 | { |
| 296 | USED(op, p); | 301 | USED(op, p); |
| 297 | return 0; | 302 | return -1; |
| 298 | } | 303 | } |
| 299 | | 304 | |
| 300 | static int | 305 | static int |
| 301 | ppstrokec(Op *op, Page *p) | 306 | ppstrokec(Op *op, Page *p) |
| 302 | { | 307 | { |
| 303 | USED(op, p); | 308 | USED(op, p); |
| 304 | return 0; | 309 | return -1; |
| 305 | } | 310 | } |
| 306 | | 311 | |
| 307 | static int | 312 | static int |
| 308 | ppfill(Op *op, Page *p) | 313 | ppfill(Op *op, Page *p) |
| 309 | { | 314 | { |
| 310 | USED(op, p); | 315 | USED(op, p); |
| 311 | return 0; | 316 | return -1; |
| 312 | } | 317 | } |
| 313 | | 318 | |
| 314 | static int | 319 | static int |
| 315 | ppfills(Op *op, Page *p) | 320 | ppfills(Op *op, Page *p) |
| 316 | { | 321 | { |
| 317 | USED(op, p); | 322 | USED(op, p); |
| 318 | return 0; | 323 | return -1; |
| 319 | } | 324 | } |
| 320 | | 325 | |
| 321 | static int | 326 | static int |
| 322 | ppfillcfs(Op *op, Page *p) | 327 | ppfillcfs(Op *op, Page *p) |
| 323 | { | 328 | { |
| 324 | USED(op, p); | 329 | USED(op, p); |
| 325 | return 0; | 330 | return -1; |
| 326 | } | 331 | } |
| 327 | | 332 | |
| 328 | static int | 333 | static int |
| 329 | ppc(Op *op, Page *p) | 334 | ppc(Op *op, Page *p) |
| 330 | { | 335 | { |
| 331 | USED(op, p); | 336 | USED(op, p); |
| 332 | return 0; | 337 | return -1; |
| 333 | } | 338 | } |
| 334 | | 339 | |
| 335 | static int | 340 | static int |
| 336 | cpclip(Op *op, Page *p) | 341 | cpclip(Op *op, Page *p) |
| 337 | { | 342 | { |
| 338 | USED(op, p); | 343 | USED(op, p); |
| 339 | return 0; | 344 | return -1; |
| 340 | } | 345 | } |
| 341 | | 346 | |
| 342 | char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"}; | 347 | static char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"}; |
| 343 | ColorSpace colorspacechans[] = { | 348 | static 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 |
| 350 | iccbasedcspace(Object *icc, ColorSpace *c) | 355 | iccbasedcspace(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 | |
| 363 | static int | 369 | static 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")) == &null | 385 | 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 | |
| 394 | static int | 402 | static 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 | |
| 406 | static int | 415 | static 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 | |
| 415 | static int | 424 | static int |
| 416 | cgray(Op *op, Page *p) | 425 | cgray(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 | |
| 435 | static int | 445 | static int |
| 436 | crgb(Op *op, Page *p) | 446 | crgb(Op *op, Page *p) |
| 437 | { | 447 | { |
| 438 | USED(op, p); | 448 | USED(op, p); |
| 439 | return 0; | 449 | return -1; |
| 440 | } | 450 | } |
| 441 | | 451 | |
| 442 | static int | 452 | static int |
| 443 | ccmyk(Op *op, Page *p) | 453 | ccmyk(Op *op, Page *p) |
| 444 | { | 454 | { |
| 445 | USED(op, p); | 455 | USED(op, p); |
| 446 | return 0; | 456 | return -1; |
| 447 | } | 457 | } |
| 448 | | 458 | |
| 449 | static int | 459 | static int |
| 450 | sshade(Op *op, Page *p) | 460 | sshade(Op *op, Page *p) |
| 451 | { | 461 | { |
| 452 | USED(op, p); | 462 | USED(op, p); |
| 453 | return 0; | 463 | return -1; |
| 454 | } | 464 | } |
| 455 | | 465 | |
| 456 | static int | 466 | static int |
| 457 | eoobject(Op *op, Page *p) | 467 | eoobject(Op *op, Page *p) |
| 458 | { | 468 | { |
| 459 | USED(op, p); | 469 | USED(op, p); |
| 460 | return 0; | 470 | return -1; |
| 461 | } | 471 | } |
| 462 | | 472 | |
| 463 | static int | 473 | static int |
| 464 | iibegin(Op *op, Page *p) | 474 | iibegin(Op *op, Page *p) |
| 465 | { | 475 | { |
| 466 | USED(op, p); | 476 | USED(op, p); |
| 467 | return 0; | 477 | return -1; |
| 468 | } | 478 | } |
| 469 | | 479 | |
| 470 | static int | 480 | static int |
| 471 | iidata(Op *op, Page *p) | 481 | iidata(Op *op, Page *p) |
| 472 | { | 482 | { |
| 473 | USED(op, p); | 483 | USED(op, p); |
| 474 | return 0; | 484 | return -1; |
| 475 | } | 485 | } |
| 476 | | 486 | |
| 477 | static int | 487 | static int |
| 478 | iiend(Op *op, Page *p) | 488 | iiend(Op *op, Page *p) |
| 479 | { | 489 | { |
| 480 | USED(op, p); | 490 | USED(op, p); |
| 481 | return 0; | 491 | return -1; |
| 482 | } | 492 | } |
| 483 | | 493 | |
| 484 | static int | 494 | static 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 | |
| 492 | static int | 502 | static 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 | |
| 500 | static int | 510 | static int |
| 501 | tshscale(Op *op, Page *p) | 511 | tshscale(Op *op, Page *p) |
| 502 | { | 512 | { |
| 503 | USED(op, p); | 513 | USED(op, p); |
| 504 | return 0; | 514 | return -1; |
| 505 | } | 515 | } |
| 506 | | 516 | |
| 507 | static int | 517 | static 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 | |
| 541 | static int | 555 | static 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 | |
| 557 | static int | 571 | static int |
| 558 | tsrendmode(Op *op, Page *p) | 572 | tsrendmode(Op *op, Page *p) |
| 559 | { | 573 | { |
| 560 | USED(op, p); | 574 | USED(op, p); |
| 561 | return 0; | 575 | return -1; |
| 562 | } | 576 | } |
| 563 | | 577 | |
| 564 | static int | 578 | static int |
| 565 | tsrise(Op *op, Page *p) | 579 | tsrise(Op *op, Page *p) |
| 566 | { | 580 | { |
| 567 | USED(op, p); | 581 | USED(op, p); |
| 568 | return 0; | 582 | return -1; |
| 569 | } | 583 | } |
| 570 | | 584 | |
| 571 | static int | 585 | static int |
| 572 | tobegin(Op *op, Page *p) | 586 | tobegin(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 |
| 586 | toend(Op *op, Page *p) | 600 | toend(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 |
| 597 | tmove(Page *p, double x, double y, int tlm) | 611 | tmove(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 |
| 606 | tpmove(Op *op, Page *p) | 621 | tpmove(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 | |
| 617 | static int | 633 | static int |
| 618 | tpmatrix(Op *op, Page *p) | 634 | tpmatrix(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 | } else | 735 | }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 | |
| 794 | static int | 813 | static 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 | |
| 804 | static int | 823 | static 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 | |
| 819 | static int | 838 | static 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 |
| 838 | t3width(Op *op, Page *p) | 857 | t3width(Op *op, Page *p) |
| 839 | { | 858 | { |
| 840 | USED(op, p); | 859 | USED(op, p); |
| 841 | return 0; | 860 | return -1; |
| 842 | } | 861 | } |
| 843 | | 862 | |
| 844 | static int | 863 | static int |
| 845 | t3widthbb(Op *op, Page *p) | 864 | t3widthbb(Op *op, Page *p) |
| 846 | { | 865 | { |
| 847 | USED(op, p); | 866 | USED(op, p); |
| 848 | return 0; | 867 | return -1; |
| 849 | } | 868 | } |
| 850 | | 869 | |
| 851 | static int | 870 | static 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 | |
| 865 | static int | 884 | static 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 | |
| 879 | static int | 898 | static 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 | |
| 894 | static int | 913 | static 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 | |
| 909 | static int | 928 | static int |
| 910 | t4idiv(Op *op, Page *p) | 929 | t4idiv(Op *op, Page *p) |
| 911 | { | 930 | { |
| 912 | USED(op, p); | 931 | USED(op, p); |
| 913 | return 0; | 932 | return -1; |
| 914 | } | 933 | } |
| 915 | | 934 | |
| 916 | static int | 935 | static int |
| 917 | t4mod(Op *op, Page *p) | 936 | t4mod(Op *op, Page *p) |
| 918 | { | 937 | { |
| 919 | USED(op, p); | 938 | USED(op, p); |
| 920 | return 0; | 939 | return -1; |
| 921 | } | 940 | } |
| 922 | | 941 | |
| 923 | static int | 942 | static int |
| 924 | t4neg(Op *op, Page *p) | 943 | t4neg(Op *op, Page *p) |
| 925 | { | 944 | { |
| 926 | USED(op, p); | 945 | USED(op, p); |
| 927 | return 0; | 946 | return -1; |
| 928 | } | 947 | } |
| 929 | | 948 | |
| 930 | static int | 949 | static int |
| 931 | t4abs(Op *op, Page *p) | 950 | t4abs(Op *op, Page *p) |
| 932 | { | 951 | { |
| 933 | USED(op, p); | 952 | USED(op, p); |
| 934 | return 0; | 953 | return -1; |
| 935 | } | 954 | } |
| 936 | | 955 | |
| 937 | static int | 956 | static int |
| 938 | t4ceiling(Op *op, Page *p) | 957 | t4ceiling(Op *op, Page *p) |
| 939 | { | 958 | { |
| 940 | USED(op, p); | 959 | USED(op, p); |
| 941 | return 0; | 960 | return -1; |
| 942 | } | 961 | } |
| 943 | | 962 | |
| 944 | static int | 963 | static int |
| 945 | t4floor(Op *op, Page *p) | 964 | t4floor(Op *op, Page *p) |
| 946 | { | 965 | { |
| 947 | USED(op, p); | 966 | USED(op, p); |
| 948 | return 0; | 967 | return -1; |
| 949 | } | 968 | } |
| 950 | | 969 | |
| 951 | static int | 970 | static int |
| 952 | t4round(Op *op, Page *p) | 971 | t4round(Op *op, Page *p) |
| 953 | { | 972 | { |
| 954 | USED(op, p); | 973 | USED(op, p); |
| 955 | return 0; | 974 | return -1; |
| 956 | } | 975 | } |
| 957 | | 976 | |
| 958 | static int | 977 | static int |
| 959 | t4truncate(Op *op, Page *p) | 978 | t4truncate(Op *op, Page *p) |
| 960 | { | 979 | { |
| 961 | USED(op, p); | 980 | USED(op, p); |
| 962 | return 0; | 981 | return -1; |
| 963 | } | 982 | } |
| 964 | | 983 | |
| 965 | static int | 984 | static int |
| 966 | t4sqrt(Op *op, Page *p) | 985 | t4sqrt(Op *op, Page *p) |
| 967 | { | 986 | { |
| 968 | USED(op, p); | 987 | USED(op, p); |
| 969 | return 0; | 988 | return -1; |
| 970 | } | 989 | } |
| 971 | | 990 | |
| 972 | static int | 991 | static int |
| 973 | t4sin(Op *op, Page *p) | 992 | t4sin(Op *op, Page *p) |
| 974 | { | 993 | { |
| 975 | USED(op, p); | 994 | USED(op, p); |
| 976 | return 0; | 995 | return -1; |
| 977 | } | 996 | } |
| 978 | | 997 | |
| 979 | static int | 998 | static int |
| 980 | t4cos(Op *op, Page *p) | 999 | t4cos(Op *op, Page *p) |
| 981 | { | 1000 | { |
| 982 | USED(op, p); | 1001 | USED(op, p); |
| 983 | return 0; | 1002 | return -1; |
| 984 | } | 1003 | } |
| 985 | | 1004 | |
| 986 | static int | 1005 | static int |
| 987 | t4atan(Op *op, Page *p) | 1006 | t4atan(Op *op, Page *p) |
| 988 | { | 1007 | { |
| 989 | USED(op, p); | 1008 | USED(op, p); |
| 990 | return 0; | 1009 | return -1; |
| 991 | } | 1010 | } |
| 992 | | 1011 | |
| 993 | static int | 1012 | static int |
| 994 | t4exp(Op *op, Page *p) | 1013 | t4exp(Op *op, Page *p) |
| 995 | { | 1014 | { |
| 996 | USED(op, p); | 1015 | USED(op, p); |
| 997 | return 0; | 1016 | return -1; |
| 998 | } | 1017 | } |
| 999 | | 1018 | |
| 1000 | static int | 1019 | static int |
| 1001 | t4ln(Op *op, Page *p) | 1020 | t4ln(Op *op, Page *p) |
| 1002 | { | 1021 | { |
| 1003 | USED(op, p); | 1022 | USED(op, p); |
| 1004 | return 0; | 1023 | return -1; |
| 1005 | } | 1024 | } |
| 1006 | | 1025 | |
| 1007 | static int | 1026 | static int |
| 1008 | t4log(Op *op, Page *p) | 1027 | t4log(Op *op, Page *p) |
| 1009 | { | 1028 | { |
| 1010 | USED(op, p); | 1029 | USED(op, p); |
| 1011 | return 0; | 1030 | return -1; |
| 1012 | } | 1031 | } |
| 1013 | | 1032 | |
| 1014 | static int | 1033 | static int |
| 1015 | t4cvi(Op *op, Page *p) | 1034 | t4cvi(Op *op, Page *p) |
| 1016 | { | 1035 | { |
| 1017 | USED(op, p); | 1036 | USED(op, p); |
| 1018 | return 0; | 1037 | return -1; |
| 1019 | } | 1038 | } |
| 1020 | | 1039 | |
| 1021 | static int | 1040 | static int |
| 1022 | t4cvr(Op *op, Page *p) | 1041 | t4cvr(Op *op, Page *p) |
| 1023 | { | 1042 | { |
| 1024 | USED(op, p); | 1043 | USED(op, p); |
| 1025 | return 0; | 1044 | return -1; |
| 1026 | } | 1045 | } |
| 1027 | | 1046 | |
| 1028 | static int | 1047 | static int |
| 1029 | t4eq(Op *op, Page *p) | 1048 | t4eq(Op *op, Page *p) |
| 1030 | { | 1049 | { |
| 1031 | USED(op, p); | 1050 | USED(op, p); |
| 1032 | return 0; | 1051 | return -1; |
| 1033 | } | 1052 | } |
| 1034 | | 1053 | |
| 1035 | static int | 1054 | static int |
| 1036 | t4ne(Op *op, Page *p) | 1055 | t4ne(Op *op, Page *p) |
| 1037 | { | 1056 | { |
| 1038 | USED(op, p); | 1057 | USED(op, p); |
| 1039 | return 0; | 1058 | return -1; |
| 1040 | } | 1059 | } |
| 1041 | | 1060 | |
| 1042 | static int | 1061 | static int |
| 1043 | t4gt(Op *op, Page *p) | 1062 | t4gt(Op *op, Page *p) |
| 1044 | { | 1063 | { |
| 1045 | USED(op, p); | 1064 | USED(op, p); |
| 1046 | return 0; | 1065 | return -1; |
| 1047 | } | 1066 | } |
| 1048 | | 1067 | |
| 1049 | static int | 1068 | static int |
| 1050 | t4ge(Op *op, Page *p) | 1069 | t4ge(Op *op, Page *p) |
| 1051 | { | 1070 | { |
| 1052 | USED(op, p); | 1071 | USED(op, p); |
| 1053 | return 0; | 1072 | return -1; |
| 1054 | } | 1073 | } |
| 1055 | | 1074 | |
| 1056 | static int | 1075 | static int |
| 1057 | t4lt(Op *op, Page *p) | 1076 | t4lt(Op *op, Page *p) |
| 1058 | { | 1077 | { |
| 1059 | USED(op, p); | 1078 | USED(op, p); |
| 1060 | return 0; | 1079 | return -1; |
| 1061 | } | 1080 | } |
| 1062 | | 1081 | |
| 1063 | static int | 1082 | static int |
| 1064 | t4le(Op *op, Page *p) | 1083 | t4le(Op *op, Page *p) |
| 1065 | { | 1084 | { |
| 1066 | USED(op, p); | 1085 | USED(op, p); |
| 1067 | return 0; | 1086 | return -1; |
| 1068 | } | 1087 | } |
| 1069 | | 1088 | |
| 1070 | static int | 1089 | static int |
| 1071 | t4and(Op *op, Page *p) | 1090 | t4and(Op *op, Page *p) |
| 1072 | { | 1091 | { |
| 1073 | USED(op, p); | 1092 | USED(op, p); |
| 1074 | return 0; | 1093 | return -1; |
| 1075 | } | 1094 | } |
| 1076 | | 1095 | |
| 1077 | static int | 1096 | static int |
| 1078 | t4or(Op *op, Page *p) | 1097 | t4or(Op *op, Page *p) |
| 1079 | { | 1098 | { |
| 1080 | USED(op, p); | 1099 | USED(op, p); |
| 1081 | return 0; | 1100 | return -1; |
| 1082 | } | 1101 | } |
| 1083 | | 1102 | |
| 1084 | static int | 1103 | static int |
| 1085 | t4xor(Op *op, Page *p) | 1104 | t4xor(Op *op, Page *p) |
| 1086 | { | 1105 | { |
| 1087 | USED(op, p); | 1106 | USED(op, p); |
| 1088 | return 0; | 1107 | return -1; |
| 1089 | } | 1108 | } |
| 1090 | | 1109 | |
| 1091 | static int | 1110 | static int |
| 1092 | t4not(Op *op, Page *p) | 1111 | t4not(Op *op, Page *p) |
| 1093 | { | 1112 | { |
| 1094 | USED(op, p); | 1113 | USED(op, p); |
| 1095 | return 0; | 1114 | return -1; |
| 1096 | } | 1115 | } |
| 1097 | | 1116 | |
| 1098 | static int | 1117 | static int |
| 1099 | t4bitshift(Op *op, Page *p) | 1118 | t4bitshift(Op *op, Page *p) |
| 1100 | { | 1119 | { |
| 1101 | USED(op, p); | 1120 | USED(op, p); |
| 1102 | return 0; | 1121 | return -1; |
| 1103 | } | 1122 | } |
| 1104 | | 1123 | |
| 1105 | static int | 1124 | static int |
| 1106 | t4true(Op *op, Page *p) | 1125 | t4true(Op *op, Page *p) |
| 1107 | { | 1126 | { |
| 1108 | USED(op, p); | 1127 | USED(op, p); |
| 1109 | return 0; | 1128 | return -1; |
| 1110 | } | 1129 | } |
| 1111 | | 1130 | |
| 1112 | static int | 1131 | static int |
| 1113 | t4false(Op *op, Page *p) | 1132 | t4false(Op *op, Page *p) |
| 1114 | { | 1133 | { |
| 1115 | USED(op, p); | 1134 | USED(op, p); |
| 1116 | return 0; | 1135 | return -1; |
| 1117 | } | 1136 | } |
| 1118 | | 1137 | |
| 1119 | static int | 1138 | static int |
| 1120 | t4if(Op *op, Page *p) | 1139 | t4if(Op *op, Page *p) |
| 1121 | { | 1140 | { |
| 1122 | USED(op, p); | 1141 | USED(op, p); |
| 1123 | return 0; | 1142 | return -1; |
| 1124 | } | 1143 | } |
| 1125 | | 1144 | |
| 1126 | static int | 1145 | static int |
| 1127 | t4ifelse(Op *op, Page *p) | 1146 | t4ifelse(Op *op, Page *p) |
| 1128 | { | 1147 | { |
| 1129 | USED(op, p); | 1148 | USED(op, p); |
| 1130 | return 0; | 1149 | return -1; |
| 1131 | } | 1150 | } |
| 1132 | | 1151 | |
| 1133 | static int | 1152 | static int |
| 1134 | t4pop(Op *op, Page *p) | 1153 | t4pop(Op *op, Page *p) |
| 1135 | { | 1154 | { |
| 1136 | USED(op, p); | 1155 | USED(op, p); |
| 1137 | return 0; | 1156 | return -1; |
| 1138 | } | 1157 | } |
| 1139 | | 1158 | |
| 1140 | static int | 1159 | static int |
| 1141 | t4exch(Op *op, Page *p) | 1160 | t4exch(Op *op, Page *p) |
| 1142 | { | 1161 | { |
| 1143 | USED(op, p); | 1162 | USED(op, p); |
| 1144 | return 0; | 1163 | return -1; |
| 1145 | } | 1164 | } |
| 1146 | | 1165 | |
| 1147 | static int | 1166 | static int |
| 1148 | t4dup(Op *op, Page *p) | 1167 | t4dup(Op *op, Page *p) |
| 1149 | { | 1168 | { |
| 1150 | USED(op, p); | 1169 | USED(op, p); |
| 1151 | return 0; | 1170 | return -1; |
| 1152 | } | 1171 | } |
| 1153 | | 1172 | |
| 1154 | static int | 1173 | static int |
| 1155 | t4copy(Op *op, Page *p) | 1174 | t4copy(Op *op, Page *p) |
| 1156 | { | 1175 | { |
| 1157 | USED(op, p); | 1176 | USED(op, p); |
| 1158 | return 0; | 1177 | return -1; |
| 1159 | } | 1178 | } |
| 1160 | | 1179 | |
| 1161 | static int | 1180 | static int |
| 1162 | t4index(Op *op, Page *p) | 1181 | t4index(Op *op, Page *p) |
| 1163 | { | 1182 | { |
| 1164 | USED(op, p); | 1183 | USED(op, p); |
| 1165 | return 0; | 1184 | return -1; |
| 1166 | } | 1185 | } |
| 1167 | | 1186 | |
| 1168 | static int | 1187 | static int |
| 1169 | t4roll(Op *op, Page *p) | 1188 | t4roll(Op *op, Page *p) |
| 1170 | { | 1189 | { |
| 1171 | USED(op, p); | 1190 | USED(op, p); |
| 1172 | return 0; | 1191 | return -1; |
| 1173 | } | 1192 | } |
| 1174 | | 1193 | |
| 1175 | static int | 1194 | static int |
| 1176 | opignore(Op *op, Page *p) | 1195 | opignore(Op *op, Page *p) |
| 1177 | { | 1196 | { |
| 1178 | USED(op, p); | 1197 | USED(op, p); |
| 1179 | return 0; | 1198 | return -1; |
| 1180 | } | 1199 | } |
| 1181 | | 1200 | |
| 1182 | static Op ops[] = { | 1201 | static Op ops[] = { |
| @@ -1426,6 +1445,7 @@ void · 243 unmodified lines |
| 1426 | pagegsclean(Page *p) | 1445 | pagegsclean(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 | |
| 1447 | void | 1467 | void |
| @@ -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; |
| | 1524 | err: |
| | 1525 | werrstr("pagerendercontent: %r"); |
| | 1526 | pdfobjfree(o); |
| | 1527 | Sclose(s); |
| | 1528 | return -1; |
| 1506 | } | 1529 | } |
| 1507 | | 1530 | |
| 1508 | int | 1531 | int |
| @@ -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; |
| | 1561 | err: |
| 1536 | pagegsclean(p); | 1562 | pagegsclean(p); |
| 1537 | return 1; | 1563 | return -1; |
| 1538 | } | 1564 | } |