From 890599cc49cc9cfd2a3f38367c321b05349d4276 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Fri, 14 Jun 2013 23:14:35 +0430 Subject: [PATCH] post: support "x X PS" It also handles BeginObject and EndObject; this should be enough for pic's fill operator. --- out.c | 37 +++++++++++++++++++++++++++++++++---- post.c | 36 +++++++++++++++++++++++++++++++++--- post.h | 6 +++--- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/out.c b/out.c index 210842f..c20e863 100644 --- a/out.c +++ b/out.c @@ -166,44 +166,73 @@ void outsize(int s) o_s = s; } -void drawbeg(void) +static int draw_path; /* number of path segments */ +static int draw_point; /* point was set for postscript newpath */ + +static void drawmv(void) +{ + if (!draw_point) + outf("%d %d m ", o_h, o_v); + draw_point = 1; +} + +/* if s is not NULL, start a multi-segment path */ +void drawbeg(char *s) { o_flush(); out_fontup(o_f); - outf("newpath %d %d m ", o_h, o_v); + if (draw_path) + return; + draw_path = s != NULL; + if (s) + outf("gsave newpath %s\n", s); + else + outf("newpath "); } -void drawend(void) +void drawend(char *s) { - outf("stroke\n"); + if (draw_path && !s) + return; + draw_path = 0; + draw_point = 0; + if (s) + outf("%s grestore\n", s); + else + outf("stroke\n"); } void drawl(int h, int v) { + drawmv(); outrel(h, v); outf("%d %d drawl ", o_h, o_v); } void drawc(int c) { + drawmv(); outrel(c, 0); outf("%d %d drawe ", c, c); } void drawe(int h, int v) { + drawmv(); outrel(h, 0); outf("%d %d drawe ", h, v); } void drawa(int h1, int v1, int h2, int v2) { + drawmv(); outf("%d %d %d %d drawa ", h1, v1, h2, v2); outrel(h1 + h2, v1 + v2); } void draws(int h1, int v1, int h2, int v2) { + drawmv(); outf("%d %d %d %d %d %d draws ", o_h, o_v, o_h + h1, o_v + v1, o_h + h1 + h2, o_v + v1 + v2); outrel(h1, v1); diff --git a/post.c b/post.c index 7c71e9d..50570fc 100644 --- a/post.c +++ b/post.c @@ -5,8 +5,9 @@ * * This program is released under the Modified BSD license. */ -#include #include +#include +#include #include "post.h" static int o_pg; @@ -117,6 +118,20 @@ static void nextword(char *s) *s = '\0'; } +/* read until eol */ +static void readln(char *s) +{ + int c; + c = next(); + while (c > 0 && c != '\n') { + *s++ = c; + c = next(); + } + if (c == '\n') + back(c); + *s = '\0'; +} + static void postspline(int h1, int v1) { int h2, v2; @@ -134,7 +149,7 @@ static void postdraw(void) { int h1, h2, v1, v2; int c = next(); - drawbeg(); + drawbeg(NULL); switch (c) { case 'l': h1 = nextnum(); @@ -165,10 +180,24 @@ static void postdraw(void) postspline(h1, v1); break; } - drawend(); + drawend(NULL); nexteol(); } +static void postps(void) +{ + char cmd[ILNLEN]; + char arg[ILNLEN]; + nextword(cmd); + readln(arg); + if (!strcmp("PS", cmd) || !strcmp("ps", cmd)) + out("%s\n", arg); + if (!strcmp("BeginObject", cmd)) + drawbeg(arg); + if (!strcmp("EndObject", cmd)) + drawend(arg); +} + static char devpath[PATHLEN] = "devutf"; static void postx(void) @@ -193,6 +222,7 @@ static void postx(void) case 's': break; case 'X': + postps(); break; } nexteol(); diff --git a/post.h b/post.h index 1b21d6f..315133c 100644 --- a/post.h +++ b/post.h @@ -4,7 +4,7 @@ #define FNLEN 32 /* font name length */ #define NGLYPHS 512 /* glyphs in fonts */ #define GNLEN 32 /* glyph name length */ -#define ILNLEN 256 /* line limit of input files */ +#define ILNLEN 1000 /* line limit of input files */ #define LNLEN 4000 /* line buffer length (ren.c/out.c) */ #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -64,8 +64,8 @@ void outsize(int s); void outpage(void); extern char o_fonts[]; -void drawbeg(void); -void drawend(void); +void drawbeg(char *s); +void drawend(char *s); void drawl(int h, int v); void drawc(int c); void drawe(int h, int v); -- 2.11.4.GIT