• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

修订版543d1981ff7fd814a25ff11471cfbe62aeee76b0 (tree)
时间2014-05-01 21:05:14
作者Hans Breuer <hans@breu...>
CommiterHans Breuer

Log Message

pgf: Fix fill rule, alpha/transparency and optimize draw_beziergon

PGF is capablle to render bezier with holes and can do stroke and fill
in one step. ALso there is opacity for stroke and fill.
Included a small tex documented to test some of our sample diagrams with:
pdflatex pgf-test

更改概述

差异

--- a/plug-ins/pgf/render_pgf.c
+++ b/plug-ins/pgf/render_pgf.c
@@ -177,6 +177,29 @@ void (*orig_draw_bezier_with_arrows) (DiaRenderer *renderer, BezPoint *points, i
177177
178178
179179
180+/*!
181+ * \brief Advertize special capabilities
182+ *
183+ * Some objects drawing adapts to capabilities advertized by the respective
184+ * renderer. Usually there is a fallback, but generally the real thing should
185+ * be better.
186+ *
187+ * \memberof _PgfRenderer
188+ */
189+static gboolean
190+is_capable_to (DiaRenderer *renderer, RenderCapability cap)
191+{
192+ if (RENDER_HOLES == cap)
193+ return TRUE;
194+ else if (RENDER_ALPHA == cap)
195+ return TRUE;
196+ else if (RENDER_AFFINE == cap)
197+ return FALSE; /* not now */
198+ else if (RENDER_PATTERN == cap)
199+ return FALSE; /* might be possible, too */
200+ return FALSE;
201+}
202+
180203 static void pgf_renderer_class_init (PgfRendererClass *klass);
181204
182205 static gpointer parent_class = NULL;
@@ -227,6 +250,7 @@ pgf_renderer_class_init (PgfRendererClass *klass)
227250
228251 renderer_class->begin_render = begin_render;
229252 renderer_class->end_render = end_render;
253+ renderer_class->is_capable_to = is_capable_to;
230254
231255 renderer_class->set_linewidth = set_linewidth;
232256 renderer_class->set_linecaps = set_linecaps;
@@ -288,6 +312,8 @@ set_line_color(PgfRenderer *renderer,Color *color)
288312 pgf_dtostr(green_buf, (gdouble) color->green),
289313 pgf_dtostr(blue_buf, (gdouble) color->blue) );
290314 fprintf(renderer->file,"\\pgfsetstrokecolor{dialinecolor}\n");
315+ fprintf(renderer->file,"\\pgfsetstrokeopacity{%s}\n",
316+ pgf_dtostr(red_buf, (gdouble) color->alpha));
291317 }
292318
293319 static void
@@ -297,11 +323,13 @@ set_fill_color(PgfRenderer *renderer,Color *color)
297323 gchar green_buf[DTOSTR_BUF_SIZE];
298324 gchar blue_buf[DTOSTR_BUF_SIZE];
299325
300- fprintf(renderer->file, "\\definecolor{dialinecolor}{rgb}{%s, %s, %s}\n",
326+ fprintf(renderer->file, "\\definecolor{diafillcolor}{rgb}{%s, %s, %s}\n",
301327 pgf_dtostr(red_buf, (gdouble) color->red),
302328 pgf_dtostr(green_buf, (gdouble) color->green),
303329 pgf_dtostr(blue_buf, (gdouble) color->blue) );
304- fprintf(renderer->file,"\\pgfsetfillcolor{dialinecolor}\n");
330+ fprintf(renderer->file,"\\pgfsetfillcolor{diafillcolor}\n");
331+ fprintf(renderer->file,"\\pgfsetfillopacity{%s}\n",
332+ pgf_dtostr(red_buf, (gdouble) color->alpha));
305333 }
306334
307335 static void
@@ -751,10 +779,11 @@ fill_ellipse(DiaRenderer *self,
751779 }
752780
753781 static void
754-pgf_bezier(PgfRenderer *renderer,
755- BezPoint *points,
756- gint numpoints,
757- Color *color, gboolean filled)
782+pgf_bezier (PgfRenderer *renderer,
783+ BezPoint *points,
784+ gint numpoints,
785+ Color *fill, Color *stroke,
786+ gboolean closed)
758787 {
759788 gint i;
760789 gchar p1x_buf[DTOSTR_BUF_SIZE];
@@ -764,20 +793,20 @@ pgf_bezier(PgfRenderer *renderer,
764793 gchar p3x_buf[DTOSTR_BUF_SIZE];
765794 gchar p3y_buf[DTOSTR_BUF_SIZE];
766795
767- if (!filled) {set_line_color(renderer,color);}
768- else {set_fill_color(renderer,color);}
796+ if (fill)
797+ set_fill_color(renderer,fill);
798+ if (stroke)
799+ set_line_color(renderer,stroke);
769800
770801 if (points[0].type != BEZ_MOVE_TO)
771802 g_warning("first BezPoint must be a BEZ_MOVE_TO");
772803
773- fprintf(renderer->file, "\\pgfpathmoveto{\\pgfpoint{%s\\du}{%s\\du}}\n",
774- pgf_dtostr(p1x_buf,points[0].p1.x),
775- pgf_dtostr(p1y_buf,points[0].p1.y) );
776-
777- for (i = 1; i < numpoints; i++)
804+ for (i = 0; i < numpoints; i++)
778805 switch (points[i].type) {
779806 case BEZ_MOVE_TO:
780- g_warning("only first BezPoint can be a BEZ_MOVE_TO");
807+ fprintf(renderer->file, "\\pgfpathmoveto{\\pgfpoint{%s\\du}{%s\\du}}\n",
808+ pgf_dtostr(p1x_buf,points[i].p1.x),
809+ pgf_dtostr(p1y_buf,points[i].p1.y) );
781810 break;
782811 case BEZ_LINE_TO:
783812 fprintf(renderer->file, "\\pgfpathlineto{\\pgfpoint{%s\\du}{%s\\du}}\n",
@@ -797,11 +826,14 @@ pgf_bezier(PgfRenderer *renderer,
797826 break;
798827 }
799828
800- if (filled)
829+ if (closed)
830+ fprintf(renderer->file, "\\pgfpathclose\n");
831+ if (fill && stroke)
832+ fprintf(renderer->file, "\\pgfusepath{fill,stroke}\n");
833+ else if (fill)
801834 fprintf(renderer->file, "\\pgfusepath{fill}\n");
802-
803835 /* fill[fillstyle=solid,fillcolor=diafillcolor,linecolor=diafillcolor]}\n"); */
804- else
836+ else if (stroke)
805837 fprintf(renderer->file, "\\pgfusepath{stroke}\n");
806838 }
807839
@@ -813,7 +845,7 @@ draw_bezier(DiaRenderer *self,
813845 {
814846 PgfRenderer *renderer = PGF_RENDERER(self);
815847
816- pgf_bezier(renderer,points,numpoints,color,FALSE);
848+ pgf_bezier(renderer,points,numpoints,NULL,color,FALSE);
817849 }
818850
819851
@@ -827,11 +859,7 @@ draw_beziergon (DiaRenderer *self,
827859 {
828860 PgfRenderer *renderer = PGF_RENDERER(self);
829861
830- /* XXX: still not closing the path */
831- if (fill)
832- pgf_bezier(renderer,points,numpoints,fill,TRUE);
833- if (stroke)
834- pgf_bezier(renderer,points,numpoints,stroke,FALSE);
862+ pgf_bezier(renderer,points,numpoints,fill,stroke,TRUE);
835863 }
836864
837865 static int
@@ -1125,6 +1153,7 @@ draw_string(DiaRenderer *self,
11251153 gchar py_buf[DTOSTR_BUF_SIZE];
11261154
11271155 set_line_color(renderer,color);
1156+ set_fill_color(renderer,color);
11281157
11291158 fprintf(renderer->file,"\\node");
11301159 switch (alignment) {
@@ -1211,7 +1240,7 @@ export_pgf(DiagramData *data, DiaContext *ctx,
12111240 " \\newlength{\\du}\n"
12121241 "\\fi\n"
12131242 "\\setlength{\\du}{15\\unitlength}\n"
1214- "\\begin{tikzpicture}\n",
1243+ "\\begin{tikzpicture}[even odd rule]\n",
12151244 diafilename,
12161245 VERSION,
12171246 ctime(&time_now),
--- /dev/null
+++ b/samples/pgf-test.tex
@@ -0,0 +1,14 @@
1+\documentclass[landscape]{article}
2+\usepackage{tikz}
3+\title{Dia Export Test}
4+\author{Hans Breuer}
5+\begin{document}
6+\maketitle
7+\begin{center}
8+\include{convert-to-path}
9+\include{jigsaw}
10+\include{render-test}
11+\end{center}
12+\end{document}
13+
14+