[dia] xfig: optimize draw_(ellipse|polygon|rect) to combine stroke and fill
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] xfig: optimize draw_(ellipse|polygon|rect) to combine stroke and fill
- Date: Thu, 4 Sep 2014 16:01:32 +0000 (UTC)
commit 9fb20c71312868c10ef3927f167bbfee27f1959e
Author: Hans Breuer <hans breuer org>
Date: Thu Sep 4 17:59:56 2014 +0200
xfig: optimize draw_(ellipse|polygon|rect) to combine stroke and fill
Tested with a modified render-test.dia because the original converted to
.fig make xfig 3.2.5c crash on every linestyle other than solid or dotted.
Also tested via xfig plug-in round-trip. For some reason the new single
objects for ellipse, rect and polygon are still put into a group. But
that's an issue to be tackled in xfig-import.c if at all.
plug-ins/xfig/xfig-export.c | 176 +++++++++----------------------------------
1 files changed, 36 insertions(+), 140 deletions(-)
---
diff --git a/plug-ins/xfig/xfig-export.c b/plug-ins/xfig/xfig-export.c
index bb0e8ba..2d7ed3b 100644
--- a/plug-ins/xfig/xfig-export.c
+++ b/plug-ins/xfig/xfig-export.c
@@ -685,53 +685,28 @@ draw_polyline_with_arrows(DiaRenderer *self,
fprintf(renderer->file, "\n");
}
-static void
-stroke_polygon (DiaRenderer *self,
- Point *points, int num_points,
- Color *color)
-{
- int i;
- XfigRenderer *renderer = XFIG_RENDERER(self);
- gchar d_buf[DTOSTR_BUF_SIZE];
-
- if (renderer->color_pass) {
- figCheckColor(renderer, color);
- return;
- }
-
- fprintf(renderer->file, "2 3 %d %d %d 0 %d 0 -1 %s %d %d 0 0 0 %d\n",
- figLineStyle(renderer), figLineWidth(renderer),
- figColor(renderer, color), figDepth(renderer),
- xfig_dtostr(d_buf, figDashLength(renderer)),
- figJoinStyle(renderer),
- figCapsStyle(renderer), num_points+1);
- fprintf(renderer->file, "\t");
- for (i = 0; i < num_points; i++) {
- fprintf(renderer->file, "%d %d ",
- (int)figCoord(renderer, points[i].x), (int)figCoord(renderer, points[i].y));
- }
- fprintf(renderer->file, "%d %d\n",
- (int)figCoord(renderer, points[0].x), (int)figCoord(renderer, points[0].y));
-}
-
-static void
-fill_polygon(DiaRenderer *self,
- Point *points, int num_points,
- Color *color)
+static void
+draw_polygon(DiaRenderer *self,
+ Point *points, int num_points,
+ Color *fill, Color *stroke)
{
int i;
XfigRenderer *renderer = XFIG_RENDERER(self);
gchar d_buf[DTOSTR_BUF_SIZE];
if (renderer->color_pass) {
- figCheckColor(renderer, color);
+ if (stroke)
+ figCheckColor(renderer, stroke);
+ if (fill)
+ figCheckColor(renderer, fill);
return;
}
- fprintf(renderer->file, "2 3 %d 0 %d %d %d 0 20 %s %d %d 0 0 0 %d\n",
- figLineStyle(renderer),
- figColor(renderer, color), figColor(renderer, color),
+ fprintf(renderer->file, "2 3 %d %d %d %d %d 0 %d %s %d %d 0 0 0 %d\n",
+ figLineStyle(renderer), stroke ? figLineWidth(renderer) : 0,
+ stroke ? figColor(renderer, stroke) : 0, fill ? figColor(renderer, fill) : 0,
figDepth(renderer),
+ fill ? 20 : -1,
xfig_dtostr(d_buf, figDashLength(renderer)),
figJoinStyle(renderer),
figCapsStyle(renderer), num_points+1);
@@ -745,61 +720,26 @@ fill_polygon(DiaRenderer *self,
}
static void
-draw_polygon(DiaRenderer *self,
- Point *points, int num_points,
- Color *fill, Color *stroke)
-{
- /* XXX: simple port, not optimized */
- if (fill)
- fill_polygon (self, points, num_points, fill);
- if (stroke)
- stroke_polygon (self, points, num_points, stroke);
-}
-
-static void
-stroke_rect(DiaRenderer *self,
- Point *ul_corner, Point *lr_corner,
- Color *color)
-{
- XfigRenderer *renderer = XFIG_RENDERER(self);
- gchar d_buf[DTOSTR_BUF_SIZE];
-
- if (renderer->color_pass) {
- figCheckColor(renderer, color);
- return;
- }
-
- fprintf(renderer->file, "2 3 %d %d %d 0 %d 0 -1 %s %d %d 0 0 0 5\n",
- figLineStyle(renderer), figLineWidth(renderer),
- figColor(renderer, color), figDepth(renderer),
- xfig_dtostr(d_buf, figDashLength(renderer)),
- figJoinStyle(renderer),
- figCapsStyle(renderer));
- fprintf(renderer->file, "\t%d %d %d %d %d %d %d %d %d %d\n",
- (int)figCoord(renderer, ul_corner->x), (int)figCoord(renderer, ul_corner->y),
- (int)figCoord(renderer, lr_corner->x), (int)figCoord(renderer, ul_corner->y),
- (int)figCoord(renderer, lr_corner->x), (int)figCoord(renderer, lr_corner->y),
- (int)figCoord(renderer, ul_corner->x), (int)figCoord(renderer, lr_corner->y),
- (int)figCoord(renderer, ul_corner->x), (int)figCoord(renderer, ul_corner->y));
-}
-
-static void
-fill_rect(DiaRenderer *self,
+draw_rect(DiaRenderer *self,
Point *ul_corner, Point *lr_corner,
- Color *color)
+ Color *fill, Color *stroke)
{
XfigRenderer *renderer = XFIG_RENDERER(self);
gchar d_buf[DTOSTR_BUF_SIZE];
if (renderer->color_pass) {
- figCheckColor(renderer, color);
+ if (stroke)
+ figCheckColor(renderer, stroke);
+ if (fill)
+ figCheckColor(renderer, fill);
return;
}
- fprintf(renderer->file, "2 3 %d %d %d %d %d -1 20 %s %d %d 0 0 0 5\n",
- figLineStyle(renderer), figLineWidth(renderer),
- figColor(renderer, color), figColor(renderer, color),
+ fprintf(renderer->file, "2 3 %d %d %d %d %d -1 %d %s %d %d 0 0 0 5\n",
+ figLineStyle(renderer), stroke ? figLineWidth(renderer) : 0,
+ stroke ? figColor(renderer, stroke) : 0, fill ? figColor(renderer, fill) : 0,
figDepth(renderer),
+ fill ? 20 : -1,
xfig_dtostr(d_buf, figDashLength(renderer)),
figJoinStyle(renderer),
figCapsStyle(renderer));
@@ -810,17 +750,6 @@ fill_rect(DiaRenderer *self,
(int)figCoord(renderer, ul_corner->x), (int)figCoord(renderer, lr_corner->y),
(int)figCoord(renderer, ul_corner->x), (int)figCoord(renderer, ul_corner->y));
}
-static void
-draw_rect(DiaRenderer *self,
- Point *ul_corner, Point *lr_corner,
- Color *fill, Color *stroke)
-{
- /* XXX: optimize to one call? */
- if (fill)
- fill_rect (self, ul_corner, lr_corner, fill);
- if (stroke)
- stroke_rect (self, ul_corner, lr_corner, stroke);
-}
static void
draw_arc(DiaRenderer *self,
Point *center,
@@ -989,68 +918,35 @@ fill_arc(DiaRenderer *self,
}
-static void
-stroke_ellipse(DiaRenderer *self,
- Point *center,
- real width, real height,
- Color *color)
-{
- XfigRenderer *renderer = XFIG_RENDERER(self);
- gchar d_buf[DTOSTR_BUF_SIZE];
-
- if (renderer->color_pass) {
- figCheckColor(renderer, color);
- return;
- }
-
- fprintf(renderer->file, "1 1 %d %d %d -1 %d 0 -1 %s 1 0.0 %d %d %d %d 0 0 0 0\n",
- figLineStyle(renderer),
- figLineWidth(renderer),
- figColor(renderer, color),
- figDepth(renderer),
- xfig_dtostr(d_buf, figDashLength(renderer)),
- (int)figCoord(renderer, center->x), (int)figCoord(renderer, center->y),
- (int)figCoord(renderer, width/2), (int)figCoord(renderer, height/2));
-
-}
-
-static void
-fill_ellipse(DiaRenderer *self,
- Point *center,
- real width, real height,
- Color *color)
+static void
+draw_ellipse (DiaRenderer *self,
+ Point *center,
+ real width, real height,
+ Color *fill, Color *stroke)
{
XfigRenderer *renderer = XFIG_RENDERER(self);
gchar d_buf[DTOSTR_BUF_SIZE];
if (renderer->color_pass) {
- figCheckColor(renderer, color);
+ if (stroke)
+ figCheckColor(renderer, stroke);
+ if (fill)
+ figCheckColor(renderer, fill);
return;
}
- fprintf(renderer->file, "1 1 %d %d %d %d %d 0 20 %s 1 0.0 %d %d %d %d 0 0 0 0\n",
+ fprintf(renderer->file, "1 1 %d %d %d %d %d 0 %d %s 1 0.0 %d %d %d %d 0 0 0 0\n",
figLineStyle(renderer),
- figLineWidth(renderer),
- figColor(renderer, color),
- figColor(renderer, color),
+ stroke ? figLineWidth(renderer) : 0,
+ stroke ? figColor(renderer, stroke) : 0,
+ fill ? figColor(renderer, fill) : 0,
figDepth(renderer),
+ fill ? 20 : -1,
xfig_dtostr(d_buf, figDashLength(renderer)),
(int)figCoord(renderer, center->x), (int)figCoord(renderer, center->y),
(int)figCoord(renderer, width/2), (int)figCoord(renderer, height/2));
}
-static void
-draw_ellipse (DiaRenderer *self,
- Point *center,
- real width, real height,
- Color *fill, Color *stroke)
-{
- if (fill)
- fill_ellipse (self, center, width, height, fill);
- if (stroke)
- stroke_ellipse (self, center, width, height, stroke);
-}
-
static void
draw_bezier(DiaRenderer *self,
BezPoint *points,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]