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
2121 Page p;
2222 pageinit(&p);
2323 if(pagerender(&p, page))
24− fprint(1, "%s\n", p.text);
24+ write(1, p.buf.b, p.buf.sz);
2525 pagefree(&p);
2626 }
2727
op.c+23−13
@@ -298,7 +298,8 @@ tslead(Op *op, Page *p) · 297 unmodified lines
298298 int d = arrayget(p->stack, 0)->num.d / 20;
299299 while(d > 0){
300300 d -= 1;
301− fprint(1, "\n");
301+ if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
302+ sysfatal("OOM");
302303 }
303304 USED(op, p);
304305 return 0;
@@ -345,10 +346,13 @@ tpmove(Op *op, Page *p) · 40 unmodified lines
345346 Object *x, *y;
346347 x = arrayget(p->stack, 0);
347348 y = arrayget(p->stack, 1);
348− if(y->num.d != 0)
349− fprint(1, "\n");
349+ if(y->num.d != 0){
350+ if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
351+ sysfatal("OOM");
352+ }
350353 else if(x->num.d < 50)
351− fprint(1, " ");
354+ if(bufput(&p->buf, (uchar*)" ", 1) == -1)
355+ sysfatal("OOM");
352356 USED(op, p);
353357 return 0;
354358 }
@@ -364,7 +368,8 @@ static int · 9 unmodified lines
364368 tpmove0(Op *op, Page *p)
365369 {
366370 USED(op, p);
367− fprint(1, "\n");
371+ if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
372+ sysfatal("OOM");
368373 return 0;
369374 }
370375
@@ -383,10 +388,14 @@ thshowarr(Op *op, Page *p) · 12 unmodified lines
383388 int i;
384389 for(i = 0; i < arraylen(arr); i += 1){
385390 o = arrayget(arr, i);
386− if(o->type == Ostr)
387− fprint(1, "%s", o->str);
388− else if(o->num.d < -150)
389− fprint(1, " ");
391+ if(o->type == Ostr){
392+ if(bufput(&p->buf, (uchar*)o->str, o->len) == -1)
393+ sysfatal("OOM");
394+ }
395+ else if(o->num.d < -150){
396+ if(bufput(&p->buf, (uchar*)" ", 1) == -1)
397+ sysfatal("OOM");
398+ }
390399 }
391400 USED(op);
392401 return 0;
@@ -905,7 +914,7 @@ opfind(Stream *s) · 512 unmodified lines
905914 void
906915 pageinit(Page *page)
907916 {
908− page->text = nil;
917+ bufinit(&page->buf, 0, 0);
909918 // Stack is per-content-stream, so we don't create it here
910919 page->stack = nil;
911920 }
@@ -913,7 +922,7 @@ pageinit(Page *page) · 1 unmodified line
913922 void
914923 pagefree(Page *p)
915924 {
916− free(p->text);
925+ buffree(&p->buf);
917926 pdfobjfree(p->stack);
918927 }
919928
@@ -963,7 +972,8 @@ pagerendercontent(Page *p, Object *content) · 43 unmodified lines
963972 }
964973 }
965974 }
966− fprint(1, "\n");
975+ if(bufput(&p->buf, (uchar*)"\n", 1) == -1)
976+ sysfatal("OOM");
967977 Sclose(s);
968978 }
969979
@@ -978,5 +988,5 @@ pagerender(Page *p, Object *o) · 8 unmodified lines
978988 pagerendercontent(p, arrayget(content, i));
979989 else if(content->type != Onull)
980990 pagerendercontent(p, content);
981− return 0;
991+ return 1;
982992 }
pdf.h+5−5
@@ -24,11 +24,6 @@ typedef struct Stream Stream; · 23 unmodified lines
2424 typedef struct Xref Xref;
2525 typedef struct Page Page;
2626
27−struct Page {
28− Object *stack;
29− char *text;
30−};
31−
3227 struct Buffer {
3328 uchar *b;
3429 int ro;
@@ -37,6 +32,11 @@ struct Buffer { · 2 unmodified lines
3732 int off;
3833 };
3934
35+struct Page {
36+ Object *stack;
37+ Buffer buf;
38+};
39+
4040 struct Filter {
4141 char *name;
4242 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