From 690c1cb5ae08f03f88ba590cad518f94089b58d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 2 Jun 2018 02:54:38 +0200 Subject: [PATCH] Implement full path support with correct line caps (rounded|flat|squared) --- latex-output/latex-output.c | 21 +++++++++++++++++---- test-data/path.gds | Bin 256 -> 372 bytes test-data/path.pdf | Bin 1437 -> 1500 bytes test-data/path.tex | 20 +++++++++++++++++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/latex-output/latex-output.c b/latex-output/latex-output.c index 618d4ff..2b85056 100644 --- a/latex-output/latex-output.c +++ b/latex-output/latex-output.c @@ -18,6 +18,7 @@ */ #include "latex-output.h" +#include #define WRITEOUT_BUFFER(buff) fwrite((buff)->str, sizeof(char), (buff)->len, tex_file) @@ -87,8 +88,7 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt struct gds_graphics *gfx; struct gds_point *pt; GdkRGBA color; - int width; - gchar *red, *green, *blue, *opacity; + static const char *line_caps[] = {"butt", "round", "rect"}; for (temp = graphics; temp != NULL; temp = temp->next) { gfx = (struct gds_graphics *)temp->data; @@ -108,9 +108,22 @@ static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GSt g_string_printf(buffer, "cycle;\n"); WRITEOUT_BUFFER(buffer); } else if(gfx->gfx_type == GRAPHIC_PATH) { - g_string_printf(buffer, "\\draw[line width=%lf pt, draw={c%d}, opacity={%lf}] ", - gfx->width_absolute/1000.0, gfx->layer, gfx->layer, color.alpha); + + if (g_list_length(gfx->vertices) < 2) { + printf("Cannot write path with less than 2 points\n"); + break; + } + + if (gfx->path_render_type < 0 || gfx->path_render_type > 2) { + printf("Path type unrecognized. Setting to 'flushed'\n"); + gfx->path_render_type = 0; + } + + g_string_printf(buffer, "\\draw[line width=%lf pt, draw={c%d}, opacity={%lf}, cap=%s] ", + gfx->width_absolute/1000.0, gfx->layer, color.alpha, + line_caps[gfx->path_render_type]); WRITEOUT_BUFFER(buffer); + /* Append vertices */ for (temp_vertex = gfx->vertices; temp_vertex != NULL; temp_vertex = temp_vertex->next) { pt = (struct gds_point *)temp_vertex->data; diff --git a/test-data/path.gds b/test-data/path.gds index 7c21667ab6ad3039fdb5f3e0e0155f61fa722713..7599be9b1984add6421c84bb0ef29dc7ecd68143 100644 GIT binary patch literal 372 zcmZQzV_;&6V31*CVt>Q{WCNiI12Zz4L4b)ZC^au7wMaK4wYY?VL4=vr&au#84YYR(kd|g(U`_|Jp>}gXT+Re_xenN^0zexyfwl<%)dID!h{I@@ OIEaSW&JL7jVE_PtI7q$# delta 105 zcmeyu)WD>~z{bGD6u}_F$i)5#$Yx{^Wl(33LuOA@(iO%goTRU;BEbCr|8F}62Bzcx e|NpmUU|?Jcq@M!uB?boO>Hq)#yD(XU(FXtqFdfAJ diff --git a/test-data/path.pdf b/test-data/path.pdf index 3947238196aa2abf30f5afc11fae95271d41a9e8..078a01afd2e240a696a23942cd505c14815e76f6 100644 GIT binary patch delta 931 zcmbQseTRF3GPALv@nl(6&HAI0z5SRCdD^~Pw(4KFQuye|JxBHsPR@mgI0ICdb&GwB zD5!n2B|xrqoxtLm6<>}Q?z=zPQGzj1?t_PqnUadf#0bXZm0YKND_Bm?aQ5ex*vxg9 zdq>XqFIf!L9BJv!=X+jEmf+khR8e&_ZR4~#Mlt8>=T&d|bh-WGyOhe=O5eEakEL@= zJ~uh>Qs;^TY3mbnrUo~fvP1_Py;6Kx`}CKC>E$qiGyySzbNcN3-TLn?-IHDEaob9# zM{C>MfVA@Fpp~WVcaIkQI(bwvokd($BT?)eWsy=Gcdpb#KXW8e8 zKi_8-x_4g*D&^DiEt6+HxnR$#pr__>j+VOj(tQ^FXPhH*L(DAiB=?4#%C`p!lkIIh zLa&_6nSD#D`ta6mzj(_|@3#N5e}Ck+TKWFJh3kc6wl`09V@zN-GB7eVHZqvJmQe=I zzQFjSezt=^+xy?z_mZnSu5)j>GO0C7_;$P5!A)~x1lo1yDJ?m&Aa(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;jM(LR%*EYz--^oRT=jkSF2!W+b5f;|KbPH@*&ax1Tgq zisx@VbNSRW1=}h)44_GvMO;dX{IaR;)Rz`8h!Dc=|=@TOoHYrEB@eo)SC0%xwN^ ztDe@K^KIwbbH2TuK6wF4PJn@-fs3()n}xZhfs?bdnX!?Rk*SHHA&_h4Y-D6+V5eY1 zP)RJ8zE5gidP#u*mGJJrq} oZOOC`ns!nXb3v^9q%5xDlEk8tilWpsE<;0O3ocbvSARDy04_X!XaE2J diff --git a/test-data/path.tex b/test-data/path.tex index 8646f0d..805b2fa 100644 --- a/test-data/path.tex +++ b/test-data/path.tex @@ -18,7 +18,25 @@ \ifcreatepdflayers \begin{scope}[ocg={ref=1, status=visible,name={TOP-Layer}}] \fi] -\draw[line width=0.300000 pt, draw={c1}, opacity={1.000000}] (-1.218000 pt, 0.711000 pt) -- (-0.197000 pt, 0.425000 pt) -- (-0.027000 pt, -0.046000 pt) -- (0.919000 pt, -0.304000 pt); +\draw[line width=0.300000 pt, draw={c1}, opacity={1.000000}, cap=rect] (-1.108000 pt, 0.589000 pt) -- (-0.498000 pt, 0.589000 pt) -- (-0.255000 pt, 0.343000 pt); +\ifcreatepdflayers +\end{scope} +\fi +\end{pgfonlayer} +\begin{pgfonlayer}{l1} +\ifcreatepdflayers +\begin{scope}[ocg={ref=1, status=visible,name={TOP-Layer}}] +\fi] +\draw[line width=0.300000 pt, draw={c1}, opacity={1.000000}, cap=butt] (-1.031000 pt, 0.326000 pt) -- (-1.028000 pt, 0.093000 pt) -- (-0.282000 pt, -0.019000 pt); +\ifcreatepdflayers +\end{scope} +\fi +\end{pgfonlayer} +\begin{pgfonlayer}{l1} +\ifcreatepdflayers +\begin{scope}[ocg={ref=1, status=visible,name={TOP-Layer}}] +\fi] +\draw[line width=0.300000 pt, draw={c1}, opacity={1.000000}, cap=round] (0.076000 pt, 0.059000 pt) -- (0.660000 pt, 0.027000 pt) -- (0.871000 pt, 0.599000 pt); \ifcreatepdflayers \end{scope} \fi