作図ソフト dia の改良版
Revisão | 543d1981ff7fd814a25ff11471cfbe62aeee76b0 (tree) |
---|---|
Hora | 2014-05-01 21:05:14 |
Autor | Hans Breuer <hans@breu...> |
Commiter | Hans Breuer |
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
@@ -177,6 +177,29 @@ void (*orig_draw_bezier_with_arrows) (DiaRenderer *renderer, BezPoint *points, i | ||
177 | 177 | |
178 | 178 | |
179 | 179 | |
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 | + | |
180 | 203 | static void pgf_renderer_class_init (PgfRendererClass *klass); |
181 | 204 | |
182 | 205 | static gpointer parent_class = NULL; |
@@ -227,6 +250,7 @@ pgf_renderer_class_init (PgfRendererClass *klass) | ||
227 | 250 | |
228 | 251 | renderer_class->begin_render = begin_render; |
229 | 252 | renderer_class->end_render = end_render; |
253 | + renderer_class->is_capable_to = is_capable_to; | |
230 | 254 | |
231 | 255 | renderer_class->set_linewidth = set_linewidth; |
232 | 256 | renderer_class->set_linecaps = set_linecaps; |
@@ -288,6 +312,8 @@ set_line_color(PgfRenderer *renderer,Color *color) | ||
288 | 312 | pgf_dtostr(green_buf, (gdouble) color->green), |
289 | 313 | pgf_dtostr(blue_buf, (gdouble) color->blue) ); |
290 | 314 | fprintf(renderer->file,"\\pgfsetstrokecolor{dialinecolor}\n"); |
315 | + fprintf(renderer->file,"\\pgfsetstrokeopacity{%s}\n", | |
316 | + pgf_dtostr(red_buf, (gdouble) color->alpha)); | |
291 | 317 | } |
292 | 318 | |
293 | 319 | static void |
@@ -297,11 +323,13 @@ set_fill_color(PgfRenderer *renderer,Color *color) | ||
297 | 323 | gchar green_buf[DTOSTR_BUF_SIZE]; |
298 | 324 | gchar blue_buf[DTOSTR_BUF_SIZE]; |
299 | 325 | |
300 | - fprintf(renderer->file, "\\definecolor{dialinecolor}{rgb}{%s, %s, %s}\n", | |
326 | + fprintf(renderer->file, "\\definecolor{diafillcolor}{rgb}{%s, %s, %s}\n", | |
301 | 327 | pgf_dtostr(red_buf, (gdouble) color->red), |
302 | 328 | pgf_dtostr(green_buf, (gdouble) color->green), |
303 | 329 | 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)); | |
305 | 333 | } |
306 | 334 | |
307 | 335 | static void |
@@ -751,10 +779,11 @@ fill_ellipse(DiaRenderer *self, | ||
751 | 779 | } |
752 | 780 | |
753 | 781 | 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) | |
758 | 787 | { |
759 | 788 | gint i; |
760 | 789 | gchar p1x_buf[DTOSTR_BUF_SIZE]; |
@@ -764,20 +793,20 @@ pgf_bezier(PgfRenderer *renderer, | ||
764 | 793 | gchar p3x_buf[DTOSTR_BUF_SIZE]; |
765 | 794 | gchar p3y_buf[DTOSTR_BUF_SIZE]; |
766 | 795 | |
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); | |
769 | 800 | |
770 | 801 | if (points[0].type != BEZ_MOVE_TO) |
771 | 802 | g_warning("first BezPoint must be a BEZ_MOVE_TO"); |
772 | 803 | |
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++) | |
778 | 805 | switch (points[i].type) { |
779 | 806 | 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) ); | |
781 | 810 | break; |
782 | 811 | case BEZ_LINE_TO: |
783 | 812 | fprintf(renderer->file, "\\pgfpathlineto{\\pgfpoint{%s\\du}{%s\\du}}\n", |
@@ -797,11 +826,14 @@ pgf_bezier(PgfRenderer *renderer, | ||
797 | 826 | break; |
798 | 827 | } |
799 | 828 | |
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) | |
801 | 834 | fprintf(renderer->file, "\\pgfusepath{fill}\n"); |
802 | - | |
803 | 835 | /* fill[fillstyle=solid,fillcolor=diafillcolor,linecolor=diafillcolor]}\n"); */ |
804 | - else | |
836 | + else if (stroke) | |
805 | 837 | fprintf(renderer->file, "\\pgfusepath{stroke}\n"); |
806 | 838 | } |
807 | 839 |
@@ -813,7 +845,7 @@ draw_bezier(DiaRenderer *self, | ||
813 | 845 | { |
814 | 846 | PgfRenderer *renderer = PGF_RENDERER(self); |
815 | 847 | |
816 | - pgf_bezier(renderer,points,numpoints,color,FALSE); | |
848 | + pgf_bezier(renderer,points,numpoints,NULL,color,FALSE); | |
817 | 849 | } |
818 | 850 | |
819 | 851 |
@@ -827,11 +859,7 @@ draw_beziergon (DiaRenderer *self, | ||
827 | 859 | { |
828 | 860 | PgfRenderer *renderer = PGF_RENDERER(self); |
829 | 861 | |
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); | |
835 | 863 | } |
836 | 864 | |
837 | 865 | static int |
@@ -1125,6 +1153,7 @@ draw_string(DiaRenderer *self, | ||
1125 | 1153 | gchar py_buf[DTOSTR_BUF_SIZE]; |
1126 | 1154 | |
1127 | 1155 | set_line_color(renderer,color); |
1156 | + set_fill_color(renderer,color); | |
1128 | 1157 | |
1129 | 1158 | fprintf(renderer->file,"\\node"); |
1130 | 1159 | switch (alignment) { |
@@ -1211,7 +1240,7 @@ export_pgf(DiagramData *data, DiaContext *ctx, | ||
1211 | 1240 | " \\newlength{\\du}\n" |
1212 | 1241 | "\\fi\n" |
1213 | 1242 | "\\setlength{\\du}{15\\unitlength}\n" |
1214 | - "\\begin{tikzpicture}\n", | |
1243 | + "\\begin{tikzpicture}[even odd rule]\n", | |
1215 | 1244 | diafilename, |
1216 | 1245 | VERSION, |
1217 | 1246 | ctime(&time_now), |
@@ -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 | + |