Skip to content

Commit

Permalink
Improve rendering of arrows, fix #172.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarwinNE committed Apr 19, 2020
1 parent 4e0f425 commit 5b6b0ce
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 360 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/net/sourceforge/fidocadj/export/PointPr.class
OSes/android/fidocadj/bin/
OSes/android/fidocadj/gen/
bin/.DS_Store
Expand Down
249 changes: 53 additions & 196 deletions dev_tools/fidocadj_cpd.txt

Large diffs are not rendered by default.

312 changes: 207 additions & 105 deletions dev_tools/fidocadj_pmd.html

Large diffs are not rendered by default.

34 changes: 23 additions & 11 deletions src/net/sourceforge/fidocadj/export/ExportEPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2019 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
</pre>
@author Davide Bucci
*/
Expand Down Expand Up @@ -341,15 +341,25 @@ public void exportLine (double x1, double y1,
ColorInterface c=l.getColor();
checkColorAndWidth(c, strokeWidth);
registerDash(dashStyle);



out.write(""+x1+" "+y1+" moveto "+
x2+" "+y2+" lineto stroke\n");
if (arrowStart) exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
if (arrowEnd) exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
double xstart=x1, ystart=y1;
double xend=x2, yend=y2;

if (arrowStart) {
PointPr p=exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xstart=p.x;
ystart=p.y;
}
if (arrowEnd) {
PointPr p=exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xend=p.x;
yend=p.y;
}
out.write(""+xstart+" "+ystart+" moveto "+
xend+" "+yend+" lineto stroke\n");
}

/** Called when exporting an arrow.
Expand All @@ -360,10 +370,11 @@ public void exportLine (double x1, double y1,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return the coordinates of the base of the arrow.
@throws IOException when things goes horribly wrong, for example if
the file in which the output is being done is not accessible.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
Expand Down Expand Up @@ -428,6 +439,7 @@ public void exportArrow(double x, double y, double xc, double yc,
" moveto\n"+Globals.roundTo(x4)+" "+Globals.roundTo(y4)+
" lineto\nstroke\n");
}
return new PointPr(x0,y0);
}

/** Called when exporting a Macro call.
Expand Down
6 changes: 4 additions & 2 deletions src/net/sourceforge/fidocadj/export/ExportEagle.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2019 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
</pre>
Expand Down Expand Up @@ -457,15 +457,17 @@ public boolean exportCurve(PointDouble[] vertices, int nVertices,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return always (0,0).
@throws IOException when things goes horribly wrong, for example if
the file in which the output is being done is not accessible.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
{
// Does nothing, since it will not be useful here.
return new PointPr();
}

/** Export a number: truncate it to four decimals
Expand Down
6 changes: 4 additions & 2 deletions src/net/sourceforge/fidocadj/export/ExportFidoCad.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Export towards FidoCAD (!)
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2019 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
</pre>
@author Davide Bucci
Expand Down Expand Up @@ -546,14 +546,16 @@ public void exportRectangle(int x1, int y1, int x2, int y2,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return always (0,0).
@throws IOException if a disaster happens, i.e. a file can not be
accessed.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
{
// Does nothing, since it will not be useful here.
return new PointPr();
}
}
2 changes: 1 addition & 1 deletion src/net/sourceforge/fidocadj/export/ExportGraphic.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2007-2019 by Davide Bucci
Copyright 2007-2020 by Davide Bucci
</pre>
@author Davide Bucci
Expand Down
3 changes: 2 additions & 1 deletion src/net/sourceforge/fidocadj/export/ExportInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ public void exportRectangle(int x1, int y1, int x2, int y2,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return the coordinates of the base of the arrow.
@throws IOException if an error occurs.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException;
Expand Down
7 changes: 4 additions & 3 deletions src/net/sourceforge/fidocadj/export/ExportPCBRND.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2019 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
Copyright 2017 Erich Heinzle
</pre>
Expand Down Expand Up @@ -608,19 +608,20 @@ public boolean exportCurve(PointDouble[] vertices, int nVertices,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return always (0,0).
@throws IOException when things goes horribly wrong, for example if
the file in which the output is being done is not accessible.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
{
// Does nothing, since it will not be useful here.
return new PointPr();
}

/** Export a number: truncate it to four decimals
*/
private String een(double n)
{
Expand Down
30 changes: 22 additions & 8 deletions src/net/sourceforge/fidocadj/export/ExportPDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2019 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
</pre>
@author Davide Bucci
Expand Down Expand Up @@ -939,19 +939,31 @@ public void exportLine (double x1, double y1,
double strokeWidth)
throws IOException
{
double xstart=x1, ystart=y1;
double xend=x2, yend=y2;

LayerDesc l=(LayerDesc)layerV.get(layer);
ColorInterface c=l.getColor();

checkColorAndWidth(c, strokeWidth);
registerDash(dashStyle);

outt.write(" "+x1+" "+y1+" m "+
x2+" "+y2+" l S\n");
if (arrowStart) {
PointPr p=exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xstart=p.x;
ystart=p.y;
}
if (arrowEnd) {
PointPr p=exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xend=p.x;
yend=p.y;
}

if (arrowStart) exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
if (arrowEnd) exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
outt.write(" "+xstart+" "+ystart+" m "+ xend+" "+yend+" l S\n");
}

/** Called when exporting a Macro call.
Expand Down Expand Up @@ -1341,10 +1353,11 @@ private void registerDash(int dashStyle)
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return the coordinates of the base of the arrow.
@throws IOException if a disaster happens, i.e. a file can not be
accessed.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
Expand Down Expand Up @@ -1403,5 +1416,6 @@ public void exportArrow(double x, double y, double xc, double yc,
outt.write(""+Globals.roundTo(x3)+" "+Globals.roundTo(y3)+" m\n"+
Globals.roundTo(x4)+" "+Globals.roundTo(y4)+" l s\n");
}
return new PointPr(x0,y0);
}
}
33 changes: 22 additions & 11 deletions src/net/sourceforge/fidocadj/export/ExportPGF.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,25 @@ public void exportLine (double x1, double y1,
{
registerColorSize(layer, strokeWidth);
registerDash(dashStyle);

out.write("\\pgfline{\\pgfxy("+x1+","+y1+")}{\\pgfxy("+
x2+","+y2+")}\n");


if (arrowStart) exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
if (arrowEnd) exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
double xstart=x1, ystart=y1;
double xend=x2, yend=y2;

if (arrowStart) {
PointPr p=exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xstart=p.x;
ystart=p.y;
}
if (arrowEnd) {
PointPr p=exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xend=p.x;
yend=p.y;
}
out.write("\\pgfline{\\pgfxy("+xstart+","+ystart+")}{\\pgfxy("+
xend+","+yend+")}\n");
}

/** Called when exporting an arrow.
Expand All @@ -319,10 +329,11 @@ public void exportLine (double x1, double y1,
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return the coordinates of the base of the arrow.
@throws IOException if a disaster happens, i.e. a file can not be
accessed.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
Expand Down Expand Up @@ -384,7 +395,7 @@ public void exportArrow(double x, double y, double xc, double yc,
out.write("\\pgfline{\\pgfxy("+x3+","+y3+")}{\\pgfxy("+
x4+","+y4+")}\n");
}

return new PointPr(x0,y0);
}

/** Called when exporting a Macro call.
Expand Down
33 changes: 24 additions & 9 deletions src/net/sourceforge/fidocadj/export/ExportSVG.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
along with FidoCadJ. If not,
@see <a href=http://www.gnu.org/licenses/>http://www.gnu.org/licenses/</a>.
Copyright 2008-2015 by Davide Bucci
Copyright 2008-2020 by Davide Bucci
</pre>
Expand Down Expand Up @@ -303,14 +303,27 @@ public void exportLine (double x1, double y1,
LayerDesc l=(LayerDesc)layerV.get(layer);
c=l.getColor();
strokeWidth=sW;
out.write("<line x1=\""+cLe(x1)+"\" y1=\""+cLe(y1)+"\" x2=\""+
cLe(x2)+"\" y2=\""+cLe(y2)+"\" ");
checkColorAndWidth("fill=\"none\"", dashStyle);

if (arrowStart) exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
if (arrowEnd) exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
double xstart=x1, ystart=y1;
double xend=x2, yend=y2;

if (arrowStart) {
PointPr p=exportArrow(x1, y1, x2, y2, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xstart=p.x;
ystart=p.y;
}
if (arrowEnd) {
PointPr p=exportArrow(x2, y2, x1, y1, arrowLength,
arrowHalfWidth, arrowStyle);
// Fix #172
xend=p.x;
yend=p.y;
}
out.write("<line x1=\""+cLe(xstart)+"\" y1=\""+cLe(ystart)+"\" x2=\""+
cLe(xend)+"\" y2=\""+cLe(yend)+"\" ");
checkColorAndWidth("fill=\"none\"", dashStyle);
}

/** Called when exporting a Macro call.
Expand Down Expand Up @@ -683,10 +696,11 @@ private void checkColorAndWidth(String fill_pattern, int dashStyle)
@param l length of the arrow.
@param h width of the arrow.
@param style style of the arrow.
@return the coordinates of the base of the arrow.
@throws IOException if a disaster happens, i.e. a file can not be
accessed.
*/
public void exportArrow(double x, double y, double xc, double yc,
public PointPr exportArrow(double x, double y, double xc, double yc,
double l, double h,
int style)
throws IOException
Expand Down Expand Up @@ -755,5 +769,6 @@ public void exportArrow(double x, double y, double xc, double yc,
cLe(x4)+"\" y2=\""+cLe(y4)+"\" ");
checkColorAndWidth("fill=\"none\"", 0);
}
return new PointPr(x0,y0);
}
}
23 changes: 23 additions & 0 deletions src/net/sourceforge/fidocadj/export/PointPr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.sourceforge.fidocadj.export;

/** A simple point featuring double-precision coordinates
*/
public class PointPr
{
public double x;
public double y;
/** Standard constructor, yielding a (0,0) coordinate.
*/
public PointPr()
{
x=0;y=0;
}
/** Constructor, yielding a generic coordinate.
@param xx the x coordinate.
@param yy the y coordinate.
*/
public PointPr(double xx, double yy)
{
x=xx;y=yy;
}
}
Loading

0 comments on commit 5b6b0ce

Please sign in to comment.