Even after "+109 LOConsistency" it was still inconsistent. This one is contentious: makes debugging if/else statments occupying the same line with the condition un-easily-breakpointable (among other things?).
Unified · Split
| @@ -81,11 +81,9 @@ · 80 unmodified lines | |||
| 81 | #define lprintf(...) | 81 | #define lprintf(...) |
| 82 | #endif | 82 | #endif |
| 83 | 83 | ||
| 84 | #define ARSERT(cond) for (;;) { \ | 84 | #define ARSERT(cond) for (;;) { \ |
| 85 | if (!(cond)) { \ | 85 | if (!(cond)) errx (1, "%s:%d " #cond, __FILE__, __LINE__); \ |
| 86 | errx (1, "%s:%d " #cond, __FILE__, __LINE__); \ | 86 | break; \ |
| 87 | } \ | ||
| 88 | break; \ | ||
| 89 | } (void) 0 | 87 | } (void) 0 |
| 90 | 88 | ||
| 91 | #define ML(d) extern value ml_##d; value ml_##d | 89 | #define ML(d) extern value ml_##d; value ml_##d |
| @@ -204,25 +202,20 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; · 112 unmodified lines | |||
| 204 | static void lock (const char *cap) | 202 | static void lock (const char *cap) |
| 205 | { | 203 | { |
| 206 | int ret = pthread_mutex_lock (&mutex); | 204 | int ret = pthread_mutex_lock (&mutex); |
| 207 | if (ret) { | 205 | if (ret) errx (1, "%s: pthread_mutex_lock: %s", cap, strerror (ret)); |
| 208 | errx (1, "%s: pthread_mutex_lock: %s", cap, strerror (ret)); | ||
| 209 | } | ||
| 210 | } | 206 | } |
| 211 | 207 | ||
| 212 | static void unlock (const char *cap) | 208 | static void unlock (const char *cap) |
| 213 | { | 209 | { |
| 214 | int ret = pthread_mutex_unlock (&mutex); | 210 | int ret = pthread_mutex_unlock (&mutex); |
| 215 | if (ret) { | 211 | if (ret) errx (1, "%s: pthread_mutex_unlock: %s", cap, strerror (ret)); |
| 216 | errx (1, "%s: pthread_mutex_unlock: %s", cap, strerror (ret)); | ||
| 217 | } | ||
| 218 | } | 212 | } |
| 219 | 213 | ||
| 220 | static int trylock (const char *cap) | 214 | static int trylock (const char *cap) |
| 221 | { | 215 | { |
| 222 | int ret = pthread_mutex_trylock (&mutex); | 216 | int ret = pthread_mutex_trylock (&mutex); |
| 223 | if (ret && ret != EBUSY) { | 217 | if (ret && ret != EBUSY) |
| 224 | errx (1, "%s: pthread_mutex_trylock: %s", cap, strerror (ret)); | 218 | errx (1, "%s: pthread_mutex_trylock: %s", cap, strerror (ret)); |
| 225 | } | ||
| 226 | return ret == EBUSY; | 219 | return ret == EBUSY; |
| 227 | } | 220 | } |
| 228 | 221 | ||
| @@ -230,9 +223,7 @@ static int hasdata (void) · 1 unmodified line | |||
| 230 | { | 223 | { |
| 231 | int ret, avail; | 224 | int ret, avail; |
| 232 | ret = ioctl (state.csock, FIONREAD, &avail); | 225 | ret = ioctl (state.csock, FIONREAD, &avail); |
| 233 | if (ret) { | 226 | if (ret) err (1, "hasdata: FIONREAD error ret=%d", ret); |
| 234 | err (1, "hasdata: FIONREAD error ret=%d", ret); | ||
| 235 | } | ||
| 236 | return avail > 0; | 227 | return avail > 0; |
| 237 | } | 228 | } |
| 238 | 229 | ||
| @@ -242,9 +233,7 @@ ML (hasdata (value fd_v)) · 3 unmodified lines | |||
| 242 | int ret, avail; | 233 | int ret, avail; |
| 243 | 234 | ||
| 244 | ret = ioctl (Int_val (fd_v), FIONREAD, &avail); | 235 | ret = ioctl (Int_val (fd_v), FIONREAD, &avail); |
| 245 | if (ret) { | 236 | if (ret) uerror ("ioctl (FIONREAD)", Nothing); |
| 246 | uerror ("ioctl (FIONREAD)", Nothing); | ||
| 247 | } | ||
| 248 | CAMLreturn (Val_bool (avail > 0)); | 237 | CAMLreturn (Val_bool (avail > 0)); |
| 249 | } | 238 | } |
| 250 | 239 | ||
| @@ -255,12 +244,8 @@ static void readdata (int fd, void *p, int size) · 4 unmodified lines | |||
| 255 | again: | 244 | again: |
| 256 | n = read (fd, p, size); | 245 | n = read (fd, p, size); |
| 257 | if (n - size) { | 246 | if (n - size) { |
| 258 | if (n < 0 && errno == EINTR) { | 247 | if (n < 0 && errno == EINTR) goto again; |
| 259 | goto again; | 248 | if (!n) errx (1, "EOF while reading"); |
| 260 | } | ||
| 261 | if (!n) { | ||
| 262 | errx (1, "EOF while reading"); | ||
| 263 | } | ||
| 264 | errx (1, "read (fd %d, req %d, ret %zd)", fd, size, n); | 249 | errx (1, "read (fd %d, req %d, ret %zd)", fd, size, n); |
| 265 | } | 250 | } |
| 266 | } | 251 | } |
| @@ -280,9 +265,7 @@ again: · 13 unmodified lines | |||
| 280 | goto again; | 265 | goto again; |
| 281 | } | 266 | } |
| 282 | if (n - size - 4) { | 267 | if (n - size - 4) { |
| 283 | if (!n) { | 268 | if (!n) errx (1, "EOF while writing data"); |
| 284 | errx (1, "EOF while writing data"); | ||
| 285 | } | ||
| 286 | err (1, "writev (fd %d, req %d, ret %zd)", fd, size + 4, n); | 269 | err (1, "writev (fd %d, req %d, ret %zd)", fd, size + 4, n); |
| 287 | } | 270 | } |
| 288 | } | 271 | } |
| @@ -329,21 +312,13 @@ static void GCC_FMT_ATTR (1, 2) printd (const char *fmt, ...) · 40 unmodified lines | |||
| 329 | writedata (state.csock, buf, len); | 312 | writedata (state.csock, buf, len); |
| 330 | break; | 313 | break; |
| 331 | } | 314 | } |
| 332 | else { | 315 | else size = len + 5; |
| 333 | size = len + 5; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | else { | ||
| 337 | err (1, "vsnprintf for `%s' failed", fmt); | ||
| 338 | } | 316 | } |
| 317 | else err (1, "vsnprintf for `%s' failed", fmt); | ||
| 339 | buf = realloc (buf == fbuf ? NULL : buf, size); | 318 | buf = realloc (buf == fbuf ? NULL : buf, size); |
| 340 | if (!buf) { | 319 | if (!buf) err (1, "realloc for temp buf (%d bytes) failed", size); |
| 341 | err (1, "realloc for temp buf (%d bytes) failed", size); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | if (buf != fbuf) { | ||
| 345 | free (buf); | ||
| 346 | } | 320 | } |
| 321 | if (buf != fbuf) free (buf); | ||
| 347 | } | 322 | } |
| 348 | 323 | ||
| 349 | static void closedoc (void) | 324 | static void closedoc (void) |
| @@ -409,14 +384,10 @@ static void docinfo (void) · 59 unmodified lines | |||
| 409 | again: | 384 | again: |
| 410 | need = fz_lookup_metadata (state.ctx, state.doc, tab[i].tag, buf, len); | 385 | need = fz_lookup_metadata (state.ctx, state.doc, tab[i].tag, buf, len); |
| 411 | if (need > 0) { | 386 | if (need > 0) { |
| 412 | if (need <= len) { | 387 | if (need <= len) printd ("info %s\t%s", tab[i].name, buf); |
| 413 | printd ("info %s\t%s", tab[i].name, buf); | ||
| 414 | } | ||
| 415 | else { | 388 | else { |
| 416 | buf = realloc (buf, need); | 389 | buf = realloc (buf, need); |
| 417 | if (!buf) { | 390 | if (!buf) err (1, "docinfo realloc %d", need); |
| 418 | err (1, "docinfo realloc %d", need); | ||
| 419 | } | ||
| 420 | len = need; | 391 | len = need; |
| 421 | goto again; | 392 | goto again; |
| 422 | } | 393 | } |
| @@ -442,15 +413,9 @@ static void unlinktile (struct tile *tile) · 19 unmodified lines | |||
| 442 | 413 | ||
| 443 | static void freepage (struct page *page) | 414 | static void freepage (struct page *page) |
| 444 | { | 415 | { |
| 445 | if (!page) { | 416 | if (!page) return; |
| 446 | return; | 417 | if (page->text) fz_drop_stext_page (state.ctx, page->text); |
| 447 | } | 418 | if (page->slinks) free (page->slinks); |
| 448 | if (page->text) { | ||
| 449 | fz_drop_stext_page (state.ctx, page->text); | ||
| 450 | } | ||
| 451 | if (page->slinks) { | ||
| 452 | free (page->slinks); | ||
| 453 | } | ||
| 454 | fz_drop_display_list (state.ctx, page->dlist); | 419 | fz_drop_display_list (state.ctx, page->dlist); |
| 455 | fz_drop_page (state.ctx, page->fzpage); | 420 | fz_drop_page (state.ctx, page->fzpage); |
| 456 | free (page); | 421 | free (page); |
| @@ -463,9 +428,7 @@ static void freetile (struct tile *tile) · 6 unmodified lines | |||
| 463 | #if 0 | 428 | #if 0 |
| 464 | fz_drop_pixmap (state.ctx, tile->pixmap); | 429 | fz_drop_pixmap (state.ctx, tile->pixmap); |
| 465 | #else /* piggyback */ | 430 | #else /* piggyback */ |
| 466 | if (state.pig) { | 431 | if (state.pig) fz_drop_pixmap (state.ctx, state.pig); |
| 467 | fz_drop_pixmap (state.ctx, state.pig); | ||
| 468 | } | ||
| 469 | state.pig = tile->pixmap; | 432 | state.pig = tile->pixmap; |
| 470 | #endif | 433 | #endif |
| 471 | } | 434 | } |
| @@ -480,9 +443,7 @@ static void trimctm (pdf_page *page, int pindex) · 8 unmodified lines | |||
| 480 | { | 443 | { |
| 481 | struct pagedim *pdim = &state.pagedims[pindex]; | 444 | struct pagedim *pdim = &state.pagedims[pindex]; |
| 482 | 445 | ||
| 483 | if (!page) { | 446 | if (!page) return; |
| 484 | return; | ||
| 485 | } | ||
| 486 | if (!pdim->tctmready) { | 447 | if (!pdim->tctmready) { |
| 487 | fz_rect realbox, mediabox; | 448 | fz_rect realbox, mediabox; |
| 488 | fz_matrix page_ctm, ctm; | 449 | fz_matrix page_ctm, ctm; |
| @@ -507,10 +468,8 @@ static fz_matrix pagectm1 (fz_page *fzpage, struct pagedim *pdim) · 18 unmodified lines | |||
| 507 | trimctm (pdf_page_from_fz_page (state.ctx, fzpage), (int) pdimno); | 468 | trimctm (pdf_page_from_fz_page (state.ctx, fzpage), (int) pdimno); |
| 508 | ctm = fz_concat (pdim->tctm, pdim->ctm); | 469 | ctm = fz_concat (pdim->tctm, pdim->ctm); |
| 509 | } | 470 | } |
| 510 | else { | 471 | else ctm = fz_concat (fz_translate (-pdim->mediabox.x0, -pdim->mediabox.y0), |
| 511 | ctm = fz_concat (fz_translate (-pdim->mediabox.x0, -pdim->mediabox.y0), | 472 | pdim->ctm); |
| 512 | pdim->ctm); | ||
| 513 | } | ||
| 514 | return ctm; | 473 | return ctm; |
| 515 | } | 474 | } |
| 516 | 475 | ||
| @@ -525,9 +484,7 @@ static void *loadpage (int pageno, int pindex) · 8 unmodified lines | |||
| 525 | struct page *page; | 484 | struct page *page; |
| 526 | 485 | ||
| 527 | page = calloc (sizeof (struct page), 1); | 486 | page = calloc (sizeof (struct page), 1); |
| 528 | if (!page) { | 487 | if (!page) err (1, "calloc page %d", pageno); |
| 529 | err (1, "calloc page %d", pageno); | ||
| 530 | } | ||
| 531 | 488 | ||
| 532 | page->dlist = fz_new_display_list (state.ctx, fz_infinite_rect); | 489 | page->dlist = fz_new_display_list (state.ctx, fz_infinite_rect); |
| 533 | dev = fz_new_list_device (state.ctx, page->dlist); | 490 | dev = fz_new_list_device (state.ctx, page->dlist); |
| @@ -558,9 +515,7 @@ static struct tile *alloctile (int h) · 24 unmodified lines | |||
| 558 | slicecount = (h + state.sliceheight - 1) / state.sliceheight; | 515 | slicecount = (h + state.sliceheight - 1) / state.sliceheight; |
| 559 | tilesize = sizeof (*tile) + ((slicecount - 1) * sizeof (struct slice)); | 516 | tilesize = sizeof (*tile) + ((slicecount - 1) * sizeof (struct slice)); |
| 560 | tile = calloc (tilesize, 1); | 517 | tile = calloc (tilesize, 1); |
| 561 | if (!tile) { | 518 | if (!tile) err (1, "cannot allocate tile (%zu bytes)", tilesize); |
| 562 | err (1, "cannot allocate tile (%zu bytes)", tilesize); | ||
| 563 | } | ||
| 564 | for (int i = 0; i < slicecount; ++i) { | 519 | for (int i = 0; i < slicecount; ++i) { |
| 565 | int sh = fz_mini (h, state.sliceheight); | 520 | int sh = fz_mini (h, state.sliceheight); |
| 566 | tile->slices[i].h = sh; | 521 | tile->slices[i].h = sh; |
| @@ -598,9 +553,7 @@ static struct tile *rendertile (struct page *page, int x, int y, int w, int h, · 31 unmodified lines | |||
| 598 | tile->pixmap->x = bbox.x0; | 553 | tile->pixmap->x = bbox.x0; |
| 599 | tile->pixmap->y = bbox.y0; | 554 | tile->pixmap->y = bbox.y0; |
| 600 | } | 555 | } |
| 601 | else { | 556 | else fz_drop_pixmap (state.ctx, state.pig); |
| 602 | fz_drop_pixmap (state.ctx, state.pig); | ||
| 603 | } | ||
| 604 | state.pig = NULL; | 557 | state.pig = NULL; |
| 605 | } | 558 | } |
| 606 | if (!tile->pixmap) { | 559 | if (!tile->pixmap) { |
| @@ -610,11 +563,8 @@ static struct tile *rendertile (struct page *page, int x, int y, int w, int h, · 3 unmodified lines | |||
| 610 | bbox, NULL, 1, pbo->ptr); | 563 | bbox, NULL, 1, pbo->ptr); |
| 611 | tile->pbo = pbo; | 564 | tile->pbo = pbo; |
| 612 | } | 565 | } |
| 613 | else { | 566 | else tile->pixmap = fz_new_pixmap_with_bbox ( |
| 614 | tile->pixmap = | 567 | state.ctx, state.colorspace, bbox, NULL, 1); |
| 615 | fz_new_pixmap_with_bbox (state.ctx, state.colorspace, bbox, | ||
| 616 | NULL, 1); | ||
| 617 | } | ||
| 618 | } | 568 | } |
| 619 | 569 | ||
| 620 | tile->w = w; | 570 | tile->w = w; |
| @@ -673,9 +623,7 @@ static void initpdims1 (void) · 52 unmodified lines | |||
| 673 | } | 623 | } |
| 674 | } | 624 | } |
| 675 | } | 625 | } |
| 676 | if (!pageobj) { | 626 | if (!pageobj) pageobj = pdf_lookup_page_obj (ctx, pdf, pageno); |
| 677 | pageobj = pdf_lookup_page_obj (ctx, pdf, pageno); | ||
| 678 | } | ||
| 679 | 627 | ||
| 680 | rotate = pdf_to_int (ctx, pdf_dict_gets (ctx, pageobj, "Rotate")); | 628 | rotate = pdf_to_int (ctx, pdf_dict_gets (ctx, pageobj, "Rotate")); |
| 681 | 629 | ||
| @@ -706,9 +654,7 @@ static void initpdims1 (void) · 24 unmodified lines | |||
| 706 | rect = fz_transform_rect (rect, ctm); | 654 | rect = fz_transform_rect (rect, ctm); |
| 707 | rect = fz_intersect_rect (rect, mediabox); | 655 | rect = fz_intersect_rect (rect, mediabox); |
| 708 | 656 | ||
| 709 | if (!fz_is_empty_rect (rect)) { | 657 | if (!fz_is_empty_rect (rect)) mediabox = rect; |
| 710 | mediabox = rect; | ||
| 711 | } | ||
| 712 | 658 | ||
| 713 | obj = pdf_new_array (ctx, pdf, 4); | 659 | obj = pdf_new_array (ctx, pdf, 4); |
| 714 | pdf_array_push_real (ctx, obj, mediabox.x0); | 660 | pdf_array_push_real (ctx, obj, mediabox.x0); |
| @@ -727,11 +673,10 @@ static void initpdims1 (void) · 12 unmodified lines | |||
| 727 | fz_drop_page (ctx, &page->super); | 673 | fz_drop_page (ctx, &page->super); |
| 728 | show = (pageno + 1 == state.pagecount) | 674 | show = (pageno + 1 == state.pagecount) |
| 729 | || (trim ? pageno % 5 == 0 : pageno % 20 == 0); | 675 | || (trim ? pageno % 5 == 0 : pageno % 20 == 0); |
| 730 | if (show) { | 676 | if (show) |
| 731 | printd ("progress %f Trimming %d", | 677 | printd ("progress %f Trimming %d", |
| 732 | (double) (pageno + 1) / state.pagecount, | 678 | (double) (pageno + 1) / state.pagecount, |
| 733 | pageno + 1); | 679 | pageno + 1); |
| 734 | } | ||
| 735 | } | 680 | } |
| 736 | fz_catch (ctx) { | 681 | fz_catch (ctx) { |
| 737 | printd ("emsg failed to load page %d", pageno); | 682 | printd ("emsg failed to load page %d", pageno); |
| @@ -760,22 +705,14 @@ static void initpdims1 (void) · 22 unmodified lines | |||
| 760 | cropbox = | 705 | cropbox = |
| 761 | pdf_to_rect (ctx, pdf_dict_gets (ctx, pageobj, "CropBox")); | 706 | pdf_to_rect (ctx, pdf_dict_gets (ctx, pageobj, "CropBox")); |
| 762 | if (!fz_is_empty_rect (cropbox)) { | 707 | if (!fz_is_empty_rect (cropbox)) { |
| 763 | if (empty) { | 708 | if (empty) mediabox = cropbox; |
| 764 | mediabox = cropbox; | 709 | else mediabox = fz_intersect_rect (mediabox, cropbox); |
| 765 | } | ||
| 766 | else { | ||
| 767 | mediabox = fz_intersect_rect (mediabox, cropbox); | ||
| 768 | } | ||
| 769 | } | 710 | } |
| 770 | else { | 711 | else { |
| 771 | if (empty) { | 712 | if (empty) { |
| 772 | if (fz_is_empty_rect (rootmediabox)) { | 713 | if (fz_is_empty_rect (rootmediabox)) |
| 773 | printd ("emsg cannot find page size for page %d", | 714 | printd ("emsg cannot find page %d size", pageno); |
| 774 | pageno); | 715 | else mediabox = rootmediabox; |
| 775 | } | ||
| 776 | else { | ||
| 777 | mediabox = rootmediabox; | ||
| 778 | } | ||
| 779 | } | 716 | } |
| 780 | } | 717 | } |
| 781 | } | 718 | } |
| @@ -802,9 +739,7 @@ static void initpdims1 (void) · 20 unmodified lines | |||
| 802 | rect.y1 += state.trimfuzz.y1; | 739 | rect.y1 += state.trimfuzz.y1; |
| 803 | rect = fz_intersect_rect (rect, mediabox); | 740 | rect = fz_intersect_rect (rect, mediabox); |
| 804 | 741 | ||
| 805 | if (!fz_is_empty_rect (rect)) { | 742 | if (!fz_is_empty_rect (rect)) mediabox = rect; |
| 806 | mediabox = rect; | ||
| 807 | } | ||
| 808 | } | 743 | } |
| 809 | fz_drop_page (ctx, page); | 744 | fz_drop_page (ctx, page); |
| 810 | } | 745 | } |
| @@ -819,11 +754,9 @@ static void initpdims1 (void) · 8 unmodified lines | |||
| 819 | fz_drop_page (ctx, page); | 754 | fz_drop_page (ctx, page); |
| 820 | 755 | ||
| 821 | show = !state.trimmargins && pageno % 20 == 0; | 756 | show = !state.trimmargins && pageno % 20 == 0; |
| 822 | if (show) { | 757 | if (show) printd ("progress %f Gathering dimensions %d", |
| 823 | printd ("progress %f Gathering dimensions %d", | 758 | (double) (pageno) / state.pagecount, |
| 824 | (double) (pageno) / state.pagecount, | 759 | pageno); |
| 825 | pageno); | ||
| 826 | } | ||
| 827 | } | 760 | } |
| 828 | fz_catch (ctx) { | 761 | fz_catch (ctx) { |
| 829 | printd ("emsg failed to load page %d", pageno); | 762 | printd ("emsg failed to load page %d", pageno); |
| @@ -838,10 +771,8 @@ static void initpdims1 (void) · 8 unmodified lines | |||
| 838 | 771 | ||
| 839 | size = (state.pagedimcount + 1) * sizeof (*state.pagedims); | 772 | size = (state.pagedimcount + 1) * sizeof (*state.pagedims); |
| 840 | state.pagedims = realloc (state.pagedims, size); | 773 | state.pagedims = realloc (state.pagedims, size); |
| 841 | if (!state.pagedims) { | 774 | if (!state.pagedims) err (1, "realloc pagedims to %zu (%d elems)", |
| 842 | err (1, "realloc pagedims to %zu (%d elems)", | 775 | size, state.pagedimcount + 1); |
| 843 | size, state.pagedimcount + 1); | ||
| 844 | } | ||
| 845 | 776 | ||
| 846 | p = &state.pagedims[state.pagedimcount++]; | 777 | p = &state.pagedims[state.pagedimcount++]; |
| 847 | p->rotate = rotate; | 778 | p->rotate = rotate; |
| @@ -865,17 +796,15 @@ static void initpdims (void) · 17 unmodified lines | |||
| 865 | } | 796 | } |
| 866 | size_t size = (state.pagedimcount + 1) * sizeof (*state.pagedims); | 797 | size_t size = (state.pagedimcount + 1) * sizeof (*state.pagedims); |
| 867 | state.pagedims = realloc (state.pagedims, size); | 798 | state.pagedims = realloc (state.pagedims, size); |
| 868 | if (!state.pagedims) { | 799 | if (!state.pagedims) |
| 869 | err (1, "realloc pagedims to %zu (%d elems)", | 800 | err (1, "realloc pagedims to %zu (%d elems)", |
| 870 | size, state.pagedimcount + 1); | 801 | size, state.pagedimcount + 1); |
| 871 | } | ||
| 872 | if (fread (state.pagedims, | 802 | if (fread (state.pagedims, |
| 873 | sizeof (*state.pagedims), | 803 | sizeof (*state.pagedims), |
| 874 | state.pagedimcount+1, | 804 | state.pagedimcount+1, |
| 875 | f) - (state.pagedimcount+1)) { | 805 | f) - (state.pagedimcount+1)) |
| 876 | err (1, "fread pagedim data %zu %d", | 806 | err (1, "fread pagedim data %zu %d", |
| 877 | sizeof (*state.pagedims), state.pagedimcount+1); | 807 | sizeof (*state.pagedims), state.pagedimcount+1); |
| 878 | } | ||
| 879 | fclose (f); | 808 | fclose (f); |
| 880 | } | 809 | } |
| 881 | 810 | ||
| @@ -883,20 +812,17 @@ static void initpdims (void) · 1 unmodified line | |||
| 883 | initpdims1 (); | 812 | initpdims1 (); |
| 884 | if (state.dcf) { | 813 | if (state.dcf) { |
| 885 | f = fopen (state.dcf, "wb"); | 814 | f = fopen (state.dcf, "wb"); |
| 886 | if (!f) { | 815 | if (!f) err (1, "fopen %s for writing", state.dcf); |
| 887 | err (1, "fopen %s for writing", state.dcf); | ||
| 888 | } | ||
| 889 | if (fwrite (&state.pagedimcount, | 816 | if (fwrite (&state.pagedimcount, |
| 890 | sizeof (state.pagedimcount), 1, f) - 1) { | 817 | sizeof (state.pagedimcount), 1, f) - 1) |
| 891 | err (1, "fwrite pagedimcunt %zu", sizeof (state.pagedimcount)); | 818 | err (1, "fwrite pagedimcunt %zu", sizeof (state.pagedimcount)); |
| 892 | } | ||
| 893 | if (fwrite (state.pagedims, sizeof (*state.pagedims), | 819 | if (fwrite (state.pagedims, sizeof (*state.pagedims), |
| 894 | state.pagedimcount + 1, f) | 820 | state.pagedimcount + 1, f) |
| 895 | - (state.pagedimcount + 1)) { | 821 | - (state.pagedimcount + 1)) |
| 896 | err (1, "fwrite pagedim data %zu %u", | 822 | err (1, "fwrite pagedim data %zu %u", |
| 897 | sizeof (*state.pagedims), state.pagedimcount+1); | 823 | sizeof (*state.pagedims), state.pagedimcount+1); |
| 898 | } fclose (f); | ||
| 899 | } | 824 | } |
| 825 | fclose (f); | ||
| 900 | } | 826 | } |
| 901 | } | 827 | } |
| 902 | 828 | ||
| @@ -908,9 +834,7 @@ static void layout (void) · 5 unmodified lines | |||
| 908 | struct pagedim *p = NULL; | 834 | struct pagedim *p = NULL; |
| 909 | float zw, w, maxw = 0.0, zoom = 1.0; | 835 | float zw, w, maxw = 0.0, zoom = 1.0; |
| 910 | 836 | ||
| 911 | if (state.pagedimcount == 0) { | 837 | if (state.pagedimcount == 0) return; |
| 912 | return; | ||
| 913 | } | ||
| 914 | 838 | ||
| 915 | switch (state.fitmodel) { | 839 | switch (state.fitmodel) { |
| 916 | case FitProportional: | 840 | case FitProportional: |
| @@ -1019,12 +943,8 @@ static void recurse_outline (fz_outline *outline, int level) · 102 unmodified lines | |||
| 1019 | printd ("o %d %d %d %d %s", | 943 | printd ("o %d %d %d %d %s", |
| 1020 | level, outline->page, (int) p.y, h, outline->title); | 944 | level, outline->page, (int) p.y, h, outline->title); |
| 1021 | } | 945 | } |
| 1022 | else { | 946 | else printd ("on %d %s", level, outline->title); |
| 1023 | printd ("on %d %s", level, outline->title); | 947 | if (outline->down) recurse_outline (outline->down, level + 1); |
| 1024 | } | ||
| 1025 | if (outline->down) { | ||
| 1026 | recurse_outline (outline->down, level + 1); | ||
| 1027 | } | ||
| 1028 | outline = outline->next; | 948 | outline = outline->next; |
| 1029 | } | 949 | } |
| 1030 | } | 950 | } |
| @@ -1033,9 +953,7 @@ static void process_outline (void) · 2 unmodified lines | |||
| 1033 | { | 953 | { |
| 1034 | fz_outline *outline; | 954 | fz_outline *outline; |
| 1035 | 955 | ||
| 1036 | if (!state.needoutline || !state.pagedimcount) { | 956 | if (!state.needoutline || !state.pagedimcount) return; |
| 1037 | return; | ||
| 1038 | } | ||
| 1039 | 957 | ||
| 1040 | state.needoutline = 0; | 958 | state.needoutline = 0; |
| 1041 | outline = fz_load_outline (state.ctx, state.doc); | 959 | outline = fz_load_outline (state.ctx, state.doc); |
| @@ -1053,18 +971,14 @@ static char *strofline (fz_stext_line *line) · 11 unmodified lines | |||
| 1053 | size_t size = 0, cap = 80; | 971 | size_t size = 0, cap = 80; |
| 1054 | 972 | ||
| 1055 | p = malloc (cap + 1); | 973 | p = malloc (cap + 1); |
| 1056 | if (!p) { | 974 | if (!p) return NULL; |
| 1057 | return NULL; | ||
| 1058 | } | ||
| 1059 | 975 | ||
| 1060 | for (ch = line->first_char; ch; ch = ch->next) { | 976 | for (ch = line->first_char; ch; ch = ch->next) { |
| 1061 | int n = fz_runetochar (utf8, ch->c); | 977 | int n = fz_runetochar (utf8, ch->c); |
| 1062 | if (size + n > cap) { | 978 | if (size + n > cap) { |
| 1063 | cap *= 2; | 979 | cap *= 2; |
| 1064 | p = realloc (p, cap + 1); | 980 | p = realloc (p, cap + 1); |
| 1065 | if (!p) { | 981 | if (!p) return NULL; |
| 1066 | return NULL; | ||
| 1067 | } | ||
| 1068 | } | 982 | } |
| 1069 | 983 | ||
| 1070 | memcpy (p + size, utf8, n); | 984 | memcpy (p + size, utf8, n); |
| @@ -1082,9 +996,7 @@ static int matchline (regex_t *re, fz_stext_line *line, · 11 unmodified lines | |||
| 1082 | regmatch_t rm; | 996 | regmatch_t rm; |
| 1083 | 997 | ||
| 1084 | p = strofline (line); | 998 | p = strofline (line); |
| 1085 | if (!p) { | 999 | if (!p) return -1; |
| 1086 | return -1; | ||
| 1087 | } | ||
| 1088 | 1000 | ||
| 1089 | ret = regexec (re, p, 1, &rm, 0); | 1001 | ret = regexec (re, p, 1, &rm, 0); |
| 1090 | if (ret) { | 1002 | if (ret) { |
| @@ -1113,9 +1025,7 @@ static int matchline (regex_t *re, fz_stext_line *line, · 22 unmodified lines | |||
| 1113 | } | 1025 | } |
| 1114 | for (;ch; ch = ch->next) { | 1026 | for (;ch; ch = ch->next) { |
| 1115 | o += fz_runelen (ch->c); | 1027 | o += fz_runelen (ch->c); |
| 1116 | if (o > rm.rm_eo) { | 1028 | if (o > rm.rm_eo) break; |
| 1117 | break; | ||
| 1118 | } | ||
| 1119 | } | 1029 | } |
| 1120 | e = ch->quad; | 1030 | e = ch->quad; |
| 1121 | 1031 | ||
| @@ -1131,14 +1041,12 @@ static int matchline (regex_t *re, fz_stext_line *line, · 9 unmodified lines | |||
| 1131 | pageno + 1, (int) (rm.rm_eo - rm.rm_so), &p[rm.rm_so], | 1041 | pageno + 1, (int) (rm.rm_eo - rm.rm_so), &p[rm.rm_so], |
| 1132 | now () - start); | 1042 | now () - start); |
| 1133 | } | 1043 | } |
| 1134 | else { | 1044 | else printd ("match %d %d %f %f %f %f %f %f %f %f", |
| 1135 | printd ("match %d %d %f %f %f %f %f %f %f %f", | 1045 | pageno, 2, |
| 1136 | pageno, 2, | 1046 | s.ul.x, s.ul.y, |
| 1137 | s.ul.x, s.ul.y, | 1047 | e.ur.x, s.ul.y, |
| 1138 | e.ur.x, s.ul.y, | 1048 | e.lr.x, e.lr.y, |
| 1139 | e.lr.x, e.lr.y, | 1049 | s.ul.x, e.lr.y); |
| 1140 | s.ul.x, e.lr.y); | ||
| 1141 | } | ||
| 1142 | free (p); | 1050 | free (p); |
| 1143 | return 1; | 1051 | return 1; |
| 1144 | } | 1052 | } |
| @@ -1164,11 +1072,9 @@ static void search (regex_t *re, int pageno, int y, int forward) · 19 unmodified lines | |||
| 1164 | pageno); | 1072 | pageno); |
| 1165 | stop = 1; | 1073 | stop = 1; |
| 1166 | } | 1074 | } |
| 1167 | else { | 1075 | else printd ("progress %f searching in page %d", |
| 1168 | printd ("progress %f searching in page %d", | 1076 | (double) (pageno + 1) / state.pagecount, |
| 1169 | (double) (pageno + 1) / state.pagecount, | 1077 | pageno); |
| 1170 | pageno); | ||
| 1171 | } | ||
| 1172 | } | 1078 | } |
| 1173 | pdim = pdimofpageno (pageno); | 1079 | pdim = pdimofpageno (pageno); |
| 1174 | text = fz_new_stext_page (state.ctx, pdim->mediabox); | 1080 | text = fz_new_stext_page (state.ctx, pdim->mediabox); |
| @@ -1184,13 +1090,10 @@ static void search (regex_t *re, int pageno, int y, int forward) · 9 unmodified lines | |||
| 1184 | for (block = text->first_block; block; block = block->next) { | 1090 | for (block = text->first_block; block; block = block->next) { |
| 1185 | fz_stext_line *line; | 1091 | fz_stext_line *line; |
| 1186 | 1092 | ||
| 1187 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 1093 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 1188 | continue; | 1094 | |
| 1189 | } | ||
| 1190 | for (line = block->u.t.first_line; line; line = line->next) { | 1095 | for (line = block->u.t.first_line; line; line = line->next) { |
| 1191 | if (line->bbox.y0 < y + 1) { | 1096 | if (line->bbox.y0 < y + 1) continue; |
| 1192 | continue; | ||
| 1193 | } | ||
| 1194 | 1097 | ||
| 1195 | switch (matchline (re, line, stop, pageno, start)) { | 1098 | switch (matchline (re, line, stop, pageno, start)) { |
| 1196 | case 0: break; | 1099 | case 0: break; |
| @@ -1204,13 +1107,10 @@ static void search (regex_t *re, int pageno, int y, int forward) · 7 unmodified lines | |||
| 1204 | for (block = text->last_block; block; block = block->prev) { | 1107 | for (block = text->last_block; block; block = block->prev) { |
| 1205 | fz_stext_line *line; | 1108 | fz_stext_line *line; |
| 1206 | 1109 | ||
| 1207 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 1110 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 1208 | continue; | 1111 | |
| 1209 | } | ||
| 1210 | for (line = block->u.t.last_line; line; line = line->prev) { | 1112 | for (line = block->u.t.last_line; line; line = line->prev) { |
| 1211 | if (line->bbox.y0 < y + 1) { | 1113 | if (line->bbox.y0 < y + 1) continue; |
| 1212 | continue; | ||
| 1213 | } | ||
| 1214 | 1114 | ||
| 1215 | switch (matchline (re, line, stop, pageno, start)) { | 1115 | switch (matchline (re, line, stop, pageno, start)) { |
| 1216 | case 0: break; | 1116 | case 0: break; |
| @@ -1234,9 +1134,7 @@ static void search (regex_t *re, int pageno, int y, int forward) · 17 unmodified lines | |||
| 1234 | fz_drop_page (state.ctx, page); | 1134 | fz_drop_page (state.ctx, page); |
| 1235 | } | 1135 | } |
| 1236 | end = now (); | 1136 | end = now (); |
| 1237 | if (!stop) { | 1137 | if (!stop) printd ("progress 1 no matches %f sec", end - start); |
| 1238 | printd ("progress 1 no matches %f sec", end - start); | ||
| 1239 | } | ||
| 1240 | printd ("clearrects"); | 1138 | printd ("clearrects"); |
| 1241 | } | 1139 | } |
| 1242 | 1140 | ||
| @@ -1264,20 +1162,15 @@ static void realloctexts (int texcount) · 21 unmodified lines | |||
| 1264 | { | 1162 | { |
| 1265 | size_t size; | 1163 | size_t size; |
| 1266 | 1164 | ||
| 1267 | if (texcount == state.tex.count) { | 1165 | if (texcount == state.tex.count) return; |
| 1268 | return; | ||
| 1269 | } | ||
| 1270 | 1166 | ||
| 1271 | if (texcount < state.tex.count) { | 1167 | if (texcount < state.tex.count) |
| 1272 | glDeleteTextures (state.tex.count - texcount, | 1168 | glDeleteTextures (state.tex.count - texcount, |
| 1273 | state.tex.ids + texcount); | 1169 | state.tex.ids + texcount); |
| 1274 | } | ||
| 1275 | 1170 | ||
| 1276 | size = texcount * (sizeof (*state.tex.ids) + sizeof (*state.tex.owners)); | 1171 | size = texcount * (sizeof (*state.tex.ids) + sizeof (*state.tex.owners)); |
| 1277 | state.tex.ids = realloc (state.tex.ids, size); | 1172 | state.tex.ids = realloc (state.tex.ids, size); |
| 1278 | if (!state.tex.ids) { | 1173 | if (!state.tex.ids) err (1, "realloc texs %zu", size); |
| 1279 | err (1, "realloc texs %zu", size); | ||
| 1280 | } | ||
| 1281 | 1174 | ||
| 1282 | state.tex.owners = (void *) (state.tex.ids + texcount); | 1175 | state.tex.owners = (void *) (state.tex.ids + texcount); |
| 1283 | if (texcount > state.tex.count) { | 1176 | if (texcount > state.tex.count) { |
| @@ -1298,9 +1191,7 @@ static char *mbtoutf8 (char *s) · 14 unmodified lines | |||
| 1298 | wchar_t *tmp; | 1191 | wchar_t *tmp; |
| 1299 | size_t i, ret, len; | 1192 | size_t i, ret, len; |
| 1300 | 1193 | ||
| 1301 | if (state.utf8cs) { | 1194 | if (state.utf8cs) return s; |
| 1302 | return s; | ||
| 1303 | } | ||
| 1304 | 1195 | ||
| 1305 | len = mbstowcs (NULL, s, strlen (s)); | 1196 | len = mbstowcs (NULL, s, strlen (s)); |
| 1306 | if (len == 0 || len == (size_t) -1) { | 1197 | if (len == 0 || len == (size_t) -1) { |
| @@ -1371,15 +1262,11 @@ static void * mainloop (void UNUSED_ATTR *unused) · 64 unmodified lines | |||
| 1371 | fz_var (oldlen); | 1262 | fz_var (oldlen); |
| 1372 | for (;;) { | 1263 | for (;;) { |
| 1373 | len = readlen (state.csock); | 1264 | len = readlen (state.csock); |
| 1374 | if (len == 0) { | 1265 | if (len == 0) errx (1, "readlen returned 0"); |
| 1375 | errx (1, "readlen returned 0"); | ||
| 1376 | } | ||
| 1377 | 1266 | ||
| 1378 | if (oldlen < len + 1) { | 1267 | if (oldlen < len + 1) { |
| 1379 | p = realloc (p, len + 1); | 1268 | p = realloc (p, len + 1); |
| 1380 | if (!p) { | 1269 | if (!p) err (1, "realloc %d failed", len + 1); |
| 1381 | err (1, "realloc %d failed", len + 1); | ||
| 1382 | } | ||
| 1383 | oldlen = len + 1; | 1270 | oldlen = len + 1; |
| 1384 | } | 1271 | } |
| 1385 | readdata (state.csock, p, len); | 1272 | readdata (state.csock, p, len); |
| @@ -1394,17 +1281,14 @@ static void * mainloop (void UNUSED_ATTR *unused) · 8 unmodified lines | |||
| 1394 | 1281 | ||
| 1395 | fz_var (ok); | 1282 | fz_var (ok); |
| 1396 | ret = sscanf (p + 5, " %d %d %n", &usedoccss, &layouth, &off); | 1283 | ret = sscanf (p + 5, " %d %d %n", &usedoccss, &layouth, &off); |
| 1397 | if (ret != 2) { | 1284 | if (ret != 2) errx (1, "malformed open `%.*s' ret=%d", len, p, ret); |
| 1398 | errx (1, "malformed open `%.*s' ret=%d", len, p, ret); | ||
| 1399 | } | ||
| 1400 | 1285 | ||
| 1401 | filename = p + 5 + off; | 1286 | filename = p + 5 + off; |
| 1402 | filenamelen = strlen (filename); | 1287 | filenamelen = strlen (filename); |
| 1403 | password = filename + filenamelen + 1; | 1288 | password = filename + filenamelen + 1; |
| 1404 | 1289 | ||
| 1405 | if (password[strlen (password) + 1]) { | 1290 | if (password[strlen (password) + 1]) |
| 1406 | fz_set_user_css (state.ctx, password + strlen (password) + 1); | 1291 | fz_set_user_css (state.ctx, password + strlen (password) + 1); |
| 1407 | } | ||
| 1408 | 1292 | ||
| 1409 | lock ("open"); | 1293 | lock ("open"); |
| 1410 | fz_set_use_document_css (state.ctx, usedoccss); | 1294 | fz_set_use_document_css (state.ctx, usedoccss); |
| @@ -1415,9 +1299,7 @@ static void * mainloop (void UNUSED_ATTR *unused) · 4 unmodified lines | |||
| 1415 | utf8filename = mbtoutf8 (filename); | 1299 | utf8filename = mbtoutf8 (filename); |
| 1416 | printd ("emsg Error loading %s: %s", | 1300 | printd ("emsg Error loading %s: %s", |
| 1417 | utf8filename, fz_caught_message (state.ctx)); | 1301 | utf8filename, fz_caught_message (state.ctx)); |
| 1418 | if (utf8filename != filename) { | 1302 | if (utf8filename != filename) free (utf8filename); |
| 1419 | free (utf8filename); | ||
| 1420 | } | ||
| 1421 | } | 1303 | } |
| 1422 | if (ok) { | 1304 | if (ok) { |
| 1423 | docinfo (); | 1305 | docinfo (); |
| @@ -1430,9 +1312,7 @@ static void * mainloop (void UNUSED_ATTR *unused) · 6 unmodified lines | |||
| 1430 | int i, colorspace; | 1312 | int i, colorspace; |
| 1431 | 1313 | ||
| 1432 | ret = sscanf (p + 2, " %d", &colorspace); | 1314 | ret = sscanf (p + 2, " %d", &colorspace); |
| 1433 | if (ret != 1) { | 1315 | if (ret != 1) errx (1, "malformed cs `%.*s' ret=%d", len, p, ret); |
| 1434 | errx (1, "malformed cs `%.*s' ret=%d", len, p, ret); | ||
| 1435 | } | ||
| 1436 | lock ("cs"); | 1316 | lock ("cs"); |
| 1437 | set_tex_params (colorspace); | 1317 | set_tex_params (colorspace); |
| 1438 | for (i = 0; i < state.tex.count; ++i) { | 1318 | for (i = 0; i < state.tex.count; ++i) { |
| @@ -1445,9 +1325,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 6 unmodified lines | |||
| 1445 | void *ptr; | 1325 | void *ptr; |
| 1446 | 1326 | ||
| 1447 | ret = sscanf (p + 8, " %" SCNxPTR, (uintptr_t *) &ptr); | 1327 | ret = sscanf (p + 8, " %" SCNxPTR, (uintptr_t *) &ptr); |
| 1448 | if (ret != 1) { | 1328 | if (ret != 1) |
| 1449 | errx (1, "malformed freepage `%.*s' ret=%d", len, p, ret); | 1329 | errx (1, "malformed freepage `%.*s' ret=%d", len, p, ret); |
| 1450 | } | ||
| 1451 | lock ("freepage"); | 1330 | lock ("freepage"); |
| 1452 | freepage (ptr); | 1331 | freepage (ptr); |
| 1453 | unlock ("freepage"); | 1332 | unlock ("freepage"); |
| @@ -1456,9 +1335,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 2 unmodified lines | |||
| 1456 | void *ptr; | 1335 | void *ptr; |
| 1457 | 1336 | ||
| 1458 | ret = sscanf (p + 8, " %" SCNxPTR, (uintptr_t *) &ptr); | 1337 | ret = sscanf (p + 8, " %" SCNxPTR, (uintptr_t *) &ptr); |
| 1459 | if (ret != 1) { | 1338 | if (ret != 1) |
| 1460 | errx (1, "malformed freetile `%.*s' ret=%d", len, p, ret); | 1339 | errx (1, "malformed freetile `%.*s' ret=%d", len, p, ret); |
| 1461 | } | ||
| 1462 | lock ("freetile"); | 1340 | lock ("freetile"); |
| 1463 | freetile (ptr); | 1341 | freetile (ptr); |
| 1464 | unlock ("freetile"); | 1342 | unlock ("freetile"); |
| @@ -1470,9 +1348,7 @@ static void * mainloop (void UNUSED_ATTR *unused) · 5 unmodified lines | |||
| 1470 | 1348 | ||
| 1471 | ret = sscanf (p + 6, " %d %d %d %d,%n", | 1349 | ret = sscanf (p + 6, " %d %d %d %d,%n", |
| 1472 | &icase, &pageno, &y, &forward, &len2); | 1350 | &icase, &pageno, &y, &forward, &len2); |
| 1473 | if (ret != 4) { | 1351 | if (ret != 4) errx (1, "malformed search `%s' ret=%d", p, ret); |
| 1474 | errx (1, "malformed search `%s' ret=%d", p, ret); | ||
| 1475 | } | ||
| 1476 | 1352 | ||
| 1477 | pattern = p + 6 + len2; | 1353 | pattern = p + 6 + len2; |
| 1478 | ret = regcomp (&re, pattern, | 1354 | ret = regcomp (&re, pattern, |
| @@ -1496,9 +1372,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 17 unmodified lines | |||
| 1496 | 1372 | ||
| 1497 | printd ("clear"); | 1373 | printd ("clear"); |
| 1498 | ret = sscanf (p + 8, " %d %d %d", &w, &h, &fitmodel); | 1374 | ret = sscanf (p + 8, " %d %d %d", &w, &h, &fitmodel); |
| 1499 | if (ret != 3) { | 1375 | if (ret != 3) |
| 1500 | errx (1, "malformed geometry `%.*s' ret=%d", len, p, ret); | 1376 | errx (1, "malformed geometry `%.*s' ret=%d", len, p, ret); |
| 1501 | } | ||
| 1502 | 1377 | ||
| 1503 | lock ("geometry"); | 1378 | lock ("geometry"); |
| 1504 | state.h = h; | 1379 | state.h = h; |
| @@ -1525,14 +1400,12 @@ static void * mainloop (void UNUSED_ATTR *unused) · 20 unmodified lines | |||
| 1525 | printd ("clear"); | 1400 | printd ("clear"); |
| 1526 | ret = sscanf (p + 9, " %d %d %d %n", | 1401 | ret = sscanf (p + 9, " %d %d %d %n", |
| 1527 | &rotate, &fitmodel, &h, &off); | 1402 | &rotate, &fitmodel, &h, &off); |
| 1528 | if (ret != 3) { | 1403 | if (ret != 3) |
| 1529 | errx (1, "bad reqlayout line `%.*s' ret=%d", len, p, ret); | 1404 | errx (1, "bad reqlayout line `%.*s' ret=%d", len, p, ret); |
| 1530 | } | ||
| 1531 | lock ("reqlayout"); | 1405 | lock ("reqlayout"); |
| 1532 | pdf = pdf_specifics (state.ctx, state.doc); | 1406 | pdf = pdf_specifics (state.ctx, state.doc); |
| 1533 | if (state.rotate != rotate || state.fitmodel != fitmodel) { | 1407 | if (state.rotate != rotate || state.fitmodel != fitmodel) |
| 1534 | state.gen += 1; | 1408 | state.gen += 1; |
| 1535 | } | ||
| 1536 | state.rotate = rotate; | 1409 | state.rotate = rotate; |
| 1537 | state.fitmodel = fitmodel; | 1410 | state.fitmodel = fitmodel; |
| 1538 | state.h = h; | 1411 | state.h = h; |
| @@ -1560,9 +1433,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 21 unmodified lines | |||
| 1560 | int pageno, pindex; | 1433 | int pageno, pindex; |
| 1561 | 1434 | ||
| 1562 | ret = sscanf (p + 4, " %d %d", &pageno, &pindex); | 1435 | ret = sscanf (p + 4, " %d %d", &pageno, &pindex); |
| 1563 | if (ret != 2) { | 1436 | if (ret != 2) |
| 1564 | errx (1, "bad page line `%.*s' ret=%d", len, p, ret); | 1437 | errx (1, "bad page line `%.*s' ret=%d", len, p, ret); |
| 1565 | } | ||
| 1566 | 1438 | ||
| 1567 | lock ("page"); | 1439 | lock ("page"); |
| 1568 | a = now (); | 1440 | a = now (); |
| @@ -1582,9 +1454,7 @@ static void * mainloop (void UNUSED_ATTR *unused) · 13 unmodified lines | |||
| 1582 | ret = sscanf (p + 4, " %" SCNxPTR " %d %d %d %d %" SCNxPTR, | 1454 | ret = sscanf (p + 4, " %" SCNxPTR " %d %d %d %d %" SCNxPTR, |
| 1583 | (uintptr_t *) &page, &x, &y, &w, &h, | 1455 | (uintptr_t *) &page, &x, &y, &w, &h, |
| 1584 | (uintptr_t *) &data); | 1456 | (uintptr_t *) &data); |
| 1585 | if (ret != 6) { | 1457 | if (ret != 6) errx (1, "bad tile line `%.*s' ret=%d", len, p, ret); |
| 1586 | errx (1, "bad tile line `%.*s' ret=%d", len, p, ret); | ||
| 1587 | } | ||
| 1588 | 1458 | ||
| 1589 | lock ("tile"); | 1459 | lock ("tile"); |
| 1590 | a = now (); | 1460 | a = now (); |
| @@ -1603,9 +1473,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 12 unmodified lines | |||
| 1603 | 1473 | ||
| 1604 | ret = sscanf (p + 7, " %d %d %d %d %d", | 1474 | ret = sscanf (p + 7, " %d %d %d %d %d", |
| 1605 | &trimmargins, &fuzz.x0, &fuzz.y0, &fuzz.x1, &fuzz.y1); | 1475 | &trimmargins, &fuzz.x0, &fuzz.y0, &fuzz.x1, &fuzz.y1); |
| 1606 | if (ret != 5) { | 1476 | if (ret != 5) |
| 1607 | errx (1, "malformed trimset `%.*s' ret=%d", len, p, ret); | 1477 | errx (1, "malformed trimset `%.*s' ret=%d", len, p, ret); |
| 1608 | } | ||
| 1609 | lock ("trimset"); | 1478 | lock ("trimset"); |
| 1610 | state.trimmargins = trimmargins; | 1479 | state.trimmargins = trimmargins; |
| 1611 | if (memcmp (&fuzz, &state.trimfuzz, sizeof (fuzz))) { | 1480 | if (memcmp (&fuzz, &state.trimfuzz, sizeof (fuzz))) { |
| @@ -1620,9 +1489,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 8 unmodified lines | |||
| 1620 | 1489 | ||
| 1621 | ret = sscanf (p + 7, " %d %d %d %d %d", | 1490 | ret = sscanf (p + 7, " %d %d %d %d %d", |
| 1622 | &trimmargins, &fuzz.x0, &fuzz.y0, &fuzz.x1, &fuzz.y1); | 1491 | &trimmargins, &fuzz.x0, &fuzz.y0, &fuzz.x1, &fuzz.y1); |
| 1623 | if (ret != 5) { | 1492 | if (ret != 5) |
| 1624 | errx (1, "malformed settrim `%.*s' ret=%d", len, p, ret); | 1493 | errx (1, "malformed settrim `%.*s' ret=%d", len, p, ret); |
| 1625 | } | ||
| 1626 | printd ("clear"); | 1494 | printd ("clear"); |
| 1627 | lock ("settrim"); | 1495 | lock ("settrim"); |
| 1628 | state.trimmargins = trimmargins; | 1496 | state.trimmargins = trimmargins; |
| @@ -1644,9 +1512,8 @@ static void * mainloop (void UNUSED_ATTR *unused) · 15 unmodified lines | |||
| 1644 | int h; | 1512 | int h; |
| 1645 | 1513 | ||
| 1646 | ret = sscanf (p + 6, " %d", &h); | 1514 | ret = sscanf (p + 6, " %d", &h); |
| 1647 | if (ret != 1) { | 1515 | if (ret != 1) |
| 1648 | errx (1, "malformed sliceh `%.*s' ret=%d", len, p, ret); | 1516 | errx (1, "malformed sliceh `%.*s' ret=%d", len, p, ret); |
| 1649 | } | ||
| 1650 | if (h != state.sliceheight) { | 1517 | if (h != state.sliceheight) { |
| 1651 | state.sliceheight = h; | 1518 | state.sliceheight = h; |
| 1652 | for (int i = 0; i < state.tex.count; ++i) { | 1519 | for (int i = 0; i < state.tex.count; ++i) { |
| @@ -1729,9 +1596,7 @@ static void showsel (struct page *page, int ox, int oy) · 76 unmodified lines | |||
| 1729 | int seen = 0; | 1596 | int seen = 0; |
| 1730 | unsigned char selcolor[] = {15,15,15,140}; | 1597 | unsigned char selcolor[] = {15,15,15,140}; |
| 1731 | 1598 | ||
| 1732 | if (!page->fmark || !page->lmark) { | 1599 | if (!page->fmark || !page->lmark) return; |
| 1733 | return; | ||
| 1734 | } | ||
| 1735 | 1600 | ||
| 1736 | glEnable (GL_BLEND); | 1601 | glEnable (GL_BLEND); |
| 1737 | glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA); | 1602 | glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA); |
| @@ -1743,22 +1608,16 @@ static void showsel (struct page *page, int ox, int oy) · 5 unmodified lines | |||
| 1743 | for (block = page->text->first_block; block; block = block->next) { | 1608 | for (block = page->text->first_block; block; block = block->next) { |
| 1744 | fz_stext_line *line; | 1609 | fz_stext_line *line; |
| 1745 | 1610 | ||
| 1746 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 1611 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 1747 | continue; | ||
| 1748 | } | ||
| 1749 | for (line = block->u.t.first_line; line; line = line->next) { | 1612 | for (line = block->u.t.first_line; line; line = line->next) { |
| 1750 | fz_stext_char *ch; | 1613 | fz_stext_char *ch; |
| 1751 | 1614 | ||
| 1752 | rect = fz_empty_rect; | 1615 | rect = fz_empty_rect; |
| 1753 | for (ch = line->first_char; ch; ch = ch->next) { | 1616 | for (ch = line->first_char; ch; ch = ch->next) { |
| 1754 | fz_rect r; | 1617 | fz_rect r; |
| 1755 | if (ch == page->fmark) { | 1618 | if (ch == page->fmark) seen = 1; |
| 1756 | seen = 1; | ||
| 1757 | } | ||
| 1758 | r = fz_rect_from_quad (ch->quad); | 1619 | r = fz_rect_from_quad (ch->quad); |
| 1759 | if (seen) { | 1620 | if (seen) rect = fz_union_rect (rect, r); |
| 1760 | rect = fz_union_rect (rect, r); | ||
| 1761 | } | ||
| 1762 | if (ch == page->lmark) { | 1621 | if (ch == page->lmark) { |
| 1763 | bbox = fz_round_rect (rect); | 1622 | bbox = fz_round_rect (rect); |
| 1764 | recti (bbox.x0 + ox, bbox.y0 + oy, | 1623 | recti (bbox.x0 + ox, bbox.y0 + oy, |
| @@ -1882,12 +1741,8 @@ static void highlightlinks (struct page *page, int xoff, int yoff) · 117 unmodified lines | |||
| 1882 | p4.y = link->rect.y1; | 1741 | p4.y = link->rect.y1; |
| 1883 | 1742 | ||
| 1884 | /* TODO: different colours for different schemes */ | 1743 | /* TODO: different colours for different schemes */ |
| 1885 | if (fz_is_external_link (state.ctx, link->uri)) { | 1744 | if (fz_is_external_link (state.ctx, link->uri)) glColor3ub (0, 0, 255); |
| 1886 | glColor3ub (0, 0, 255); | 1745 | else glColor3ub (255, 0, 0); |
| 1887 | } | ||
| 1888 | else { | ||
| 1889 | glColor3ub (255, 0, 0); | ||
| 1890 | } | ||
| 1891 | 1746 | ||
| 1892 | stipplerect (ctm, p1, p2, p3, p4, texcoords, vertices); | 1747 | stipplerect (ctm, p1, p2, p3, p4, texcoords, vertices); |
| 1893 | } | 1748 | } |
| @@ -1920,9 +1775,7 @@ static int compareslinks (const void *l, const void *r) · 26 unmodified lines | |||
| 1920 | { | 1775 | { |
| 1921 | struct slink const *ls = l; | 1776 | struct slink const *ls = l; |
| 1922 | struct slink const *rs = r; | 1777 | struct slink const *rs = r; |
| 1923 | if (ls->bbox.y0 == rs->bbox.y0) { | 1778 | if (ls->bbox.y0 == rs->bbox.y0) return ls->bbox.x0 - rs->bbox.x0; |
| 1924 | return ls->bbox.x0 - rs->bbox.x0; | ||
| 1925 | } | ||
| 1926 | return ls->bbox.y0 - rs->bbox.y0; | 1779 | return ls->bbox.y0 - rs->bbox.y0; |
| 1927 | } | 1780 | } |
| 1928 | 1781 | ||
| @@ -1954,18 +1807,14 @@ static void ensureannots (struct page *page) · 25 unmodified lines | |||
| 1954 | pdf_page *pdfpage; | 1807 | pdf_page *pdfpage; |
| 1955 | 1808 | ||
| 1956 | pdf = pdf_specifics (state.ctx, state.doc); | 1809 | pdf = pdf_specifics (state.ctx, state.doc); |
| 1957 | if (!pdf) { | 1810 | if (!pdf) return; |
| 1958 | return; | ||
| 1959 | } | ||
| 1960 | 1811 | ||
| 1961 | pdfpage = pdf_page_from_fz_page (state.ctx, page->fzpage); | 1812 | pdfpage = pdf_page_from_fz_page (state.ctx, page->fzpage); |
| 1962 | if (state.gen != page->agen) { | 1813 | if (state.gen != page->agen) { |
| 1963 | dropannots (page); | 1814 | dropannots (page); |
| 1964 | page->agen = state.gen; | 1815 | page->agen = state.gen; |
| 1965 | } | 1816 | } |
| 1966 | if (page->annots) { | 1817 | if (page->annots) return; |
| 1967 | return; | ||
| 1968 | } | ||
| 1969 | 1818 | ||
| 1970 | for (annot = pdf_first_annot (state.ctx, pdfpage); | 1819 | for (annot = pdf_first_annot (state.ctx, pdfpage); |
| 1971 | annot; | 1820 | annot; |
| @@ -1976,9 +1825,7 @@ static void ensureannots (struct page *page) · 4 unmodified lines | |||
| 1976 | if (count > 0) { | 1825 | if (count > 0) { |
| 1977 | page->annotcount = count; | 1826 | page->annotcount = count; |
| 1978 | page->annots = calloc (count, annotsize); | 1827 | page->annots = calloc (count, annotsize); |
| 1979 | if (!page->annots) { | 1828 | if (!page->annots) err (1, "calloc annots %d", count); |
| 1980 | err (1, "calloc annots %d", count); | ||
| 1981 | } | ||
| 1982 | 1829 | ||
| 1983 | for (annot = pdf_first_annot (state.ctx, pdfpage), i = 0; | 1830 | for (annot = pdf_first_annot (state.ctx, pdfpage), i = 0; |
| 1984 | annot; | 1831 | annot; |
| @@ -2017,9 +1864,7 @@ static void ensureslinks (struct page *page) · 32 unmodified lines | |||
| 2017 | dropslinks (page); | 1864 | dropslinks (page); |
| 2018 | page->sgen = state.gen; | 1865 | page->sgen = state.gen; |
| 2019 | } | 1866 | } |
| 2020 | if (page->slinks) { | 1867 | if (page->slinks) return; |
| 2021 | return; | ||
| 2022 | } | ||
| 2023 | 1868 | ||
| 2024 | ensurelinks (page); | 1869 | ensurelinks (page); |
| 2025 | ctm = pagectm (page); | 1870 | ctm = pagectm (page); |
| @@ -2033,9 +1878,7 @@ static void ensureslinks (struct page *page) · 7 unmodified lines | |||
| 2033 | 1878 | ||
| 2034 | page->slinkcount = count; | 1879 | page->slinkcount = count; |
| 2035 | page->slinks = calloc (count, slinksize); | 1880 | page->slinks = calloc (count, slinksize); |
| 2036 | if (!page->slinks) { | 1881 | if (!page->slinks) err (1, "calloc slinks %d", count); |
| 2037 | err (1, "calloc slinks %d", count); | ||
| 2038 | } | ||
| 2039 | 1882 | ||
| 2040 | for (i = 0, link = page->links; link; ++i, link = link->next) { | 1883 | for (i = 0, link = page->links; link; ++i, link = link->next) { |
| 2041 | fz_rect rect; | 1884 | fz_rect rect; |
| @@ -2112,24 +1955,17 @@ static void uploadslice (struct tile *tile, struct slice *slice) · 70 unmodified lines | |||
| 2112 | offset += slice1->h * tile->w * tile->pixmap->n; | 1955 | offset += slice1->h * tile->w * tile->pixmap->n; |
| 2113 | } | 1956 | } |
| 2114 | if (slice->texindex != -1 && slice->texindex < state.tex.count | 1957 | if (slice->texindex != -1 && slice->texindex < state.tex.count |
| 2115 | && state.tex.owners[slice->texindex].slice == slice) { | 1958 | && state.tex.owners[slice->texindex].slice == slice) |
| 2116 | glBindTexture (TEXT_TYPE, state.tex.ids[slice->texindex]); | 1959 | glBindTexture (TEXT_TYPE, state.tex.ids[slice->texindex]); |
| 2117 | } | ||
| 2118 | else { | 1960 | else { |
| 2119 | int subimage = 0; | 1961 | int subimage = 0; |
| 2120 | int texindex = state.tex.index++ % state.tex.count; | 1962 | int texindex = state.tex.index++ % state.tex.count; |
| 2121 | 1963 | ||
| 2122 | if (state.tex.owners[texindex].w == tile->w) { | 1964 | if (state.tex.owners[texindex].w == tile->w) { |
| 2123 | if (state.tex.owners[texindex].h >= slice->h) { | 1965 | if (state.tex.owners[texindex].h >= slice->h) subimage = 1; |
| 2124 | subimage = 1; | 1966 | else state.tex.owners[texindex].h = slice->h; |
| 2125 | } | ||
| 2126 | else { | ||
| 2127 | state.tex.owners[texindex].h = slice->h; | ||
| 2128 | } | ||
| 2129 | } | ||
| 2130 | else { | ||
| 2131 | state.tex.owners[texindex].h = slice->h; | ||
| 2132 | } | 1967 | } |
| 1968 | else state.tex.owners[texindex].h = slice->h; | ||
| 2133 | 1969 | ||
| 2134 | state.tex.owners[texindex].w = tile->w; | 1970 | state.tex.owners[texindex].w = tile->w; |
| 2135 | state.tex.owners[texindex].slice = slice; | 1971 | state.tex.owners[texindex].slice = slice; |
| @@ -2146,21 +1982,17 @@ static void uploadslice (struct tile *tile, struct slice *slice) · 10 unmodified lines | |||
| 2146 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, tile->pbo->id); | 1982 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, tile->pbo->id); |
| 2147 | texdata = 0; | 1983 | texdata = 0; |
| 2148 | } | 1984 | } |
| 2149 | else { | 1985 | else texdata = tile->pixmap->samples; |
| 2150 | texdata = tile->pixmap->samples; | 1986 | if (subimage) glTexSubImage2D (TEXT_TYPE, |
| 2151 | } | 1987 | 0, |
| 2152 | if (subimage) { | 1988 | 0, |
| 2153 | glTexSubImage2D (TEXT_TYPE, | 1989 | 0, |
| 2154 | 0, | 1990 | tile->w, |
| 2155 | 0, | 1991 | slice->h, |
| 2156 | 0, | 1992 | state.tex.form, |
| 2157 | tile->w, | 1993 | state.tex.ty, |
| 2158 | slice->h, | 1994 | texdata+offset |
| 2159 | state.tex.form, | 1995 | ); |
| 2160 | state.tex.ty, | ||
| 2161 | texdata+offset | ||
| 2162 | ); | ||
| 2163 | } | ||
| 2164 | else { | 1996 | else { |
| 2165 | glTexImage2D (TEXT_TYPE, | 1997 | glTexImage2D (TEXT_TYPE, |
| 2166 | 0, | 1998 | 0, |
| @@ -2173,9 +2005,7 @@ static void uploadslice (struct tile *tile, struct slice *slice) · 6 unmodified lines | |||
| 2173 | texdata+offset | 2005 | texdata+offset |
| 2174 | ); | 2006 | ); |
| 2175 | } | 2007 | } |
| 2176 | if (tile->pbo) { | 2008 | if (tile->pbo) state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 2177 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0); | ||
| 2178 | } | ||
| 2179 | } | 2009 | } |
| 2180 | } | 2010 | } |
| 2181 | 2011 | ||
| @@ -2304,17 +2134,13 @@ ML (postprocess (value ptr_v, value hlinks_v, · 122 unmodified lines | |||
| 2304 | } | 2134 | } |
| 2305 | 2135 | ||
| 2306 | ensureannots (page); | 2136 | ensureannots (page); |
| 2307 | if (hlmask & 1) { | 2137 | if (hlmask & 1) highlightlinks (page, xoff, yoff); |
| 2308 | highlightlinks (page, xoff, yoff); | ||
| 2309 | } | ||
| 2310 | if (hlmask & 2) { | 2138 | if (hlmask & 2) { |
| 2311 | highlightslinks (page, xoff, yoff, noff, targ, STTI (tlen), | 2139 | highlightslinks (page, xoff, yoff, noff, targ, STTI (tlen), |
| 2312 | chars, STTI (clen), hfsize); | 2140 | chars, STTI (clen), hfsize); |
| 2313 | noff = page->slinkcount; | 2141 | noff = page->slinkcount; |
| 2314 | } | 2142 | } |
| 2315 | if (page->tgen == state.gen) { | 2143 | if (page->tgen == state.gen) showsel (page, xoff, yoff); |
| 2316 | showsel (page, xoff, yoff); | ||
| 2317 | } | ||
| 2318 | unlock (__func__); | 2144 | unlock (__func__); |
| 2319 | 2145 | ||
| 2320 | done: | 2146 | done: |
| @@ -2339,17 +2165,13 @@ static struct annot *getannot (struct page *page, int x, int y) · 18 unmodified lines | |||
| 2339 | const fz_matrix *tctm; | 2165 | const fz_matrix *tctm; |
| 2340 | pdf_document *pdf = pdf_specifics (state.ctx, state.doc); | 2166 | pdf_document *pdf = pdf_specifics (state.ctx, state.doc); |
| 2341 | 2167 | ||
| 2342 | if (!page->annots) { | 2168 | if (!page->annots) return NULL; |
| 2343 | return NULL; | ||
| 2344 | } | ||
| 2345 | 2169 | ||
| 2346 | if (pdf) { | 2170 | if (pdf) { |
| 2347 | trimctm (pdf_page_from_fz_page (state.ctx, page->fzpage), page->pdimno); | 2171 | trimctm (pdf_page_from_fz_page (state.ctx, page->fzpage), page->pdimno); |
| 2348 | tctm = &state.pagedims[page->pdimno].tctm; | 2172 | tctm = &state.pagedims[page->pdimno].tctm; |
| 2349 | } | 2173 | } |
| 2350 | else { | 2174 | else tctm = &fz_identity; |
| 2351 | tctm = &fz_identity; | ||
| 2352 | } | ||
| 2353 | 2175 | ||
| 2354 | p.x = x; | 2176 | p.x = x; |
| 2355 | p.y = y; | 2177 | p.y = y; |
| @@ -2435,9 +2257,7 @@ ML (find_page_with_links (value start_page_v, value dir_v)) · 79 unmodified lines | |||
| 2435 | fz_catch (state.ctx) { | 2257 | fz_catch (state.ctx) { |
| 2436 | found = 0; | 2258 | found = 0; |
| 2437 | } | 2259 | } |
| 2438 | if (page) { | 2260 | if (page) fz_drop_page (state.ctx, &page->super); |
| 2439 | fz_drop_page (state.ctx, &page->super); | ||
| 2440 | } | ||
| 2441 | } | 2261 | } |
| 2442 | else { | 2262 | else { |
| 2443 | fz_page *page = fz_load_page (state.ctx, state.doc, i); | 2263 | fz_page *page = fz_load_page (state.ctx, state.doc, i); |
| @@ -2563,9 +2383,7 @@ ML (findlink (value ptr_v, value dir_v)) · 119 unmodified lines | |||
| 2563 | break; | 2383 | break; |
| 2564 | 2384 | ||
| 2565 | case dir_last: | 2385 | case dir_last: |
| 2566 | if (page->slinks) { | 2386 | if (page->slinks) found = page->slinks + (page->slinkcount - 1); |
| 2567 | found = page->slinks + (page->slinkcount - 1); | ||
| 2568 | } | ||
| 2569 | break; | 2387 | break; |
| 2570 | } | 2388 | } |
| 2571 | } | 2389 | } |
| @@ -2694,9 +2512,7 @@ ML (whatsunder (value ptr_v, value x_v, value y_v)) · 122 unmodified lines | |||
| 2694 | struct pagedim *pdim; | 2512 | struct pagedim *pdim; |
| 2695 | 2513 | ||
| 2696 | ret_v = Val_int (0); | 2514 | ret_v = Val_int (0); |
| 2697 | if (trylock (__func__)) { | 2515 | if (trylock (__func__)) goto done; |
| 2698 | goto done; | ||
| 2699 | } | ||
| 2700 | 2516 | ||
| 2701 | page = parse_pointer (__func__, ptr); | 2517 | page = parse_pointer (__func__, ptr); |
| 2702 | pdim = &state.pagedims[page->pdimno]; | 2518 | pdim = &state.pagedims[page->pdimno]; |
| @@ -2740,19 +2556,13 @@ ML (whatsunder (value ptr_v, value x_v, value y_v)) · 37 unmodified lines | |||
| 2740 | for (block = page->text->first_block; block; block = block->next) { | 2556 | for (block = page->text->first_block; block; block = block->next) { |
| 2741 | fz_stext_line *line; | 2557 | fz_stext_line *line; |
| 2742 | 2558 | ||
| 2743 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 2559 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 2744 | continue; | 2560 | if (!fz_is_point_inside_rect (p, block->bbox)) continue; |
| 2745 | } | ||
| 2746 | if (!fz_is_point_inside_rect (p, block->bbox)) { | ||
| 2747 | continue; | ||
| 2748 | } | ||
| 2749 | 2561 | ||
| 2750 | for (line = block->u.t.first_line; line; line = line->next) { | 2562 | for (line = block->u.t.first_line; line; line = line->next) { |
| 2751 | fz_stext_char *ch; | 2563 | fz_stext_char *ch; |
| 2752 | 2564 | ||
| 2753 | if (!fz_is_point_inside_rect (p, line->bbox)) { | 2565 | if (!fz_is_point_inside_rect (p, line->bbox)) continue; |
| 2754 | continue; | ||
| 2755 | } | ||
| 2756 | 2566 | ||
| 2757 | for (ch = line->first_char; ch; ch = ch->next) { | 2567 | for (ch = line->first_char; ch; ch = ch->next) { |
| 2758 | if (!fz_is_point_inside_quad (p, ch->quad)) { | 2568 | if (!fz_is_point_inside_quad (p, ch->quad)) { |
| @@ -2760,9 +2570,7 @@ ML (whatsunder (value ptr_v, value x_v, value y_v)) · 1 unmodified line | |||
| 2760 | FT_FaceRec *face = fz_font_ft_face (state.ctx, | 2570 | FT_FaceRec *face = fz_font_ft_face (state.ctx, |
| 2761 | ch->font); | 2571 | ch->font); |
| 2762 | 2572 | ||
| 2763 | if (!n2) { | 2573 | if (!n2) n2 = "<unknown font>"; |
| 2764 | n2 = "<unknown font>"; | ||
| 2765 | } | ||
| 2766 | 2574 | ||
| 2767 | if (face && face->family_name) { | 2575 | if (face && face->family_name) { |
| 2768 | char *s; | 2576 | char *s; |
| @@ -2781,9 +2589,7 @@ ML (whatsunder (value ptr_v, value x_v, value y_v)) · 12 unmodified lines | |||
| 2781 | } | 2589 | } |
| 2782 | } | 2590 | } |
| 2783 | } | 2591 | } |
| 2784 | if (str_v == Val_unit) { | 2592 | if (str_v == Val_unit) str_v = caml_copy_string (n2); |
| 2785 | str_v = caml_copy_string (n2); | ||
| 2786 | } | ||
| 2787 | ret_v = caml_alloc_small (1, utext); | 2593 | ret_v = caml_alloc_small (1, utext); |
| 2788 | Field (ret_v, 0) = str_v; | 2594 | Field (ret_v, 0) = str_v; |
| 2789 | goto unlock; | 2595 | goto unlock; |
| @@ -2836,9 +2642,7 @@ ML (markunder (value ptr_v, value x_v, value y_v, value mark_v)) · 46 unmodified lines | |||
| 2836 | fz_point p = { .x = Int_val (x_v), .y = Int_val (y_v) }; | 2642 | fz_point p = { .x = Int_val (x_v), .y = Int_val (y_v) }; |
| 2837 | 2643 | ||
| 2838 | ret_v = Val_bool (0); | 2644 | ret_v = Val_bool (0); |
| 2839 | if (trylock (__func__)) { | 2645 | if (trylock (__func__)) goto done; |
| 2840 | goto done; | ||
| 2841 | } | ||
| 2842 | 2646 | ||
| 2843 | page = parse_pointer (__func__, String_val (ptr_v)); | 2647 | page = parse_pointer (__func__, String_val (ptr_v)); |
| 2844 | pdim = &state.pagedims[page->pdimno]; | 2648 | pdim = &state.pagedims[page->pdimno]; |
| @@ -2856,12 +2660,8 @@ ML (markunder (value ptr_v, value x_v, value y_v, value mark_v)) · 11 unmodified lines | |||
| 2856 | p.y += pdim->bounds.y0; | 2660 | p.y += pdim->bounds.y0; |
| 2857 | 2661 | ||
| 2858 | for (block = page->text->first_block; block; block = block->next) { | 2662 | for (block = page->text->first_block; block; block = block->next) { |
| 2859 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 2663 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 2860 | continue; | 2664 | if (!fz_is_point_inside_rect (p, block->bbox)) continue; |
| 2861 | } | ||
| 2862 | if (!fz_is_point_inside_rect (p, block->bbox)) { | ||
| 2863 | continue; | ||
| 2864 | } | ||
| 2865 | 2665 | ||
| 2866 | if (mark == mark_block) { | 2666 | if (mark == mark_block) { |
| 2867 | page->fmark = block->u.t.first_line->first_char; | 2667 | page->fmark = block->u.t.first_line->first_char; |
| @@ -2892,15 +2692,11 @@ ML (markunder (value ptr_v, value x_v, value y_v, value mark_v)) · 24 unmodified lines | |||
| 2892 | first = NULL; | 2692 | first = NULL; |
| 2893 | } | 2693 | } |
| 2894 | else { | 2694 | else { |
| 2895 | if (!first) { | 2695 | if (!first) first = ch2; |
| 2896 | first = ch2; | ||
| 2897 | } | ||
| 2898 | } | 2696 | } |
| 2899 | } | 2697 | } |
| 2900 | for (ch2 = ch; ch2; ch2 = ch2->next) { | 2698 | for (ch2 = ch; ch2; ch2 = ch2->next) { |
| 2901 | if (uninteresting (ch2->c)) { | 2699 | if (uninteresting (ch2->c)) break; |
| 2902 | break; | ||
| 2903 | } | ||
| 2904 | last = ch2; | 2700 | last = ch2; |
| 2905 | } | 2701 | } |
| 2906 | 2702 | ||
| @@ -2934,9 +2730,7 @@ ML (rectofblock (value ptr_v, value x_v, value y_v)) · 27 unmodified lines | |||
| 2934 | fz_point p = { .x = Int_val (x_v), .y = Int_val (y_v) }; | 2730 | fz_point p = { .x = Int_val (x_v), .y = Int_val (y_v) }; |
| 2935 | 2731 | ||
| 2936 | ret_v = Val_int (0); | 2732 | ret_v = Val_int (0); |
| 2937 | if (trylock (__func__)) { | 2733 | if (trylock (__func__)) goto done; |
| 2938 | goto done; | ||
| 2939 | } | ||
| 2940 | 2734 | ||
| 2941 | page = parse_pointer (__func__, String_val (ptr_v)); | 2735 | page = parse_pointer (__func__, String_val (ptr_v)); |
| 2942 | pdim = &state.pagedims[page->pdimno]; | 2736 | pdim = &state.pagedims[page->pdimno]; |
| @@ -2959,8 +2753,7 @@ ML (rectofblock (value ptr_v, value x_v, value y_v)) · 16 unmodified lines | |||
| 2959 | continue; | 2753 | continue; |
| 2960 | } | 2754 | } |
| 2961 | 2755 | ||
| 2962 | if (fz_is_point_inside_rect (p, *b)) | 2756 | if (fz_is_point_inside_rect (p, *b)) break; |
| 2963 | break; | ||
| 2964 | b = NULL; | 2757 | b = NULL; |
| 2965 | } | 2758 | } |
| 2966 | if (b) { | 2759 | if (b) { |
| @@ -2989,9 +2782,7 @@ ML0 (seltext (value ptr_v, value rect_v)) · 22 unmodified lines | |||
| 2989 | fz_stext_block *block; | 2782 | fz_stext_block *block; |
| 2990 | fz_stext_char *fc, *lc; | 2783 | fz_stext_char *fc, *lc; |
| 2991 | 2784 | ||
| 2992 | if (trylock (__func__)) { | 2785 | if (trylock (__func__)) goto done; |
| 2993 | goto done; | ||
| 2994 | } | ||
| 2995 | 2786 | ||
| 2996 | page = parse_pointer (__func__, String_val (ptr_v)); | 2787 | page = parse_pointer (__func__, String_val (ptr_v)); |
| 2997 | ensuretext (page); | 2788 | ensuretext (page); |
| @@ -3014,18 +2805,13 @@ ML0 (seltext (value ptr_v, value rect_v)) · 16 unmodified lines | |||
| 3014 | lc = page->lmark; | 2805 | lc = page->lmark; |
| 3015 | 2806 | ||
| 3016 | for (block = page->text->first_block; block; block = block->next) { | 2807 | for (block = page->text->first_block; block; block = block->next) { |
| 3017 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 2808 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 3018 | continue; | 2809 | |
| 3019 | } | ||
| 3020 | for (line = block->u.t.first_line; line; line = line->next) { | 2810 | for (line = block->u.t.first_line; line; line = line->next) { |
| 3021 | for (ch = line->first_char; ch; ch = ch->next) { | 2811 | for (ch = line->first_char; ch; ch = ch->next) { |
| 3022 | fz_point p0 = { .x = x0, .y = y0 }, p1 = { .x = x1, .y = y1 }; | 2812 | fz_point p0 = { .x = x0, .y = y0 }, p1 = { .x = x1, .y = y1 }; |
| 3023 | if (fz_is_point_inside_quad (p0, ch->quad)) { | 2813 | if (fz_is_point_inside_quad (p0, ch->quad)) fc = ch; |
| 3024 | fc = ch; | 2814 | if (fz_is_point_inside_quad (p1, ch->quad)) lc = ch; |
| 3025 | } | ||
| 3026 | if (fz_is_point_inside_quad (p1, ch->quad)) { | ||
| 3027 | lc = ch; | ||
| 3028 | } | ||
| 3029 | } | 2815 | } |
| 3030 | } | 2816 | } |
| 3031 | } | 2817 | } |
| @@ -3075,9 +2861,8 @@ ML (spawn (value command_v, value fds_v)) · 43 unmodified lines | |||
| 3075 | char *argv[] = { "/bin/sh", "-c", NULL, NULL }; | 2861 | char *argv[] = { "/bin/sh", "-c", NULL, NULL }; |
| 3076 | 2862 | ||
| 3077 | argv[2] = &Byte (command_v, 0); | 2863 | argv[2] = &Byte (command_v, 0); |
| 3078 | if ((ret = posix_spawn_file_actions_init (&fa)) != 0) { | 2864 | if ((ret = posix_spawn_file_actions_init (&fa)) != 0) |
| 3079 | unix_error (ret, "posix_spawn_file_actions_init", Nothing); | 2865 | unix_error (ret, "posix_spawn_file_actions_init", Nothing); |
| 3080 | } | ||
| 3081 | 2866 | ||
| 3082 | if ((ret = posix_spawnattr_init (&attr)) != 0) { | 2867 | if ((ret = posix_spawnattr_init (&attr)) != 0) { |
| 3083 | msg = "posix_spawnattr_init"; | 2868 | msg = "posix_spawnattr_init"; |
| @@ -3164,9 +2949,7 @@ ML0 (copysel (value fd_v, value ptr_v)) · 80 unmodified lines | |||
| 3164 | fz_stext_block *block; | 2949 | fz_stext_block *block; |
| 3165 | int fd = Int_val (fd_v); | 2950 | int fd = Int_val (fd_v); |
| 3166 | 2951 | ||
| 3167 | if (trylock (__func__)) { | 2952 | if (trylock (__func__)) goto done; |
| 3168 | goto done; | ||
| 3169 | } | ||
| 3170 | 2953 | ||
| 3171 | page = parse_pointer (__func__, String_val (ptr_v)); | 2954 | page = parse_pointer (__func__, String_val (ptr_v)); |
| 3172 | 2955 | ||
| @@ -3183,26 +2966,21 @@ ML0 (copysel (value fd_v, value ptr_v)) · 10 unmodified lines | |||
| 3183 | } | 2966 | } |
| 3184 | 2967 | ||
| 3185 | for (block = page->text->first_block; block; block = block->next) { | 2968 | for (block = page->text->first_block; block; block = block->next) { |
| 3186 | if (block->type != FZ_STEXT_BLOCK_TEXT) { | 2969 | if (block->type != FZ_STEXT_BLOCK_TEXT) continue; |
| 3187 | continue; | 2970 | |
| 3188 | } | ||
| 3189 | for (line = block->u.t.first_line; line; line = line->next) { | 2971 | for (line = block->u.t.first_line; line; line = line->next) { |
| 3190 | fz_stext_char *ch; | 2972 | fz_stext_char *ch; |
| 3191 | for (ch = line->first_char; ch; ch = ch->next) { | 2973 | for (ch = line->first_char; ch; ch = ch->next) { |
| 3192 | if (seen || ch == page->fmark) { | 2974 | if (seen || ch == page->fmark) { |
| 3193 | do { | 2975 | do { |
| 3194 | pipechar (f, ch); | 2976 | pipechar (f, ch); |
| 3195 | if (ch == page->lmark) { | 2977 | if (ch == page->lmark) goto close; |
| 3196 | goto close; | ||
| 3197 | } | ||
| 3198 | } while ((ch = ch->next)); | 2978 | } while ((ch = ch->next)); |
| 3199 | seen = 1; | 2979 | seen = 1; |
| 3200 | break; | 2980 | break; |
| 3201 | } | 2981 | } |
| 3202 | } | 2982 | } |
| 3203 | if (seen) { | 2983 | if (seen) fputc ('\n', f); |
| 3204 | fputc ('\n', f); | ||
| 3205 | } | ||
| 3206 | } | 2984 | } |
| 3207 | } | 2985 | } |
| 3208 | close: | 2986 | close: |
| @@ -3210,10 +2988,9 @@ close: · 1 unmodified line | |||
| 3210 | int ret = fclose (f); | 2988 | int ret = fclose (f); |
| 3211 | fd = -1; | 2989 | fd = -1; |
| 3212 | if (ret == -1) { | 2990 | if (ret == -1) { |
| 3213 | if (errno != ECHILD) { | 2991 | if (errno != ECHILD) |
| 3214 | printd ("emsg failed to close sel pipe: %d:%s", | 2992 | printd ("emsg failed to close sel pipe: %d:%s", |
| 3215 | errno, strerror (errno)); | 2993 | errno, strerror (errno)); |
| 3216 | } | ||
| 3217 | } | 2994 | } |
| 3218 | } | 2995 | } |
| 3219 | unlock: | 2996 | unlock: |
| @@ -3221,10 +2998,9 @@ unlock: · 1 unmodified line | |||
| 3221 | 2998 | ||
| 3222 | done: | 2999 | done: |
| 3223 | if (fd >= 0) { | 3000 | if (fd >= 0) { |
| 3224 | if (close (fd)) { | 3001 | if (close (fd)) |
| 3225 | printd ("emsg failed to close sel pipe: %d:%s", | 3002 | printd ("emsg failed to close sel pipe: %d:%s", |
| 3226 | errno, strerror (errno)); | 3003 | errno, strerror (errno)); |
| 3227 | } | ||
| 3228 | } | 3004 | } |
| 3229 | CAMLreturn0; | 3005 | CAMLreturn0; |
| 3230 | } | 3006 | } |
| @@ -3237,9 +3013,7 @@ ML (getpdimrect (value pagedimno_v)) · 6 unmodified lines | |||
| 3237 | fz_rect box; | 3013 | fz_rect box; |
| 3238 | 3014 | ||
| 3239 | ret_v = caml_alloc_small (4 * Double_wosize, Double_array_tag); | 3015 | ret_v = caml_alloc_small (4 * Double_wosize, Double_array_tag); |
| 3240 | if (trylock (__func__)) { | 3016 | if (trylock (__func__)) box = fz_empty_rect; |
| 3241 | box = fz_empty_rect; | ||
| 3242 | } | ||
| 3243 | else { | 3017 | else { |
| 3244 | box = state.pagedims[pagedimno].mediabox; | 3018 | box = state.pagedims[pagedimno].mediabox; |
| 3245 | unlock (__func__); | 3019 | unlock (__func__); |
| @@ -3267,9 +3041,7 @@ ML (zoom_for_height (value winw_v, value winh_v, value dw_v, value cols_v)) · 21 unmodified lines | |||
| 3267 | float cols = Int_val (cols_v); | 3041 | float cols = Int_val (cols_v); |
| 3268 | float pw = 1.0, ph = 1.0; | 3042 | float pw = 1.0, ph = 1.0; |
| 3269 | 3043 | ||
| 3270 | if (trylock (__func__)) { | 3044 | if (trylock (__func__)) goto done; |
| 3271 | goto done; | ||
| 3272 | } | ||
| 3273 | 3045 | ||
| 3274 | for (i = 0, p = state.pagedims; i < state.pagedimcount; ++i, ++p) { | 3046 | for (i = 0, p = state.pagedims; i < state.pagedimcount; ++i, ++p) { |
| 3275 | float w = p->pagebox.x1 / cols; | 3047 | float w = p->pagebox.x1 / cols; |
| @@ -3277,13 +3049,9 @@ ML (zoom_for_height (value winw_v, value winh_v, value dw_v, value cols_v)) · 1 unmodified line | |||
| 3277 | if (h > maxh) { | 3049 | if (h > maxh) { |
| 3278 | maxh = h; | 3050 | maxh = h; |
| 3279 | ph = h; | 3051 | ph = h; |
| 3280 | if (state.fitmodel != FitProportional) { | 3052 | if (state.fitmodel != FitProportional) pw = w; |
| 3281 | pw = w; | ||
| 3282 | } | ||
| 3283 | } | ||
| 3284 | if ((state.fitmodel == FitProportional) && w > pw) { | ||
| 3285 | pw = w; | ||
| 3286 | } | 3053 | } |
| 3054 | if ((state.fitmodel == FitProportional) && w > pw) pw = w; | ||
| 3287 | } | 3055 | } |
| 3288 | 3056 | ||
| 3289 | zoom = (((winh / ph) * pw) + dw) / winw; | 3057 | zoom = (((winh / ph) * pw) + dw) / winw; |
| @@ -3301,9 +3069,7 @@ ML (getmaxw (value unit_v)) · 11 unmodified lines | |||
| 3301 | float maxw = -1.; | 3069 | float maxw = -1.; |
| 3302 | struct pagedim *p; | 3070 | struct pagedim *p; |
| 3303 | 3071 | ||
| 3304 | if (trylock (__func__)) { | 3072 | if (trylock (__func__)) goto done; |
| 3305 | goto done; | ||
| 3306 | } | ||
| 3307 | 3073 | ||
| 3308 | for (i = 0, p = state.pagedims; i < state.pagedimcount; ++i, ++p) { | 3074 | for (i = 0, p = state.pagedims; i < state.pagedimcount; ++i, ++p) { |
| 3309 | float w = p->pagebox.x1; | 3075 | float w = p->pagebox.x1; |
| @@ -3437,9 +3203,7 @@ ML (platform (value unit_v)) · 127 unmodified lines | |||
| 3437 | #elif defined __APPLE__ | 3203 | #elif defined __APPLE__ |
| 3438 | platid = pimacos; | 3204 | platid = pimacos; |
| 3439 | #endif | 3205 | #endif |
| 3440 | if (uname (&buf)) { | 3206 | if (uname (&buf)) err (1, "uname"); |
| 3441 | err (1, "uname"); | ||
| 3442 | } | ||
| 3443 | 3207 | ||
| 3444 | tup_v = caml_alloc_tuple (2); | 3208 | tup_v = caml_alloc_tuple (2); |
| 3445 | { | 3209 | { |
| @@ -3462,9 +3226,7 @@ ML0 (cloexec (value fd_v)) · 16 unmodified lines | |||
| 3462 | CAMLparam1 (fd_v); | 3226 | CAMLparam1 (fd_v); |
| 3463 | int fd = Int_val (fd_v); | 3227 | int fd = Int_val (fd_v); |
| 3464 | 3228 | ||
| 3465 | if (fcntl (fd, F_SETFD, FD_CLOEXEC, 1)) { | 3229 | if (fcntl (fd, F_SETFD, FD_CLOEXEC, 1)) uerror ("fcntl", Nothing); |
| 3466 | uerror ("fcntl", Nothing); | ||
| 3467 | } | ||
| 3468 | CAMLreturn0; | 3230 | CAMLreturn0; |
| 3469 | } | 3231 | } |
| 3470 | 3232 | ||
| @@ -3479,9 +3241,7 @@ ML (getpbo (value w_v, value h_v, value cs_v)) · 8 unmodified lines | |||
| 3479 | 3241 | ||
| 3480 | if (state.bo_usable) { | 3242 | if (state.bo_usable) { |
| 3481 | pbo = calloc (sizeof (*pbo), 1); | 3243 | pbo = calloc (sizeof (*pbo), 1); |
| 3482 | if (!pbo) { | 3244 | if (!pbo) err (1, "calloc pbo"); |
| 3483 | err (1, "calloc pbo"); | ||
| 3484 | } | ||
| 3485 | 3245 | ||
| 3486 | switch (cs) { | 3246 | switch (cs) { |
| 3487 | case 0: | 3247 | case 0: |
| @@ -3513,24 +3273,18 @@ ML (getpbo (value w_v, value h_v, value cs_v)) · 25 unmodified lines | |||
| 3513 | char *s; | 3273 | char *s; |
| 3514 | 3274 | ||
| 3515 | res = snprintf (NULL, 0, "%" PRIxPTR, (uintptr_t) pbo); | 3275 | res = snprintf (NULL, 0, "%" PRIxPTR, (uintptr_t) pbo); |
| 3516 | if (res < 0) { | 3276 | if (res < 0) |
| 3517 | err (1, "snprintf %" PRIxPTR " failed", (uintptr_t) pbo); | 3277 | err (1, "snprintf %" PRIxPTR " failed", (uintptr_t) pbo); |
| 3518 | } | ||
| 3519 | s = malloc (res+1); | 3278 | s = malloc (res+1); |
| 3520 | if (!s) { | 3279 | if (!s) err (1, "malloc %d bytes failed", res+1); |
| 3521 | err (1, "malloc %d bytes failed", res+1); | ||
| 3522 | } | ||
| 3523 | res = sprintf (s, "%" PRIxPTR, (uintptr_t) pbo); | 3280 | res = sprintf (s, "%" PRIxPTR, (uintptr_t) pbo); |
| 3524 | if (res < 0) { | 3281 | if (res < 0) |
| 3525 | err (1, "sprintf %" PRIxPTR " failed", (uintptr_t) pbo); | 3282 | err (1, "sprintf %" PRIxPTR " failed", (uintptr_t) pbo); |
| 3526 | } | ||
| 3527 | ret_v = caml_copy_string (s); | 3283 | ret_v = caml_copy_string (s); |
| 3528 | free (s); | 3284 | free (s); |
| 3529 | } | 3285 | } |
| 3530 | } | 3286 | } |
| 3531 | else { | 3287 | else ret_v = caml_copy_string ("0"); |
| 3532 | ret_v = caml_copy_string ("0"); | ||
| 3533 | } | ||
| 3534 | CAMLreturn (ret_v); | 3288 | CAMLreturn (ret_v); |
| 3535 | } | 3289 | } |
| 3536 | 3290 | ||
| @@ -3555,9 +3309,8 @@ ML0 (unmappbo (value ptr_v)) · 18 unmodified lines | |||
| 3555 | 3309 | ||
| 3556 | if (tile->pbo) { | 3310 | if (tile->pbo) { |
| 3557 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, tile->pbo->id); | 3311 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, tile->pbo->id); |
| 3558 | if (state.glUnmapBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB) == GL_FALSE) { | 3312 | if (state.glUnmapBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB) == GL_FALSE) |
| 3559 | errx (1, "glUnmapBufferARB failed: %#x\n", glGetError ()); | 3313 | errx (1, "glUnmapBufferARB failed: %#x\n", glGetError ()); |
| 3560 | } | ||
| 3561 | tile->pbo->ptr = NULL; | 3314 | tile->pbo->ptr = NULL; |
| 3562 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0); | 3315 | state.glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 3563 | } | 3316 | } |
| @@ -3600,9 +3353,7 @@ ML (unproject (value ptr_v, value x_v, value y_v)) · 36 unmodified lines | |||
| 3600 | pdim = &state.pagedims[page->pdimno]; | 3353 | pdim = &state.pagedims[page->pdimno]; |
| 3601 | 3354 | ||
| 3602 | ret_v = Val_int (0); | 3355 | ret_v = Val_int (0); |
| 3603 | if (trylock (__func__)) { | 3356 | if (trylock (__func__)) goto done; |
| 3604 | goto done; | ||
| 3605 | } | ||
| 3606 | 3357 | ||
| 3607 | p.x = x + pdim->bounds.x0; | 3358 | p.x = x + pdim->bounds.x0; |
| 3608 | p.y = y + pdim->bounds.y0; | 3359 | p.y = y + pdim->bounds.y0; |
| @@ -3637,21 +3388,16 @@ ML (project (value ptr_v, value pageno_v, value pdimno_v, value x_v, value y_v)) · 28 unmodified lines | |||
| 3637 | ret_v = Val_int (0); | 3388 | ret_v = Val_int (0); |
| 3638 | lock (__func__); | 3389 | lock (__func__); |
| 3639 | 3390 | ||
| 3640 | if (!*s) { | 3391 | if (!*s) page = loadpage (pageno, pdimno); |
| 3641 | page = loadpage (pageno, pdimno); | 3392 | else page = parse_pointer (__func__, String_val (ptr_v)); |
| 3642 | } | ||
| 3643 | else { | ||
| 3644 | page = parse_pointer (__func__, String_val (ptr_v)); | ||
| 3645 | } | ||
| 3646 | pdim = &state.pagedims[pdimno]; | 3393 | pdim = &state.pagedims[pdimno]; |
| 3647 | 3394 | ||
| 3648 | if (pdf_specifics (state.ctx, state.doc)) { | 3395 | if (pdf_specifics (state.ctx, state.doc)) { |
| 3649 | trimctm (pdf_page_from_fz_page (state.ctx, page->fzpage), page->pdimno); | 3396 | trimctm (pdf_page_from_fz_page (state.ctx, page->fzpage), page->pdimno); |
| 3650 | ctm = state.pagedims[page->pdimno].tctm; | 3397 | ctm = state.pagedims[page->pdimno].tctm; |
| 3651 | } | 3398 | } |
| 3652 | else { | 3399 | else ctm = fz_identity; |
| 3653 | ctm = fz_identity; | 3400 | |
| 3654 | } | ||
| 3655 | p.x = x + pdim->bounds.x0; | 3401 | p.x = x + pdim->bounds.x0; |
| 3656 | p.y = y + pdim->bounds.y0; | 3402 | p.y = y + pdim->bounds.y0; |
| 3657 | 3403 | ||
| @@ -3662,9 +3408,7 @@ ML (project (value ptr_v, value pageno_v, value pdimno_v, value x_v, value y_v)) · 4 unmodified lines | |||
| 3662 | Field (ret_v, 0) = caml_copy_double ((double) p.x); | 3408 | Field (ret_v, 0) = caml_copy_double ((double) p.x); |
| 3663 | Field (ret_v, 1) = caml_copy_double ((double) p.y); | 3409 | Field (ret_v, 1) = caml_copy_double ((double) p.y); |
| 3664 | 3410 | ||
| 3665 | if (!*s) { | 3411 | if (!*s) freepage (page); |
| 3666 | freepage (page); | ||
| 3667 | } | ||
| 3668 | unlock (__func__); | 3412 | unlock (__func__); |
| 3669 | CAMLreturn (ret_v); | 3413 | CAMLreturn (ret_v); |
| 3670 | } | 3414 | } |
| @@ -3743,9 +3487,7 @@ ML0 (savedoc (value path_v)) · 72 unmodified lines | |||
| 3743 | CAMLparam1 (path_v); | 3487 | CAMLparam1 (path_v); |
| 3744 | pdf_document *pdf = pdf_specifics (state.ctx, state.doc); | 3488 | pdf_document *pdf = pdf_specifics (state.ctx, state.doc); |
| 3745 | 3489 | ||
| 3746 | if (pdf) { | 3490 | if (pdf) pdf_save_document (state.ctx, pdf, String_val (path_v), NULL); |
| 3747 | pdf_save_document (state.ctx, pdf, String_val (path_v), NULL); | ||
| 3748 | } | ||
| 3749 | CAMLreturn0; | 3491 | CAMLreturn0; |
| 3750 | } | 3492 | } |
| 3751 | 3493 | ||
| @@ -3793,9 +3535,8 @@ static fz_font *lsff (fz_context *ctx,int UNUSED_ATTR script, · 41 unmodified lines | |||
| 3793 | 3535 | ||
| 3794 | if (!done) { | 3536 | if (!done) { |
| 3795 | char *path = getenv ("LLPP_FALLBACK_FONT"); | 3537 | char *path = getenv ("LLPP_FALLBACK_FONT"); |
| 3796 | if (path) { | 3538 | if (path) |
| 3797 | font = fz_new_font_from_file (ctx, NULL, path, 0, 1); | 3539 | font = fz_new_font_from_file (ctx, NULL, path, 0, 1); |
| 3798 | } | ||
| 3799 | done = 1; | 3540 | done = 1; |
| 3800 | } | 3541 | } |
| 3801 | return font; | 3542 | return font; |
| @@ -3809,9 +3550,7 @@ ML0 (setdcf (value path_v)) · 7 unmodified lines | |||
| 3809 | size_t len = caml_string_length (path_v); | 3550 | size_t len = caml_string_length (path_v); |
| 3810 | if (*p) { | 3551 | if (*p) { |
| 3811 | state.dcf = malloc (len + 1); | 3552 | state.dcf = malloc (len + 1); |
| 3812 | if (!state.dcf) { | 3553 | if (!state.dcf) err (1, "malloc dimpath %zu", len + 1); |
| 3813 | err (1, "malloc dimpath %zu", len + 1); | ||
| 3814 | } | ||
| 3815 | memcpy (state.dcf, p, len); | 3554 | memcpy (state.dcf, p, len); |
| 3816 | state.dcf[len] = 0; | 3555 | state.dcf[len] = 0; |
| 3817 | } | 3556 | } |
| @@ -3824,14 +3563,10 @@ ML (init (value csock_v, value params_v)) · 6 unmodified lines | |||
| 3824 | int ret, texcount, colorspace, mustoresize; | 3563 | int ret, texcount, colorspace, mustoresize; |
| 3825 | const char *fontpath; | 3564 | const char *fontpath; |
| 3826 | 3565 | ||
| 3827 | if (pipe (state.pfds)) { | 3566 | if (pipe (state.pfds)) err (1, "pipe"); |
| 3828 | err (1, "pipe"); | ||
| 3829 | } | ||
| 3830 | for (int ntries = 0; ntries < 1737; ++ntries) { | 3567 | for (int ntries = 0; ntries < 1737; ++ntries) { |
| 3831 | if (-1 == dup2 (state.pfds[1], 2)) { | 3568 | if (-1 == dup2 (state.pfds[1], 2)) { |
| 3832 | if (EINTR == errno) { | 3569 | if (EINTR == errno) continue; |
| 3833 | continue; | ||
| 3834 | } | ||
| 3835 | err (1, "dup2"); | 3570 | err (1, "dup2"); |
| 3836 | } | 3571 | } |
| 3837 | break; | 3572 | break; |
| @@ -3855,9 +3590,7 @@ ML (init (value csock_v, value params_v)) · 17 unmodified lines | |||
| 3855 | const char *cset = nl_langinfo (CODESET); | 3590 | const char *cset = nl_langinfo (CODESET); |
| 3856 | state.utf8cs = !strcmp (cset, "UTF-8"); | 3591 | state.utf8cs = !strcmp (cset, "UTF-8"); |
| 3857 | } | 3592 | } |
| 3858 | else { | 3593 | else printd ("emsg setlocale: %d:%s", errno, strerror (errno)); |
| 3859 | printd ("emsg setlocale: %d:%s", errno, strerror (errno)); | ||
| 3860 | } | ||
| 3861 | #endif | 3594 | #endif |
| 3862 | 3595 | ||
| 3863 | state.ctx = fz_new_context (NULL, NULL, mustoresize); | 3596 | state.ctx = fz_new_context (NULL, NULL, mustoresize); |
| @@ -3875,9 +3608,7 @@ ML (init (value csock_v, value params_v)) · 11 unmodified lines | |||
| 3875 | 3608 | ||
| 3876 | set_tex_params (colorspace); | 3609 | set_tex_params (colorspace); |
| 3877 | 3610 | ||
| 3878 | if (*fontpath) { | 3611 | if (*fontpath) state.face = load_font (fontpath); |
| 3879 | state.face = load_font (fontpath); | ||
| 3880 | } | ||
| 3881 | else { | 3612 | else { |
| 3882 | int len; | 3613 | int len; |
| 3883 | const unsigned char *data; | 3614 | const unsigned char *data; |
| @@ -3885,18 +3616,14 @@ ML (init (value csock_v, value params_v)) · 1 unmodified line | |||
| 3885 | data = pdf_lookup_substitute_font (state.ctx, 0, 0, 0, 0, &len); | 3616 | data = pdf_lookup_substitute_font (state.ctx, 0, 0, 0, 0, &len); |
| 3886 | state.face = load_builtin_font (data, len); | 3617 | state.face = load_builtin_font (data, len); |
| 3887 | } | 3618 | } |
| 3888 | if (!state.face) { | 3619 | if (!state.face) _exit (1); |
| 3889 | _exit (1); | ||
| 3890 | } | ||
| 3891 | 3620 | ||
| 3892 | realloctexts (texcount); | 3621 | realloctexts (texcount); |
| 3893 | setuppbo (); | 3622 | setuppbo (); |
| 3894 | makestippletex (); | 3623 | makestippletex (); |
| 3895 | 3624 | ||
| 3896 | ret = pthread_create (&state.thread, NULL, mainloop, NULL); | 3625 | ret = pthread_create (&state.thread, NULL, mainloop, NULL); |
| 3897 | if (ret) { | 3626 | if (ret) errx (1, "pthread_create: %s", strerror (ret)); |
| 3898 | errx (1, "pthread_create: %s", strerror (ret)); | ||
| 3899 | } | ||
| 3900 | 3627 | ||
| 3901 | CAMLreturn (Val_int (state.pfds[0])); | 3628 | CAMLreturn (Val_int (state.pfds[0])); |
| 3902 | } | 3629 | } |