Make first real commit: copy of CaRMetal 4.2.8
This commit is contained in:
parent
002acfc88e
commit
c312811084
1120 changed files with 226843 additions and 1 deletions
55
rene/zirkel/graphics/Drawing.java
Normal file
55
rene/zirkel/graphics/Drawing.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import rene.util.MyVector;
|
||||
import rene.zirkel.structures.CoordinatesXY;
|
||||
|
||||
// file: Drawing.java
|
||||
|
||||
public class Drawing {
|
||||
MyVector P;
|
||||
int Col;
|
||||
|
||||
public Drawing() {
|
||||
P = new MyVector();
|
||||
|
||||
}
|
||||
|
||||
public void addXY(final double x, final double y) {
|
||||
P.addElement(new CoordinatesXY(x, y));
|
||||
}
|
||||
|
||||
public Enumeration elements() {
|
||||
return P.elements();
|
||||
}
|
||||
|
||||
public void setColor(final int col) {
|
||||
Col = col;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return Col;
|
||||
}
|
||||
}
|
489
rene/zirkel/graphics/EPSGraphics.java
Normal file
489
rene/zirkel/graphics/EPSGraphics.java
Normal file
|
@ -0,0 +1,489 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
/* Graphics class supporting EPS export from plots.
|
||||
|
||||
Copyright (c) 1998-2000 The Regents of the University of
|
||||
California.
|
||||
|
||||
Modified, completed and extended by R. Grothmann
|
||||
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
class EpsFontMetrics extends FontMetrics {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
Font F;
|
||||
|
||||
public EpsFontMetrics(final Font f) {
|
||||
super(f); // a dummy font.
|
||||
F = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int stringWidth(final String s) {
|
||||
return s.length() * F.getSize() / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return F.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAscent() {
|
||||
return F.getSize() * 4 / 5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class EpsPoint {
|
||||
double x, y;
|
||||
|
||||
public EpsPoint(final double xx, final double yy) {
|
||||
x = xx;
|
||||
y = yy;
|
||||
}
|
||||
}
|
||||
|
||||
public class EPSGraphics {
|
||||
|
||||
// ///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// // private variables
|
||||
// //
|
||||
|
||||
private Color _currentColor = Color.black;
|
||||
private Font _currentFont;
|
||||
private final double _height;
|
||||
int _orientation;
|
||||
private final OutputStream _out;
|
||||
private final StringBuffer _buffer = new StringBuffer();
|
||||
private double LineWidth = 1;
|
||||
|
||||
public static final int PORTRAIT = 0;
|
||||
public static final int LANDSCAPE = 1;
|
||||
|
||||
private FontMetrics FM;
|
||||
|
||||
public EPSGraphics(final OutputStream out, final double width,
|
||||
final double height, final int orientation, final boolean clip) {
|
||||
_height = height;
|
||||
_orientation = orientation;
|
||||
_out = out;
|
||||
_buffer.append("%!PS-Adobe-3.0 EPSF-3.0\n");
|
||||
_buffer.append("%%Creator: QCircuitBuilder\n");
|
||||
_buffer.append("%%BoundingBox: 50 50 " + (int) (50 + width) + " "
|
||||
+ (int) (50 + height) + "\n");
|
||||
// _buffer.append("%%Orientation: " + (_orientation == PORTRAIT ?
|
||||
// "Portrait" : "Landscape"));
|
||||
// _buffer.append("%%PageOrientation: " + (_orientation == PORTRAIT ?
|
||||
// "Portrait" : "Landscape"));
|
||||
_buffer.append("%%Pages: 1\n");
|
||||
_buffer.append("%%Page: 1 1\n");
|
||||
_buffer.append("%%LanguageLevel: 2\n");
|
||||
if (clip)
|
||||
clipRect(0, 0, width, height);
|
||||
_buffer.append("/Helvetica findfont 10 scalefont setfont\n");
|
||||
}
|
||||
|
||||
public void clearRect(final int x, final int y, final int width,
|
||||
final int height) {
|
||||
}
|
||||
|
||||
// Clip
|
||||
public void clipRect(final double x, final double y, final double width,
|
||||
final double height) {
|
||||
final EpsPoint start = _convert(x, y);
|
||||
// _fillPattern();
|
||||
_buffer.append("newpath " + round(start.x) + " " + round(start.y)
|
||||
+ " moveto\n");
|
||||
_buffer.append("0 " + round(-height) + " rlineto\n");
|
||||
_buffer.append("" + round(width) + " 0 rlineto\n");
|
||||
_buffer.append("0 " + round(height) + " rlineto\n");
|
||||
_buffer.append("" + round(-width) + " 0 rlineto\n");
|
||||
_buffer.append("closepath clip\n");
|
||||
}
|
||||
|
||||
private double round(final double x) {
|
||||
return Math.round(x * 1000.0) / 1000.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a line, using the current color, between the points (x1, y1) and
|
||||
* (x2, y2) in this graphics context's coordinate system.
|
||||
*
|
||||
* @param x1
|
||||
* the x coordinate of the first point.
|
||||
* @param y1
|
||||
* the y coordinate of the first point.
|
||||
* @param x2
|
||||
* the x coordinate of the second point.
|
||||
* @param y2
|
||||
* the y coordinate of the second point.
|
||||
*/
|
||||
public void drawLine(final double x1, final double y1, final double x2,
|
||||
final double y2) {
|
||||
final EpsPoint start = _convert(x1, y1);
|
||||
final EpsPoint end = _convert(x2, y2);
|
||||
_buffer.append("newpath " + round(start.x) + " " + round(start.y)
|
||||
+ " moveto\n");
|
||||
_buffer.append("" + round(end.x) + " " + round(end.y) + " lineto\n");
|
||||
_buffer.append("stroke\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a closed polygon defined by arrays of x and y coordinates. Each pair
|
||||
* of (x, y) coordinates defines a vertex. The third argument gives the
|
||||
* number of vertices. If the arrays are not long enough to define this many
|
||||
* vertices, or if the third argument is less than three, then nothing is
|
||||
* drawn.
|
||||
*
|
||||
* @param xPoints
|
||||
* An array of x coordinates.
|
||||
* @param yPoints
|
||||
* An array of y coordinates.
|
||||
* @param nPoints
|
||||
* The total number of vertices.
|
||||
*/
|
||||
public void drawPolygon(final double xPoints[], final double yPoints[],
|
||||
final int nPoints) {
|
||||
if (!_polygon(xPoints, yPoints, nPoints)) {
|
||||
return;
|
||||
} else {
|
||||
_buffer.append("closepath stroke\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an oval bounded by the specified rectangle with the current color.
|
||||
*
|
||||
* @param x
|
||||
* The x coordinate of the upper left corner
|
||||
* @param y
|
||||
* The y coordinate of the upper left corner
|
||||
* @param width
|
||||
* The width of the oval to be filled.
|
||||
* @param height
|
||||
* The height of the oval to be filled.
|
||||
*/
|
||||
// FIXME: Currently, this ignores the fourth argument and
|
||||
// draws a circle with diameter given by the third argument.
|
||||
public void drawOval(final double x, final double y, final double width,
|
||||
final double height) {
|
||||
final double radius = width / 2.0;
|
||||
_buffer.append("newpath " + _convertX(x + radius) + " "
|
||||
+ _convertY(y + radius) + " " + round(radius)
|
||||
+ " 0 360 arc closepath stroke\n");
|
||||
}
|
||||
|
||||
public void drawRect(final double x, final double y, final double width,
|
||||
final double height) {
|
||||
final EpsPoint start = _convert(x, y);
|
||||
_buffer.append("newpath " + round(start.x) + " " + round(start.y)
|
||||
+ " moveto\n");
|
||||
_buffer.append("0 " + round(-height) + " rlineto\n");
|
||||
_buffer.append("" + round(width) + " 0 rlineto\n");
|
||||
_buffer.append("0 " + round(height) + " rlineto\n");
|
||||
_buffer.append("" + round(-width) + " 0 rlineto\n");
|
||||
_buffer.append("closepath stroke\n");
|
||||
}
|
||||
|
||||
public void drawRoundRect(final double x, final double y,
|
||||
final double width, final double height, final int arcWidth,
|
||||
final int arcHeight) {
|
||||
}
|
||||
|
||||
public void drawString(
|
||||
final java.text.AttributedCharacterIterator iterator, final int x,
|
||||
final int y) {
|
||||
}
|
||||
|
||||
public void drawString(final String str, final double x, final double y) {
|
||||
getFontMetrics();
|
||||
final EpsPoint start = _convert(x, y);
|
||||
_buffer.append("" + start.x + " " + start.y + " moveto\n");
|
||||
_buffer.append("(" + str + ") show\n");
|
||||
}
|
||||
|
||||
public void drawArc(final double x, final double y, final double width,
|
||||
final double height, final double startAngle, final double arcAngle) {
|
||||
final double radius = width / 2.0;
|
||||
_buffer.append("newpath " + _convertX(x + radius) + " "
|
||||
+ _convertY(y + radius) + " " + round(radius) + " "
|
||||
+ round(startAngle) + " " + " " + round(startAngle + arcAngle)
|
||||
+ " arc stroke\n");
|
||||
}
|
||||
|
||||
public void fillArc(final double x, final double y, final double width,
|
||||
final double height, final double startAngle, final double arcAngle) {
|
||||
final double radius = width / 2.0;
|
||||
_buffer.append("newpath " + _convertX(x + radius) + " "
|
||||
+ _convertY(y + radius) + " " + " moveto "
|
||||
+ _convertX(x + radius) + " " + _convertY(y + radius) + " "
|
||||
+ radius + " " + round(startAngle) + " "
|
||||
+ round(startAngle + arcAngle) + " arc closepath fill\n");
|
||||
}
|
||||
|
||||
public void fillChord(final double x, final double y, final double width,
|
||||
final double height, final double startAngle, final double arcAngle) {
|
||||
final double radius = width / 2.0;
|
||||
_buffer.append("newpath " + _convertX(x + radius) + " "
|
||||
+ _convertY(y + radius) + " " + round(radius) + " "
|
||||
+ round(startAngle) + " " + round(startAngle + arcAngle)
|
||||
+ " arc fill\n");
|
||||
}
|
||||
|
||||
public void fillPolygon(final double xPoints[], final double yPoints[],
|
||||
final int nPoints) {
|
||||
if (!_polygon(xPoints, yPoints, nPoints)) {
|
||||
return;
|
||||
} else {
|
||||
_buffer.append("closepath fill\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill an oval bounded by the specified rectangle with the current color.
|
||||
*
|
||||
* @param x
|
||||
* The x coordinate of the upper left corner
|
||||
* @param y
|
||||
* The y coordinate of the upper left corner
|
||||
* @param width
|
||||
* The width of the oval to be filled.
|
||||
* @param height
|
||||
* The height of the oval to be filled.
|
||||
*/
|
||||
// FIXME: Currently, this ignores the fourth argument and draws a circle
|
||||
// with diameter given by the third argument.
|
||||
public void fillOval(final double x, final double y, final double width,
|
||||
final double height) {
|
||||
final double radius = width / 2.0;
|
||||
_buffer.append("newpath " + _convertX(x + radius) + " "
|
||||
+ _convertY(y + radius) + " " + radius
|
||||
+ " 0 360 arc closepath fill\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the specified rectangle and draw a thin outline around it. The left
|
||||
* and right edges of the rectangle are at x and x + width - 1. The top and
|
||||
* bottom edges are at y and y + height - 1. The resulting rectangle covers
|
||||
* an area width pixels wide by height pixels tall. The rectangle is filled
|
||||
* using the brightness of the current color to set the level of gray.
|
||||
*
|
||||
* @param x
|
||||
* The x coordinate of the top left corner.
|
||||
* @param y
|
||||
* The y coordinate of the top left corner.
|
||||
* @param width
|
||||
* The width of the rectangle.
|
||||
* @param height
|
||||
* The height of the rectangle.
|
||||
*/
|
||||
public void fillRect(final double x, final double y, final double width,
|
||||
final double height) {
|
||||
final EpsPoint start = _convert(x, y);
|
||||
// _fillPattern();
|
||||
_buffer.append("newpath " + start.x + " " + start.y + " moveto\n");
|
||||
_buffer.append("0 " + round(-height) + " rlineto\n");
|
||||
_buffer.append("" + round(width) + " 0 rlineto\n");
|
||||
_buffer.append("0 " + round(height) + " rlineto\n");
|
||||
_buffer.append("" + round(-width) + " 0 rlineto\n");
|
||||
_buffer.append("closepath gsave fill grestore\n");
|
||||
_buffer.append("0.5 setlinewidth 0 setgray [] 0 setdash stroke\n");
|
||||
// reset the gray scale to black
|
||||
_buffer.append(round(LineWidth) + " setlinewidth\n");
|
||||
}
|
||||
|
||||
public void fillRoundRect(final double x, final double y,
|
||||
final double width, final double height, final int arcWidth,
|
||||
final int arcHeight) {
|
||||
}
|
||||
|
||||
public Shape getClip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Rectangle getClipBounds() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return _currentColor;
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return _currentFont;
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics(final Font f) {
|
||||
if (FM == null)
|
||||
FM = new EpsFontMetrics(new Font("dialog", Font.PLAIN, 20));
|
||||
return FM;
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics() {
|
||||
return getFontMetrics(_currentFont);
|
||||
}
|
||||
|
||||
public void setFont(final Font font) {
|
||||
final int size = font.getSize();
|
||||
final boolean bold = font.isBold();
|
||||
if (bold) {
|
||||
_buffer.append("/Helvetica-Bold findfont\n");
|
||||
} else {
|
||||
_buffer.append("/Helvetica findfont\n");
|
||||
}
|
||||
_buffer.append("" + size + " scalefont setfont\n");
|
||||
_currentFont = font;
|
||||
FM = new EpsFontMetrics(font);
|
||||
}
|
||||
|
||||
public void setClip(final Shape clip) {
|
||||
}
|
||||
|
||||
public void setClip(final int x, final int y, final int width,
|
||||
final int height) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current color.
|
||||
*
|
||||
* @param c
|
||||
* The desired current color.
|
||||
*/
|
||||
public void setColor(final Color c) {
|
||||
_buffer.append(c.getRed() / 255.0);
|
||||
_buffer.append(" ");
|
||||
_buffer.append(c.getGreen() / 255.0);
|
||||
|
||||
_buffer.append(" ");
|
||||
_buffer.append(c.getBlue() / 255.0);
|
||||
|
||||
_buffer.append(" setrgbcolor\n");
|
||||
// _buffer.append("[] 0 setdash\n");
|
||||
// _buffer.append("1 setlinewidth\n");
|
||||
|
||||
_currentColor = c;
|
||||
}
|
||||
|
||||
public void setLineWidth(final double w) {
|
||||
_buffer.append(round(w) + " setlinewidth\n");
|
||||
LineWidth = w;
|
||||
}
|
||||
|
||||
public void setDash(final double a, final double b) {
|
||||
_buffer.append("[" + round(a) + " " + round(b) + " ] 0 setdash\n");
|
||||
}
|
||||
|
||||
public void clearDash() {
|
||||
_buffer.append("[ ] 0 setdash\n");
|
||||
}
|
||||
|
||||
public void setPaintMode() {
|
||||
}
|
||||
|
||||
public void setXORMode(final Color c1) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue the PostScript showpage command, then write and flush the output.
|
||||
*/
|
||||
public void showpage(final String name) {
|
||||
try {
|
||||
// _buffer.append("showpage\n");
|
||||
_buffer.append("%%EOF");
|
||||
|
||||
final PrintWriter output = new PrintWriter(new java.io.FileWriter(
|
||||
name));
|
||||
|
||||
output.println(_buffer.toString());
|
||||
output.flush();
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue the PostScript showpage command, then write and flush the output.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
_buffer.append("showpage\n");
|
||||
_buffer.append("%%EOF");
|
||||
|
||||
final PrintWriter output = new PrintWriter(_out);
|
||||
|
||||
output.println(_buffer.toString());
|
||||
output.flush();
|
||||
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// // private methods
|
||||
// //
|
||||
|
||||
// Convert the screen coordinate system to that of postscript.
|
||||
private EpsPoint _convert(final double x, final double y) {
|
||||
return new EpsPoint(round(x + 50), round(_height + 50 - y));
|
||||
}
|
||||
|
||||
private double _convertX(final double x) {
|
||||
return round(x + 50);
|
||||
}
|
||||
|
||||
private double _convertY(final double y) {
|
||||
return round(_height + 50 - y);
|
||||
}
|
||||
|
||||
// Draw a closed polygon defined by arrays of x and y coordinates.
|
||||
// Return false if arguments are misformed.
|
||||
private boolean _polygon(final double xPoints[], final double yPoints[],
|
||||
final int nPoints) {
|
||||
if (nPoints < 3 || xPoints.length < nPoints || yPoints.length < nPoints)
|
||||
return false;
|
||||
final EpsPoint start = _convert(xPoints[0], yPoints[0]);
|
||||
_buffer.append("newpath " + round(start.x) + " " + round(start.y)
|
||||
+ " moveto\n");
|
||||
for (int i = 1; i < nPoints; i++) {
|
||||
final EpsPoint vertex = _convert(xPoints[i], yPoints[i]);
|
||||
_buffer.append("" + round(vertex.x) + " " + round(vertex.y)
|
||||
+ " lineto\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
58
rene/zirkel/graphics/FontStruct.java
Normal file
58
rene/zirkel/graphics/FontStruct.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
/**
|
||||
* @author Rene An internal class to hold a font sructure (size, face and font
|
||||
* object)
|
||||
*/
|
||||
public class FontStruct {
|
||||
final int max = 4;
|
||||
double Size[] = new double[max];
|
||||
boolean Bold[] = new boolean[max];
|
||||
Font F[] = new Font[4];
|
||||
int Next = 0;
|
||||
|
||||
public void storeFont(double size, final boolean bold, final Font f) {
|
||||
if (Next >= max)
|
||||
Next = 0;
|
||||
Size[Next] = size;
|
||||
Bold[Next] = bold;
|
||||
F[Next] = f;
|
||||
Next++;
|
||||
}
|
||||
|
||||
public Font getFont(double size, final boolean bold) {
|
||||
for (int i = 0; i < max; i++) {
|
||||
if (F[i] == null)
|
||||
break;
|
||||
if (Size[i] == size && Bold[i] == bold)
|
||||
return F[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
}
|
||||
}
|
96
rene/zirkel/graphics/FunctionPolygonFiller.java
Normal file
96
rene/zirkel/graphics/FunctionPolygonFiller.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import rene.zirkel.objects.FunctionObject;
|
||||
import rene.zirkel.structures.Coordinates;
|
||||
|
||||
/**
|
||||
* @author Rene
|
||||
*
|
||||
*/
|
||||
public class FunctionPolygonFiller {
|
||||
|
||||
MyGraphics G;
|
||||
FunctionObject O;
|
||||
Vector V;
|
||||
double Ymin, Ymax;
|
||||
boolean cartesian = true;
|
||||
|
||||
public FunctionPolygonFiller(final MyGraphics g, final FunctionObject o,
|
||||
final double ymin, final double ymax) {
|
||||
G = g;
|
||||
O = o;
|
||||
Ymin = ymin - 100;
|
||||
Ymax = ymax + 100;
|
||||
cartesian = O.isCartesian();
|
||||
V = new Vector();
|
||||
}
|
||||
|
||||
public void add(final double c, final double r) {
|
||||
double r0 = r;
|
||||
if (r > Ymax) {
|
||||
r0 = Ymax;
|
||||
} else if (r < Ymin) {
|
||||
r0 = Ymin;
|
||||
}
|
||||
V.add(new Coordinates(c, r0));
|
||||
}
|
||||
|
||||
public void fillPolygon(final double origin) {
|
||||
final int bord = cartesian ? 2 : 0;
|
||||
final int nx = V.size() + bord;
|
||||
if (nx > bord) {
|
||||
final double x[] = new double[nx];
|
||||
final double y[] = new double[nx];
|
||||
final Enumeration e = V.elements();
|
||||
int i = 0;
|
||||
if (e.hasMoreElements()) {
|
||||
final Coordinates c = (Coordinates) e.nextElement();
|
||||
if (cartesian) {
|
||||
x[i] = c.X;
|
||||
y[i++] = origin;
|
||||
x[i] = c.X;
|
||||
y[i++] = c.Y;
|
||||
} else {
|
||||
x[i] = c.X;
|
||||
y[i++] = c.Y;
|
||||
}
|
||||
}
|
||||
while (e.hasMoreElements()) {
|
||||
final Coordinates c = (Coordinates) e.nextElement();
|
||||
x[i] = c.X;
|
||||
y[i++] = c.Y;
|
||||
}
|
||||
if (cartesian) {
|
||||
x[i] = x[i - 1];
|
||||
y[i] = origin;
|
||||
}
|
||||
G.fillPolygon(x, y, nx, false, true, O);
|
||||
V.removeAllElements();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
94
rene/zirkel/graphics/LatexOutput.java
Normal file
94
rene/zirkel/graphics/LatexOutput.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import rene.gui.Global;
|
||||
|
||||
public class LatexOutput {
|
||||
PrintWriter Out;
|
||||
double W, H;
|
||||
boolean DoubleDollar, Dollar, NoDollar;
|
||||
|
||||
public LatexOutput(final PrintWriter out) {
|
||||
Out = out;
|
||||
DoubleDollar = Global.getParameter("options.doubledollar", true);
|
||||
Dollar = Global.getParameter("options.dollar", true);
|
||||
NoDollar = Global.getParameter("options.nodollar", false);
|
||||
}
|
||||
|
||||
public void open(final double w, final double h, final double dpi,
|
||||
final String picfilename) {
|
||||
W = w;
|
||||
H = h;
|
||||
Out.println("\\setlength{\\unitlength}{" + (2.54 / dpi) + "cm}");
|
||||
Out.println("\\begin{picture}(" + round(w) + "," + round(h) + ")");
|
||||
final String s = picfilename.replace('\\', '/');
|
||||
Out.println("\\put(0,0){\\includegraphics[width="
|
||||
+ round(w / dpi * 2.54) + "cm]{" + s + "}}");
|
||||
Out.println("%\\put(0,0){\\includegraphics[width="
|
||||
+ round(w / dpi * 2.54) + "cm,bb=0 0 " + ((int) w) + " "
|
||||
+ ((int) h) + "]{" + s + "}}");
|
||||
}
|
||||
|
||||
public void close() {
|
||||
Out.println("\\end{picture}");
|
||||
Out.close();
|
||||
}
|
||||
|
||||
public boolean println(String s, final double x, final double y,
|
||||
final boolean force) {
|
||||
if (s.startsWith("$$")) {
|
||||
if (!DoubleDollar)
|
||||
return false;
|
||||
s = s.substring(1);
|
||||
if (s.endsWith("$$"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
if (!s.endsWith("$"))
|
||||
s = s + "$";
|
||||
} else if (!force && s.startsWith("$")) {
|
||||
if (!Dollar)
|
||||
return false;
|
||||
if (!s.endsWith("$"))
|
||||
s = s + "$";
|
||||
} else if (!force) {
|
||||
if (!NoDollar)
|
||||
return false;
|
||||
}
|
||||
// Out.println("\\put("+round(x)+","+round(H-y)+"){\\makebox(0,0)[lt]{"+s+"}}");
|
||||
Out.println("\\put(" + round(x) + "," + round(H - y) + "){" + s + "}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean println(final String s, final double x, final double y) {
|
||||
return println(s, x, y, false);
|
||||
}
|
||||
|
||||
public double round(final double x) {
|
||||
return Math.floor(x * 1000 + 0.5) / 1000;
|
||||
}
|
||||
|
||||
public boolean printDollar() {
|
||||
return Dollar;
|
||||
}
|
||||
}
|
867
rene/zirkel/graphics/MainGraphics.java
Normal file
867
rene/zirkel/graphics/MainGraphics.java
Normal file
|
@ -0,0 +1,867 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ImageObserver;
|
||||
import rene.gui.Global;
|
||||
import rene.zirkel.ZirkelFrame;
|
||||
import rene.zirkel.objects.ConstructionObject;
|
||||
import rene.zirkel.objects.PointObject;
|
||||
import de.erichseifert.vectorgraphics2d.EPSGraphics2D;
|
||||
import de.erichseifert.vectorgraphics2d.SVGGraphics2D;
|
||||
import de.erichseifert.vectorgraphics2d.VectorGraphics2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import rene.zirkel.ZirkelCanvas;
|
||||
|
||||
public class MainGraphics extends MyGraphics {
|
||||
|
||||
Graphics2D G=null;
|
||||
BasicStroke Thin, Normal, Thick, SuperThick, DCross, DCrossNormal;
|
||||
// AlphaComposite C, CO;
|
||||
ZirkelCanvas ZC=null;
|
||||
|
||||
// Constructeur appelé par le paint de ZirkelCanvas ainsi que pour les exports :
|
||||
public MainGraphics(final Graphics2D g, ZirkelCanvas zc) {
|
||||
G=g;
|
||||
ZC=zc;
|
||||
G.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
G.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
G.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
G.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
G.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
|
||||
RenderingHints.VALUE_STROKE_PURE);
|
||||
|
||||
if ((G instanceof EPSGraphics2D)||(G instanceof SVGGraphics2D)) {
|
||||
VectorGraphics2D vg2D=(VectorGraphics2D) G;
|
||||
vg2D.setFontRendering(VectorGraphics2D.FontRendering.VECTORS);
|
||||
}
|
||||
|
||||
|
||||
setDefaultLineSize(ZC.lineSize());
|
||||
setDefaultFont(ZC.fontSize(), Global.getParameter("font.large", false), Global.getParameter("font.bold", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(final Color c) {
|
||||
G.setColor(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(final ConstructionObject o) {
|
||||
G.setStroke(Normal);
|
||||
Color Col, LightCol, BrighterCol, BrighterLightCol;
|
||||
// it's a personnal color :
|
||||
if (o.getSpecialColor()!=null) {
|
||||
final int i=o.getConditionalColor();
|
||||
if (i!=-1) {
|
||||
Col=ZirkelFrame.Colors[i];
|
||||
LightCol=ZirkelFrame.LightColors[i];
|
||||
BrighterCol=ZirkelFrame.BrighterColors[i];
|
||||
BrighterLightCol=ZirkelFrame.BrighterLightColors[i];
|
||||
} else {
|
||||
final double lambda=0.4;
|
||||
Col=o.getSpecialColor();
|
||||
|
||||
// System.out.println(o.getName()+" : "+Col);
|
||||
|
||||
final int r=(int) (255*(1-lambda)+Col.getRed()*lambda);
|
||||
final int g=(int) (255*(1-lambda)+Col.getGreen()
|
||||
*lambda);
|
||||
final int b=(int) (255*(1-lambda)+Col.getBlue()
|
||||
*lambda);
|
||||
LightCol=new Color(r, g, b);
|
||||
BrighterCol=Col.brighter();
|
||||
BrighterLightCol=LightCol.brighter();
|
||||
}
|
||||
} else {
|
||||
final int i=o.getColorIndex();
|
||||
Col=ZirkelFrame.Colors[i];
|
||||
LightCol=ZirkelFrame.LightColors[i];
|
||||
BrighterCol=ZirkelFrame.BrighterColors[i];
|
||||
BrighterLightCol=ZirkelFrame.BrighterLightColors[i];
|
||||
}
|
||||
if (o.isJobTarget()) {
|
||||
setColor(ZirkelFrame.TargetColor);
|
||||
} else if (o.indicated()) {
|
||||
setColor(ZirkelFrame.IndicateColor);
|
||||
} else if (o.selected()) {
|
||||
setColor(ZirkelFrame.SelectColor);
|
||||
} else {
|
||||
if (o.getColorType()==ConstructionObject.THIN) {
|
||||
if (o.isHidden()) {
|
||||
setColor(BrighterLightCol);
|
||||
} else {
|
||||
setColor(LightCol);
|
||||
}
|
||||
} else {
|
||||
if (o.isHidden()) {
|
||||
setColor(BrighterCol);
|
||||
} else {
|
||||
setColor(Col);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o.getColorType()==ConstructionObject.THIN) {
|
||||
G.setStroke(Thin);
|
||||
} else if (o.getColorType()==ConstructionObject.THICK) {
|
||||
G.setStroke(Thick);
|
||||
} else {
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRect(final int x, final int y, final int w, final int h,
|
||||
final Color c) {
|
||||
G.setColor(c);
|
||||
G.fillRect(x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFillColor(final ConstructionObject o) {
|
||||
G.setStroke(Normal);
|
||||
if (o.isJobTarget()) {
|
||||
setColor(ZirkelFrame.TargetColor);
|
||||
} else if ((o instanceof PointObject)&&o.indicated()) {
|
||||
setColor(ZirkelFrame.IndicateColor);
|
||||
} else {
|
||||
Color Col, LightCol, BrighterCol, BrighterLightCol;
|
||||
// it's a personnal color :
|
||||
if (o.getSpecialColor()!=null) {
|
||||
final int i=o.getConditionalColor();
|
||||
if (i!=-1) {
|
||||
Col=ZirkelFrame.Colors[i];
|
||||
LightCol=ZirkelFrame.LightColors[i];
|
||||
BrighterCol=ZirkelFrame.BrighterColors[i];
|
||||
BrighterLightCol=ZirkelFrame.BrighterLightColors[i];
|
||||
} else {
|
||||
final double lambda=0.4;
|
||||
Col=o.getSpecialColor();
|
||||
final int r=(int) (255*(1-lambda)+Col.getRed()
|
||||
*lambda);
|
||||
final int g=(int) (255*(1-lambda)+Col.getGreen()
|
||||
*lambda);
|
||||
final int b=(int) (255*(1-lambda)+Col.getBlue()
|
||||
*lambda);
|
||||
LightCol=new Color(r, g, b);
|
||||
BrighterCol=Col.brighter();
|
||||
BrighterLightCol=LightCol.brighter();
|
||||
}
|
||||
} else {
|
||||
final int i=o.getColorIndex();
|
||||
Col=ZirkelFrame.Colors[i];
|
||||
LightCol=ZirkelFrame.LightColors[i];
|
||||
BrighterCol=ZirkelFrame.BrighterColors[i];
|
||||
BrighterLightCol=ZirkelFrame.BrighterLightColors[i];
|
||||
}
|
||||
if (o.getColorType()!=ConstructionObject.THICK) {
|
||||
if (o.isHidden()) {
|
||||
setColor(BrighterLightCol);
|
||||
} else {
|
||||
setColor(LightCol);
|
||||
}
|
||||
} else {
|
||||
if (o.isHidden()) {
|
||||
setColor(BrighterCol);
|
||||
} else {
|
||||
setColor(Col);
|
||||
}
|
||||
}
|
||||
if (o.getColorType()==ConstructionObject.THIN) {
|
||||
G.setStroke(Thin);
|
||||
} else if (o.getColorType()==ConstructionObject.THICK) {
|
||||
G.setStroke(Thick);
|
||||
} else {
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabelColor(final ConstructionObject o) {
|
||||
if (o.labelSelected()) {
|
||||
setColor(ZirkelFrame.SelectColor);
|
||||
} else if (o.isFilled()) {
|
||||
final int type=o.getColorType();
|
||||
o.setColorType(ConstructionObject.NORMAL);
|
||||
setColor(o);
|
||||
o.setColorType(type);
|
||||
} else {
|
||||
setColor(o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRect(final double x, final double y, final double w,
|
||||
final double h) {
|
||||
if (test(x)||test(y)||test(x+w)||test(y+h)) {
|
||||
return;
|
||||
}
|
||||
G.setStroke(Normal);
|
||||
G.draw(new Rectangle2D.Double(x, y, w, h));
|
||||
}
|
||||
|
||||
public void drawMarkerRect(final double x, final double y, final double w,
|
||||
final double h) {
|
||||
if (test(x)||test(y)||test(x+w)||test(y+h)) {
|
||||
return;
|
||||
}
|
||||
G.setColor(ZirkelFrame.IndicateColor);
|
||||
G.setStroke(SuperThick);
|
||||
G.draw(new Rectangle2D.Double(x, y, w, h));
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(final double x, final double y, final double x1,
|
||||
final double y1) {
|
||||
if (test(x)||test(y)||test(x1)||test(y1)) {
|
||||
return;
|
||||
}
|
||||
G.setStroke(Normal);
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawThickLine(final double x, final double y, final double x1,
|
||||
final double y1) {
|
||||
if (test(x)||test(y)||test(x1)||test(y1)) {
|
||||
return;
|
||||
}
|
||||
G.setStroke(Thick);
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
|
||||
public void drawMarkerLine(final double x, final double y, final double x1,
|
||||
final double y1) {
|
||||
if (test(x)||test(y)||test(x1)||test(y1)) {
|
||||
return;
|
||||
}
|
||||
G.setColor(ZirkelFrame.IndicateColor);
|
||||
G.setStroke(SuperThick);
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(final double x, final double y, final double x1,
|
||||
final double y1, final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(x1)||test(y1)) {
|
||||
return;
|
||||
}
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
}
|
||||
|
||||
public boolean test(final double x) {
|
||||
return Math.abs(x)>1e5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawArc(final double x, final double y, final double w,
|
||||
final double h, final double a, final double b) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
}
|
||||
G.setStroke(Normal);
|
||||
G.draw(new Arc2D.Double(x, y, w, h, a, b, Arc2D.OPEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawArc(final double x, final double y, final double w,
|
||||
final double h, final double a, final double b,
|
||||
final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
} else {
|
||||
G.draw(new Arc2D.Double(x, y, w, h, a, b, Arc2D.OPEN));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontMetrics getFontMetrics() {
|
||||
return G.getFontMetrics();
|
||||
}
|
||||
private MyFormula TXF=null;
|
||||
|
||||
public void setTeXEqn(final String s) {
|
||||
if (ZC==null) {
|
||||
return;
|
||||
}
|
||||
if (TXF==null) {
|
||||
try {
|
||||
// Si la librairie JLaTeXMath est présente :
|
||||
TXF=new MyTeXFormula(ZC, G);
|
||||
} catch (Error e) {
|
||||
// Sinon on passe au bon vieux HotEqn :
|
||||
TXF=new MyHotEqnFormula(ZC, G);
|
||||
}
|
||||
}
|
||||
TXF.setEquation(s);
|
||||
}
|
||||
|
||||
public double paintTeXEqn(double c, double r) {
|
||||
if (TXF==null) {
|
||||
return 0;
|
||||
}
|
||||
G.setStroke(Normal);
|
||||
return TXF.paint(c, r, G);
|
||||
}
|
||||
|
||||
public double drawStringExtended(String s, final double x, final double y) {
|
||||
Font myFont=G.getFont();
|
||||
double w=0;
|
||||
boolean isTeX=false;
|
||||
String[] strs=computeString(s);
|
||||
// Alternance texte-formule. La première boucle correspond à du texte,
|
||||
// la deuxième à une formule TeX, troisième à du texte, etc... :
|
||||
for (String mystr:strs){
|
||||
if (isTeX){
|
||||
setTeXEqn(mystr);
|
||||
paintTeXEqn(x+w, y-TXF.getEquationAscent()+StrAsc);
|
||||
w+=TXF.getEquationWidth();
|
||||
}else{
|
||||
G.setFont(myFont);
|
||||
drawString(mystr, x+w, y+StrAsc);
|
||||
w+=getFontMetrics().getStringBounds(mystr, G).getWidth();
|
||||
}
|
||||
isTeX=!isTeX;
|
||||
}
|
||||
return StrH;
|
||||
}
|
||||
|
||||
|
||||
private double StrH=0, StrW=0, StrAsc=0;
|
||||
private String Str="";
|
||||
private String[] Strs;
|
||||
|
||||
public String[] computeString(String s){
|
||||
if (s.equals(Str)) {
|
||||
return Strs;
|
||||
}
|
||||
Str=s;
|
||||
Strs=s.split("\\$");
|
||||
Font myFont=G.getFont();
|
||||
StrAsc=0;
|
||||
StrH=0;
|
||||
StrW=0;
|
||||
boolean isTeX=false;
|
||||
// Alternance texte-formule :
|
||||
for (String mystr:Strs){
|
||||
if (isTeX){
|
||||
setTeXEqn(mystr);
|
||||
StrH=Math.max(StrH, TXF.getEquationHeight());
|
||||
StrW+=TXF.getEquationWidth();
|
||||
StrAsc= Math.max(StrAsc, TXF.getEquationAscent());
|
||||
}else{
|
||||
G.setFont(myFont);
|
||||
StrH=Math.max(StrH, getFontMetrics().getStringBounds(mystr, G).getHeight());
|
||||
StrW+=getFontMetrics().getStringBounds(mystr, G).getWidth();
|
||||
StrAsc=Math.max(StrAsc, getFontMetrics().getLineMetrics(mystr, G).getAscent());
|
||||
}
|
||||
isTeX=!isTeX;
|
||||
}
|
||||
return Strs;
|
||||
}
|
||||
|
||||
public double getW() {
|
||||
return StrW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double stringWidth(final String s) {
|
||||
computeString(s);
|
||||
return StrW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double stringHeight(final String s) {
|
||||
computeString(s);
|
||||
return StrH;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double stringAscent(final String s) {
|
||||
computeString(s);
|
||||
return StrAsc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void drawString(final String s, final double x, final double y) {
|
||||
if (test(x)||test(y)) {
|
||||
return;
|
||||
}
|
||||
G.drawString(s, (float) x, (float) y);
|
||||
// G.drawString(AngleObject.translateToUnicode("éèéééer"), (float) x, (float) y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOval(final double x, final double y, final double w,
|
||||
final double h) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
}
|
||||
G.setStroke(Normal);
|
||||
G.draw(new Ellipse2D.Double(x, y, w, h));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOval(final double x, final double y, final double w,
|
||||
final double h, final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
} else {
|
||||
G.draw(new Ellipse2D.Double(x, y, w, h));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawCircle(final double x, final double y, final double r,
|
||||
final ConstructionObject o) {
|
||||
if (r>10*(W+H)) {
|
||||
drawLargeCircleArc(x, y, r, 0, 360);
|
||||
} else {
|
||||
G.draw(new Ellipse2D.Double(x-r, y-r, 2*r, 2*r));
|
||||
}
|
||||
}
|
||||
|
||||
public void drawMarkerArc(final double x, final double y, final double r,
|
||||
final double a, final double b) {
|
||||
if (test(x)||test(y)||test(r)) {
|
||||
return;
|
||||
}
|
||||
G.setColor(ZirkelFrame.IndicateColor);
|
||||
G.setStroke(SuperThick);
|
||||
G.draw(new Arc2D.Double(x-r, y-r, 2*r, 2*r, a, b, Arc2D.OPEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawCircleArc(final double x, final double y, final double r,
|
||||
final double a, final double b, final ConstructionObject o) {
|
||||
if (r>10*(W+H)) {
|
||||
drawLargeCircleArc(x, y, r, a, b);
|
||||
} else {
|
||||
G.draw(new Arc2D.Double(x-r, y-r, 2*r, 2*r, a, b,
|
||||
Arc2D.OPEN));
|
||||
}
|
||||
}
|
||||
|
||||
void drawLargeCircleArc(final double x, final double y, final double r,
|
||||
final double a, final double b) {
|
||||
if (r>1E10) {
|
||||
return;
|
||||
}
|
||||
final double dw=Math.sqrt((W+H)/r/10);
|
||||
double w=a;
|
||||
double x0=x+r*Math.cos(w/180*Math.PI);
|
||||
double y0=y-r*Math.sin(w/180*Math.PI);
|
||||
w=w+dw;
|
||||
while (w<a+b+dw) {
|
||||
if (w>a+b) {
|
||||
w=a+b;
|
||||
}
|
||||
final double x1=x+r*Math.cos(w/180*Math.PI);
|
||||
final double y1=y-r*Math.sin(w/180*Math.PI);
|
||||
final double dx=(x0+x1)/2, dy=(y0+y1)/2;
|
||||
if (Math.sqrt(dx*dx+dy*dy)<=10*(W+H)) {
|
||||
G.draw(new Line2D.Double(x0, y0, x1, y1));
|
||||
}
|
||||
x0=x1;
|
||||
y0=y1;
|
||||
w+=dw;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillRect(final double x, final double y, final double w,
|
||||
final double h, final boolean outline, final boolean transparent,
|
||||
final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
}
|
||||
setFillColor(o);
|
||||
Color oldC=G.getColor();
|
||||
int alpha=(transparent&&!o.isSolid())?128:255;
|
||||
Color c=new Color(oldC.getRed(), oldC.getGreen(), oldC.getBlue(), alpha);
|
||||
G.setColor(c);
|
||||
G.fill(new Rectangle2D.Double(x, y, w, h));
|
||||
G.setColor(oldC);
|
||||
if (outline) {
|
||||
setColor(o);
|
||||
G.draw(new Rectangle2D.Double(x, y, w, h));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillOval(final double x, final double y, final double w,
|
||||
final double h, final boolean outline, final boolean transparent,
|
||||
final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
}
|
||||
if (o.getColorType()!=ConstructionObject.INVISIBLE) {
|
||||
setFillColor(o);
|
||||
Color oldC=G.getColor();
|
||||
int alpha=(transparent&&!o.isSolid())?128:255;
|
||||
Color c=new Color(oldC.getRed(), oldC.getGreen(), oldC.getBlue(), alpha);
|
||||
G.setColor(c);
|
||||
try {
|
||||
G.fill(new Ellipse2D.Double(x, y, w, h));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
G.setColor(oldC);
|
||||
}
|
||||
if (outline) {
|
||||
setColor(o);
|
||||
drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillArc(final double x, final double y, final double w,
|
||||
final double h, final double a, final double b,
|
||||
final boolean outline, final boolean transparent,
|
||||
final boolean arcb, final ConstructionObject o) {
|
||||
if (test(x)||test(y)||test(w)||test(h)) {
|
||||
return;
|
||||
}
|
||||
setFillColor(o);
|
||||
Color oldC=G.getColor();
|
||||
int alpha=(transparent&&!o.isSolid())?128:255;
|
||||
Color c=new Color(oldC.getRed(), oldC.getGreen(), oldC.getBlue(), alpha);
|
||||
G.setColor(c);
|
||||
final Arc2D arc=new Arc2D.Double(x, y, w, h, a, b, arcb?Arc2D.PIE
|
||||
:Arc2D.CHORD);
|
||||
G.fill(arc);
|
||||
G.setColor(oldC);
|
||||
if (outline) {
|
||||
setColor(o);
|
||||
arc.setArcType(Arc2D.OPEN);
|
||||
G.setStroke(Normal);
|
||||
G.draw(arc);
|
||||
}
|
||||
}
|
||||
int xx[]=new int[64], yy[]=new int[64];
|
||||
|
||||
@Override
|
||||
public void fillPolygon(final double x[], final double y[], final int n,
|
||||
final boolean outline, final boolean transparent,
|
||||
final ConstructionObject o) {
|
||||
if (n<1) return;
|
||||
|
||||
Path2D path=new Path2D.Double();
|
||||
path.moveTo(x[0], y[0]);
|
||||
for (int i=1;i<n;i++) {
|
||||
path.lineTo(x[i], y[i]);
|
||||
}
|
||||
path.lineTo(x[0], y[0]);
|
||||
|
||||
if (o.getColorType()!=ConstructionObject.INVISIBLE) {
|
||||
setFillColor(o);
|
||||
Color oldC=G.getColor();
|
||||
int alpha=(transparent&&!o.isSolid())?128:255;
|
||||
Color c=new Color(oldC.getRed(), oldC.getGreen(), oldC.getBlue(), alpha);
|
||||
G.setColor(c);
|
||||
G.fill(path);
|
||||
G.setColor(oldC);
|
||||
}
|
||||
if (outline) {
|
||||
setColor(o);
|
||||
G.setStroke(Normal);
|
||||
G.draw(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Uniquement appelée par AreaObject :
|
||||
@Override
|
||||
public void fillPolygon(final double x[], final double y[], final int n,
|
||||
final ConstructionObject o) {
|
||||
if (n<1) return;
|
||||
|
||||
Path2D path=new Path2D.Double();
|
||||
path.moveTo(x[0], y[0]);
|
||||
for (int i=1;i<n;i++) {
|
||||
path.lineTo(x[i], y[i]);
|
||||
}
|
||||
path.lineTo(x[0], y[0]);
|
||||
|
||||
if (o.isFilled()) {
|
||||
// Petite modif de code. On passe aux couleurs avec transparence plutôt qu'utiliser
|
||||
// le setComposite :
|
||||
setFillColor(o);
|
||||
Color oldC=G.getColor();
|
||||
int alpha=((o.getColorType()!=ConstructionObject.THICK)&&(!o.isSolid()))?128:255;
|
||||
Color c=new Color(oldC.getRed(), oldC.getGreen(), oldC.getBlue(), alpha);
|
||||
G.setColor(c);
|
||||
G.fill(path);
|
||||
G.setColor(oldC);
|
||||
}
|
||||
if (!o.isFilled()||o.indicated()||o.selected()
|
||||
||o.getColorType()==ConstructionObject.NORMAL) {
|
||||
setColor(o);
|
||||
if (o.indicated()||o.selected()) {
|
||||
G.setStroke(Normal);
|
||||
} else {
|
||||
if (o.getColorType()==ConstructionObject.THIN) {
|
||||
G.setStroke(Thin);
|
||||
} else if (o.getColorType()==ConstructionObject.THICK) {
|
||||
G.setStroke(Thick);
|
||||
} else {
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
}
|
||||
G.draw(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawImage(final Image i, final int x, final int y,
|
||||
final ImageObserver o) {
|
||||
G.drawImage(i, x, y, o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawImage(final Image i, final int x, final int y, final int w,
|
||||
final int h, final ImageObserver o) {
|
||||
G.drawImage(i, x, y, w, h, o);
|
||||
}
|
||||
|
||||
|
||||
FontStruct FS=new FontStruct();
|
||||
|
||||
@Override
|
||||
public void setDefaultLineSize(double graphicsLineSize) {
|
||||
final float dash[]={(float) (graphicsLineSize*5.0), (float) (graphicsLineSize*5.0)};
|
||||
Thin=new BasicStroke((float) (graphicsLineSize), BasicStroke.CAP_BUTT,
|
||||
BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
|
||||
Normal=new BasicStroke((float) (graphicsLineSize), BasicStroke.CAP_ROUND,
|
||||
BasicStroke.JOIN_MITER);
|
||||
Thick=new BasicStroke((float) (graphicsLineSize*2.0), BasicStroke.CAP_ROUND,
|
||||
BasicStroke.JOIN_MITER);
|
||||
DCross=new BasicStroke((float) (graphicsLineSize*3.0),
|
||||
BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
|
||||
DCrossNormal=new BasicStroke((float) (graphicsLineSize*1.5),
|
||||
BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
|
||||
SuperThick=new BasicStroke((float) (20), BasicStroke.CAP_ROUND,
|
||||
BasicStroke.JOIN_ROUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFont(double h, final boolean bold) {
|
||||
Font f=FS.getFont(h, bold);
|
||||
if (f!=null) {
|
||||
G.setFont(f);
|
||||
} else {
|
||||
if (G instanceof VectorGraphics2D) {
|
||||
f=new Font("Arial",
|
||||
bold?Font.BOLD:Font.PLAIN, (int)h);
|
||||
f=f.deriveFont((float)h);
|
||||
} else {
|
||||
f=new Font(Global.getParameter("font.name", "dialog"),
|
||||
bold?Font.BOLD:Font.PLAIN, (int)h);
|
||||
f=f.deriveFont((float)h);
|
||||
}
|
||||
|
||||
// f=new Font(Global.getParameter("font.name", "dialog"),
|
||||
// bold?Font.BOLD:Font.PLAIN, h);
|
||||
FS.storeFont(h, bold, f);
|
||||
G.setFont(f);
|
||||
}
|
||||
}
|
||||
double fsize;
|
||||
boolean flarge, fbold;
|
||||
int ffactor=Global.getParameter("ffactor", 130);
|
||||
|
||||
@Override
|
||||
public void setDefaultFont(double h, final boolean large,
|
||||
final boolean bold) {
|
||||
ffactor=Global.getParameter("ffactor", 130);
|
||||
fsize=h;
|
||||
flarge=large;
|
||||
fbold=bold;
|
||||
setFont(large, bold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFont(final boolean large, final boolean bold) {
|
||||
|
||||
double size=fsize;
|
||||
// int size=eric.JGlobals.FixFontSize(fsize);
|
||||
|
||||
if (large) {
|
||||
size=size*ffactor/100;
|
||||
}
|
||||
if (flarge) {
|
||||
size=size*ffactor/100;
|
||||
}
|
||||
setFont(size, bold||fbold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawImage(final Image i, final double x, final double y,
|
||||
final double x1, final double y1, final double x2, final double y2,
|
||||
final ImageObserver o) {
|
||||
try {
|
||||
final int w=i.getWidth(o), h=i.getHeight(o);
|
||||
final AffineTransform AT=new AffineTransform((x1-x)/w,
|
||||
(y1-y)/w, (x2-x)/h, (y2-y)/h, x, y);
|
||||
G.drawImage(i, AT, o);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Graphics getGraphics() {
|
||||
return G;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void fillOval(final double x, final double y, final double w,
|
||||
final double h, final Color WithColor) {
|
||||
try {
|
||||
G.setColor(WithColor);
|
||||
G.fill(new Ellipse2D.Double(x, y, w, h));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillRect(final double x, final double y, final double w,
|
||||
final double h, final Color WithColor) {
|
||||
try {
|
||||
G.setColor(WithColor);
|
||||
G.fill(new Rectangle2D.Double(x, y, w, h));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDiamond(final double x, final double y, final double w,
|
||||
final boolean isThick, final ConstructionObject o) {
|
||||
AffineTransform aT=G.getTransform();
|
||||
Rectangle2D r=new Rectangle2D.Double(x, y, w, w);
|
||||
AffineTransform rotate45=AffineTransform.getRotateInstance(Math.PI/4, x+w/2, y+w/2);
|
||||
G.transform(rotate45);
|
||||
if (isThick) {
|
||||
setColor(o);
|
||||
} else {
|
||||
G.setColor(new Color(250, 250, 250));
|
||||
}
|
||||
G.fill(r);
|
||||
if (!isThick) {
|
||||
setColor(o);
|
||||
G.draw(r);
|
||||
}
|
||||
G.setTransform(aT);
|
||||
|
||||
// final double dw=w/2;
|
||||
// final int dx[]=new int[4], dy[]=new int[4];
|
||||
// dx[0]=(int) (x+dw);
|
||||
// dy[0]=(int) (y);
|
||||
// dx[1]=(int) (x+w);
|
||||
// dy[1]=(int) (y+dw);
|
||||
// dx[2]=(int) (x+dw);
|
||||
// dy[2]=(int) (y+w);
|
||||
// dx[3]=(int) (x);
|
||||
// dy[3]=(int) (y+dw);
|
||||
// if (isThick) {
|
||||
// setColor(o);
|
||||
// } else {
|
||||
// G.setColor(new Color(250, 250, 250));
|
||||
// }
|
||||
// G.fillPolygon(dx, dy, 4);
|
||||
// if (!isThick) {
|
||||
// setColor(o);
|
||||
// G.drawPolygon(dx, dy, 4);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDcross(final double x, final double y, final double w,
|
||||
final boolean isThick, final ConstructionObject o) {
|
||||
final double x1=x+w, y1=y+w;
|
||||
setColor(o);
|
||||
if (isThick) {
|
||||
G.setStroke(DCross);
|
||||
} else {
|
||||
G.setStroke(DCrossNormal);
|
||||
}
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
G.draw(new Line2D.Double(x, y1, x1, y));
|
||||
G.setStroke(Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAntialiasing(final boolean bool) {
|
||||
if (bool) {
|
||||
G.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// G.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
// RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
} else {
|
||||
G.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
// G.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
// RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAxisLine(final double x, final double y, final double x1,
|
||||
final double y1, float thickness) {
|
||||
if (test(x)||test(y)||test(x1)||test(y1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// G.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
|
||||
// RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
// G.setStroke(new BasicStroke(thickness));
|
||||
G.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
|
||||
G.draw(new Line2D.Double(x, y, x1, y1));
|
||||
G.setStroke(Normal);
|
||||
// G.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
|
||||
// RenderingHints.VALUE_STROKE_PURE);
|
||||
}
|
||||
}
|
26
rene/zirkel/graphics/MyFormula.java
Normal file
26
rene/zirkel/graphics/MyFormula.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author erichake
|
||||
*/
|
||||
public abstract class MyFormula {
|
||||
|
||||
protected float EQwidth=0f, EQheight=0f;
|
||||
protected float EQbaseLine=0f;
|
||||
|
||||
public abstract void setEquation(String s);
|
||||
public abstract double getEquationWidth();
|
||||
public abstract double getEquationHeight();
|
||||
public abstract double getEquationAscent();
|
||||
public abstract String getEquation();
|
||||
public abstract double paint(double c, double r, Graphics2D g);
|
||||
|
||||
}
|
143
rene/zirkel/graphics/MyGraphics.java
Normal file
143
rene/zirkel/graphics/MyGraphics.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
import rene.zirkel.objects.ConstructionObject;
|
||||
|
||||
public abstract class MyGraphics {
|
||||
double W = 1000, H = 1000;
|
||||
|
||||
public void setSize(final double w, final double h) {
|
||||
W = w;
|
||||
H = h;
|
||||
}
|
||||
|
||||
public abstract void clearRect(int x, int y, int w, int h, Color c);
|
||||
|
||||
public abstract void setColor(Color c);
|
||||
|
||||
public abstract void setColor(ConstructionObject o);
|
||||
|
||||
public abstract void setFillColor(ConstructionObject o);
|
||||
|
||||
public abstract void setLabelColor(ConstructionObject o);
|
||||
|
||||
public abstract void drawRect(double x, double y, double w, double h);
|
||||
|
||||
public abstract void drawAxisLine(double x, double y, double x1, double y1, float thickness);
|
||||
|
||||
public abstract void drawLine(double x, double y, double x1, double y1,
|
||||
ConstructionObject o);
|
||||
|
||||
public abstract void drawLine(double x, double y, double x1, double y1);
|
||||
|
||||
public abstract void drawThickLine(double x, double y, double x1, double y1);
|
||||
|
||||
public abstract void drawArc(double x, double y, double w, double h,
|
||||
double a, double b);
|
||||
|
||||
public abstract void drawArc(double x, double y, double w, double h,
|
||||
double a, double b, ConstructionObject o);
|
||||
|
||||
public void drawCircleArc(final double x, final double y, final double r,
|
||||
final double a, final double b, final ConstructionObject o) {
|
||||
drawArc(x - r, y - r, 2 * r, 2 * r, a, b, o);
|
||||
}
|
||||
|
||||
// public abstract int drawLaTeXString(String s, double x, double y);
|
||||
|
||||
public abstract void drawString(String s, double x, double y);
|
||||
|
||||
public abstract void drawOval(double x, double y, double w, double h);
|
||||
|
||||
public abstract void drawOval(double x, double y, double w, double h,
|
||||
ConstructionObject o);
|
||||
|
||||
public void drawCircle(final double x, final double y, final double r,
|
||||
final ConstructionObject o) {
|
||||
drawOval(x - r, y - r, 2 * r, 2 * r, o);
|
||||
}
|
||||
|
||||
public abstract void fillRect(double x, double y, double w, double h,
|
||||
boolean outline, boolean transparent, ConstructionObject o);
|
||||
|
||||
public abstract void fillRect(double x, double y, double w, double h,
|
||||
Color WithColor);
|
||||
|
||||
public abstract void fillOval(double x, double y, double w, double h,
|
||||
boolean outline, boolean transparent, ConstructionObject o);
|
||||
|
||||
public abstract void fillOval(double x, double y, double w, double h,
|
||||
Color WithColor);
|
||||
|
||||
public abstract void fillPolygon(double x[], double y[], int n,
|
||||
boolean outline, boolean tranparent, ConstructionObject o);
|
||||
|
||||
public abstract void fillPolygon(double x[], double y[], int n,
|
||||
ConstructionObject o);
|
||||
|
||||
public abstract void drawDiamond(double x, double y, double w,
|
||||
boolean isThick, ConstructionObject o);
|
||||
|
||||
public abstract void drawDcross(double x, double y, double w,
|
||||
boolean isThick, ConstructionObject o);
|
||||
|
||||
public abstract void fillArc(double x, double y, double w, double h,
|
||||
double a, double b, boolean outline, boolean transparent,
|
||||
boolean arc, ConstructionObject o);
|
||||
|
||||
public abstract void drawImage(Image i, int x, int y, ImageObserver o);
|
||||
|
||||
public abstract void drawImage(Image i, int x, int y, int w, int h,
|
||||
ImageObserver o);
|
||||
|
||||
public abstract void drawImage(Image i, double x, double y, double x1,
|
||||
double y1, double x2, double y2, ImageObserver o);
|
||||
|
||||
public abstract void setDefaultFont(double size, boolean large, boolean bold);
|
||||
|
||||
public abstract void setDefaultLineSize(double graphicsLineSize);
|
||||
|
||||
public abstract void setFont(boolean large, boolean bold);
|
||||
|
||||
public abstract void setFont(double size, boolean bold);
|
||||
|
||||
public abstract FontMetrics getFontMetrics();
|
||||
|
||||
public abstract Graphics getGraphics();
|
||||
|
||||
public abstract double stringAscent(String s);
|
||||
|
||||
public abstract double stringWidth(String s);
|
||||
|
||||
public abstract double stringHeight(String s);
|
||||
|
||||
public abstract double drawStringExtended(String s, double x, double y);
|
||||
|
||||
public abstract void setAntialiasing(boolean bool);
|
||||
}
|
58
rene/zirkel/graphics/MyHotEqnFormula.java
Normal file
58
rene/zirkel/graphics/MyHotEqnFormula.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import atp.sHotEqn;
|
||||
import java.awt.Graphics2D;
|
||||
import rene.zirkel.ZirkelCanvas;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author erichake
|
||||
*/
|
||||
public class MyHotEqnFormula extends MyFormula {
|
||||
|
||||
private sHotEqn HE=null;
|
||||
private String EQ="";
|
||||
private ZirkelCanvas ZC;
|
||||
private Graphics2D G=null;
|
||||
|
||||
public MyHotEqnFormula(ZirkelCanvas zc, Graphics2D g) {
|
||||
ZC=zc;
|
||||
G=g;
|
||||
HE=new sHotEqn(ZC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEquation(String s) {
|
||||
EQ=s;
|
||||
HE.setEquation(s);
|
||||
EQwidth=HE.getSizeof(HE.getEquation(), G).width;
|
||||
EQheight=HE.getSizeof(HE.getEquation(), G).height;
|
||||
EQbaseLine=HE.getAscent(HE.getEquation(), G);
|
||||
}
|
||||
|
||||
public double getEquationWidth() {
|
||||
return EQwidth;
|
||||
}
|
||||
|
||||
public double getEquationHeight() {
|
||||
return EQheight;
|
||||
}
|
||||
|
||||
public double getEquationAscent() {
|
||||
double d=EQbaseLine;
|
||||
return d;
|
||||
}
|
||||
|
||||
public String getEquation() {
|
||||
return EQ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double paint(double c, double r, Graphics2D g) {
|
||||
return HE.paint((int)c, (int)r, G);
|
||||
}
|
||||
}
|
107
rene/zirkel/graphics/MyTeXFormula.java
Normal file
107
rene/zirkel/graphics/MyTeXFormula.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import de.erichseifert.vectorgraphics2d.VectorGraphics2D;
|
||||
import de.erichseifert.vectorgraphics2d.VectorGraphics2D.FontRendering;
|
||||
import java.awt.Graphics2D;
|
||||
import org.scilab.forge.jlatexmath.Box;
|
||||
import org.scilab.forge.jlatexmath.DefaultTeXFont;
|
||||
import org.scilab.forge.jlatexmath.StrutBox;
|
||||
import org.scilab.forge.jlatexmath.TeXConstants;
|
||||
import org.scilab.forge.jlatexmath.TeXEnvironment;
|
||||
import org.scilab.forge.jlatexmath.TeXFormula;
|
||||
import rene.zirkel.ZirkelCanvas;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author erichake
|
||||
*/
|
||||
public class MyTeXFormula extends MyFormula {
|
||||
|
||||
private TeXFormula JTeX=null;
|
||||
private String EQ="";
|
||||
private ZirkelCanvas ZC;
|
||||
private Graphics2D G=null;
|
||||
private boolean parseError=false;
|
||||
|
||||
public MyTeXFormula(ZirkelCanvas zc, Graphics2D g) {
|
||||
ZC=zc;
|
||||
G=g;
|
||||
try {
|
||||
JTeX=new TeXFormula();
|
||||
} catch (Exception e) {
|
||||
JTeX=null;
|
||||
}
|
||||
}
|
||||
|
||||
public MyTeXIcon createTeXIcon(int style, float size) {
|
||||
TeXEnvironment te=new TeXEnvironment(style, new DefaultTeXFont(size));
|
||||
Box box;
|
||||
if (JTeX.root==null) {
|
||||
box=new StrutBox(0, 0, 0, 0);
|
||||
} else {
|
||||
box=JTeX.root.createBox(te);
|
||||
}
|
||||
MyTeXIcon ti=new MyTeXIcon(box, size);
|
||||
ti.isColored=te.isColored;
|
||||
return ti;
|
||||
}
|
||||
|
||||
public void setEquation(String s) {
|
||||
EQ=s;
|
||||
try {
|
||||
JTeX.setLaTeX(s);
|
||||
MyTeXIcon icon=createTeXIcon(TeXConstants.STYLE_DISPLAY, (float) ZC.fontSize());
|
||||
EQwidth=icon.getTrueIconWidth();
|
||||
EQheight=icon.getTrueIconHeight();
|
||||
EQbaseLine=icon.getBaseLine();
|
||||
parseError=false;
|
||||
} catch (Exception e) {
|
||||
EQwidth=0;
|
||||
EQheight=0;
|
||||
EQbaseLine=0;
|
||||
parseError=true;
|
||||
System.out.println("jlatexmath.ParseException");
|
||||
}
|
||||
}
|
||||
|
||||
public double getEquationWidth() {
|
||||
return EQwidth;
|
||||
}
|
||||
|
||||
public double getEquationHeight() {
|
||||
return EQheight;
|
||||
}
|
||||
|
||||
public double getEquationAscent() {
|
||||
double d=EQheight*EQbaseLine;
|
||||
return d;
|
||||
}
|
||||
|
||||
public String getEquation() {
|
||||
return EQ;
|
||||
}
|
||||
|
||||
public double paint(double c, double r, Graphics2D g) {
|
||||
if (parseError) {
|
||||
return 0;
|
||||
}
|
||||
float col=(float) c;
|
||||
float row=(float) r;
|
||||
JTeX.setColor(g.getColor());
|
||||
MyTeXIcon icon=createTeXIcon(org.scilab.forge.jlatexmath.TeXConstants.STYLE_DISPLAY, (float) ZC.fontSize());
|
||||
if (g instanceof VectorGraphics2D) {
|
||||
VectorGraphics2D vg2d=(VectorGraphics2D) g;
|
||||
FontRendering oldFontRendering=vg2d.getFontRendering();
|
||||
vg2d.setFontRendering(VectorGraphics2D.FontRendering.VECTORS);
|
||||
icon.paintIcon(null, g, col, row);
|
||||
vg2d.setFontRendering(oldFontRendering);
|
||||
} else {
|
||||
icon.paintIcon(null, g, col, row);
|
||||
}
|
||||
return icon.getTrueIconHeight();
|
||||
}
|
||||
}
|
74
rene/zirkel/graphics/MyTeXIcon.java
Normal file
74
rene/zirkel/graphics/MyTeXIcon.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import org.scilab.forge.jlatexmath.Box;
|
||||
import org.scilab.forge.jlatexmath.TeXIcon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author erichake
|
||||
*/
|
||||
public class MyTeXIcon extends TeXIcon {
|
||||
Box box;
|
||||
private final float size;
|
||||
private Insets insets = new Insets(0, 0, 0, 0);
|
||||
private Color fg = new Color(0, 0, 0);
|
||||
|
||||
protected MyTeXIcon(Box b, float size) {
|
||||
super(b,size,true);
|
||||
box = b;
|
||||
if (defaultSize != -1) {
|
||||
size = defaultSize;
|
||||
}
|
||||
|
||||
if (magFactor != 0) {
|
||||
this.size = size * Math.abs(magFactor);
|
||||
} else {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, float x, float y) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
// copy graphics settings
|
||||
RenderingHints oldHints = g2.getRenderingHints();
|
||||
AffineTransform oldAt = g2.getTransform();
|
||||
Color oldColor = g2.getColor();
|
||||
|
||||
// new settings
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
g2.scale(size, size); // the point size
|
||||
g2.setColor(c != null ? c.getForeground() : fg); // foreground will be used as default painting color
|
||||
|
||||
// draw formula box
|
||||
box.draw(g2,x/size, y /size+box.getHeight());
|
||||
|
||||
// restore graphics settings
|
||||
g2.setRenderingHints(oldHints);
|
||||
g2.setTransform(oldAt);
|
||||
g2.setColor(oldColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBaseLine() {
|
||||
return ( box.getHeight() /(box.getHeight()+box.getDepth()));
|
||||
}
|
||||
|
||||
}
|
146
rene/zirkel/graphics/PolygonDrawer.java
Normal file
146
rene/zirkel/graphics/PolygonDrawer.java
Normal file
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import rene.zirkel.objects.ConstructionObject;
|
||||
|
||||
/**
|
||||
* @author Rene
|
||||
*
|
||||
*/
|
||||
public class PolygonDrawer {
|
||||
|
||||
MyGraphics G;
|
||||
ConstructionObject O;
|
||||
double C, R;
|
||||
double oldR=Double.NaN;
|
||||
double C1, R1;
|
||||
boolean HaveToFinish;
|
||||
// private double step=9.0;
|
||||
private double maxGap=20;
|
||||
public boolean Marker=false;
|
||||
public boolean Started;
|
||||
boolean Solid;
|
||||
boolean haveToCheckDiscontinuity;
|
||||
|
||||
public PolygonDrawer(boolean checkDiscontinuity, final MyGraphics g, final ConstructionObject o) {
|
||||
G=g;
|
||||
O=o;
|
||||
Started=false;
|
||||
haveToCheckDiscontinuity=checkDiscontinuity;
|
||||
// step=9.0*O.getConstruction().getOne()*O.getConstruction().getOne();
|
||||
maxGap=20*O.getConstruction().getOne();
|
||||
}
|
||||
|
||||
public boolean isLineOnDiscontinuity(final double c, final double r) {
|
||||
if ((!haveToCheckDiscontinuity)||(Double.isNaN(oldR))) {
|
||||
return false;
|
||||
}
|
||||
if (((R-oldR)*(r-R))<0) { // Si il y a changement de signe de la "dérivée"
|
||||
if (Math.abs(r-R)>maxGap) { // Et si en plus le "trou" est trop grand
|
||||
finishPolygon();
|
||||
startPolygon(c, r); // On commence un nouveau polygone
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void startPolygon(final double c, final double r) {
|
||||
C=c;
|
||||
R=r;
|
||||
oldR=Double.NaN;
|
||||
HaveToFinish=false;
|
||||
Started=true;
|
||||
}
|
||||
|
||||
// public void drawTo(final double c, final double r, final boolean dodraw) {
|
||||
// if (!Started) {
|
||||
// startPolygon(c, r);
|
||||
// return;
|
||||
// }
|
||||
// if (!isLineOnDiscontinuity(c, r)) {
|
||||
// if (dodraw||(c-C)*(c-C)+(r-R)*(r-R)>step) {
|
||||
// if (Marker) {
|
||||
// ((MainGraphics) G).drawMarkerLine(C, R, c, r);
|
||||
// } else {
|
||||
// G.drawLine(C, R, c, r, O);
|
||||
// }
|
||||
// oldR=R;
|
||||
// C=c;
|
||||
// R=r;
|
||||
// HaveToFinish=false;
|
||||
// } else {
|
||||
//
|
||||
// C1=c;
|
||||
// R1=r;
|
||||
// HaveToFinish=true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void drawTo(final double c, final double r) {
|
||||
// drawTo(c, r, false);
|
||||
if (!Started) {
|
||||
startPolygon(c, r);
|
||||
return;
|
||||
}
|
||||
if (!isLineOnDiscontinuity(c, r)) {
|
||||
if (Marker) {
|
||||
((MainGraphics) G).drawMarkerLine(C, R, c, r);
|
||||
} else {
|
||||
G.drawLine(C, R, c, r, O);
|
||||
}
|
||||
oldR=R;
|
||||
C=c;
|
||||
R=r;
|
||||
HaveToFinish=false;
|
||||
}
|
||||
}
|
||||
|
||||
public void finishPolygon() {
|
||||
if (HaveToFinish) {
|
||||
if (Marker) {
|
||||
((MainGraphics) G).drawMarkerLine(C, R, C1, R1);
|
||||
} else {
|
||||
G.drawLine(C, R, C1, R1, O);
|
||||
}
|
||||
HaveToFinish=false;
|
||||
}
|
||||
Started=false;
|
||||
}
|
||||
|
||||
public boolean hasStarted() {
|
||||
return Started;
|
||||
}
|
||||
|
||||
public double c() {
|
||||
return C;
|
||||
}
|
||||
|
||||
public double r() {
|
||||
return R;
|
||||
}
|
||||
|
||||
public void useAsMarker() {
|
||||
Marker=true;
|
||||
// step=18;
|
||||
}
|
||||
}
|
124
rene/zirkel/graphics/PolygonFiller.java
Normal file
124
rene/zirkel/graphics/PolygonFiller.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import rene.zirkel.objects.ConstructionObject;
|
||||
|
||||
/**
|
||||
* @author Rene
|
||||
*
|
||||
*/
|
||||
public class PolygonFiller {
|
||||
MyGraphics G;
|
||||
ConstructionObject O;
|
||||
double C, R;
|
||||
double C1, R1;
|
||||
boolean HaveToFinish;
|
||||
public static int step = 5;
|
||||
public boolean Started;
|
||||
boolean Solid;
|
||||
|
||||
double x[], y[];
|
||||
int nx;
|
||||
|
||||
public PolygonFiller(final MyGraphics g, final ConstructionObject o) {
|
||||
G = g;
|
||||
O = o;
|
||||
Started = false;
|
||||
}
|
||||
|
||||
public void startPolygon(final double c, final double r) {
|
||||
C = c;
|
||||
R = r;
|
||||
HaveToFinish = false;
|
||||
nx = 0;
|
||||
Started = true;
|
||||
drawTo(c, r, false);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
nx = 0;
|
||||
Started = false;
|
||||
}
|
||||
|
||||
public void drawTo(final double c, final double r) {
|
||||
drawTo(c, r, true);
|
||||
}
|
||||
|
||||
public void drawTo(final double c, final double r, final boolean optimized) {
|
||||
if (!Started) {
|
||||
startPolygon(c, r);
|
||||
return;
|
||||
}
|
||||
if (!optimized || (c - C) * (c - C) + (r - R) * (r - R) > step) {
|
||||
if (x == null) {
|
||||
x = new double[1000];
|
||||
y = new double[1000];
|
||||
nx = 0;
|
||||
}
|
||||
if (nx >= x.length) {
|
||||
final double xn[] = new double[2 * x.length];
|
||||
final double yn[] = new double[2 * x.length];
|
||||
for (int i = 0; i < nx; i++) {
|
||||
xn[i] = x[i];
|
||||
yn[i] = y[i];
|
||||
}
|
||||
x = xn;
|
||||
y = yn;
|
||||
}
|
||||
x[nx] = c;
|
||||
y[nx++] = r;
|
||||
C = c;
|
||||
R = r;
|
||||
HaveToFinish = false;
|
||||
} else {
|
||||
C1 = c;
|
||||
R1 = r;
|
||||
HaveToFinish = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void finishPolygon() {
|
||||
if (HaveToFinish) {
|
||||
drawTo(C1, R1, false);
|
||||
HaveToFinish = false;
|
||||
}
|
||||
G.fillPolygon(x, y, nx, false, true, O);
|
||||
Started = false;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return nx;
|
||||
}
|
||||
|
||||
public double x(final int i) {
|
||||
return x[i];
|
||||
}
|
||||
|
||||
public double y(final int i) {
|
||||
return y[i];
|
||||
}
|
||||
|
||||
public void setGraphics(final MyGraphics g) {
|
||||
G = g;
|
||||
}
|
||||
}
|
33
rene/zirkel/graphics/TrackPainter.java
Normal file
33
rene/zirkel/graphics/TrackPainter.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.zirkel.graphics;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import rene.zirkel.ZirkelCanvas;
|
||||
|
||||
public interface TrackPainter {
|
||||
public Enumeration elements();
|
||||
|
||||
public void paint(MyGraphics g, ZirkelCanvas zc);
|
||||
|
||||
public void validate(ZirkelCanvas zc);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue