2
* LaTeXDrawPSTricksParserActions.java
4
package latexDraw.parsers.pstricks;
6
import java.awt.geom.Arc2D;
7
import java.awt.geom.Point2D;
8
import java.util.Vector;
10
import latexDraw.figures.*;
11
import latexDraw.figures.properties.Arrowable;
12
import latexDraw.parsers.InvalidFormatCommandException;
13
import latexDraw.parsers.NotFullyManagedException;
14
import latexDraw.parsers.pstricks.PSTricksParameters.PositionParameters;
15
import latexDraw.psTricks.PSTricksConstants;
16
import latexDraw.util.LaTeXDrawPoint2D;
20
* This class defines actions to do on a given command for the LaTeXDraw project.<br>
22
* This file is part of LaTeXDraw<br>
23
* Copyright (c) 2005-2008 Arnaud BLOUIN<br>
25
* LaTeXDraw is free software; you can redistribute it and/or modify
26
* it under the terms of the GNU General Public License as published by
27
* the Free Software Foundation; either version 2 of the License, or
28
* any later version.<br>
30
* LaTeXDraw is distributed without any warranty; without even the
31
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
32
* PURPOSE. See the GNU General Public License for more details.<br>
36
* @author Arnaud BLOUIN<br>
39
public class LaTeXDrawPSTricksParserActions extends PSTricksParserActionsManager
41
/** The parsed figures. */
42
protected Vector<Figure> figures;
44
/** The figures contained in the pscustom command. Cleared at the end of each <code>pscustom</code> command.*/
45
public Vector<Figure> psCustFigures;
50
* The constructor by default.
52
public LaTeXDrawPSTricksParserActions()
55
psCustFigures = new Vector<Figure>();
56
figures = new Vector<Figure>();
63
public void actionsOnText(Vector<PSTricksParameters> params) throws InvalidFormatCommandException
65
if(params.isEmpty()) return;
67
if(params.lastElement().textParsed.length()!=0)
69
PSTricksParameters last = params.lastElement();
71
PositionParameters pp = null;
72
int i = params.size()-1;
74
while(pp==null && i>=0)
76
pp = params.elementAt(i).getPosition();
81
pp = new PositionParameters();
83
Text t = new Text(true);
84
Point2D.Double position = moveCoordinate(params, new Point2D.Double(0,0));
85
double angle = Math.toRadians(PSTricksParameters.getWholeRotationAngle(params));
87
if(position==null) throw new InvalidFormatCommandException("text", -1); //$NON-NLS-1$
89
if(last.textSize!=null && last.textSize.length()!=0)
90
t.setSizeByCommand(last.textSize);
92
if((last.textSeries!=null && last.textSeries.equals("b")) || last.textBold) //$NON-NLS-1$
94
else t.setIsBold(false);
96
if((last.textShape!=null && (last.textShape.equals("sl") || //$NON-NLS-1$
97
last.textShape.equals("it")) || last.textItalic)) //$NON-NLS-1$
99
else t.setIsItalic(false);
101
t.setRotationAngle(-angle);
102
t.setText(last.textParsed);
103
t.setLinesColor(last.textColor);
105
if(last.textFamily!=null && last.textFamily.length()!=0)
106
t.setTextFontByFamily(last.textFamily);
108
t.updateFontsBorders();
110
LaTeXDrawPoint2D pos = new LaTeXDrawPoint2D(position.x*Figure.PPC-t.getWidth()/2.,
111
(position.y*Figure.PPC-t.getFontMetrics().getHeight()/4.)*-1);
113
if(pp.refPoint!=PositionParameters.REF_POINT_DEFAULT_CENTER)
115
double addX=0, addY=0;
116
Point2D.Double gc = new Point2D.Double((pos.x+t.getWidth())/2.,(pos.y+t.getHeight())/2.);
118
if(pp.refPoint==PositionParameters.REF_POINT_BASE)
119
addY=-t.getFontMetrics().getDescent();
120
else if(pp.refPoint==PositionParameters.REF_POINT_TOP)
121
addY=t.getFontMetrics().getAscent()/2.;
122
else if(pp.refPoint==PositionParameters.REF_POINT_BOTTOM)
123
addY=-t.getFontMetrics().getDescent()*2;
124
else if(pp.refPoint==PositionParameters.REF_POINT_LEFT)
125
addX=t.getWidth()/2.;
126
else if(pp.refPoint==PositionParameters.REF_POINT_RIGHT)
127
addX=-t.getWidth()/2.;
128
else if(pp.refPoint==PositionParameters.REF_POINT_RIGHT+PositionParameters.REF_POINT_BASE)
130
addY=-t.getFontMetrics().getDescent();
131
addX=-t.getWidth()/2.;
132
}else if(pp.refPoint==PositionParameters.REF_POINT_RIGHT+PositionParameters.REF_POINT_BOTTOM)
134
addY=-t.getFontMetrics().getDescent()*2;
135
addX=-t.getWidth()/2.;
136
}else if(pp.refPoint==PositionParameters.REF_POINT_RIGHT+PositionParameters.REF_POINT_TOP)
138
addY=t.getFontMetrics().getAscent()/2.;
139
addX=-t.getWidth()/2.;
140
}else if(pp.refPoint==PositionParameters.REF_POINT_LEFT+PositionParameters.REF_POINT_BASE)
142
addY=-t.getFontMetrics().getDescent();
143
addX=t.getWidth()/2.;
144
}else if(pp.refPoint==PositionParameters.REF_POINT_LEFT+PositionParameters.REF_POINT_BOTTOM)
146
addY=-t.getFontMetrics().getDescent()*2;
147
addX=t.getWidth()/2.;
148
}else if(pp.refPoint==PositionParameters.REF_POINT_LEFT+PositionParameters.REF_POINT_TOP)
150
addY=t.getFontMetrics().getAscent()/2.;
151
addX=t.getWidth()/2.;
154
addX+=pp.labelSep*Figure.PPC;
156
Point2D.Double pt = rotatePoint(new Point2D.Double(gc.x+addX, gc.y-addY), gc, angle);
157
pos.setLocation(pos.x+(pt.x-gc.x), pos.y-(pt.y-gc.y));
161
t.updateFontsBorders();
163
if(last.psCustomP.fromPsCustom)
164
psCustFigures.add(t);
174
* @return the figures
176
public Vector<Figure> getFigures()
184
* Allows to set the parameters of a figure <code>f</code>.
186
public void setFigureParameters(PSTricksParameters p, Figure f, boolean hasStar)
190
if(f.canHaveShadow())
192
f.setHasShadow(p.isShadow);
193
f.setShadowAngle(Math.toRadians(p.shadowAngle));
194
f.setShadowSize(Math.abs(p.shadowSize)*Figure.PPC);
195
f.setShadowColor(p.shadowCol);
200
f.setHatchingSep(p.hatchSep*Figure.PPC);
201
f.setGradientAngle(Math.toRadians(p.gradAngle));
202
f.setGradientEndColor(p.gradEnd);
203
f.setGradientMidPoint(p.gradMidPoint);
204
f.setGradientStartColor(p.gradBegin);
207
f.setLinesColor(p.lineColor);
208
f.setBordersPosition(p.borderPos);
209
f.setDoubleColor(p.dbleColor);
210
f.setDoubleSep(Math.abs(p.dbleSep*Figure.PPC));
211
f.setHasDoubleBoundary(p.dbleLine);
212
f.setHatchingColor(p.hatchCol);
213
if(p.fillStyle.equals(PSTricksConstants.TOKEN_FILL_SOLID))
214
f.setHatchingStyle(PSTricksConstants.TOKEN_FILL_NONE);
215
else f.setHatchingStyle(
216
p.fillStyle.endsWith("*") ? p.fillStyle.substring(0, p.fillStyle.length()-1) : p.fillStyle);//$NON-NLS-1$
217
f.setHatchingWidth((float)Math.abs(p.hatchWidth*Figure.PPC));
218
f.setDotSep((float) p.dotStep*Figure.PPC);
219
f.setHatchingAngle(Math.toRadians(p.hatchAngle));
220
f.setBlackDashLength((float)p.dashBlack*Figure.PPC);
221
f.setWhiteDashLength((float)p.dashWhite*Figure.PPC);
222
f.setInteriorColor(p.fillColor);
223
f.setIsFilled(p.fillStyle.equals(PSTricksConstants.TOKEN_FILL_SOLID) ||
224
p.fillStyle.equals(PSTricksConstants.TOKEN_FILL_CROSSHATCH_F) ||
225
p.fillStyle.equals(PSTricksConstants.TOKEN_FILL_HLINES_F) ||
226
p.fillStyle.equals(PSTricksConstants.TOKEN_FILL_VLINES_F));
227
f.setLineStyle(p.lineStyle);
228
f.setThickness((float)(Math.abs(p.lineWidth*Figure.PPC)));
233
f.setInteriorColor(f.getLinesColor());
234
f.setHasDoubleBoundary(false);
235
f.setLineStyle(PSTricksConstants.LINE_NONE_STYLE);
236
f.setHatchingStyle(PSTricksConstants.TOKEN_FILL_NONE);
237
f.setBordersPosition(PSTricksConstants.BORDERS_INSIDE);
247
public int actionsOnFrameEllipse(int line, boolean hasStar, Vector<PSTricksParameters> ps, String params,
248
boolean isFrame) throws InvalidFormatCommandException
252
if(ps.isEmpty()) return ERR_END_CMD_INDEX;
255
PSTricksParameters p = ps.lastElement();
256
Point2D.Double p1 = new Point2D.Double(p.origin.x, p.origin.y);
257
Point2D.Double p2 = new Point2D.Double();
258
PSTricksParameters newP = new PSTricksParameters(p);
259
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
260
int end = parseParametersFrameEllipse(line, params, p1, p2, newP);
261
double xunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.xUnit : newP.unit;
262
double yunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.yUnit : newP.unit ;
264
p1.setLocation(p1.x+p.origin.x, p1.y+p.origin.y);
268
p2.setLocation(p2.x+p.origin.x, p2.y+p.origin.y);
271
p1 = moveCoordinate(ps, p1);
272
p2 = moveCoordinate(ps, p2);
273
p3 = new Point2D.Double((p1.x+p2.x)/2.,(p1.y+p2.y)/2.);
274
p1 = rotatePoint(p1, p3, angle);
275
p2 = rotatePoint(p2, p3, angle);
278
p1.setLocation(p1.x*Figure.PPC*xunit, p1.y*Figure.PPC*-1*yunit);
279
p2.setLocation(p2.x*Figure.PPC*xunit, p2.y*Figure.PPC*-1*yunit);
281
LaTeXDrawPoint2D pt1 = new LaTeXDrawPoint2D(p1.x, p2.y);
282
LaTeXDrawPoint2D pt2 = new LaTeXDrawPoint2D(p2.x, p2.y);
283
LaTeXDrawPoint2D pt3 = new LaTeXDrawPoint2D(p1.x, p1.y);
284
LaTeXDrawPoint2D pt4 = new LaTeXDrawPoint2D(p2.x, p1.y);
286
f = new LaTeXDrawRectangle(pt1, pt2, pt3, pt4, true);
287
((LaTeXDrawRectangle)f).setIsRound(newP.frameArc>0);
288
if(newP.frameArc>0) ((LaTeXDrawRectangle)f).setFrameArc(newP.frameArc);
292
p1 = moveCoordinate(ps, p1);
293
p1.setLocation(p1.x*Figure.PPC*xunit, p1.y*Figure.PPC*-1*yunit);
294
p2.setLocation(p2.x*Figure.PPC*xunit, p2.y*Figure.PPC*-1*yunit);
296
LaTeXDrawPoint2D pt1 = new LaTeXDrawPoint2D(p1.x-p2.x, p1.y+p2.y);
297
LaTeXDrawPoint2D pt2 = new LaTeXDrawPoint2D(p1.x+p2.x, p1.y+p2.y);
298
LaTeXDrawPoint2D pt3 = new LaTeXDrawPoint2D(p1.x-p2.x, p1.y-p2.y);
299
LaTeXDrawPoint2D pt4 = new LaTeXDrawPoint2D(p1.x+p2.x, p1.y-p2.y);
301
f = new Ellipse(pt1, pt2, pt3, pt4, true);
304
setFigureParameters(newP, f, hasStar);
305
f.setRotationAngle(angle);
307
if(p.psCustomP.fromPsCustom)
308
psCustFigures.add(f);
317
throw new InvalidFormatCommandException("psframe", line); //$NON-NLS-1$
318
throw new InvalidFormatCommandException("psellipse", line); //$NON-NLS-1$
326
public int actionsOnCircle(int line, boolean hasStar, Vector<PSTricksParameters> ps, String params)
327
throws InvalidFormatCommandException
331
PSTricksParameters p = ps.lastElement();
332
Point2D.Double center = new Point2D.Double(p.origin.x, p.origin.y);
333
double[] radius = {1};
334
PSTricksParameters newP = new PSTricksParameters(p);
336
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
337
int end = parseParametersCircle(line, params, center, radius, newP);
338
LaTeXDrawPoint2D pt1, pt2, pt3, pt4;
339
center = moveCoordinate(ps, center);
341
pt1 = new LaTeXDrawPoint2D((p.origin.x+center.x-radius[0])*Figure.PPC*newP.unit,
342
(p.origin.y+center.y+radius[0])*Figure.PPC*-1*newP.unit);
343
pt2 = new LaTeXDrawPoint2D((p.origin.x+center.x+radius[0])*Figure.PPC*newP.unit,
344
(p.origin.y+center.y+radius[0])*Figure.PPC*-1*newP.unit);
345
pt3 = new LaTeXDrawPoint2D((p.origin.x+center.x-radius[0])*Figure.PPC*newP.unit,
346
(p.origin.y+center.y-radius[0])*Figure.PPC*-1*newP.unit);
347
pt4 = new LaTeXDrawPoint2D((p.origin.x+center.x+radius[0])*Figure.PPC*newP.unit,
348
(p.origin.y+center.y-radius[0])*Figure.PPC*-1*newP.unit);
350
c = new Circle(pt1, pt2, pt3, pt4, true);
351
setFigureParameters(newP, c, hasStar);
352
c.setRotationAngle(angle);
354
if(p.psCustomP.fromPsCustom)
355
psCustFigures.add(c);
361
}catch(Exception e) { throw new InvalidFormatCommandException("pscircle", line); } //$NON-NLS-1$
370
public int actionsOnDot(int line, Vector<PSTricksParameters> ps, String params,
371
boolean noCoordinatePossible) throws InvalidFormatCommandException
375
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
376
// It can have several points defined
377
Vector<Point2D.Double> center = new Vector<Point2D.Double>();
378
PSTricksParameters last = ps.lastElement();
379
PSTricksParameters newP = new PSTricksParameters(last);
380
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
381
int end = parseParametersDot(line, params, center, newP, noCoordinatePossible);
382
double xunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.xUnit : newP.unit;
383
double yunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.yUnit : newP.unit ;
384
newP.arrowDotSD = newP.arrowDotSD+newP.arrowDotSN<0 ? Math.abs(newP.arrowDotSD) : newP.arrowDotSD;
385
newP.arrowDotSN = newP.arrowDotSD+newP.arrowDotSN<0 ? Math.abs(newP.arrowDotSN) : newP.arrowDotSN;
386
newP.dotScale1 = Math.abs(newP.dotScale1);
388
for(Point2D.Double pt: center)
390
pt = moveCoordinate(ps, pt);
391
Dot d = new Dot(new LaTeXDrawPoint2D(pt.x*Figure.PPC*xunit, pt.y*Figure.PPC*-1*yunit),
393
setFigureParameters(newP, d, false);
395
d.setCurrentStyle(newP.dotStyle);
396
d.setWidth((float)((newP.arrowDotSD+newP.arrowDotSN*newP.lineWidth)*newP.dotScale1)*Figure.PPC);
397
d.setRotationAngle(Math.toRadians(-newP.dotAngle)+angle);
398
d.setInteriorColor(newP.fillColor);
400
if(!last.psCustomP.fromPsCustom)
406
}catch(Exception e) { throw new InvalidFormatCommandException("psdot", line); }//$NON-NLS-1$
415
public int actionsOnLine(int line, boolean hasStar, Vector<PSTricksParameters> ps,
416
String params) throws InvalidFormatCommandException
420
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
422
Vector<Point2D.Double> pts = new Vector<Point2D.Double>();
423
PSTricksParameters last = ps.lastElement();
424
PSTricksParameters newP = new PSTricksParameters(last);
426
int end = parseParametersLine(line, params, pts, newP);
427
double xunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.xUnit : newP.unit;
428
double yunit = newP.unit==PSTricksConstants.DEFAULT_UNIT? newP.yUnit : newP.unit ;
430
if(pts.isEmpty()) return end;
433
for(Point2D.Double pt : pts)
434
pt.setLocation(moveCoordinate(ps, pt));
436
if(pts.size()>2)//joined lines
437
f = new JoinedLines(new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), true);
439
f = new Line(new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), true);
442
Point2D.Double ptOld= null;
444
for(Point2D.Double pt : pts)
445
if(!pt.equals(ptOld))
447
((LaTeXDrawPolygon)f).addPoint(new LaTeXDrawPoint2D(pt.x*Figure.PPC*xunit,
448
pt.y*Figure.PPC*-1*yunit));
452
if(pts.size()>2)//joined lines
454
((JoinedLines)f).removePointAt(0);
455
((JoinedLines)f).removePointAt(0);
456
((JoinedLines)f).setArrow2Style(ArrowHead.invertArrowStyle(newP.arrowStyle[1]));
458
if(((JoinedLines)f).getNbPoints()<2)
463
((Line)f).removePointAt(0);
464
((Line)f).removePointAt(0);
465
((Line)f).setArrow2Style(newP.arrowStyle[1]);
468
((Arrowable)f).setArrow1Style(newP.arrowStyle[0]);
469
setArrowParameters(((Arrowable)f).getArrowHead1(), newP);
470
setArrowParameters(((Arrowable)f).getArrowHead2(), newP);
471
setFigureParameters(newP, f, hasStar);
473
if(last.psCustomP.fromPsCustom)
474
psCustFigures.add(f);
480
}catch(Exception e) { e.printStackTrace(); throw new InvalidFormatCommandException("psline", line); }//$NON-NLS-1$
487
* Sets the parameters of an arrowhead.
488
* @param ah The arrowhead.
489
* @param param The parameters.
492
protected void setArrowParameters(ArrowHead ah, PSTricksParameters param)
494
ah.setArrowInset(param.arrowInset);
495
ah.setArrowLength(param.arrowLgth);
496
ah.setArrowSizeDim(param.arrowSizeD*Figure.PPC);
497
ah.setArrowSizeNum(param.arrowSizeN);
498
ah.setBracketNum(param.arrowBrLgth);
499
ah.setDotSizeDim((param.arrowDotSD+param.arrowDotSN<0 ? Math.abs(param.arrowDotSD) : param.arrowDotSD)*Figure.PPC);
500
ah.setDotSizeNum(param.arrowDotSD+param.arrowDotSN<0 ? Math.abs(param.arrowDotSN) : param.arrowDotSN);
501
ah.setRBracketNum(param.arrowrBrLgth);
502
ah.setTBarSizeDim(param.arrowTBarSD+param.arrowTBarSD<0 ? Math.abs(param.arrowTBarSD) : param.arrowTBarSD*Figure.PPC);
503
ah.setTBarSizeNum(param.arrowTBarSD+param.arrowTBarSD<0 ? Math.abs(param.arrowTBarSN) : param.arrowTBarSN);
510
public int actionsOnPolygon(int line, boolean hasStar, Vector<PSTricksParameters> ps,
511
String params) throws InvalidFormatCommandException
515
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
517
Vector<Point2D.Double> pts = new Vector<Point2D.Double>();
518
PSTricksParameters last = ps.lastElement();
519
PSTricksParameters newP = new PSTricksParameters(last);
520
int end = parseParametersPolygon(line, params, pts, newP);
521
double xunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.xUnit;
522
double yunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.yUnit;
524
if(pts.size()<2) return end;
526
LaTeXDrawPolygon pol = new LaTeXDrawPolygon(new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), true);
527
Point2D.Double ptOld= null;
530
pts.add(new Point2D.Double(newP.origin.x, newP.origin.y));
532
for(Point2D.Double pt : pts)
534
pt.setLocation(moveCoordinate(ps, pt));
535
if(!pt.equals(ptOld))
537
pol.addPoint(new LaTeXDrawPoint2D(pt.x*Figure.PPC*xunit, pt.y*Figure.PPC*-1*yunit));
542
pol.removePointAt(0);
543
pol.removePointAt(0);
545
if(pol.getNbPoints()<3)
548
setFigureParameters(newP, pol, hasStar);
551
pol.updateGravityCenter();
553
if(last.psCustomP.fromPsCustom)
554
psCustFigures.add(pol);
560
}catch(Exception e) { throw new InvalidFormatCommandException("pspolygon", line); }//$NON-NLS-1$
570
public int actionsOnDiamondTriangle(int line, boolean hasStar, Vector<PSTricksParameters> ps,
571
String params, boolean isDiamondNotTriangle) throws InvalidFormatCommandException
575
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
577
PSTricksParameters p = ps.lastElement();
578
Point2D.Double p1 = new Point2D.Double(p.origin.x, p.origin.y);
579
Point2D.Double p2 = new Point2D.Double();
580
PSTricksParameters newP = new PSTricksParameters(p);
582
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
583
int end = parseParametersFrameEllipse(line, params, p1, p2, newP);
584
double xunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.xUnit;
585
double yunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.yUnit;
586
p1.setLocation(p1.x+p.origin.x, p1.y+p.origin.y);
588
if(ps.size()>1) moduloA = ps.elementAt(ps.size()-2).degrees;
591
if(isDiamondNotTriangle)
594
p1 = moveCoordinate(ps, p1);
596
LaTeXDrawPoint2D pt1 = new LaTeXDrawPoint2D((p1.x-p2.x)*Figure.PPC*xunit,
597
(p1.y-p2.y)*Figure.PPC*-1*yunit);
598
LaTeXDrawPoint2D pt2 = new LaTeXDrawPoint2D((p1.x+p2.x)*Figure.PPC*xunit,
599
(p1.y-p2.y)*Figure.PPC*-1*yunit);
600
LaTeXDrawPoint2D pt3 = new LaTeXDrawPoint2D((p1.x-p2.x)*Figure.PPC*xunit,
601
(p1.y+p2.y)*Figure.PPC*-1*yunit);
602
LaTeXDrawPoint2D pt4 = new LaTeXDrawPoint2D((p1.x+p2.x)*Figure.PPC*xunit,
603
(p1.y+p2.y)*Figure.PPC*-1*yunit);
605
f = new Rhombus(pt1, pt2, pt3, pt4, true);
609
Point2D.Double p3 = new Point2D.Double();
612
p1 = moveCoordinate(ps, p1);
613
p3 = new Point2D.Double(p1.x,p1.y-p2.y/2.);
614
p1 = rotatePoint(p1, p3, -angle);
617
LaTeXDrawPoint2D pt1 = new LaTeXDrawPoint2D((p1.x-p2.x/2.)*Figure.PPC*xunit,
618
(p1.y+p2.y)*Figure.PPC*-1*yunit);
619
LaTeXDrawPoint2D pt2 = new LaTeXDrawPoint2D((p1.x+p2.x/2.)*Figure.PPC*xunit,
620
(p1.y+p2.y)*Figure.PPC*-1*yunit);
621
LaTeXDrawPoint2D pt3 = new LaTeXDrawPoint2D((p1.x-p2.x/2.)*Figure.PPC*xunit,
622
(p1.y)*Figure.PPC*-1*yunit);
623
LaTeXDrawPoint2D pt4 = new LaTeXDrawPoint2D((p1.x+p2.x/2.)*Figure.PPC*xunit,
624
(p1.y)*Figure.PPC*-1*yunit);
626
f = new Triangle(pt1, pt2, pt3, pt4, true);
628
if((newP.gangle%moduloA)!=0)
630
LaTeXDrawPoint2D gc = f.getGravityCenter();
631
LaTeXDrawPoint2D base = new LaTeXDrawPoint2D((pt1.x+pt2.x)/2., pt3.y);
632
LaTeXDrawPoint2D newGc = Figure.rotatePoint(gc, base, Math.toRadians(-(360/moduloA)*newP.gangle));
637
setFigureParameters(newP, f, hasStar);
639
if(isDiamondNotTriangle)
641
Rhombus r = ((Rhombus)f);
642
r.setShadowAngle(r.getShadowAngle()-Math.toRadians(newP.gangle%moduloA));
643
r.setHatchingAngle(r.getHatchingAngle()-Math.toRadians(newP.gangle%moduloA));
644
r.setGradientAngle(r.getGradientAngle()-Math.toRadians(newP.gangle%moduloA));
646
if((newP.gangle%moduloA)!=0)
647
r.setRotationAngle(Math.toRadians(-(360/moduloA)*newP.gangle)+angle);
648
else r.setRotationAngle(angle);
652
Triangle t = ((Triangle)f);
653
boolean reverse = t.getPoint(0).y>t.getPoint(2).y;
655
t.setRotationAngle(angle); // fixes #1556340
658
t.setShadowAngle(t.getShadowAngle()+Math.PI);
659
t.setGradientAngle(t.getGradientAngle()+Math.PI);
663
if(p.psCustomP.fromPsCustom)
664
psCustFigures.add(f);
672
if(isDiamondNotTriangle)
673
throw new InvalidFormatCommandException("psdiamond", line); //$NON-NLS-1$
674
throw new InvalidFormatCommandException("triangle", line); //$NON-NLS-1$
683
public int actionsOnBezierCurve(int line, boolean hasStar, Vector<PSTricksParameters> ps,
684
String params) throws InvalidFormatCommandException
688
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
690
Vector<Point2D.Double> pts = new Vector<Point2D.Double>();
691
PSTricksParameters last = ps.lastElement();
692
PSTricksParameters newP = new PSTricksParameters(last);
694
int ended = parseParametersBezierCurve(line, params, pts, newP), i, size, j;
695
double xunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.xUnit;
696
double yunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.yUnit;
698
if(pts.size()<3) return ended;
700
for(Point2D.Double pt : pts)
701
pt.setLocation(moveCoordinate(ps, pt));
704
p1 = new LaTeXDrawPoint2D(newP.origin.x*Figure.PPC*xunit, newP.origin.y*-1*Figure.PPC*yunit);
707
p1 = new LaTeXDrawPoint2D(pts.firstElement().x*Figure.PPC*xunit, pts.firstElement().y*-1*Figure.PPC*yunit);
708
pts.removeElementAt(0);
712
BezierCurve f = new BezierCurve(p1,
713
new LaTeXDrawPoint2D(pts.elementAt(2).x*Figure.PPC*xunit,
714
pts.elementAt(2).y*-1*Figure.PPC*yunit), true);
716
f.setXCoordFirstCtrl(pts.firstElement().x*Figure.PPC*xunit, 0);
717
f.setYCoordFirstCtrl(pts.firstElement().y*-1*Figure.PPC*yunit, 0);
718
f.setXCoordFirstCtrl(pts.elementAt(1).x*Figure.PPC*xunit, 1);
719
f.setYCoordFirstCtrl(pts.elementAt(1).y*-1*Figure.PPC*yunit, 1);
727
pt2 = pts.elementAt(i);
730
f.addPoint(new LaTeXDrawPoint2D(pts.elementAt(i).x*Figure.PPC*xunit,
731
pts.elementAt(i).y*-1*Figure.PPC*yunit));
733
f.setXCoordFirstCtrl(pt2.x*Figure.PPC*xunit, j);
734
f.setYCoordFirstCtrl(pt2.y*-1*Figure.PPC*yunit, j);
739
setFigureParameters(newP, f, hasStar);
741
f.updateSecondControlPoints();
744
f.setShowPoints(newP.showPoints);
746
f.replaceLastPointByClosing();
748
((Arrowable)f).setArrow1Style(newP.arrowStyle[0]);
749
((Arrowable)f).setArrow2Style(ArrowHead.invertArrowStyle(newP.arrowStyle[1]));
750
setArrowParameters(((Arrowable)f).getArrowHead1(), newP);
751
setArrowParameters(((Arrowable)f).getArrowHead2(), newP);
753
if(f.getNbPoints()>1)
754
if(last.psCustomP.fromPsCustom)
755
psCustFigures.add(f);
761
}catch(Exception e) { throw new InvalidFormatCommandException("psbezier", line); } //$NON-NLS-1$
769
public int actionsOnArcWedge(int line, boolean hasStar, Vector<PSTricksParameters> ps, String params,
770
boolean isArc) throws InvalidFormatCommandException
774
PSTricksParameters p = ps.lastElement();
775
Point2D.Double center = (Point2D.Double)p.origin.clone();
776
PSTricksParameters newP = new PSTricksParameters(p);
777
double[] angle1 = {0}, angle2 = {0}, radius = {0};
778
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
780
int end = parseParametersArcWedge(line, params, radius, center, angle1, angle2, newP, isArc);
782
center = moveCoordinate(ps, center);
784
Arc f = new Arc(new LaTeXDrawPoint2D((center.x-radius[0])*Figure.PPC*newP.xUnit,
785
(center.y+radius[0])*Figure.PPC*-1*newP.xUnit),
786
new LaTeXDrawPoint2D((center.x+radius[0])*Figure.PPC*newP.xUnit,
787
(center.y-radius[0])*Figure.PPC*-1*newP.xUnit), isArc ? Arc2D.OPEN : Arc2D.PIE, true);
789
f.setStartAngle(Math.toRadians(angle1[0]));
790
f.setEndAngle(Math.toRadians(angle2[0]));
791
f.setShowPoints(newP.showPoints);
792
f.setArrow1Style(newP.arrowStyle[0]);
794
String currentArrowRStyle = newP.arrowStyle[1];
795
if(currentArrowRStyle.equals(PSTricksConstants.DLARROW_STYLE))
796
currentArrowRStyle = PSTricksConstants.DRARROW_STYLE;
797
else if(currentArrowRStyle.equals(PSTricksConstants.DRARROW_STYLE))
798
currentArrowRStyle = PSTricksConstants.DLARROW_STYLE;
799
else if(currentArrowRStyle.equals(PSTricksConstants.RARROW_STYLE))
800
currentArrowRStyle = PSTricksConstants.LARROW_STYLE;
801
else if(currentArrowRStyle.equals(PSTricksConstants.LARROW_STYLE))
802
currentArrowRStyle = PSTricksConstants.RARROW_STYLE;
803
else if(currentArrowRStyle.equals(PSTricksConstants.DLARROW_STYLE))
804
currentArrowRStyle = PSTricksConstants.DRARROW_STYLE;
805
else if(currentArrowRStyle.equals(PSTricksConstants.LRBRACKET_STYLE))
806
currentArrowRStyle = PSTricksConstants.RRBRACKET_STYLE;
807
else if(currentArrowRStyle.equals(PSTricksConstants.RRBRACKET_STYLE))
808
currentArrowRStyle = PSTricksConstants.LRBRACKET_STYLE;
809
else if(currentArrowRStyle.equals(PSTricksConstants.RSBRACKET_STYLE))
810
currentArrowRStyle = PSTricksConstants.LSBRACKET_STYLE;
811
else if(currentArrowRStyle.equals(PSTricksConstants.LSBRACKET_STYLE))
812
currentArrowRStyle = PSTricksConstants.RSBRACKET_STYLE;
814
f.setArrow2Style(currentArrowRStyle);
816
setArrowParameters(f.getArrowHead1(), newP);
817
setArrowParameters(f.getArrowHead2(), newP);
818
setFigureParameters(newP, f, hasStar);
819
f.setRotationAngle(angle);
821
if(p.psCustomP.fromPsCustom)
822
psCustFigures.add(f);
831
throw new InvalidFormatCommandException("psarc", line); //$NON-NLS-1$
832
throw new InvalidFormatCommandException("pswedge", line); //$NON-NLS-1$
840
public int actionsOnGridAxes(int line, Vector<PSTricksParameters> ps, Point2D.Double pictureSWPt,
841
Point2D.Double pictureNEPt, String params, boolean isGrid) throws InvalidFormatCommandException
845
if(ps==null || ps.isEmpty()) return ERR_END_CMD_INDEX;
847
Vector<Point2D.Double> pts = new Vector<Point2D.Double>();
848
PSTricksParameters last = ps.lastElement();
849
PSTricksParameters newP = new PSTricksParameters(last);
850
int gridEndX, gridEndY, gridStartX, gridStartY, originX, originY;
851
double angle = Math.toRadians(-PSTricksParameters.getWholeRotationAngle(ps));
852
int end = parseParametersGridAxes(line, params, pts, newP);
853
double xunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.xUnit;
854
double yunit = newP.unit!=PSTricksConstants.DEFAULT_UNIT? newP.unit : newP.yUnit;
855
newP.origin.setLocation(moveCoordinate(ps, newP.origin));
856
boolean isGridXLabelReverse = false;
857
boolean isGridYLabelReverse = false;
862
gridEndX = (pictureNEPt.x-((int)pictureNEPt.x))>0.5 ? (int)pictureNEPt.x+1 : (int)pictureNEPt.x;
863
else gridEndX = (((int)pictureNEPt.x)-pictureNEPt.x)>0.5 ? (int)pictureNEPt.x-1 : (int)pictureNEPt.x;
865
gridEndY = (pictureNEPt.y-((int)pictureNEPt.y))>0.5 ? (int)pictureNEPt.y+1 : (int)pictureNEPt.y;
866
else gridEndY = (((int)pictureNEPt.y)-pictureNEPt.y)>0.5 ? (int)pictureNEPt.y-1 : (int)pictureNEPt.y;
869
gridStartX = originX = (pictureSWPt.x-((int)pictureSWPt.x))>0.5 ? (int)pictureSWPt.x+1 : (int)pictureSWPt.x;
870
else gridStartX = originX = (((int)pictureSWPt.x)-pictureSWPt.x)>0.5 ? (int)pictureSWPt.x-1 : (int)pictureSWPt.x;
873
gridStartY = originY = (pictureSWPt.y-((int)pictureSWPt.y))>0.5 ? (int)pictureSWPt.y+1 : (int)pictureSWPt.y;
874
else gridStartY = originY = (((int)pictureSWPt.y)-pictureSWPt.y)>0.5 ? (int)pictureSWPt.y-1 : (int)pictureSWPt.y;
879
gridStartX = gridStartY = originX = originY = 0;
880
gridEndX = (int)pts.firstElement().x;
881
gridEndY = (int)pts.firstElement().y;
886
originX = gridStartX = (int)pts.firstElement().x;
887
originY = gridStartY = (int)pts.firstElement().y;
888
gridEndX = (int)pts.elementAt(1).x;
889
gridEndY = (int)pts.elementAt(1).y;
893
originX = (int)pts.firstElement().x;
894
originY = (int)pts.firstElement().y;
895
gridStartX = (int)pts.elementAt(1).x;
896
gridStartY = (int)pts.elementAt(1).y;
897
gridEndX = (int)pts.elementAt(2).x;
898
gridEndY = (int)pts.elementAt(2).y;
901
if(gridStartX>=gridEndX)
904
gridEndX = gridStartX;
906
isGridXLabelReverse = true;
909
if(gridStartY>=gridEndY)
912
gridEndY = gridStartY;
914
isGridYLabelReverse = true;
917
LaTeXDrawPoint2D position = new LaTeXDrawPoint2D(newP.origin.x*Figure.PPC,newP.origin.y*Figure.PPC*-1);
922
Point2D.Double tmp1 = new Point2D.Double(
923
position.x+((gridEndX+gridStartX)/2.)*Figure.PPC*xunit,
924
position.y-((gridEndY+gridStartY)/2.)*Figure.PPC*yunit);
925
Point2D.Double tmp = rotatePoint(tmp1, position, angle);
926
position.setLocation(position.x+(tmp.x-tmp1.x), position.y+(tmp.y-tmp1.y));
931
f = new Grid(position, true);
934
g.setGridDots(newP.gridDots);
935
g.setGridLabelsColor(newP.labelsGridCol);
936
g.setGridLabelsSize((int)((newP.gridLabel*PSTricksConstants.CM_VAL_PT)/0.6));
937
g.setGridWidth((float)Math.abs(newP.gridWidth*Figure.PPC));
938
g.setSubGridColor(newP.subGridCol);
939
g.setSubGridDiv(newP.subGridDiv);
940
g.setSubGridDots(newP.subGridDots);
941
g.setSubGridWidth((float)Math.abs(newP.subGridWidth*Figure.PPC));
942
g.setOriginX(originX);
943
g.setOriginY(originY);
944
g.setLinesColor(newP.gridColor);
948
f = new Axe(position, true);
950
a.setOriginX((int)newP.ox);
951
a.setOriginY((int)newP.oy);
952
a.setLabelsDisplayedToken(newP.labels);
953
a.setTicksDisplayedToken(newP.ticks);
954
a.setTicksStyleToken(newP.ticksStyle);
955
a.setTicksSize(newP.ticksSize*Figure.PPC);
956
a.setIncrementX(newP.dxIncrement);
957
a.setIncrementY(newP.dyIncrement);
958
a.setDistLabelsX(newP.dxLabelDist);
959
a.setDistLabelsY(newP.dyLabelDist);
960
a.setShowOrigin(newP.showOrigin);
961
a.setAxesStyleToken(newP.axesStyle);
962
setFigureParameters(newP, a, false);
964
String arrowHead2Style = newP.arrowStyle[1];
966
if(arrowHead2Style.equals(PSTricksConstants.DLARROW_STYLE))
967
arrowHead2Style = PSTricksConstants.DRARROW_STYLE;
968
else if(arrowHead2Style.equals(PSTricksConstants.DRARROW_STYLE))
969
arrowHead2Style = PSTricksConstants.DLARROW_STYLE;
970
else if(arrowHead2Style.equals(PSTricksConstants.RARROW_STYLE))
971
arrowHead2Style = PSTricksConstants.LARROW_STYLE;
972
else if(arrowHead2Style.equals(PSTricksConstants.LARROW_STYLE))
973
arrowHead2Style = PSTricksConstants.RARROW_STYLE;
974
else if(arrowHead2Style.equals(PSTricksConstants.DLARROW_STYLE))
975
arrowHead2Style = PSTricksConstants.DRARROW_STYLE;
976
else if(arrowHead2Style.equals(PSTricksConstants.LRBRACKET_STYLE))
977
arrowHead2Style = PSTricksConstants.RRBRACKET_STYLE;
978
else if(arrowHead2Style.equals(PSTricksConstants.RRBRACKET_STYLE))
979
arrowHead2Style = PSTricksConstants.LRBRACKET_STYLE;
980
else if(arrowHead2Style.equals(PSTricksConstants.RSBRACKET_STYLE))
981
arrowHead2Style = PSTricksConstants.LSBRACKET_STYLE;
982
else if(arrowHead2Style.equals(PSTricksConstants.LSBRACKET_STYLE))
983
arrowHead2Style = PSTricksConstants.RSBRACKET_STYLE;
985
((Arrowable)a).setArrow1Style(newP.arrowStyle[0]);
986
((Arrowable)a).setArrow2Style(arrowHead2Style);
987
setArrowParameters(((Arrowable)a).getArrowHead1(), newP);
988
setArrowParameters(((Arrowable)a).getArrowHead2(), newP);
991
f.setGridEndX(gridEndX);
992
f.setGridEndY(gridEndY);
993
f.setGridStartX(gridStartX);
994
f.setGridStartY(gridStartY);
996
f.updateBorders(null);
998
f.setRotationAngle(angle);
999
f.setXLabelSouth(!isGridYLabelReverse);
1000
f.setYLabelWest(!isGridXLabelReverse);
1002
if(!last.psCustomP.fromPsCustom)
1007
}catch(Exception e) { throw new InvalidFormatCommandException("psgrid or psaxes", line); } //$NON-NLS-1$
1014
public int actionsOnPicture(int line, Vector<PSTricksParameters> ps,
1015
String params) throws InvalidFormatCommandException
1019
String[] path = {""};//$NON-NLS-1$
1020
int end = parseParametersPicture(line, params, path);
1021
// LaTeXDrawPoint2D position = new LaTeXDrawPoint2D();
1022
// BatchConvertFrame bcf = new BatchConvertFrame();
1023
// Image image = bcf.getImage(new File(path[0]));
1024
// BufferedImage bufferedI = new BufferedImage(image.getWidth(null),
1025
// image.getHeight(null), BufferedImage.TYPE_INT_RGB );
1026
// Graphics g = bufferedI.createGraphics();
1027
// g.drawImage(image,0,0,null);
1030
// Picture p = new Picture(true, position, bufferedI, path[0]);
1038
e.printStackTrace();
1039
throw new InvalidFormatCommandException("includegraphics", line); //$NON-NLS-1$
1047
public int actionsOnFramedBox(int nLine, boolean hasStar, Vector<PSTricksParameters> ps,
1048
String cmd, String params, int type) throws InvalidFormatCommandException
1050
int i = ps.size()-1;
1051
PSTricksParameters pp = null;
1053
while(pp==null && i>=0)
1054
if(ps.elementAt(i).getPosition()!=null)
1055
pp = ps.elementAt(i);
1059
pp = ps.firstElement();
1061
FramedBox fb = new FramedBox(pp.psBoxText);
1062
fb.setStart(pp.textForFrame.length());
1064
PSTricksParameters newP = new PSTricksParameters(ps.lastElement());
1069
goToNextChar(params, j);
1070
if(params.charAt(j[0])=='*')
1073
goToNextChar(params, j);
1076
catch(Exception e1) { throw new InvalidFormatCommandException(nLine); }
1078
if(params.charAt(j[0])=='[')
1083
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1084
end = parseParametersFrameEllipse(nLine, params, null, null, newP);
1087
((LaTeXDrawRectangle)fb.getBox()).setFrameArc(newP.frameArc);
1088
((LaTeXDrawRectangle)fb.getBox()).setIsRound(true);
1092
fb.setBoxType(FramedBox.BOX_CIRCLE);
1093
end = parseParametersCircle(nLine, params, null, null, newP);
1096
fb.setBoxType(FramedBox.BOX_TRIANGLE);
1097
end = parseParametersPolygon(nLine, params, null, newP);
1100
fb.setBoxType(FramedBox.BOX_DIAMOND);
1101
end = parseParametersPolygon(nLine, params, null, newP);
1104
fb.setBoxType(FramedBox.BOX_ELLIPSE);
1105
end = parseParametersFrameEllipse(nLine, params, null, null, newP);
1108
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1109
end = parseParametersFrameEllipse(nLine, params, null, null, newP);
1112
((LaTeXDrawRectangle)fb.getBox()).setFrameArc(newP.frameArc);
1113
((LaTeXDrawRectangle)fb.getBox()).setIsRound(true);
1117
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1118
end = parseParametersFrameEllipse(nLine, params, null, null, newP);
1121
((LaTeXDrawRectangle)fb.getBox()).setFrameArc(newP.frameArc);
1122
((LaTeXDrawRectangle)fb.getBox()).setIsRound(true);
1131
goToNextChar(params, j);
1132
} catch(Exception e1) { throw new InvalidFormatCommandException(nLine); }
1137
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1140
fb.setBoxType(FramedBox.BOX_CIRCLE);
1143
fb.setBoxType(FramedBox.BOX_TRIANGLE);
1146
fb.setBoxType(FramedBox.BOX_DIAMOND);
1149
fb.setBoxType(FramedBox.BOX_ELLIPSE);
1152
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1155
fb.setBoxType(FramedBox.BOX_RECTANGLE);
1160
if(params.charAt(j[0])!='{')//psframebox3, psframebox[framesep=0.3]3 for instance.
1162
PSTricksParameters p;
1163
boolean again = true;
1164
int k = ps.size()-1;
1166
while(again && k>=0)
1168
p = ps.elementAt(k);
1169
if(p.getPosition()!=null)
1172
p.textForFrame+=params.charAt(j[0]);
1176
p.textForFrame+=params.charAt(j[0]);
1184
while(p==null && k>=0)
1185
if(ps.elementAt(k).getPosition()!=null)
1186
p = ps.elementAt(k);
1190
p = ps.firstElement();
1192
p.psBox.lastElement().setEnd(p.textForFrame.length());
1193
p.psBox.add(0, p.psBox.remove(p.psBox.size()-1));
1198
fb.setFrameSep(newP.frameSep*Figure.PPC);
1199
fb.setBoxSep(newP.boxSep);
1201
setFigureParameters(newP, fb.getBox(), hasStar);
1205
fb.getBox().setIsFilled(true);
1206
fb.getBox().setInteriorColor(newP.fillColor);
1207
fb.getBox().setLinesColor(newP.fillColor);
1213
fb.getBox().setHasDoubleBoundary(true);
1216
fb.getBox().setHasShadow(true);
1231
public void actionsOnTerminatedFramedBoxes(Vector<PSTricksParameters> params) throws InvalidFormatCommandException
1233
PSTricksParameters pp = params.lastElement();
1235
String str = pp.psBoxText.getText();
1238
str = " ";//$NON-NLS-1$
1240
pp.textParsed = pp.textForFrame;
1241
actionsOnText(params);
1243
if(pp.psBox.isEmpty())
1246
Text txt = (Text)figures.remove(figures.size()-1);
1247
boolean simpleBox = pp.psBox.size()==1 && pp.psBox.firstElement().getBoxedText().equals(txt.getText());
1251
FramedBox fb = pp.psBox.firstElement();
1255
fb.getBox().setBordersPosition(PSTricksConstants.BORDERS_OUTSIDE);
1256
txt.setSimpleBox(fb);
1259
for(FramedBox fb : pp.psBox)
1263
fb.getBox().setBordersPosition(PSTricksConstants.BORDERS_OUTSIDE);
1266
txt.setHasFramedBox(!pp.psBox.isEmpty());
1267
txt.setHasSimpleFramedBox(simpleBox);
1268
txt.updateFramedBoxes();
1269
txt.updateFontsBorders();
1271
if(!pp.psCustomP.fromPsCustom)
1276
if(txt.getSimpleBox().getBoxType()==FramedBox.BOX_TRIANGLE)
1278
double height = (txt.getSimpleBox().getBox().getTheSEBoundPoint().y-
1279
txt.getSimpleBox().getBox().getTheNWBoundPoint().y)/4.;
1280
LaTeXDrawPoint2D pos = txt.getPosition();
1281
txt.setPosition(new LaTeXDrawPoint2D(pos.x, pos.y+height));
1282
txt.getSimpleBox().getBox().updateShape();
1287
FramedBox fb, max=null;
1288
double xMin=Double.MAX_VALUE;
1289
int i=0, size = txt.getMultipleBox().size();
1293
fb = txt.getMultipleBox().elementAt(i);
1295
if(fb.isBoxSep() && fb.getBoxType()==FramedBox.BOX_TRIANGLE &&
1296
fb.getBox().getTheNWBoundPoint().x<xMin)
1298
xMin = fb.getBox().getTheNWBoundPoint().x;
1306
double height = (max.getBox().getTheSEBoundPoint().y-max.getBox().getTheNWBoundPoint().y)/4.;
1308
LaTeXDrawPoint2D pos = txt.getPosition();
1309
txt.setPosition(new LaTeXDrawPoint2D(pos.x, pos.y+height));
1310
max.getBox().updateShape();
1315
txt.updateFramedBoxes();
1316
txt.updateFontsBorders();
1324
* Optimises the figures; for instance, frame are transformed in square.
1325
* @param vFigures The figures to optimise.
1328
public static void optimizeCode(Vector<Figure> vFigures)
1330
Vector<Arc> vArcs = new Vector<Arc>();
1331
Vector<Line> vLines = new Vector<Line>();
1332
Vector<BezierCurve> vCurves = new Vector<BezierCurve>();
1333
int sizevl, i, size, j;
1335
for(Figure f : vFigures)
1336
if(f instanceof Line)
1337
vLines.add((Line)f);
1339
if(f instanceof Arc)
1342
if(f instanceof BezierCurve)
1343
vCurves.add((BezierCurve)f);
1345
sizevl = vLines.size();
1347
for(Arc a : vArcs)// We check if we can convert arc+line in chord.
1348
if(a.getType()==Arc2D.OPEN)
1350
boolean again = true;
1352
LaTeXDrawPoint2D startP, endP, p1, p2;
1355
while(again && i<sizevl)
1357
l = vLines.elementAt(i);
1358
startP = a.getStartPoint(true);
1359
endP = a.getEndPoint(true);
1365
if((startP.equals(p1, 1) && endP.equals(p2, 1)) ||
1366
(startP.equals(p2, 1) && endP.equals(p1, 1)))
1372
if(!again && a.isParametersEquals(l, false, true))
1375
a.setType(Arc2D.CHORD);
1379
if(vCurves.size()>1)// We try to concat the BĆ©zier curves.
1381
if(vCurves.size()<200)// We must set a limit otherwise it may have a freeze.
1385
for(j=0; j<vCurves.size(); j++)
1388
b1 = vCurves.elementAt(j);
1390
while(i<vCurves.size())
1392
b2 = vCurves.elementAt(i);
1394
if(b1.isJoined(b2)==1 && b1.isParametersEquals(b2, true, true))
1397
vFigures.remove(b2);
1407
for(BezierCurve bc : vCurves)
1408
bc.replaceLastPointByClosing();
1412
while(i<vCurves.size()) // We check if the it is possible to close a curve.
1414
BezierCurve bc = vCurves.elementAt(i);
1415
bc.replaceLastPointByClosing();
1419
boolean again = true;
1420
size = vLines.size();
1422
for(int k=0; k<size && again; k++)//We try to close it with a line.
1423
if(bc.isLineClosingCurve(vLines.elementAt(k)) &&
1424
bc.isParametersEquals(vLines.elementAt(k), true, false))
1427
bc.setCloseType(BezierCurve.CLOSE_TYPE_LINE);
1429
vFigures.remove(vLines.elementAt(k));
1432
if(again)//We try to close it with a two-points curve.
1438
BezierCurve bc2 = vCurves.elementAt(j);
1440
if(bc2.getNbPoints()==2 && bc.isOpen() && bc2.isCurveClosingCurve(bc)==1 &&
1441
bc.isParametersEquals(bc2, true, false))
1444
bc.setCloseType(BezierCurve.CLOSE_TYPE_CURVE);
1447
vFigures.remove(bc2);
1454
while(j<vCurves.size() && again)
1456
BezierCurve bc2 = vCurves.elementAt(j);
1458
if(bc2.getNbPoints()==2 && bc.isOpen() && bc.isCurveClosingCurve(bc2)==1 &&
1459
bc.isParametersEquals(bc2, true, false))
1462
bc.setCloseType(BezierCurve.CLOSE_TYPE_CURVE);
1465
vFigures.remove(bc2);
1475
size = vFigures.size();
1478
Figure f = vFigures.elementAt(i);
1480
if(f instanceof LaTeXDrawRectangle && !(f instanceof Square))
1481
{// We check if we can convert frame in square.
1482
LaTeXDrawRectangle frame = (LaTeXDrawRectangle)f;
1484
if(frame.getHeight()==frame.getWidth())
1486
Square square = new Square(frame,true);
1488
vFigures.add(i, square);
1499
public void actionsOnterminatedPsCustom(PSTricksParameters param) throws NotFullyManagedException
1504
while(!psCustFigures.isEmpty())
1506
f = psCustFigures.remove(0);
1508
if(!(f instanceof AkinPoints) || ((AkinPoints)f).getNbPoints()>1)
1510
if(f instanceof AkinPoints && ((AkinPoints)f).getType()==AkinPoints.TYPE_CURVES)
1511
{// We must transform the read points.
1512
AkinPoints ak = (AkinPoints)f;
1513
int j, size = ak.getNbPoints();
1514
LaTeXDrawPoint2D prev, curr = ak.getPoint(0);
1516
for(j=1; j<size; j++)
1519
curr = ak.getPoint(j);
1520
curr.setLocation(2*curr.x-prev.x, 2*curr.y-prev.y);
1523
((AkinPoints)f).updateBorders();
1536
public void actionsOnNewPath(int line)
1538
psCustFigures.clear();
1545
public int parseOpenShadowCommand(PSTricksParameters param, int line, String txt) throws InvalidFormatCommandException
1547
PSTricksParameters pstp = new PSTricksParameters(param);
1548
int end = super.parseOpenShadowCommand(pstp, line, txt);
1550
for(Figure f : psCustFigures)
1552
f.setHasShadow(true);
1553
f.setShadowAngle(Math.toRadians(pstp.shadowAngle));
1554
f.setShadowColor(pstp.shadowCol);
1555
f.setShadowSize(Math.abs(pstp.shadowSize)*Figure.PPC);
1558
if(psCustFigures.size()>0 && psCustFigures.lastElement() instanceof AkinPoints)
1560
double xunit = param.unit!=PSTricksConstants.DEFAULT_UNIT? param.unit : param.xUnit;
1561
double yunit = param.unit!=PSTricksConstants.DEFAULT_UNIT? param.unit : param.yUnit;
1563
AkinPoints ak = new AkinPoints(new LaTeXDrawPoint2D(
1564
param.psCustomP.lastPosition.x*Figure.PPC*xunit,
1565
param.psCustomP.lastPosition.y*Figure.PPC*yunit*-1), true);
1567
ak.setType(AkinPoints.TYPE_LINES);
1568
psCustFigures.add(ak);
1578
public int actionsOnCurveTo(int line, Vector<PSTricksParameters> params, String txt)
1579
throws InvalidFormatCommandException
1581
Point2D.Double p1 = new Point2D.Double();
1582
Point2D.Double p2 = new Point2D.Double();
1583
Point2D.Double p3 = new Point2D.Double();
1584
int end = parseParametersCurveTo(line, txt, p1, p2, p3);
1585
PSTricksParameters last = params.lastElement();
1587
double xunit = last.unit!=PSTricksConstants.DEFAULT_UNIT? last.unit : last.xUnit;
1588
double yunit = last.unit!=PSTricksConstants.DEFAULT_UNIT? last.unit : last.yUnit;
1590
if(psCustFigures.isEmpty() || !(psCustFigures.lastElement() instanceof AkinPoints))
1592
ak = new AkinPoints(new LaTeXDrawPoint2D(last.psCustomP.lastPosition.x*Figure.PPC*xunit,
1593
last.psCustomP.lastPosition.y*Figure.PPC*-1*yunit), true);
1594
setFigureParameters(params.lastElement(), ak, false);
1596
psCustFigures.add(ak);
1598
else ak = (AkinPoints)psCustFigures.lastElement();
1600
ak.setType(AkinPoints.TYPE_CURVES);
1601
ak.addPoint(new LaTeXDrawPoint2D(p3.x*Figure.PPC*xunit, p3.y*Figure.PPC*-1*yunit));
1602
last.psCustomP.lastPosition.setLocation(p3);
1611
public int actionsOnLineTo(int line, Vector<PSTricksParameters> params, String txt) throws InvalidFormatCommandException
1613
Point2D.Double p1 = new Point2D.Double();
1614
int end = parseParametersLineMoveTo(line, txt, p1);
1615
PSTricksParameters last = params.lastElement();
1617
double xunit = last.unit!=PSTricksConstants.DEFAULT_UNIT? last.unit : last.xUnit;
1618
double yunit = last.unit!=PSTricksConstants.DEFAULT_UNIT? last.unit : last.yUnit;
1620
if(psCustFigures.isEmpty() || !(psCustFigures.lastElement() instanceof AkinPoints))
1622
ak = new AkinPoints(new LaTeXDrawPoint2D(last.psCustomP.lastPosition.x*Figure.PPC*xunit,
1623
last.psCustomP.lastPosition.y*Figure.PPC*-1*yunit), true);
1624
setFigureParameters(params.lastElement(), ak, false);
1626
ak.setType(AkinPoints.TYPE_LINES);
1627
psCustFigures.add(ak);
1629
else ak = (AkinPoints)psCustFigures.lastElement();
1631
ak.addPoint(new LaTeXDrawPoint2D(p1.x*Figure.PPC*xunit, p1.y*Figure.PPC*-1*yunit));
1632
last.psCustomP.lastPosition.setLocation(p1);
1641
public int actionsOnMoveTo(int line, Vector<PSTricksParameters> params, String txt) throws InvalidFormatCommandException
1643
Point2D.Double p1 = new Point2D.Double();
1644
int end = parseParametersLineMoveTo(line, txt, p1);
1645
PSTricksParameters last = params.lastElement();
1646
last.psCustomP.lastPosition.setLocation(p1);
1655
public void actionsOnClosePathCommand(int line)
1657
if(!psCustFigures.isEmpty())
1659
Figure f = psCustFigures.lastElement();
1661
if(f instanceof AkinPoints)
1662
((AkinPoints)f).setOpen(false);