ref: 486914826342df42eee2fa3a4ab3adb905938976
parent: 3ef2fcee4e2fe8e296b1b823b636b70f4bd76336
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Aug 22 15:13:34 EDT 2013
post: support filled drawing and polygons Now neatpost supports groff's Dp, DC, DE, DP. The main difference is that in neatroff filled objects use foreground color for filling.
--- a/out.c
+++ b/out.c
@@ -193,28 +193,41 @@
draw_point = 1;
}
-/* if s is not NULL, start a multi-segment path */
-void drawbeg(char *s)
+/* start a multi-segment path */
+void drawmbeg(char *s)
{
o_flush();
out_fontup(o_f);
+ draw_path = 1;
+ outf("gsave newpath %s\n", s);
+}
+
+/* end a multi-segment path */
+void drawmend(char *s)
+{
+ draw_path = 0;
+ draw_point = 0;
+ outf("%s grestore\n", s);
+}
+
+void drawbeg(void)
+{
+ o_flush();
+ out_fontup(o_f);
if (draw_path)
return;
- draw_path = s != NULL;
- if (s)
- outf("gsave newpath %s\n", s);
- else
- outf("newpath ");
+ outf("newpath ");
}
-void drawend(char *s)
+void drawend(int close, int fill)
{
- if (draw_path && !s)
+ if (draw_path)
return;
- draw_path = 0;
draw_point = 0;
- if (s)
- outf("%s grestore\n", s);
+ if (close)
+ outf("closepath ");
+ if (fill)
+ outf("fill\n");
else
outf("stroke\n");
}
--- a/post.c
+++ b/post.c
@@ -131,9 +131,25 @@
*s = '\0';
}
-static void postspline(int h1, int v1)
+static void postline(void)
{
+ int h, v;
+ while (!iseol()) {
+ h = nextnum();
+ v = nextnum();
+ drawl(h, v);
+ }
+}
+
+static void postspline(void)
+{
int h2, v2;
+ int h1 = nextnum();
+ int v1 = nextnum();
+ if (iseol()) {
+ drawl(h1, v1);
+ return;
+ }
while (!iseol()) {
h2 = nextnum();
v2 = nextnum();
@@ -148,8 +164,8 @@
{
int h1, h2, v1, v2;
int c = next();
- drawbeg(NULL);
- switch (c) {
+ drawbeg();
+ switch (tolower(c)) {
case 'l':
h1 = nextnum();
v1 = nextnum();
@@ -171,15 +187,13 @@
drawa(h1, v1, h2, v2);
break;
case '~':
- h1 = nextnum();
- v1 = nextnum();
- if (iseol())
- drawl(h1, v1);
- else
- postspline(h1, v1);
+ postspline();
break;
+ case 'p':
+ postline();
+ break;
}
- drawend(NULL);
+ drawend(c == 'p' || c == 'P', c == 'E' || c == 'C' || c == 'P');
nexteol();
}
@@ -192,9 +206,9 @@
if (!strcmp("PS", cmd) || !strcmp("ps", cmd))
out("%s\n", arg);
if (!strcmp("BeginObject", cmd))
- drawbeg(arg);
+ drawmbeg(arg);
if (!strcmp("EndObject", cmd))
- drawend(arg);
+ drawmend(arg);
}
static char devpath[PATHLEN] = "devutf";
--- a/post.h
+++ b/post.h
@@ -83,8 +83,10 @@
void outmnt(int f);
extern char o_fonts[];
-void drawbeg(char *s);
-void drawend(char *s);
+void drawbeg(void);
+void drawend(int close, int fill);
+void drawmbeg(char *s);
+void drawmend(char *s);
void drawl(int h, int v);
void drawc(int c);
void drawe(int h, int v);