History

buffered pagerender

Noam Preil committed 5 years ago

Commit 464b83a1 parent 6d2612e3 files · +29 −19Browse files

Unified · Split

3 files
  1. main.c +1 −1
  2. op.c +23 −13
  3. pdf.h +5 −5
main.c+1−1
@@ -21,7 +21,7 @@ dumppage(Object *page) · 20 unmodified lines
21 Page p;21 Page p;
22 pageinit(&p);22 pageinit(&p);
23 if(pagerender(&p, page))23 if(pagerender(&p, page))
24 fprint(1, "%s\n", p.text);24 write(1, p.buf.b, p.buf.sz);
25 pagefree(&p);25 pagefree(&p);
26}26}
27 27
op.c+23−13
@@ -298,7 +298,8 @@ tslead(Op *op, Page *p) · 297 unmodified lines
298 int d = arrayget(p->stack, 0)->num.d / 20;298 int d = arrayget(p->stack, 0)->num.d / 20;
299 while(d > 0){299 while(d > 0){
300 d -= 1;300 d -= 1;
301 fprint(1, "\n");301 if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
302 sysfatal("OOM");
302 }303 }
303 USED(op, p);304 USED(op, p);
304 return 0;305 return 0;
@@ -345,10 +346,13 @@ tpmove(Op *op, Page *p) · 40 unmodified lines
345 Object *x, *y;346 Object *x, *y;
346 x = arrayget(p->stack, 0);347 x = arrayget(p->stack, 0);
347 y = arrayget(p->stack, 1);348 y = arrayget(p->stack, 1);
348 if(y->num.d != 0)349 if(y->num.d != 0){
349 fprint(1, "\n");350 if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
351 sysfatal("OOM");
352 }
350 else if(x->num.d < 50)353 else if(x->num.d < 50)
351 fprint(1, " ");354 if(bufput(&p->buf, (uchar*)" ", 1) == -1)
355 sysfatal("OOM");
352 USED(op, p);356 USED(op, p);
353 return 0;357 return 0;
354}358}
@@ -364,7 +368,8 @@ static int · 9 unmodified lines
364tpmove0(Op *op, Page *p)368tpmove0(Op *op, Page *p)
365{369{
366 USED(op, p);370 USED(op, p);
367 fprint(1, "\n");371 if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
372 sysfatal("OOM");
368 return 0;373 return 0;
369}374}
370 375
@@ -383,10 +388,14 @@ thshowarr(Op *op, Page *p) · 12 unmodified lines
383 int i;388 int i;
384 for(i = 0; i < arraylen(arr); i += 1){389 for(i = 0; i < arraylen(arr); i += 1){
385 o = arrayget(arr, i);390 o = arrayget(arr, i);
386 if(o->type == Ostr)391 if(o->type == Ostr){
387 fprint(1, "%s", o->str);392 if(bufput(&p->buf, (uchar*)o->str, o->len) == -1)
388 else if(o->num.d < -150)393 sysfatal("OOM");
389 fprint(1, " ");394 }
395 else if(o->num.d < -150){
396 if(bufput(&p->buf, (uchar*)" ", 1) == -1)
397 sysfatal("OOM");
398 }
390 }399 }
391 USED(op);400 USED(op);
392 return 0;401 return 0;
@@ -905,7 +914,7 @@ opfind(Stream *s) · 512 unmodified lines
905void914void
906pageinit(Page *page)915pageinit(Page *page)
907{916{
908 page->text = nil;917 bufinit(&page->buf, 0, 0);
909 // Stack is per-content-stream, so we don't create it here918 // Stack is per-content-stream, so we don't create it here
910 page->stack = nil;919 page->stack = nil;
911}920}
@@ -913,7 +922,7 @@ pageinit(Page *page) · 1 unmodified line
913void922void
914pagefree(Page *p)923pagefree(Page *p)
915{924{
916 free(p->text);925 buffree(&p->buf);
917 pdfobjfree(p->stack);926 pdfobjfree(p->stack);
918}927}
919 928
@@ -963,7 +972,8 @@ pagerendercontent(Page *p, Object *content) · 43 unmodified lines
963 }972 }
964 }973 }
965 }974 }
966 fprint(1, "\n");975 if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
976 sysfatal("OOM");
967 Sclose(s);977 Sclose(s);
968}978}
969 979
@@ -978,5 +988,5 @@ pagerender(Page *p, Object *o) · 8 unmodified lines
978 pagerendercontent(p, arrayget(content, i));988 pagerendercontent(p, arrayget(content, i));
979 else if(content->type != Onull)989 else if(content->type != Onull)
980 pagerendercontent(p, content);990 pagerendercontent(p, content);
981 return 0;991 return 1;
982}992}
pdf.h+5−5
@@ -24,11 +24,6 @@ typedef struct Stream Stream; · 23 unmodified lines
24typedef struct Xref Xref;24typedef struct Xref Xref;
25typedef struct Page Page;25typedef struct Page Page;
26 26
27struct Page {
28 Object *stack;
29 char *text;
30};
31
32struct Buffer {27struct Buffer {
33 uchar *b;28 uchar *b;
34 int ro;29 int ro;
@@ -37,6 +32,11 @@ struct Buffer { · 2 unmodified lines
37 int off;32 int off;
38};33};
39 34
35struct Page {
36 Object *stack;
37 Buffer buf;
38};
39
40struct Filter {40struct Filter {
41 char *name;41 char *name;
42 int (*readall)(void *aux, Buffer *bi, Buffer *bo);42 int (*readall)(void *aux, Buffer *bi, Buffer *bo);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t