first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,61 @@
package com.itextpdf.awt;
import com.itextpdf.text.pdf.BaseFont;
import java.awt.Font;
public class AsianFontMapper extends DefaultFontMapper {
public static final String ChineseSimplifiedFont = "STSong-Light";
public static final String ChineseSimplifiedEncoding_H = "UniGB-UCS2-H";
public static final String ChineseSimplifiedEncoding_V = "UniGB-UCS2-V";
public static final String ChineseTraditionalFont_MHei = "MHei-Medium";
public static final String ChineseTraditionalFont_MSung = "MSung-Light";
public static final String ChineseTraditionalEncoding_H = "UniCNS-UCS2-H";
public static final String ChineseTraditionalEncoding_V = "UniCNS-UCS2-V";
public static final String JapaneseFont_Go = "HeiseiKakuGo-W5";
public static final String JapaneseFont_Min = "HeiseiMin-W3";
public static final String JapaneseEncoding_H = "UniJIS-UCS2-H";
public static final String JapaneseEncoding_V = "UniJIS-UCS2-V";
public static final String JapaneseEncoding_HW_H = "UniJIS-UCS2-HW-H";
public static final String JapaneseEncoding_HW_V = "UniJIS-UCS2-HW-V";
public static final String KoreanFont_GoThic = "HYGoThic-Medium";
public static final String KoreanFont_SMyeongJo = "HYSMyeongJo-Medium";
public static final String KoreanEncoding_H = "UniKS-UCS2-H";
public static final String KoreanEncoding_V = "UniKS-UCS2-V";
private final String defaultFont;
private final String encoding;
public AsianFontMapper(String font, String encoding) {
this.defaultFont = font;
this.encoding = encoding;
}
public BaseFont awtToPdf(Font font) {
try {
DefaultFontMapper.BaseFontParameters p = getBaseFontParameters(font.getFontName());
if (p != null)
return BaseFont.createFont(p.fontName, p.encoding, p.embedded, p.cached, p.ttfAfm, p.pfb);
return BaseFont.createFont(this.defaultFont, this.encoding, true);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View file

@ -0,0 +1,184 @@
package com.itextpdf.awt;
import com.itextpdf.text.ExceptionConverter;
import com.itextpdf.text.pdf.BaseFont;
import java.awt.Font;
import java.io.File;
import java.util.HashMap;
public class DefaultFontMapper implements FontMapper {
public static class BaseFontParameters {
public String fontName;
public String encoding;
public boolean embedded;
public boolean cached;
public byte[] ttfAfm;
public byte[] pfb;
public BaseFontParameters(String fontName) {
this.fontName = fontName;
this.encoding = "Cp1252";
this.embedded = true;
this.cached = true;
}
}
private HashMap<String, String> aliases = new HashMap<String, String>();
private HashMap<String, BaseFontParameters> mapper = new HashMap<String, BaseFontParameters>();
public BaseFont awtToPdf(Font font) {
try {
BaseFontParameters p = getBaseFontParameters(font.getFontName());
if (p != null)
return BaseFont.createFont(p.fontName, p.encoding, p.embedded, p.cached, p.ttfAfm, p.pfb);
String fontKey = null;
String logicalName = font.getName();
if (logicalName.equalsIgnoreCase("DialogInput") || logicalName.equalsIgnoreCase("Monospaced") || logicalName.equalsIgnoreCase("Courier")) {
if (font.isItalic()) {
if (font.isBold()) {
fontKey = "Courier-BoldOblique";
} else {
fontKey = "Courier-Oblique";
}
} else if (font.isBold()) {
fontKey = "Courier-Bold";
} else {
fontKey = "Courier";
}
} else if (logicalName.equalsIgnoreCase("Serif") || logicalName.equalsIgnoreCase("TimesRoman")) {
if (font.isItalic()) {
if (font.isBold()) {
fontKey = "Times-BoldItalic";
} else {
fontKey = "Times-Italic";
}
} else if (font.isBold()) {
fontKey = "Times-Bold";
} else {
fontKey = "Times-Roman";
}
} else if (font.isItalic()) {
if (font.isBold()) {
fontKey = "Helvetica-BoldOblique";
} else {
fontKey = "Helvetica-Oblique";
}
} else if (font.isBold()) {
fontKey = "Helvetica-Bold";
} else {
fontKey = "Helvetica";
}
return BaseFont.createFont(fontKey, "Cp1252", false);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
public Font pdfToAwt(BaseFont font, int size) {
String[][] names = font.getFullFontName();
if (names.length == 1)
return new Font(names[0][3], 0, size);
String name10 = null;
String name3x = null;
for (int k = 0; k < names.length; k++) {
String[] name = names[k];
if (name[0].equals("1") && name[1].equals("0")) {
name10 = name[3];
} else if (name[2].equals("1033")) {
name3x = name[3];
break;
}
}
String finalName = name3x;
if (finalName == null)
finalName = name10;
if (finalName == null)
finalName = names[0][3];
return new Font(finalName, 0, size);
}
public void putName(String awtName, BaseFontParameters parameters) {
this.mapper.put(awtName, parameters);
}
public void putAlias(String alias, String awtName) {
this.aliases.put(alias, awtName);
}
public BaseFontParameters getBaseFontParameters(String name) {
String alias = this.aliases.get(name);
if (alias == null)
return this.mapper.get(name);
BaseFontParameters p = this.mapper.get(alias);
if (p == null)
return this.mapper.get(name);
return p;
}
public void insertNames(Object[] allNames, String path) {
String[][] names = (String[][])allNames[2];
String main = null;
for (int k = 0; k < names.length; k++) {
String[] name = names[k];
if (name[2].equals("1033")) {
main = name[3];
break;
}
}
if (main == null)
main = names[0][3];
BaseFontParameters p = new BaseFontParameters(path);
this.mapper.put(main, p);
for (int i = 0; i < names.length; i++)
this.aliases.put(names[i][3], main);
this.aliases.put((String)allNames[0], main);
}
public int insertFile(File file) {
String name = file.getPath().toLowerCase();
try {
if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) {
Object[] allNames = BaseFont.getAllFontNames(file.getPath(), "Cp1252", null);
insertNames(allNames, file.getPath());
return 1;
}
if (name.endsWith(".ttc")) {
String[] ttcs = BaseFont.enumerateTTCNames(file.getPath());
for (int j = 0; j < ttcs.length; j++) {
String nt = file.getPath() + "," + j;
Object[] allNames = BaseFont.getAllFontNames(nt, "Cp1252", null);
insertNames(allNames, nt);
}
return 1;
}
} catch (Exception e) {}
return 0;
}
public int insertDirectory(String dir) {
File file = new File(dir);
if (!file.exists() || !file.isDirectory())
return 0;
File[] files = file.listFiles();
if (files == null)
return 0;
int count = 0;
for (int k = 0; k < files.length; k++)
count += insertFile(files[k]);
return count;
}
public HashMap<String, BaseFontParameters> getMapper() {
return this.mapper;
}
public HashMap<String, String> getAliases() {
return this.aliases;
}
}

View file

@ -0,0 +1,10 @@
package com.itextpdf.awt;
import com.itextpdf.text.pdf.BaseFont;
import java.awt.Font;
public interface FontMapper {
BaseFont awtToPdf(Font paramFont);
Font pdfToAwt(BaseFont paramBaseFont, int paramInt);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
package com.itextpdf.awt;
import com.itextpdf.text.pdf.PdfContentByte;
import java.awt.print.PrinterGraphics;
import java.awt.print.PrinterJob;
public class PdfPrinterGraphics2D extends PdfGraphics2D implements PrinterGraphics {
private PrinterJob printerJob;
public PdfPrinterGraphics2D(PdfContentByte cb, float width, float height, PrinterJob printerJob) {
super(cb, width, height);
this.printerJob = printerJob;
}
public PdfPrinterGraphics2D(PdfContentByte cb, float width, float height, boolean onlyShapes, PrinterJob printerJob) {
super(cb, width, height, onlyShapes);
this.printerJob = printerJob;
}
public PdfPrinterGraphics2D(PdfContentByte cb, float width, float height, FontMapper fontMapper, PrinterJob printerJob) {
super(cb, width, height, fontMapper, false, false, 0.0F);
this.printerJob = printerJob;
}
public PdfPrinterGraphics2D(PdfContentByte cb, float width, float height, FontMapper fontMapper, boolean onlyShapes, boolean convertImagesToJPEG, float quality, PrinterJob printerJob) {
super(cb, width, height, fontMapper, onlyShapes, convertImagesToJPEG, quality);
this.printerJob = printerJob;
}
public PrinterJob getPrinterJob() {
return this.printerJob;
}
}

View file

@ -0,0 +1,530 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.HashCode;
import com.itextpdf.awt.geom.misc.Messages;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class AffineTransform implements Cloneable, Serializable {
private static final long serialVersionUID = 1330973210523860834L;
public static final int TYPE_IDENTITY = 0;
public static final int TYPE_TRANSLATION = 1;
public static final int TYPE_UNIFORM_SCALE = 2;
public static final int TYPE_GENERAL_SCALE = 4;
public static final int TYPE_QUADRANT_ROTATION = 8;
public static final int TYPE_GENERAL_ROTATION = 16;
public static final int TYPE_GENERAL_TRANSFORM = 32;
public static final int TYPE_FLIP = 64;
public static final int TYPE_MASK_SCALE = 6;
public static final int TYPE_MASK_ROTATION = 24;
static final int TYPE_UNKNOWN = -1;
static final double ZERO = 1.0E-10D;
double m00;
double m10;
double m01;
double m11;
double m02;
double m12;
transient int type;
public AffineTransform() {
this.type = 0;
this.m00 = this.m11 = 1.0D;
this.m10 = this.m01 = this.m02 = this.m12 = 0.0D;
}
public AffineTransform(AffineTransform t) {
this.type = t.type;
this.m00 = t.m00;
this.m10 = t.m10;
this.m01 = t.m01;
this.m11 = t.m11;
this.m02 = t.m02;
this.m12 = t.m12;
}
public AffineTransform(float m00, float m10, float m01, float m11, float m02, float m12) {
this.type = -1;
this.m00 = (double)m00;
this.m10 = (double)m10;
this.m01 = (double)m01;
this.m11 = (double)m11;
this.m02 = (double)m02;
this.m12 = (double)m12;
}
public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) {
this.type = -1;
this.m00 = m00;
this.m10 = m10;
this.m01 = m01;
this.m11 = m11;
this.m02 = m02;
this.m12 = m12;
}
public AffineTransform(float[] matrix) {
this.type = -1;
this.m00 = (double)matrix[0];
this.m10 = (double)matrix[1];
this.m01 = (double)matrix[2];
this.m11 = (double)matrix[3];
if (matrix.length > 4) {
this.m02 = (double)matrix[4];
this.m12 = (double)matrix[5];
}
}
public AffineTransform(double[] matrix) {
this.type = -1;
this.m00 = matrix[0];
this.m10 = matrix[1];
this.m01 = matrix[2];
this.m11 = matrix[3];
if (matrix.length > 4) {
this.m02 = matrix[4];
this.m12 = matrix[5];
}
}
public int getType() {
if (this.type != -1)
return this.type;
int type = 0;
if (this.m00 * this.m01 + this.m10 * this.m11 != 0.0D) {
type |= 0x20;
return type;
}
if (this.m02 != 0.0D || this.m12 != 0.0D) {
type |= 0x1;
} else if (this.m00 == 1.0D && this.m11 == 1.0D && this.m01 == 0.0D && this.m10 == 0.0D) {
type = 0;
return type;
}
if (this.m00 * this.m11 - this.m01 * this.m10 < 0.0D)
type |= 0x40;
double dx = this.m00 * this.m00 + this.m10 * this.m10;
double dy = this.m01 * this.m01 + this.m11 * this.m11;
if (dx != dy) {
type |= 0x4;
} else if (dx != 1.0D) {
type |= 0x2;
}
if ((this.m00 == 0.0D && this.m11 == 0.0D) || (this.m10 == 0.0D && this.m01 == 0.0D && (this.m00 < 0.0D || this.m11 < 0.0D))) {
type |= 0x8;
} else if (this.m01 != 0.0D || this.m10 != 0.0D) {
type |= 0x10;
}
return type;
}
public double getScaleX() {
return this.m00;
}
public double getScaleY() {
return this.m11;
}
public double getShearX() {
return this.m01;
}
public double getShearY() {
return this.m10;
}
public double getTranslateX() {
return this.m02;
}
public double getTranslateY() {
return this.m12;
}
public boolean isIdentity() {
return (getType() == 0);
}
public void getMatrix(double[] matrix) {
matrix[0] = this.m00;
matrix[1] = this.m10;
matrix[2] = this.m01;
matrix[3] = this.m11;
if (matrix.length > 4) {
matrix[4] = this.m02;
matrix[5] = this.m12;
}
}
public double getDeterminant() {
return this.m00 * this.m11 - this.m01 * this.m10;
}
public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12) {
this.type = -1;
this.m00 = m00;
this.m10 = m10;
this.m01 = m01;
this.m11 = m11;
this.m02 = m02;
this.m12 = m12;
}
public void setTransform(AffineTransform t) {
this.type = t.type;
setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12);
}
public void setToIdentity() {
this.type = 0;
this.m00 = this.m11 = 1.0D;
this.m10 = this.m01 = this.m02 = this.m12 = 0.0D;
}
public void setToTranslation(double mx, double my) {
this.m00 = this.m11 = 1.0D;
this.m01 = this.m10 = 0.0D;
this.m02 = mx;
this.m12 = my;
if (mx == 0.0D && my == 0.0D) {
this.type = 0;
} else {
this.type = 1;
}
}
public void setToScale(double scx, double scy) {
this.m00 = scx;
this.m11 = scy;
this.m10 = this.m01 = this.m02 = this.m12 = 0.0D;
if (scx != 1.0D || scy != 1.0D) {
this.type = -1;
} else {
this.type = 0;
}
}
public void setToShear(double shx, double shy) {
this.m00 = this.m11 = 1.0D;
this.m02 = this.m12 = 0.0D;
this.m01 = shx;
this.m10 = shy;
if (shx != 0.0D || shy != 0.0D) {
this.type = -1;
} else {
this.type = 0;
}
}
public void setToRotation(double angle) {
double sin = Math.sin(angle);
double cos = Math.cos(angle);
if (Math.abs(cos) < 1.0E-10D) {
cos = 0.0D;
sin = (sin > 0.0D) ? 1.0D : -1.0D;
} else if (Math.abs(sin) < 1.0E-10D) {
sin = 0.0D;
cos = (cos > 0.0D) ? 1.0D : -1.0D;
}
this.m00 = this.m11 = cos;
this.m01 = -sin;
this.m10 = sin;
this.m02 = this.m12 = 0.0D;
this.type = -1;
}
public void setToRotation(double angle, double px, double py) {
setToRotation(angle);
this.m02 = px * (1.0D - this.m00) + py * this.m10;
this.m12 = py * (1.0D - this.m00) - px * this.m10;
this.type = -1;
}
public static AffineTransform getTranslateInstance(double mx, double my) {
AffineTransform t = new AffineTransform();
t.setToTranslation(mx, my);
return t;
}
public static AffineTransform getScaleInstance(double scx, double scY) {
AffineTransform t = new AffineTransform();
t.setToScale(scx, scY);
return t;
}
public static AffineTransform getShearInstance(double shx, double shy) {
AffineTransform m = new AffineTransform();
m.setToShear(shx, shy);
return m;
}
public static AffineTransform getRotateInstance(double angle) {
AffineTransform t = new AffineTransform();
t.setToRotation(angle);
return t;
}
public static AffineTransform getRotateInstance(double angle, double x, double y) {
AffineTransform t = new AffineTransform();
t.setToRotation(angle, x, y);
return t;
}
public void translate(double mx, double my) {
concatenate(getTranslateInstance(mx, my));
}
public void scale(double scx, double scy) {
concatenate(getScaleInstance(scx, scy));
}
public void shear(double shx, double shy) {
concatenate(getShearInstance(shx, shy));
}
public void rotate(double angle) {
concatenate(getRotateInstance(angle));
}
public void rotate(double angle, double px, double py) {
concatenate(getRotateInstance(angle, px, py));
}
AffineTransform multiply(AffineTransform t1, AffineTransform t2) {
return new AffineTransform(t1.m00 * t2.m00 + t1.m10 * t2.m01, t1.m00 * t2.m10 + t1.m10 * t2.m11, t1.m01 * t2.m00 + t1.m11 * t2.m01, t1.m01 * t2.m10 + t1.m11 * t2.m11, t1.m02 * t2.m00 + t1.m12 * t2.m01 + t2.m02, t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12);
}
public void concatenate(AffineTransform t) {
setTransform(multiply(t, this));
}
public void preConcatenate(AffineTransform t) {
setTransform(multiply(this, t));
}
public AffineTransform createInverse() throws NoninvertibleTransformException {
double det = getDeterminant();
if (Math.abs(det) < 1.0E-10D)
throw new NoninvertibleTransformException(Messages.getString("awt.204"));
return new AffineTransform(this.m11 / det, -this.m10 / det, -this.m01 / det, this.m00 / det, (this.m01 * this.m12 - this.m11 * this.m02) / det, (this.m10 * this.m02 - this.m00 * this.m12) / det);
}
public Point2D transform(Point2D src, Point2D dst) {
if (dst == null)
if (src instanceof Point2D.Double) {
dst = new Point2D.Double();
} else {
dst = new Point2D.Float();
}
double x = src.getX();
double y = src.getY();
dst.setLocation(x * this.m00 + y * this.m01 + this.m02, x * this.m10 + y * this.m11 + this.m12);
return dst;
}
public void transform(Point2D[] src, int srcOff, Point2D[] dst, int dstOff, int length) {
while (--length >= 0) {
Point2D srcPoint = src[srcOff++];
double x = srcPoint.getX();
double y = srcPoint.getY();
Point2D dstPoint = dst[dstOff];
if (dstPoint == null)
if (srcPoint instanceof Point2D.Double) {
dstPoint = new Point2D.Double();
} else {
dstPoint = new Point2D.Float();
}
dstPoint.setLocation(x * this.m00 + y * this.m01 + this.m02, x * this.m10 + y * this.m11 + this.m12);
dst[dstOff++] = dstPoint;
}
}
public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length) {
int step = 2;
if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) {
srcOff = srcOff + length * 2 - 2;
dstOff = dstOff + length * 2 - 2;
step = -2;
}
while (--length >= 0) {
double x = src[srcOff + 0];
double y = src[srcOff + 1];
dst[dstOff + 0] = x * this.m00 + y * this.m01 + this.m02;
dst[dstOff + 1] = x * this.m10 + y * this.m11 + this.m12;
srcOff += step;
dstOff += step;
}
}
public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
int step = 2;
if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) {
srcOff = srcOff + length * 2 - 2;
dstOff = dstOff + length * 2 - 2;
step = -2;
}
while (--length >= 0) {
float x = src[srcOff + 0];
float y = src[srcOff + 1];
dst[dstOff + 0] = (float)((double)x * this.m00 + (double)y * this.m01 + this.m02);
dst[dstOff + 1] = (float)((double)x * this.m10 + (double)y * this.m11 + this.m12);
srcOff += step;
dstOff += step;
}
}
public void transform(float[] src, int srcOff, double[] dst, int dstOff, int length) {
while (--length >= 0) {
float x = src[srcOff++];
float y = src[srcOff++];
dst[dstOff++] = (double)x * this.m00 + (double)y * this.m01 + this.m02;
dst[dstOff++] = (double)x * this.m10 + (double)y * this.m11 + this.m12;
}
}
public void transform(double[] src, int srcOff, float[] dst, int dstOff, int length) {
while (--length >= 0) {
double x = src[srcOff++];
double y = src[srcOff++];
dst[dstOff++] = (float)(x * this.m00 + y * this.m01 + this.m02);
dst[dstOff++] = (float)(x * this.m10 + y * this.m11 + this.m12);
}
}
public Point2D deltaTransform(Point2D src, Point2D dst) {
if (dst == null)
if (src instanceof Point2D.Double) {
dst = new Point2D.Double();
} else {
dst = new Point2D.Float();
}
double x = src.getX();
double y = src.getY();
dst.setLocation(x * this.m00 + y * this.m01, x * this.m10 + y * this.m11);
return dst;
}
public void deltaTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) {
while (--length >= 0) {
double x = src[srcOff++];
double y = src[srcOff++];
dst[dstOff++] = x * this.m00 + y * this.m01;
dst[dstOff++] = x * this.m10 + y * this.m11;
}
}
public Point2D inverseTransform(Point2D src, Point2D dst) throws NoninvertibleTransformException {
double det = getDeterminant();
if (Math.abs(det) < 1.0E-10D)
throw new NoninvertibleTransformException(Messages.getString("awt.204"));
if (dst == null)
if (src instanceof Point2D.Double) {
dst = new Point2D.Double();
} else {
dst = new Point2D.Float();
}
double x = src.getX() - this.m02;
double y = src.getY() - this.m12;
dst.setLocation((x * this.m11 - y * this.m01) / det, (y * this.m00 - x * this.m10) / det);
return dst;
}
public void inverseTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) throws NoninvertibleTransformException {
double det = getDeterminant();
if (Math.abs(det) < 1.0E-10D)
throw new NoninvertibleTransformException(Messages.getString("awt.204"));
while (--length >= 0) {
double x = src[srcOff++] - this.m02;
double y = src[srcOff++] - this.m12;
dst[dstOff++] = (x * this.m11 - y * this.m01) / det;
dst[dstOff++] = (y * this.m00 - x * this.m10) / det;
}
}
public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) throws NoninvertibleTransformException {
float det = (float)getDeterminant();
if ((double)Math.abs(det) < 1.0E-10D)
throw new NoninvertibleTransformException(Messages.getString("awt.204"));
while (--length >= 0) {
float x = src[srcOff++] - (float)this.m02;
float y = src[srcOff++] - (float)this.m12;
dst[dstOff++] = (x * (float)this.m11 - y * (float)this.m01) / det;
dst[dstOff++] = (y * (float)this.m00 - x * (float)this.m10) / det;
}
}
public Shape createTransformedShape(Shape src) {
if (src == null)
return null;
if (src instanceof GeneralPath)
return ((GeneralPath)src).createTransformedShape(this);
PathIterator path = src.getPathIterator(this);
GeneralPath dst = new GeneralPath(path.getWindingRule());
dst.append(path, false);
return dst;
}
public String toString() {
return getClass().getName() + "[[" + this.m00 + ", " + this.m01 + ", " + this.m02 + "], [" + this.m10 + ", " + this.m11 + ", " + this.m12 + "]]";
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
public int hashCode() {
HashCode hash = new HashCode();
hash.append(this.m00);
hash.append(this.m01);
hash.append(this.m02);
hash.append(this.m10);
hash.append(this.m11);
hash.append(this.m12);
return hash.hashCode();
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof AffineTransform) {
AffineTransform t = (AffineTransform)obj;
return (this.m00 == t.m00 && this.m01 == t.m01 && this.m02 == t.m02 && this.m10 == t.m10 && this.m11 == t.m11 && this.m12 == t.m12);
}
return false;
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
}
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.type = -1;
}
}

View file

@ -0,0 +1,489 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.gl.Crossing;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public abstract class CubicCurve2D implements Shape, Cloneable {
public abstract double getX1();
public abstract double getY1();
public abstract Point2D getP1();
public abstract double getCtrlX1();
public abstract double getCtrlY1();
public abstract Point2D getCtrlP1();
public abstract double getCtrlX2();
public abstract double getCtrlY2();
public abstract Point2D getCtrlP2();
public abstract double getX2();
public abstract double getY2();
public abstract Point2D getP2();
public abstract void setCurve(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, double paramDouble6, double paramDouble7, double paramDouble8);
public static class Float extends CubicCurve2D {
public float x1;
public float y1;
public float ctrlx1;
public float ctrly1;
public float ctrlx2;
public float ctrly2;
public float x2;
public float y2;
public Float() {}
public Float(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2) {
setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
}
public double getX1() {
return (double)this.x1;
}
public double getY1() {
return (double)this.y1;
}
public double getCtrlX1() {
return (double)this.ctrlx1;
}
public double getCtrlY1() {
return (double)this.ctrly1;
}
public double getCtrlX2() {
return (double)this.ctrlx2;
}
public double getCtrlY2() {
return (double)this.ctrly2;
}
public double getX2() {
return (double)this.x2;
}
public double getY2() {
return (double)this.y2;
}
public Point2D getP1() {
return new Point2D.Float(this.x1, this.y1);
}
public Point2D getCtrlP1() {
return new Point2D.Float(this.ctrlx1, this.ctrly1);
}
public Point2D getCtrlP2() {
return new Point2D.Float(this.ctrlx2, this.ctrly2);
}
public Point2D getP2() {
return new Point2D.Float(this.x2, this.y2);
}
public void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
this.x1 = (float)x1;
this.y1 = (float)y1;
this.ctrlx1 = (float)ctrlx1;
this.ctrly1 = (float)ctrly1;
this.ctrlx2 = (float)ctrlx2;
this.ctrly2 = (float)ctrly2;
this.x2 = (float)x2;
this.y2 = (float)y2;
}
public void setCurve(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2) {
this.x1 = x1;
this.y1 = y1;
this.ctrlx1 = ctrlx1;
this.ctrly1 = ctrly1;
this.ctrlx2 = ctrlx2;
this.ctrly2 = ctrly2;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
float rx1 = Math.min(Math.min(this.x1, this.x2), Math.min(this.ctrlx1, this.ctrlx2));
float ry1 = Math.min(Math.min(this.y1, this.y2), Math.min(this.ctrly1, this.ctrly2));
float rx2 = Math.max(Math.max(this.x1, this.x2), Math.max(this.ctrlx1, this.ctrlx2));
float ry2 = Math.max(Math.max(this.y1, this.y2), Math.max(this.ctrly1, this.ctrly2));
return new Rectangle2D.Float(rx1, ry1, rx2 - rx1, ry2 - ry1);
}
}
public static class Double extends CubicCurve2D {
public double x1;
public double y1;
public double ctrlx1;
public double ctrly1;
public double ctrlx2;
public double ctrly2;
public double x2;
public double y2;
public Double() {}
public Double(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
}
public double getX1() {
return this.x1;
}
public double getY1() {
return this.y1;
}
public double getCtrlX1() {
return this.ctrlx1;
}
public double getCtrlY1() {
return this.ctrly1;
}
public double getCtrlX2() {
return this.ctrlx2;
}
public double getCtrlY2() {
return this.ctrly2;
}
public double getX2() {
return this.x2;
}
public double getY2() {
return this.y2;
}
public Point2D getP1() {
return new Point2D.Double(this.x1, this.y1);
}
public Point2D getCtrlP1() {
return new Point2D.Double(this.ctrlx1, this.ctrly1);
}
public Point2D getCtrlP2() {
return new Point2D.Double(this.ctrlx2, this.ctrly2);
}
public Point2D getP2() {
return new Point2D.Double(this.x2, this.y2);
}
public void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
this.x1 = x1;
this.y1 = y1;
this.ctrlx1 = ctrlx1;
this.ctrly1 = ctrly1;
this.ctrlx2 = ctrlx2;
this.ctrly2 = ctrly2;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
double rx1 = Math.min(Math.min(this.x1, this.x2), Math.min(this.ctrlx1, this.ctrlx2));
double ry1 = Math.min(Math.min(this.y1, this.y2), Math.min(this.ctrly1, this.ctrly2));
double rx2 = Math.max(Math.max(this.x1, this.x2), Math.max(this.ctrlx1, this.ctrlx2));
double ry2 = Math.max(Math.max(this.y1, this.y2), Math.max(this.ctrly1, this.ctrly2));
return new Rectangle2D.Double(rx1, ry1, rx2 - rx1, ry2 - ry1);
}
}
class Iterator implements PathIterator {
CubicCurve2D c;
AffineTransform t;
int index;
Iterator(CubicCurve2D c, AffineTransform t) {
this.c = c;
this.t = t;
}
public int getWindingRule() {
return 1;
}
public boolean isDone() {
return (this.index > 1);
}
public void next() {
this.index++;
}
public int currentSegment(double[] coords) {
int type, count;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = this.c.getX1();
coords[1] = this.c.getY1();
count = 1;
} else {
type = 3;
coords[0] = this.c.getCtrlX1();
coords[1] = this.c.getCtrlY1();
coords[2] = this.c.getCtrlX2();
coords[3] = this.c.getCtrlY2();
coords[4] = this.c.getX2();
coords[5] = this.c.getY2();
count = 3;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count);
return type;
}
public int currentSegment(float[] coords) {
int type, count;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = (float)this.c.getX1();
coords[1] = (float)this.c.getY1();
count = 1;
} else {
type = 3;
coords[0] = (float)this.c.getCtrlX1();
coords[1] = (float)this.c.getCtrlY1();
coords[2] = (float)this.c.getCtrlX2();
coords[3] = (float)this.c.getCtrlY2();
coords[4] = (float)this.c.getX2();
coords[5] = (float)this.c.getY2();
count = 3;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count);
return type;
}
}
public void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2) {
setCurve(
p1.getX(), p1.getY(),
cp1.getX(), cp1.getY(),
cp2.getX(), cp2.getY(),
p2.getX(), p2.getY());
}
public void setCurve(double[] coords, int offset) {
setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6], coords[offset + 7]);
}
public void setCurve(Point2D[] points, int offset) {
setCurve(points[offset + 0]
.getX(), points[offset + 0].getY(), points[offset + 1]
.getX(), points[offset + 1].getY(), points[offset + 2]
.getX(), points[offset + 2].getY(), points[offset + 3]
.getX(), points[offset + 3].getY());
}
public void setCurve(CubicCurve2D curve) {
setCurve(
curve.getX1(), curve.getY1(),
curve.getCtrlX1(), curve.getCtrlY1(),
curve.getCtrlX2(), curve.getCtrlY2(),
curve.getX2(), curve.getY2());
}
public double getFlatnessSq() {
return getFlatnessSq(
getX1(), getY1(),
getCtrlX1(), getCtrlY1(),
getCtrlX2(), getCtrlY2(),
getX2(), getY2());
}
public static double getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
return Math.max(
Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx1, ctrly1),
Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx2, ctrly2));
}
public static double getFlatnessSq(double[] coords, int offset) {
return getFlatnessSq(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6], coords[offset + 7]);
}
public double getFlatness() {
return getFlatness(
getX1(), getY1(),
getCtrlX1(), getCtrlY1(),
getCtrlX2(), getCtrlY2(),
getX2(), getY2());
}
public static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
return Math.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
}
public static double getFlatness(double[] coords, int offset) {
return getFlatness(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], coords[offset + 4], coords[offset + 5], coords[offset + 6], coords[offset + 7]);
}
public void subdivide(CubicCurve2D left, CubicCurve2D right) {
subdivide(this, left, right);
}
public static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right) {
double x1 = src.getX1();
double y1 = src.getY1();
double cx1 = src.getCtrlX1();
double cy1 = src.getCtrlY1();
double cx2 = src.getCtrlX2();
double cy2 = src.getCtrlY2();
double x2 = src.getX2();
double y2 = src.getY2();
double cx = (cx1 + cx2) / 2.0D;
double cy = (cy1 + cy2) / 2.0D;
cx1 = (x1 + cx1) / 2.0D;
cy1 = (y1 + cy1) / 2.0D;
cx2 = (x2 + cx2) / 2.0D;
cy2 = (y2 + cy2) / 2.0D;
double ax = (cx1 + cx) / 2.0D;
double ay = (cy1 + cy) / 2.0D;
double bx = (cx2 + cx) / 2.0D;
double by = (cy2 + cy) / 2.0D;
cx = (ax + bx) / 2.0D;
cy = (ay + by) / 2.0D;
if (left != null)
left.setCurve(x1, y1, cx1, cy1, ax, ay, cx, cy);
if (right != null)
right.setCurve(cx, cy, bx, by, cx2, cy2, x2, y2);
}
public static void subdivide(double[] src, int srcOff, double[] left, int leftOff, double[] right, int rightOff) {
double x1 = src[srcOff + 0];
double y1 = src[srcOff + 1];
double cx1 = src[srcOff + 2];
double cy1 = src[srcOff + 3];
double cx2 = src[srcOff + 4];
double cy2 = src[srcOff + 5];
double x2 = src[srcOff + 6];
double y2 = src[srcOff + 7];
double cx = (cx1 + cx2) / 2.0D;
double cy = (cy1 + cy2) / 2.0D;
cx1 = (x1 + cx1) / 2.0D;
cy1 = (y1 + cy1) / 2.0D;
cx2 = (x2 + cx2) / 2.0D;
cy2 = (y2 + cy2) / 2.0D;
double ax = (cx1 + cx) / 2.0D;
double ay = (cy1 + cy) / 2.0D;
double bx = (cx2 + cx) / 2.0D;
double by = (cy2 + cy) / 2.0D;
cx = (ax + bx) / 2.0D;
cy = (ay + by) / 2.0D;
if (left != null) {
left[leftOff + 0] = x1;
left[leftOff + 1] = y1;
left[leftOff + 2] = cx1;
left[leftOff + 3] = cy1;
left[leftOff + 4] = ax;
left[leftOff + 5] = ay;
left[leftOff + 6] = cx;
left[leftOff + 7] = cy;
}
if (right != null) {
right[rightOff + 0] = cx;
right[rightOff + 1] = cy;
right[rightOff + 2] = bx;
right[rightOff + 3] = by;
right[rightOff + 4] = cx2;
right[rightOff + 5] = cy2;
right[rightOff + 6] = x2;
right[rightOff + 7] = y2;
}
}
public static int solveCubic(double[] eqn) {
return solveCubic(eqn, eqn);
}
public static int solveCubic(double[] eqn, double[] res) {
return Crossing.solveCubic(eqn, res);
}
public boolean contains(double px, double py) {
return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py));
}
public boolean contains(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross != 255 && Crossing.isInsideEvenOdd(cross));
}
public boolean intersects(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross == 255 || Crossing.isInsideEvenOdd(cross));
}
public boolean contains(Point2D p) {
return contains(p.getX(), p.getY());
}
public boolean intersects(Rectangle2D r) {
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean contains(Rectangle2D r) {
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public Rectangle getBounds() {
return getBounds2D().getBounds();
}
public PathIterator getPathIterator(AffineTransform t) {
return new Iterator(this, t);
}
public PathIterator getPathIterator(AffineTransform at, double flatness) {
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,74 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.HashCode;
import java.io.Serializable;
public class Dimension extends Dimension2D implements Serializable {
private static final long serialVersionUID = 4723952579491349524L;
public double width;
public double height;
public Dimension(Dimension d) {
this(d.width, d.height);
}
public Dimension() {
this(0, 0);
}
public Dimension(double width, double height) {
setSize(width, height);
}
public Dimension(int width, int height) {
setSize(width, height);
}
public int hashCode() {
HashCode hash = new HashCode();
hash.append(this.width);
hash.append(this.height);
return hash.hashCode();
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof Dimension) {
Dimension d = (Dimension)obj;
return (d.width == this.width && d.height == this.height);
}
return false;
}
public String toString() {
return getClass().getName() + "[width=" + this.width + ",height=" + this.height + "]";
}
public void setSize(int width, int height) {
this.width = (double)width;
this.height = (double)height;
}
public void setSize(Dimension d) {
setSize(d.width, d.height);
}
public void setSize(double width, double height) {
setSize((int)Math.ceil(width), (int)Math.ceil(height));
}
public Dimension getSize() {
return new Dimension(this.width, this.height);
}
public double getHeight() {
return this.height;
}
public double getWidth() {
return this.width;
}
}

View file

@ -0,0 +1,21 @@
package com.itextpdf.awt.geom;
public abstract class Dimension2D implements Cloneable {
public abstract double getWidth();
public abstract double getHeight();
public abstract void setSize(double paramDouble1, double paramDouble2);
public void setSize(Dimension2D d) {
setSize(d.getWidth(), d.getHeight());
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,179 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public class FlatteningPathIterator implements PathIterator {
private static final int BUFFER_SIZE = 16;
private static final int BUFFER_LIMIT = 16;
private static final int BUFFER_CAPACITY = 16;
int bufType;
int bufLimit;
int bufSize;
int bufIndex;
int bufSubdiv;
double[] buf;
boolean bufEmpty = true;
PathIterator p;
double flatness;
double flatness2;
double px;
double py;
double[] coords = new double[6];
public FlatteningPathIterator(PathIterator path, double flatness) {
this(path, flatness, 16);
}
public FlatteningPathIterator(PathIterator path, double flatness, int limit) {
if (flatness < 0.0D)
throw new IllegalArgumentException(Messages.getString("awt.206"));
if (limit < 0)
throw new IllegalArgumentException(Messages.getString("awt.207"));
if (path == null)
throw new NullPointerException(Messages.getString("awt.208"));
this.p = path;
this.flatness = flatness;
this.flatness2 = flatness * flatness;
this.bufLimit = limit;
this.bufSize = Math.min(this.bufLimit, 16);
this.buf = new double[this.bufSize];
this.bufIndex = this.bufSize;
}
public double getFlatness() {
return this.flatness;
}
public int getRecursionLimit() {
return this.bufLimit;
}
public int getWindingRule() {
return this.p.getWindingRule();
}
public boolean isDone() {
return (this.bufEmpty && this.p.isDone());
}
void evaluate() {
if (this.bufEmpty)
this.bufType = this.p.currentSegment(this.coords);
switch (this.bufType) {
case 0:
case 1:
this.px = this.coords[0];
this.py = this.coords[1];
break;
case 2:
if (this.bufEmpty) {
this.bufIndex -= 6;
this.buf[this.bufIndex + 0] = this.px;
this.buf[this.bufIndex + 1] = this.py;
System.arraycopy(this.coords, 0, this.buf, this.bufIndex + 2, 4);
this.bufSubdiv = 0;
}
while (this.bufSubdiv < this.bufLimit &&
QuadCurve2D.getFlatnessSq(this.buf, this.bufIndex) >= this.flatness2) {
if (this.bufIndex <= 4) {
double[] tmp = new double[this.bufSize + 16];
System.arraycopy(this.buf, this.bufIndex, tmp, this.bufIndex + 16, this.bufSize - this.bufIndex);
this.buf = tmp;
this.bufSize += 16;
this.bufIndex += 16;
}
QuadCurve2D.subdivide(this.buf, this.bufIndex, this.buf, this.bufIndex - 4, this.buf, this.bufIndex);
this.bufIndex -= 4;
this.bufSubdiv++;
}
this.bufIndex += 4;
this.px = this.buf[this.bufIndex];
this.py = this.buf[this.bufIndex + 1];
this.bufEmpty = (this.bufIndex == this.bufSize - 2);
if (this.bufEmpty) {
this.bufIndex = this.bufSize;
this.bufType = 1;
}
break;
case 3:
if (this.bufEmpty) {
this.bufIndex -= 8;
this.buf[this.bufIndex + 0] = this.px;
this.buf[this.bufIndex + 1] = this.py;
System.arraycopy(this.coords, 0, this.buf, this.bufIndex + 2, 6);
this.bufSubdiv = 0;
}
while (this.bufSubdiv < this.bufLimit &&
CubicCurve2D.getFlatnessSq(this.buf, this.bufIndex) >= this.flatness2) {
if (this.bufIndex <= 6) {
double[] tmp = new double[this.bufSize + 16];
System.arraycopy(this.buf, this.bufIndex, tmp, this.bufIndex + 16, this.bufSize - this.bufIndex);
this.buf = tmp;
this.bufSize += 16;
this.bufIndex += 16;
}
CubicCurve2D.subdivide(this.buf, this.bufIndex, this.buf, this.bufIndex - 6, this.buf, this.bufIndex);
this.bufIndex -= 6;
this.bufSubdiv++;
}
this.bufIndex += 6;
this.px = this.buf[this.bufIndex];
this.py = this.buf[this.bufIndex + 1];
this.bufEmpty = (this.bufIndex == this.bufSize - 2);
if (this.bufEmpty) {
this.bufIndex = this.bufSize;
this.bufType = 1;
}
break;
}
}
public void next() {
if (this.bufEmpty)
this.p.next();
}
public int currentSegment(float[] coords) {
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4Bx"));
evaluate();
int type = this.bufType;
if (type != 4) {
coords[0] = (float)this.px;
coords[1] = (float)this.py;
if (type != 0)
type = 1;
}
return type;
}
public int currentSegment(double[] coords) {
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
evaluate();
int type = this.bufType;
if (type != 4) {
coords[0] = this.px;
coords[1] = this.py;
if (type != 0)
type = 1;
}
return type;
}
}

View file

@ -0,0 +1,321 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.gl.Crossing;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public final class GeneralPath implements Shape, Cloneable {
public static final int WIND_EVEN_ODD = 0;
public static final int WIND_NON_ZERO = 1;
private static final int BUFFER_SIZE = 10;
private static final int BUFFER_CAPACITY = 10;
byte[] types;
float[] points;
int typeSize;
int pointSize;
int rule;
static int[] pointShift = new int[] { 2, 2, 4, 6, 0 };
class Iterator implements PathIterator {
int typeIndex;
int pointIndex;
GeneralPath p;
AffineTransform t;
Iterator(GeneralPath path) {
this(path, null);
}
Iterator(GeneralPath path, AffineTransform at) {
this.p = path;
this.t = at;
}
public int getWindingRule() {
return this.p.getWindingRule();
}
public boolean isDone() {
return (this.typeIndex >= this.p.typeSize);
}
public void next() {
this.typeIndex++;
}
public int currentSegment(double[] coords) {
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
int type = this.p.types[this.typeIndex];
int count = GeneralPath.pointShift[type];
for (int i = 0; i < count; i++)
coords[i] = (double)this.p.points[this.pointIndex + i];
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count / 2);
this.pointIndex += count;
return type;
}
public int currentSegment(float[] coords) {
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
int type = this.p.types[this.typeIndex];
int count = GeneralPath.pointShift[type];
System.arraycopy(this.p.points, this.pointIndex, coords, 0, count);
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count / 2);
this.pointIndex += count;
return type;
}
}
public GeneralPath() {
this(1, 10);
}
public GeneralPath(int rule) {
this(rule, 10);
}
public GeneralPath(int rule, int initialCapacity) {
setWindingRule(rule);
this.types = new byte[initialCapacity];
this.points = new float[initialCapacity * 2];
}
public GeneralPath(Shape shape) {
this(1, 10);
PathIterator p = shape.getPathIterator(null);
setWindingRule(p.getWindingRule());
append(p, false);
}
public void setWindingRule(int rule) {
if (rule != 0 && rule != 1)
throw new IllegalArgumentException(Messages.getString("awt.209"));
this.rule = rule;
}
public int getWindingRule() {
return this.rule;
}
void checkBuf(int pointCount, boolean checkMove) {
if (checkMove && this.typeSize == 0)
throw new IllegalPathStateException(Messages.getString("awt.20A"));
if (this.typeSize == this.types.length) {
byte[] tmp = new byte[this.typeSize + 10];
System.arraycopy(this.types, 0, tmp, 0, this.typeSize);
this.types = tmp;
}
if (this.pointSize + pointCount > this.points.length) {
float[] tmp = new float[this.pointSize + Math.max(20, pointCount)];
System.arraycopy(this.points, 0, tmp, 0, this.pointSize);
this.points = tmp;
}
}
public void moveTo(float x, float y) {
if (this.typeSize > 0 && this.types[this.typeSize - 1] == 0) {
this.points[this.pointSize - 2] = x;
this.points[this.pointSize - 1] = y;
} else {
checkBuf(2, false);
this.types[this.typeSize++] = 0;
this.points[this.pointSize++] = x;
this.points[this.pointSize++] = y;
}
}
public void lineTo(float x, float y) {
checkBuf(2, true);
this.types[this.typeSize++] = 1;
this.points[this.pointSize++] = x;
this.points[this.pointSize++] = y;
}
public void quadTo(float x1, float y1, float x2, float y2) {
checkBuf(4, true);
this.types[this.typeSize++] = 2;
this.points[this.pointSize++] = x1;
this.points[this.pointSize++] = y1;
this.points[this.pointSize++] = x2;
this.points[this.pointSize++] = y2;
}
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
checkBuf(6, true);
this.types[this.typeSize++] = 3;
this.points[this.pointSize++] = x1;
this.points[this.pointSize++] = y1;
this.points[this.pointSize++] = x2;
this.points[this.pointSize++] = y2;
this.points[this.pointSize++] = x3;
this.points[this.pointSize++] = y3;
}
public void closePath() {
if (this.typeSize == 0 || this.types[this.typeSize - 1] != 4) {
checkBuf(0, true);
this.types[this.typeSize++] = 4;
}
}
public void append(Shape shape, boolean connect) {
PathIterator p = shape.getPathIterator(null);
append(p, connect);
}
public void append(PathIterator path, boolean connect) {
while (!path.isDone()) {
float[] coords = new float[6];
switch (path.currentSegment(coords)) {
case 0:
if (!connect || this.typeSize == 0) {
moveTo(coords[0], coords[1]);
break;
}
if (this.types[this.typeSize - 1] != 4 && this.points[this.pointSize - 2] == coords[0] && this.points[this.pointSize - 1] == coords[1])
break;
case 1:
lineTo(coords[0], coords[1]);
break;
case 2:
quadTo(coords[0], coords[1], coords[2], coords[3]);
break;
case 3:
curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
break;
case 4:
closePath();
break;
}
path.next();
connect = false;
}
}
public Point2D getCurrentPoint() {
if (this.typeSize == 0)
return null;
int j = this.pointSize - 2;
if (this.types[this.typeSize - 1] == 4)
for (int i = this.typeSize - 2; i > 0; i--) {
int type = this.types[i];
if (type == 0)
break;
j -= pointShift[type];
}
return new Point2D.Float(this.points[j], this.points[j + 1]);
}
public void reset() {
this.typeSize = 0;
this.pointSize = 0;
}
public void transform(AffineTransform t) {
t.transform(this.points, 0, this.points, 0, this.pointSize / 2);
}
public Shape createTransformedShape(AffineTransform t) {
GeneralPath p = (GeneralPath)clone();
if (t != null)
p.transform(t);
return p;
}
public Rectangle2D getBounds2D() {
float rx1, ry1, rx2, ry2;
if (this.pointSize == 0) {
rx1 = ry1 = rx2 = ry2 = 0.0F;
} else {
int i = this.pointSize - 1;
ry1 = ry2 = this.points[i--];
rx1 = rx2 = this.points[i--];
while (i > 0) {
float y = this.points[i--];
float x = this.points[i--];
if (x < rx1) {
rx1 = x;
} else if (x > rx2) {
rx2 = x;
}
if (y < ry1) {
ry1 = y;
continue;
}
if (y > ry2)
ry2 = y;
}
}
return new Rectangle2D.Float(rx1, ry1, rx2 - rx1, ry2 - ry1);
}
public Rectangle getBounds() {
return getBounds2D().getBounds();
}
boolean isInside(int cross) {
if (this.rule == 1)
return Crossing.isInsideNonZero(cross);
return Crossing.isInsideEvenOdd(cross);
}
public boolean contains(double px, double py) {
return isInside(Crossing.crossShape(this, px, py));
}
public boolean contains(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross != 255 && isInside(cross));
}
public boolean intersects(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross == 255 || isInside(cross));
}
public boolean contains(Point2D p) {
return contains(p.getX(), p.getY());
}
public boolean contains(Rectangle2D r) {
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean intersects(Rectangle2D r) {
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public PathIterator getPathIterator(AffineTransform t) {
return new Iterator(this, t);
}
public PathIterator getPathIterator(AffineTransform t, double flatness) {
return new FlatteningPathIterator(getPathIterator(t), flatness);
}
public Object clone() {
try {
GeneralPath p = (GeneralPath)super.clone();
p.types = (byte[])this.types.clone();
p.points = (float[])this.points.clone();
return p;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,11 @@
package com.itextpdf.awt.geom;
public class IllegalPathStateException extends RuntimeException {
private static final long serialVersionUID = -5158084205220481094L;
public IllegalPathStateException() {}
public IllegalPathStateException(String s) {
super(s);
}
}

View file

@ -0,0 +1,416 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public abstract class Line2D implements Shape, Cloneable {
public abstract double getX1();
public abstract double getY1();
public abstract double getX2();
public abstract double getY2();
public abstract Point2D getP1();
public abstract Point2D getP2();
public abstract void setLine(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4);
public static class Float extends Line2D {
public float x1;
public float y1;
public float x2;
public float y2;
public Float() {}
public Float(float x1, float y1, float x2, float y2) {
setLine(x1, y1, x2, y2);
}
public Float(Point2D p1, Point2D p2) {
setLine(p1, p2);
}
public double getX1() {
return (double)this.x1;
}
public double getY1() {
return (double)this.y1;
}
public double getX2() {
return (double)this.x2;
}
public double getY2() {
return (double)this.y2;
}
public Point2D getP1() {
return new Point2D.Float(this.x1, this.y1);
}
public Point2D getP2() {
return new Point2D.Float(this.x2, this.y2);
}
public void setLine(double x1, double y1, double x2, double y2) {
this.x1 = (float)x1;
this.y1 = (float)y1;
this.x2 = (float)x2;
this.y2 = (float)y2;
}
public void setLine(float x1, float y1, float x2, float y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
float rx, ry, rw, rh;
if (this.x1 < this.x2) {
rx = this.x1;
rw = this.x2 - this.x1;
} else {
rx = this.x2;
rw = this.x1 - this.x2;
}
if (this.y1 < this.y2) {
ry = this.y1;
rh = this.y2 - this.y1;
} else {
ry = this.y2;
rh = this.y1 - this.y2;
}
return new Rectangle2D.Float(rx, ry, rw, rh);
}
}
public static class Double extends Line2D {
public double x1;
public double y1;
public double x2;
public double y2;
public Double() {}
public Double(double x1, double y1, double x2, double y2) {
setLine(x1, y1, x2, y2);
}
public Double(Point2D p1, Point2D p2) {
setLine(p1, p2);
}
public double getX1() {
return this.x1;
}
public double getY1() {
return this.y1;
}
public double getX2() {
return this.x2;
}
public double getY2() {
return this.y2;
}
public Point2D getP1() {
return new Point2D.Double(this.x1, this.y1);
}
public Point2D getP2() {
return new Point2D.Double(this.x2, this.y2);
}
public void setLine(double x1, double y1, double x2, double y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
double rx, ry, rw, rh;
if (this.x1 < this.x2) {
rx = this.x1;
rw = this.x2 - this.x1;
} else {
rx = this.x2;
rw = this.x1 - this.x2;
}
if (this.y1 < this.y2) {
ry = this.y1;
rh = this.y2 - this.y1;
} else {
ry = this.y2;
rh = this.y1 - this.y2;
}
return new Rectangle2D.Double(rx, ry, rw, rh);
}
}
class Iterator implements PathIterator {
double x1;
double y1;
double x2;
double y2;
AffineTransform t;
int index;
Iterator(Line2D l, AffineTransform at) {
this.x1 = l.getX1();
this.y1 = l.getY1();
this.x2 = l.getX2();
this.y2 = l.getY2();
this.t = at;
}
public int getWindingRule() {
return 1;
}
public boolean isDone() {
return (this.index > 1);
}
public void next() {
this.index++;
}
public int currentSegment(double[] coords) {
int type;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = this.x1;
coords[1] = this.y1;
} else {
type = 1;
coords[0] = this.x2;
coords[1] = this.y2;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, 1);
return type;
}
public int currentSegment(float[] coords) {
int type;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = (float)this.x1;
coords[1] = (float)this.y1;
} else {
type = 1;
coords[0] = (float)this.x2;
coords[1] = (float)this.y2;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, 1);
return type;
}
}
public void setLine(Point2D p1, Point2D p2) {
setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
}
public void setLine(Line2D line) {
setLine(line.getX1(), line.getY1(), line.getX2(), line.getY2());
}
public Rectangle getBounds() {
return getBounds2D().getBounds();
}
public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py) {
x2 -= x1;
y2 -= y1;
px -= x1;
py -= y1;
double t = px * y2 - py * x2;
if (t == 0.0D) {
t = px * x2 + py * y2;
if (t > 0.0D) {
px -= x2;
py -= y2;
t = px * x2 + py * y2;
if (t < 0.0D)
t = 0.0D;
}
}
return (t < 0.0D) ? -1 : ((t > 0.0D) ? 1 : 0);
}
public int relativeCCW(double px, double py) {
return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py);
}
public int relativeCCW(Point2D p) {
return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
}
public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
x2 -= x1;
y2 -= y1;
x3 -= x1;
y3 -= y1;
x4 -= x1;
y4 -= y1;
double AvB = x2 * y3 - x3 * y2;
double AvC = x2 * y4 - x4 * y2;
if (AvB == 0.0D && AvC == 0.0D) {
if (x2 != 0.0D)
return (x4 * x3 <= 0.0D || (x3 * x2 >= 0.0D && ((x2 > 0.0D) ? (x3 <= x2 || x4 <= x2) : (x3 >= x2 || x4 >= x2))));
if (y2 != 0.0D)
return (y4 * y3 <= 0.0D || (y3 * y2 >= 0.0D && ((y2 > 0.0D) ? (y3 <= y2 || y4 <= y2) : (y3 >= y2 || y4 >= y2))));
return false;
}
double BvC = x3 * y4 - x4 * y3;
return (AvB * AvC <= 0.0D && BvC * (AvB + BvC - AvC) <= 0.0D);
}
public boolean intersectsLine(double x1, double y1, double x2, double y2) {
return linesIntersect(x1, y1, x2, y2, getX1(), getY1(), getX2(), getY2());
}
public boolean intersectsLine(Line2D l) {
return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(), getX1(), getY1(), getX2(), getY2());
}
public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py) {
double dist;
x2 -= x1;
y2 -= y1;
px -= x1;
py -= y1;
if (px * x2 + py * y2 <= 0.0D) {
dist = px * px + py * py;
} else {
px = x2 - px;
py = y2 - py;
if (px * x2 + py * y2 <= 0.0D) {
dist = px * px + py * py;
} else {
dist = px * y2 - py * x2;
dist = dist * dist / (x2 * x2 + y2 * y2);
}
}
if (dist < 0.0D)
dist = 0.0D;
return dist;
}
public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py) {
return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py));
}
public double ptSegDistSq(double px, double py) {
return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
}
public double ptSegDistSq(Point2D p) {
return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
}
public double ptSegDist(double px, double py) {
return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py);
}
public double ptSegDist(Point2D p) {
return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
}
public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py) {
x2 -= x1;
y2 -= y1;
px -= x1;
py -= y1;
double s = px * y2 - py * x2;
return s * s / (x2 * x2 + y2 * y2);
}
public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py) {
return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py));
}
public double ptLineDistSq(double px, double py) {
return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
}
public double ptLineDistSq(Point2D p) {
return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
}
public double ptLineDist(double px, double py) {
return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py);
}
public double ptLineDist(Point2D p) {
return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
}
public boolean contains(double px, double py) {
return false;
}
public boolean contains(Point2D p) {
return false;
}
public boolean contains(Rectangle2D r) {
return false;
}
public boolean contains(double rx, double ry, double rw, double rh) {
return false;
}
public boolean intersects(double rx, double ry, double rw, double rh) {
return intersects(new Rectangle2D.Double(rx, ry, rw, rh));
}
public boolean intersects(Rectangle2D r) {
return r.intersectsLine(getX1(), getY1(), getX2(), getY2());
}
public PathIterator getPathIterator(AffineTransform at) {
return new Iterator(this, at);
}
public PathIterator getPathIterator(AffineTransform at, double flatness) {
return new Iterator(this, at);
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,9 @@
package com.itextpdf.awt.geom;
public class NoninvertibleTransformException extends Exception {
private static final long serialVersionUID = 6137225240503990466L;
public NoninvertibleTransformException(String s) {
super(s);
}
}

View file

@ -0,0 +1,27 @@
package com.itextpdf.awt.geom;
public interface PathIterator {
public static final int WIND_EVEN_ODD = 0;
public static final int WIND_NON_ZERO = 1;
public static final int SEG_MOVETO = 0;
public static final int SEG_LINETO = 1;
public static final int SEG_QUADTO = 2;
public static final int SEG_CUBICTO = 3;
public static final int SEG_CLOSE = 4;
int getWindingRule();
boolean isDone();
void next();
int currentSegment(float[] paramArrayOffloat);
int currentSegment(double[] paramArrayOfdouble);
}

View file

@ -0,0 +1,83 @@
package com.itextpdf.awt.geom;
import java.io.Serializable;
public class Point extends Point2D implements Serializable {
private static final long serialVersionUID = -5276940640259749850L;
public double x;
public double y;
public Point() {
setLocation(0, 0);
}
public Point(int x, int y) {
setLocation(x, y);
}
public Point(double x, double y) {
setLocation(x, y);
}
public Point(Point p) {
setLocation(p.x, p.y);
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof Point) {
Point p = (Point)obj;
return (this.x == p.x && this.y == p.y);
}
return false;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + "]";
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public Point getLocation() {
return new Point(this.x, this.y);
}
public void setLocation(Point p) {
setLocation(p.x, p.y);
}
public void setLocation(int x, int y) {
setLocation((double)x, (double)y);
}
public void setLocation(double x, double y) {
this.x = x;
this.y = y;
}
public void move(int x, int y) {
move((double)x, (double)y);
}
public void move(double x, double y) {
setLocation(x, y);
}
public void translate(int dx, int dy) {
translate((double)dx, (double)dy);
}
public void translate(double dx, double dy) {
this.x += dx;
this.y += dy;
}
}

View file

@ -0,0 +1,131 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.HashCode;
public abstract class Point2D implements Cloneable {
public abstract double getX();
public abstract double getY();
public abstract void setLocation(double paramDouble1, double paramDouble2);
public static class Float extends Point2D {
public float x;
public float y;
public Float() {}
public Float(float x, float y) {
this.x = x;
this.y = y;
}
public double getX() {
return (double)this.x;
}
public double getY() {
return (double)this.y;
}
public void setLocation(float x, float y) {
this.x = x;
this.y = y;
}
public void setLocation(double x, double y) {
this.x = (float)x;
this.y = (float)y;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + "]";
}
}
public static class Double extends Point2D {
public double x;
public double y;
public Double() {}
public Double(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public void setLocation(double x, double y) {
this.x = x;
this.y = y;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + "]";
}
}
public void setLocation(Point2D p) {
setLocation(p.getX(), p.getY());
}
public static double distanceSq(double x1, double y1, double x2, double y2) {
x2 -= x1;
y2 -= y1;
return x2 * x2 + y2 * y2;
}
public double distanceSq(double px, double py) {
return distanceSq(getX(), getY(), px, py);
}
public double distanceSq(Point2D p) {
return distanceSq(getX(), getY(), p.getX(), p.getY());
}
public static double distance(double x1, double y1, double x2, double y2) {
return Math.sqrt(distanceSq(x1, y1, x2, y2));
}
public double distance(double px, double py) {
return Math.sqrt(distanceSq(px, py));
}
public double distance(Point2D p) {
return Math.sqrt(distanceSq(p));
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
public int hashCode() {
HashCode hash = new HashCode();
hash.append(getX());
hash.append(getY());
return hash.hashCode();
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof Point2D) {
Point2D p = (Point2D)obj;
return (getX() == p.getX() && getY() == p.getY());
}
return false;
}
}

View file

@ -0,0 +1,85 @@
package com.itextpdf.awt.geom;
public class PolylineShape implements java.awt.Shape {
protected int[] x;
protected int[] y;
protected int np;
public PolylineShape(int[] x, int[] y, int nPoints) {
this.np = nPoints;
this.x = new int[this.np];
this.y = new int[this.np];
System.arraycopy(x, 0, this.x, 0, this.np);
System.arraycopy(y, 0, this.y, 0, this.np);
}
public java.awt.geom.Rectangle2D getBounds2D() {
int[] r = rect();
return (r == null) ? null : new java.awt.geom.Rectangle2D.Double((double)r[0], (double)r[1], (double)r[2], (double)r[3]);
}
public java.awt.Rectangle getBounds() {
return getBounds2D().getBounds();
}
private int[] rect() {
if (this.np == 0)
return null;
int xMin = this.x[0], yMin = this.y[0], xMax = this.x[0], yMax = this.y[0];
for (int i = 1; i < this.np; i++) {
if (this.x[i] < xMin) {
xMin = this.x[i];
} else if (this.x[i] > xMax) {
xMax = this.x[i];
}
if (this.y[i] < yMin) {
yMin = this.y[i];
} else if (this.y[i] > yMax) {
yMax = this.y[i];
}
}
return new int[] { xMin, yMin, xMax - xMin, yMax - yMin };
}
public boolean contains(double x, double y) {
return false;
}
public boolean contains(java.awt.geom.Point2D p) {
return false;
}
public boolean contains(double x, double y, double w, double h) {
return false;
}
public boolean contains(java.awt.geom.Rectangle2D r) {
return false;
}
public boolean intersects(double x, double y, double w, double h) {
return intersects(new java.awt.geom.Rectangle2D.Double(x, y, w, h));
}
public boolean intersects(java.awt.geom.Rectangle2D r) {
if (this.np == 0)
return false;
java.awt.geom.Line2D line = new java.awt.geom.Line2D.Double((double)this.x[0], (double)this.y[0], (double)this.x[0], (double)this.y[0]);
for (int i = 1; i < this.np; i++) {
line.setLine((double)this.x[i - 1], (double)this.y[i - 1], (double)this.x[i], (double)this.y[i]);
if (line.intersects(r))
return true;
}
return false;
}
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at) {
return new PolylineShapeIterator(this, at);
}
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness) {
return new PolylineShapeIterator(this, at);
}
}

View file

@ -0,0 +1,51 @@
package com.itextpdf.awt.geom;
import com.itextpdf.text.error_messages.MessageLocalization;
import java.util.NoSuchElementException;
public class PolylineShapeIterator implements java.awt.geom.PathIterator {
protected PolylineShape poly;
protected java.awt.geom.AffineTransform affine;
protected int index;
PolylineShapeIterator(PolylineShape l, java.awt.geom.AffineTransform at) {
this.poly = l;
this.affine = at;
}
public int currentSegment(double[] coords) {
if (isDone())
throw new NoSuchElementException(MessageLocalization.getComposedMessage("line.iterator.out.of.bounds"));
int type = (this.index == 0) ? 0 : 1;
coords[0] = (double)this.poly.x[this.index];
coords[1] = (double)this.poly.y[this.index];
if (this.affine != null)
this.affine.transform(coords, 0, coords, 0, 1);
return type;
}
public int currentSegment(float[] coords) {
if (isDone())
throw new NoSuchElementException(MessageLocalization.getComposedMessage("line.iterator.out.of.bounds"));
int type = (this.index == 0) ? 0 : 1;
coords[0] = (float)this.poly.x[this.index];
coords[1] = (float)this.poly.y[this.index];
if (this.affine != null)
this.affine.transform(coords, 0, coords, 0, 1);
return type;
}
public int getWindingRule() {
return 1;
}
public boolean isDone() {
return (this.index >= this.poly.np);
}
public void next() {
this.index++;
}
}

View file

@ -0,0 +1,408 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.gl.Crossing;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public abstract class QuadCurve2D implements Shape, Cloneable {
public abstract double getX1();
public abstract double getY1();
public abstract Point2D getP1();
public abstract double getCtrlX();
public abstract double getCtrlY();
public abstract Point2D getCtrlPt();
public abstract double getX2();
public abstract double getY2();
public abstract Point2D getP2();
public abstract void setCurve(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, double paramDouble6);
public static class Float extends QuadCurve2D {
public float x1;
public float y1;
public float ctrlx;
public float ctrly;
public float x2;
public float y2;
public Float() {}
public Float(float x1, float y1, float ctrlx, float ctrly, float x2, float y2) {
setCurve(x1, y1, ctrlx, ctrly, x2, y2);
}
public double getX1() {
return (double)this.x1;
}
public double getY1() {
return (double)this.y1;
}
public double getCtrlX() {
return (double)this.ctrlx;
}
public double getCtrlY() {
return (double)this.ctrly;
}
public double getX2() {
return (double)this.x2;
}
public double getY2() {
return (double)this.y2;
}
public Point2D getP1() {
return new Point2D.Float(this.x1, this.y1);
}
public Point2D getCtrlPt() {
return new Point2D.Float(this.ctrlx, this.ctrly);
}
public Point2D getP2() {
return new Point2D.Float(this.x2, this.y2);
}
public void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) {
this.x1 = (float)x1;
this.y1 = (float)y1;
this.ctrlx = (float)ctrlx;
this.ctrly = (float)ctrly;
this.x2 = (float)x2;
this.y2 = (float)y2;
}
public void setCurve(float x1, float y1, float ctrlx, float ctrly, float x2, float y2) {
this.x1 = x1;
this.y1 = y1;
this.ctrlx = ctrlx;
this.ctrly = ctrly;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
float rx0 = Math.min(Math.min(this.x1, this.x2), this.ctrlx);
float ry0 = Math.min(Math.min(this.y1, this.y2), this.ctrly);
float rx1 = Math.max(Math.max(this.x1, this.x2), this.ctrlx);
float ry1 = Math.max(Math.max(this.y1, this.y2), this.ctrly);
return new Rectangle2D.Float(rx0, ry0, rx1 - rx0, ry1 - ry0);
}
}
public static class Double extends QuadCurve2D {
public double x1;
public double y1;
public double ctrlx;
public double ctrly;
public double x2;
public double y2;
public Double() {}
public Double(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) {
setCurve(x1, y1, ctrlx, ctrly, x2, y2);
}
public double getX1() {
return this.x1;
}
public double getY1() {
return this.y1;
}
public double getCtrlX() {
return this.ctrlx;
}
public double getCtrlY() {
return this.ctrly;
}
public double getX2() {
return this.x2;
}
public double getY2() {
return this.y2;
}
public Point2D getP1() {
return new Point2D.Double(this.x1, this.y1);
}
public Point2D getCtrlPt() {
return new Point2D.Double(this.ctrlx, this.ctrly);
}
public Point2D getP2() {
return new Point2D.Double(this.x2, this.y2);
}
public void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) {
this.x1 = x1;
this.y1 = y1;
this.ctrlx = ctrlx;
this.ctrly = ctrly;
this.x2 = x2;
this.y2 = y2;
}
public Rectangle2D getBounds2D() {
double rx0 = Math.min(Math.min(this.x1, this.x2), this.ctrlx);
double ry0 = Math.min(Math.min(this.y1, this.y2), this.ctrly);
double rx1 = Math.max(Math.max(this.x1, this.x2), this.ctrlx);
double ry1 = Math.max(Math.max(this.y1, this.y2), this.ctrly);
return new Rectangle2D.Double(rx0, ry0, rx1 - rx0, ry1 - ry0);
}
}
class Iterator implements PathIterator {
QuadCurve2D c;
AffineTransform t;
int index;
Iterator(QuadCurve2D q, AffineTransform t) {
this.c = q;
this.t = t;
}
public int getWindingRule() {
return 1;
}
public boolean isDone() {
return (this.index > 1);
}
public void next() {
this.index++;
}
public int currentSegment(double[] coords) {
int type, count;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = this.c.getX1();
coords[1] = this.c.getY1();
count = 1;
} else {
type = 2;
coords[0] = this.c.getCtrlX();
coords[1] = this.c.getCtrlY();
coords[2] = this.c.getX2();
coords[3] = this.c.getY2();
count = 2;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count);
return type;
}
public int currentSegment(float[] coords) {
int type, count;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 0) {
type = 0;
coords[0] = (float)this.c.getX1();
coords[1] = (float)this.c.getY1();
count = 1;
} else {
type = 2;
coords[0] = (float)this.c.getCtrlX();
coords[1] = (float)this.c.getCtrlY();
coords[2] = (float)this.c.getX2();
coords[3] = (float)this.c.getY2();
count = 2;
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, count);
return type;
}
}
public void setCurve(Point2D p1, Point2D cp, Point2D p2) {
setCurve(p1.getX(), p1.getY(), cp.getX(), cp.getY(), p2.getX(), p2.getY());
}
public void setCurve(double[] coords, int offset) {
setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3], coords[offset + 4], coords[offset + 5]);
}
public void setCurve(Point2D[] points, int offset) {
setCurve(points[offset + 0]
.getX(), points[offset + 0].getY(), points[offset + 1]
.getX(), points[offset + 1].getY(), points[offset + 2]
.getX(), points[offset + 2].getY());
}
public void setCurve(QuadCurve2D curve) {
setCurve(
curve.getX1(), curve.getY1(),
curve.getCtrlX(), curve.getCtrlY(),
curve.getX2(), curve.getY2());
}
public double getFlatnessSq() {
return Line2D.ptSegDistSq(
getX1(), getY1(),
getX2(), getY2(),
getCtrlX(), getCtrlY());
}
public static double getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) {
return Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx, ctrly);
}
public static double getFlatnessSq(double[] coords, int offset) {
return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], coords[offset + 4], coords[offset + 5], coords[offset + 2], coords[offset + 3]);
}
public double getFlatness() {
return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY());
}
public static double getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2) {
return Line2D.ptSegDist(x1, y1, x2, y2, ctrlx, ctrly);
}
public static double getFlatness(double[] coords, int offset) {
return Line2D.ptSegDist(coords[offset + 0], coords[offset + 1], coords[offset + 4], coords[offset + 5], coords[offset + 2], coords[offset + 3]);
}
public void subdivide(QuadCurve2D left, QuadCurve2D right) {
subdivide(this, left, right);
}
public static void subdivide(QuadCurve2D src, QuadCurve2D left, QuadCurve2D right) {
double x1 = src.getX1();
double y1 = src.getY1();
double cx = src.getCtrlX();
double cy = src.getCtrlY();
double x2 = src.getX2();
double y2 = src.getY2();
double cx1 = (x1 + cx) / 2.0D;
double cy1 = (y1 + cy) / 2.0D;
double cx2 = (x2 + cx) / 2.0D;
double cy2 = (y2 + cy) / 2.0D;
cx = (cx1 + cx2) / 2.0D;
cy = (cy1 + cy2) / 2.0D;
if (left != null)
left.setCurve(x1, y1, cx1, cy1, cx, cy);
if (right != null)
right.setCurve(cx, cy, cx2, cy2, x2, y2);
}
public static void subdivide(double[] src, int srcoff, double[] left, int leftOff, double[] right, int rightOff) {
double x1 = src[srcoff + 0];
double y1 = src[srcoff + 1];
double cx = src[srcoff + 2];
double cy = src[srcoff + 3];
double x2 = src[srcoff + 4];
double y2 = src[srcoff + 5];
double cx1 = (x1 + cx) / 2.0D;
double cy1 = (y1 + cy) / 2.0D;
double cx2 = (x2 + cx) / 2.0D;
double cy2 = (y2 + cy) / 2.0D;
cx = (cx1 + cx2) / 2.0D;
cy = (cy1 + cy2) / 2.0D;
if (left != null) {
left[leftOff + 0] = x1;
left[leftOff + 1] = y1;
left[leftOff + 2] = cx1;
left[leftOff + 3] = cy1;
left[leftOff + 4] = cx;
left[leftOff + 5] = cy;
}
if (right != null) {
right[rightOff + 0] = cx;
right[rightOff + 1] = cy;
right[rightOff + 2] = cx2;
right[rightOff + 3] = cy2;
right[rightOff + 4] = x2;
right[rightOff + 5] = y2;
}
}
public static int solveQuadratic(double[] eqn) {
return solveQuadratic(eqn, eqn);
}
public static int solveQuadratic(double[] eqn, double[] res) {
return Crossing.solveQuad(eqn, res);
}
public boolean contains(double px, double py) {
return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py));
}
public boolean contains(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross != 255 && Crossing.isInsideEvenOdd(cross));
}
public boolean intersects(double rx, double ry, double rw, double rh) {
int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
return (cross == 255 || Crossing.isInsideEvenOdd(cross));
}
public boolean contains(Point2D p) {
return contains(p.getX(), p.getY());
}
public boolean intersects(Rectangle2D r) {
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean contains(Rectangle2D r) {
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public Rectangle getBounds() {
return getBounds2D().getBounds();
}
public PathIterator getPathIterator(AffineTransform t) {
return new Iterator(this, t);
}
public PathIterator getPathIterator(AffineTransform t, double flatness) {
return new FlatteningPathIterator(getPathIterator(t), flatness);
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,274 @@
package com.itextpdf.awt.geom;
import java.io.Serializable;
public class Rectangle extends Rectangle2D implements Shape, Serializable {
private static final long serialVersionUID = -4345857070255674764L;
public double x;
public double y;
public double width;
public double height;
public Rectangle() {
setBounds(0, 0, 0, 0);
}
public Rectangle(Point p) {
setBounds(p.x, p.y, 0.0D, 0.0D);
}
public Rectangle(Point p, Dimension d) {
setBounds(p.x, p.y, d.width, d.height);
}
public Rectangle(double x, double y, double width, double height) {
setBounds(x, y, width, height);
}
public Rectangle(int width, int height) {
setBounds(0, 0, width, height);
}
public Rectangle(Rectangle r) {
setBounds(r.x, r.y, r.width, r.height);
}
public Rectangle(com.itextpdf.text.Rectangle r) {
r.normalize();
setBounds((double)r.getLeft(), (double)r.getBottom(), (double)r.getWidth(), (double)r.getHeight());
}
public Rectangle(Dimension d) {
setBounds(0.0D, 0.0D, d.width, d.height);
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public double getHeight() {
return this.height;
}
public double getWidth() {
return this.width;
}
public boolean isEmpty() {
return (this.width <= 0.0D || this.height <= 0.0D);
}
public Dimension getSize() {
return new Dimension(this.width, this.height);
}
public void setSize(int mx, int my) {
setSize((double)mx, (double)my);
}
public void setSize(double width, double height) {
this.width = width;
this.height = height;
}
public void setSize(Dimension d) {
setSize(d.width, d.height);
}
public Point getLocation() {
return new Point(this.x, this.y);
}
public void setLocation(int mx, int my) {
setLocation((double)mx, (double)my);
}
public void setLocation(double x, double y) {
this.x = x;
this.y = y;
}
public void setLocation(Point p) {
setLocation(p.x, p.y);
}
public void setRect(double x, double y, double width, double height) {
int x1 = (int)Math.floor(x);
int y1 = (int)Math.floor(y);
int x2 = (int)Math.ceil(x + width);
int y2 = (int)Math.ceil(y + height);
setBounds(x1, y1, x2 - x1, y2 - y1);
}
public Rectangle getBounds() {
return new Rectangle(this.x, this.y, this.width, this.height);
}
public Rectangle2D getBounds2D() {
return getBounds();
}
public void setBounds(int x, int y, int width, int height) {
setBounds((double)x, (double)y, (double)width, (double)height);
}
public void setBounds(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.height = height;
this.width = width;
}
public void setBounds(Rectangle r) {
setBounds(r.x, r.y, r.width, r.height);
}
public void grow(int mx, int my) {
translate((double)mx, (double)my);
}
public void grow(double dx, double dy) {
this.x -= dx;
this.y -= dy;
this.width += dx + dx;
this.height += dy + dy;
}
public void translate(int mx, int my) {
translate((double)mx, (double)my);
}
public void translate(double mx, double my) {
this.x += mx;
this.y += my;
}
public void add(int px, int py) {
add((double)px, (double)py);
}
public void add(double px, double py) {
double x1 = Math.min(this.x, px);
double x2 = Math.max(this.x + this.width, px);
double y1 = Math.min(this.y, py);
double y2 = Math.max(this.y + this.height, py);
setBounds(x1, y1, x2 - x1, y2 - y1);
}
public void add(Point p) {
add(p.x, p.y);
}
public void add(Rectangle r) {
double x1 = Math.min(this.x, r.x);
double x2 = Math.max(this.x + this.width, r.x + r.width);
double y1 = Math.min(this.y, r.y);
double y2 = Math.max(this.y + this.height, r.y + r.height);
setBounds(x1, y1, x2 - x1, y2 - y1);
}
public boolean contains(int px, int py) {
return contains((double)px, (double)py);
}
public boolean contains(double px, double py) {
if (isEmpty())
return false;
if (px < this.x || py < this.y)
return false;
px -= this.x;
py -= this.y;
return (px < this.width && py < this.height);
}
public boolean contains(Point p) {
return contains(p.x, p.y);
}
public boolean contains(int rx, int ry, int rw, int rh) {
return (contains(rx, ry) && contains(rx + rw - 1, ry + rh - 1));
}
public boolean contains(double rx, double ry, double rw, double rh) {
return (contains(rx, ry) && contains(rx + rw - 0.01D, ry + rh - 0.01D));
}
public boolean contains(Rectangle r) {
return contains(r.x, r.y, r.width, r.height);
}
public Rectangle2D createIntersection(Rectangle2D r) {
if (r instanceof Rectangle)
return intersection((Rectangle)r);
Rectangle2D dst = new Rectangle2D.Double();
Rectangle2D.intersect(this, r, dst);
return dst;
}
public Rectangle intersection(Rectangle r) {
double x1 = Math.max(this.x, r.x);
double y1 = Math.max(this.y, r.y);
double x2 = Math.min(this.x + this.width, r.x + r.width);
double y2 = Math.min(this.y + this.height, r.y + r.height);
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
}
public boolean intersects(Rectangle r) {
return !intersection(r).isEmpty();
}
public int outcode(double px, double py) {
int code = 0;
if (this.width <= 0.0D) {
code |= 0x5;
} else if (px < this.x) {
code |= 0x1;
} else if (px > this.x + this.width) {
code |= 0x4;
}
if (this.height <= 0.0D) {
code |= 0xA;
} else if (py < this.y) {
code |= 0x2;
} else if (py > this.y + this.height) {
code |= 0x8;
}
return code;
}
public Rectangle2D createUnion(Rectangle2D r) {
if (r instanceof Rectangle)
return union((Rectangle)r);
Rectangle2D dst = new Rectangle2D.Double();
Rectangle2D.union(this, r, dst);
return dst;
}
public Rectangle union(Rectangle r) {
Rectangle dst = new Rectangle(this);
dst.add(r);
return dst;
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof Rectangle) {
Rectangle r = (Rectangle)obj;
return (r.x == this.x && r.y == this.y && r.width == this.width && r.height == this.height);
}
return false;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + ",width=" + this.width + ",height=" + this.height + "]";
}
}

View file

@ -0,0 +1,451 @@
package com.itextpdf.awt.geom;
import com.itextpdf.awt.geom.misc.HashCode;
import com.itextpdf.awt.geom.misc.Messages;
import java.util.NoSuchElementException;
public abstract class Rectangle2D extends RectangularShape {
public static final int OUT_LEFT = 1;
public static final int OUT_TOP = 2;
public static final int OUT_RIGHT = 4;
public static final int OUT_BOTTOM = 8;
public abstract void setRect(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4);
public abstract int outcode(double paramDouble1, double paramDouble2);
public abstract Rectangle2D createIntersection(Rectangle2D paramRectangle2D);
public abstract Rectangle2D createUnion(Rectangle2D paramRectangle2D);
public static class Float extends Rectangle2D {
public float x;
public float y;
public float width;
public float height;
public Float() {}
public Float(float x, float y, float width, float height) {
setRect(x, y, width, height);
}
public double getX() {
return (double)this.x;
}
public double getY() {
return (double)this.y;
}
public double getWidth() {
return (double)this.width;
}
public double getHeight() {
return (double)this.height;
}
public boolean isEmpty() {
return (this.width <= 0.0F || this.height <= 0.0F);
}
public void setRect(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void setRect(double x, double y, double width, double height) {
this.x = (float)x;
this.y = (float)y;
this.width = (float)width;
this.height = (float)height;
}
public void setRect(Rectangle2D r) {
this.x = (float)r.getX();
this.y = (float)r.getY();
this.width = (float)r.getWidth();
this.height = (float)r.getHeight();
}
public int outcode(double px, double py) {
int code = 0;
if (this.width <= 0.0F) {
code |= 0x5;
} else if (px < (double)this.x) {
code |= 0x1;
} else if (px > (double)(this.x + this.width)) {
code |= 0x4;
}
if (this.height <= 0.0F) {
code |= 0xA;
} else if (py < (double)this.y) {
code |= 0x2;
} else if (py > (double)(this.y + this.height)) {
code |= 0x8;
}
return code;
}
public Rectangle2D getBounds2D() {
return new Float(this.x, this.y, this.width, this.height);
}
public Rectangle2D createIntersection(Rectangle2D r) {
Rectangle2D dst;
if (r instanceof Rectangle2D.Double) {
dst = new Rectangle2D.Double();
} else {
dst = new Float();
}
Rectangle2D.intersect(this, r, dst);
return dst;
}
public Rectangle2D createUnion(Rectangle2D r) {
Rectangle2D dst;
if (r instanceof Rectangle2D.Double) {
dst = new Rectangle2D.Double();
} else {
dst = new Float();
}
Rectangle2D.union(this, r, dst);
return dst;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + ",width=" + this.width + ",height=" + this.height + "]";
}
}
public static class Double extends Rectangle2D {
public double x;
public double y;
public double width;
public double height;
public Double() {}
public Double(double x, double y, double width, double height) {
setRect(x, y, width, height);
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public double getWidth() {
return this.width;
}
public double getHeight() {
return this.height;
}
public boolean isEmpty() {
return (this.width <= 0.0D || this.height <= 0.0D);
}
public void setRect(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void setRect(Rectangle2D r) {
this.x = r.getX();
this.y = r.getY();
this.width = r.getWidth();
this.height = r.getHeight();
}
public int outcode(double px, double py) {
int code = 0;
if (this.width <= 0.0D) {
code |= 0x5;
} else if (px < this.x) {
code |= 0x1;
} else if (px > this.x + this.width) {
code |= 0x4;
}
if (this.height <= 0.0D) {
code |= 0xA;
} else if (py < this.y) {
code |= 0x2;
} else if (py > this.y + this.height) {
code |= 0x8;
}
return code;
}
public Rectangle2D getBounds2D() {
return new Double(this.x, this.y, this.width, this.height);
}
public Rectangle2D createIntersection(Rectangle2D r) {
Rectangle2D dst = new Double();
Rectangle2D.intersect(this, r, dst);
return dst;
}
public Rectangle2D createUnion(Rectangle2D r) {
Rectangle2D dest = new Double();
Rectangle2D.union(this, r, dest);
return dest;
}
public String toString() {
return getClass().getName() + "[x=" + this.x + ",y=" + this.y + ",width=" + this.width + ",height=" + this.height + "]";
}
}
class Iterator implements PathIterator {
double x;
double y;
double width;
double height;
AffineTransform t;
int index;
Iterator(Rectangle2D r, AffineTransform at) {
this.x = r.getX();
this.y = r.getY();
this.width = r.getWidth();
this.height = r.getHeight();
this.t = at;
if (this.width < 0.0D || this.height < 0.0D)
this.index = 6;
}
public int getWindingRule() {
return 1;
}
public boolean isDone() {
return (this.index > 5);
}
public void next() {
this.index++;
}
public int currentSegment(double[] coords) {
int type;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 5)
return 4;
if (this.index == 0) {
type = 0;
coords[0] = this.x;
coords[1] = this.y;
} else {
type = 1;
switch (this.index) {
case 1:
coords[0] = this.x + this.width;
coords[1] = this.y;
break;
case 2:
coords[0] = this.x + this.width;
coords[1] = this.y + this.height;
break;
case 3:
coords[0] = this.x;
coords[1] = this.y + this.height;
break;
case 4:
coords[0] = this.x;
coords[1] = this.y;
break;
}
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, 1);
return type;
}
public int currentSegment(float[] coords) {
int type;
if (isDone())
throw new NoSuchElementException(Messages.getString("awt.4B"));
if (this.index == 5)
return 4;
if (this.index == 0) {
coords[0] = (float)this.x;
coords[1] = (float)this.y;
type = 0;
} else {
type = 1;
switch (this.index) {
case 1:
coords[0] = (float)(this.x + this.width);
coords[1] = (float)this.y;
break;
case 2:
coords[0] = (float)(this.x + this.width);
coords[1] = (float)(this.y + this.height);
break;
case 3:
coords[0] = (float)this.x;
coords[1] = (float)(this.y + this.height);
break;
case 4:
coords[0] = (float)this.x;
coords[1] = (float)this.y;
break;
}
}
if (this.t != null)
this.t.transform(coords, 0, coords, 0, 1);
return type;
}
}
public void setRect(Rectangle2D r) {
setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public void setFrame(double x, double y, double width, double height) {
setRect(x, y, width, height);
}
public Rectangle2D getBounds2D() {
return (Rectangle2D)clone();
}
public boolean intersectsLine(double x1, double y1, double x2, double y2) {
double rx1 = getX();
double ry1 = getY();
double rx2 = rx1 + getWidth();
double ry2 = ry1 + getHeight();
return ((rx1 <= x1 && x1 <= rx2 && ry1 <= y1 && y1 <= ry2) || (rx1 <= x2 && x2 <= rx2 && ry1 <= y2 && y2 <= ry2) ||
Line2D.linesIntersect(rx1, ry1, rx2, ry2, x1, y1, x2, y2) ||
Line2D.linesIntersect(rx2, ry1, rx1, ry2, x1, y1, x2, y2));
}
public boolean intersectsLine(Line2D l) {
return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
}
public int outcode(Point2D p) {
return outcode(p.getX(), p.getY());
}
public boolean contains(double x, double y) {
if (isEmpty())
return false;
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return (x1 <= x && x < x2 && y1 <= y && y < y2);
}
public boolean intersects(double x, double y, double width, double height) {
if (isEmpty() || width <= 0.0D || height <= 0.0D)
return false;
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return (x + width > x1 && x < x2 && y + height > y1 && y < y2);
}
public boolean contains(double x, double y, double width, double height) {
if (isEmpty() || width <= 0.0D || height <= 0.0D)
return false;
double x1 = getX();
double y1 = getY();
double x2 = x1 + getWidth();
double y2 = y1 + getHeight();
return (x1 <= x && x + width <= x2 && y1 <= y && y + height <= y2);
}
public static void intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst) {
double x1 = Math.max(src1.getMinX(), src2.getMinX());
double y1 = Math.max(src1.getMinY(), src2.getMinY());
double x2 = Math.min(src1.getMaxX(), src2.getMaxX());
double y2 = Math.min(src1.getMaxY(), src2.getMaxY());
dst.setFrame(x1, y1, x2 - x1, y2 - y1);
}
public static void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dst) {
double x1 = Math.min(src1.getMinX(), src2.getMinX());
double y1 = Math.min(src1.getMinY(), src2.getMinY());
double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
dst.setFrame(x1, y1, x2 - x1, y2 - y1);
}
public void add(double x, double y) {
double x1 = Math.min(getMinX(), x);
double y1 = Math.min(getMinY(), y);
double x2 = Math.max(getMaxX(), x);
double y2 = Math.max(getMaxY(), y);
setRect(x1, y1, x2 - x1, y2 - y1);
}
public void add(Point2D p) {
add(p.getX(), p.getY());
}
public void add(Rectangle2D r) {
union(this, r, this);
}
public PathIterator getPathIterator(AffineTransform t) {
return new Iterator(this, t);
}
public PathIterator getPathIterator(AffineTransform t, double flatness) {
return new Iterator(this, t);
}
public int hashCode() {
HashCode hash = new HashCode();
hash.append(getX());
hash.append(getY());
hash.append(getWidth());
hash.append(getHeight());
return hash.hashCode();
}
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof Rectangle2D) {
Rectangle2D r = (Rectangle2D)obj;
return (
getX() == r.getX() &&
getY() == r.getY() &&
getWidth() == r.getWidth() &&
getHeight() == r.getHeight());
}
return false;
}
}

View file

@ -0,0 +1,116 @@
package com.itextpdf.awt.geom;
public abstract class RectangularShape implements Shape, Cloneable {
public abstract double getX();
public abstract double getY();
public abstract double getWidth();
public abstract double getHeight();
public abstract boolean isEmpty();
public abstract void setFrame(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4);
public double getMinX() {
return getX();
}
public double getMinY() {
return getY();
}
public double getMaxX() {
return getX() + getWidth();
}
public double getMaxY() {
return getY() + getHeight();
}
public double getCenterX() {
return getX() + getWidth() / 2.0D;
}
public double getCenterY() {
return getY() + getHeight() / 2.0D;
}
public Rectangle2D getFrame() {
return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
}
public void setFrame(Point2D loc, Dimension2D size) {
setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
}
public void setFrame(Rectangle2D r) {
setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public void setFrameFromDiagonal(double x1, double y1, double x2, double y2) {
double rx, ry, rw, rh;
if (x1 < x2) {
rx = x1;
rw = x2 - x1;
} else {
rx = x2;
rw = x1 - x2;
}
if (y1 < y2) {
ry = y1;
rh = y2 - y1;
} else {
ry = y2;
rh = y1 - y2;
}
setFrame(rx, ry, rw, rh);
}
public void setFrameFromDiagonal(Point2D p1, Point2D p2) {
setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());
}
public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) {
double width = Math.abs(cornerX - centerX);
double height = Math.abs(cornerY - centerY);
setFrame(centerX - width, centerY - height, width * 2.0D, height * 2.0D);
}
public void setFrameFromCenter(Point2D center, Point2D corner) {
setFrameFromCenter(center.getX(), center.getY(), corner.getX(), corner.getY());
}
public boolean contains(Point2D point) {
return contains(point.getX(), point.getY());
}
public boolean intersects(Rectangle2D rect) {
return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
}
public boolean contains(Rectangle2D rect) {
return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
}
public Rectangle getBounds() {
int x1 = (int)Math.floor(getMinX());
int y1 = (int)Math.floor(getMinY());
int x2 = (int)Math.ceil(getMaxX());
int y2 = (int)Math.ceil(getMaxY());
return new Rectangle((double)x1, (double)y1, (double)(x2 - x1), (double)(y2 - y1));
}
public PathIterator getPathIterator(AffineTransform t, double flatness) {
return new FlatteningPathIterator(getPathIterator(t), flatness);
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

View file

@ -0,0 +1,23 @@
package com.itextpdf.awt.geom;
public interface Shape {
boolean contains(double paramDouble1, double paramDouble2);
boolean contains(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4);
boolean contains(Point2D paramPoint2D);
boolean contains(Rectangle2D paramRectangle2D);
Rectangle getBounds();
Rectangle2D getBounds2D();
PathIterator getPathIterator(AffineTransform paramAffineTransform);
PathIterator getPathIterator(AffineTransform paramAffineTransform, double paramDouble);
boolean intersects(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4);
boolean intersects(Rectangle2D paramRectangle2D);
}

View file

@ -0,0 +1,611 @@
package com.itextpdf.awt.geom.gl;
import com.itextpdf.awt.geom.PathIterator;
import com.itextpdf.awt.geom.Shape;
public class Crossing {
static final double DELTA = 1.0E-5D;
static final double ROOT_DELTA = 1.0E-10D;
public static final int CROSSING = 255;
static final int UNKNOWN = 254;
public static int solveQuad(double[] eqn, double[] res) {
double a = eqn[2];
double b = eqn[1];
double c = eqn[0];
int rc = 0;
if (a == 0.0D) {
if (b == 0.0D)
return -1;
res[rc++] = -c / b;
} else {
double d = b * b - 4.0D * a * c;
if (d < 0.0D)
return 0;
d = Math.sqrt(d);
res[rc++] = (-b + d) / (a * 2.0D);
if (d != 0.0D)
res[rc++] = (-b - d) / (a * 2.0D);
}
return fixRoots(res, rc);
}
public static int solveCubic(double[] eqn, double[] res) {
double d = eqn[3];
if (d == 0.0D)
return solveQuad(eqn, res);
double a = eqn[2] / d;
double b = eqn[1] / d;
double c = eqn[0] / d;
int rc = 0;
double Q = (a * a - 3.0D * b) / 9.0D;
double R = (2.0D * a * a * a - 9.0D * a * b + 27.0D * c) / 54.0D;
double Q3 = Q * Q * Q;
double R2 = R * R;
double n = -a / 3.0D;
if (R2 < Q3) {
double t = Math.acos(R / Math.sqrt(Q3)) / 3.0D;
double p = 2.0943951023931953D;
double m = -2.0D * Math.sqrt(Q);
res[rc++] = m * Math.cos(t) + n;
res[rc++] = m * Math.cos(t + p) + n;
res[rc++] = m * Math.cos(t - p) + n;
} else {
double A = Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 0.3333333333333333D);
if (R > 0.0D)
A = -A;
if (-1.0E-10D < A && A < 1.0E-10D) {
res[rc++] = n;
} else {
double B = Q / A;
res[rc++] = A + B + n;
double delta = R2 - Q3;
if (-1.0E-10D < delta && delta < 1.0E-10D)
res[rc++] = -(A + B) / 2.0D + n;
}
}
return fixRoots(res, rc);
}
static int fixRoots(double[] res, int rc) {
int tc = 0;
for (int i = 0; i < rc; i++) {
int j = i + 1;
while (true) {
if (j < rc) {
if (isZero(res[i] - res[j]))
break;
j++;
continue;
}
res[tc++] = res[i];
break;
}
}
return tc;
}
public static class QuadCurve {
double ax;
double ay;
double bx;
double by;
double Ax;
double Ay;
double Bx;
double By;
public QuadCurve(double x1, double y1, double cx, double cy, double x2, double y2) {
this.ax = x2 - x1;
this.ay = y2 - y1;
this.bx = cx - x1;
this.by = cy - y1;
this.Bx = this.bx + this.bx;
this.Ax = this.ax - this.Bx;
this.By = this.by + this.by;
this.Ay = this.ay - this.By;
}
int cross(double[] res, int rc, double py1, double py2) {
int cross = 0;
for (int i = 0; i < rc; i++) {
double t = res[i];
if (t >= -1.0E-5D && t <= 1.00001D)
if (t < 1.0E-5D) {
if (py1 < 0.0D && ((this.bx != 0.0D) ? this.bx : (this.ax - this.bx)) < 0.0D)
cross--;
} else if (t > 0.99999D) {
if (py1 < this.ay && ((this.ax != this.bx) ? (this.ax - this.bx) : this.bx) > 0.0D)
cross++;
} else {
double ry = t * (t * this.Ay + this.By);
if (ry > py2) {
double rxt = t * this.Ax + this.bx;
if (rxt <= -1.0E-5D || rxt >= 1.0E-5D)
cross += (rxt > 0.0D) ? 1 : -1;
}
}
}
return cross;
}
int solvePoint(double[] res, double px) {
double[] eqn = { -px, this.Bx, this.Ax };
return Crossing.solveQuad(eqn, res);
}
int solveExtrem(double[] res) {
int rc = 0;
if (this.Ax != 0.0D)
res[rc++] = -this.Bx / (this.Ax + this.Ax);
if (this.Ay != 0.0D)
res[rc++] = -this.By / (this.Ay + this.Ay);
return rc;
}
int addBound(double[] bound, int bc, double[] res, int rc, double minX, double maxX, boolean changeId, int id) {
for (int i = 0; i < rc; i++) {
double t = res[i];
if (t > -1.0E-5D && t < 1.00001D) {
double rx = t * (t * this.Ax + this.Bx);
if (minX <= rx && rx <= maxX) {
bound[bc++] = t;
bound[bc++] = rx;
bound[bc++] = t * (t * this.Ay + this.By);
bound[bc++] = (double)id;
if (changeId)
id++;
}
}
}
return bc;
}
}
public static class CubicCurve {
double ax;
double ay;
double bx;
double by;
double cx;
double cy;
double Ax;
double Ay;
double Bx;
double By;
double Cx;
double Cy;
double Ax3;
double Bx2;
public CubicCurve(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2) {
this.ax = x2 - x1;
this.ay = y2 - y1;
this.bx = cx1 - x1;
this.by = cy1 - y1;
this.cx = cx2 - x1;
this.cy = cy2 - y1;
this.Cx = this.bx + this.bx + this.bx;
this.Bx = this.cx + this.cx + this.cx - this.Cx - this.Cx;
this.Ax = this.ax - this.Bx - this.Cx;
this.Cy = this.by + this.by + this.by;
this.By = this.cy + this.cy + this.cy - this.Cy - this.Cy;
this.Ay = this.ay - this.By - this.Cy;
this.Ax3 = this.Ax + this.Ax + this.Ax;
this.Bx2 = this.Bx + this.Bx;
}
int cross(double[] res, int rc, double py1, double py2) {
int cross = 0;
for (int i = 0; i < rc; i++) {
double t = res[i];
if (t < -1.0E-5D || t > 1.00001D)
continue;
if (t < 1.0E-5D) {
if (py1 < 0.0D)
if (((this.bx != 0.0D) ? this.bx : ((this.cx != this.bx) ? (this.cx - this.bx) : (this.ax - this.cx))) < 0.0D)
cross--;
continue;
}
if (t > 0.99999D) {
if (py1 < this.ay)
if (((this.ax != this.cx) ? (this.ax - this.cx) : ((this.cx != this.bx) ? (this.cx - this.bx) : this.bx)) > 0.0D)
cross++;
continue;
}
double ry = t * (t * (t * this.Ay + this.By) + this.Cy);
if (ry > py2) {
double rxt = t * (t * this.Ax3 + this.Bx2) + this.Cx;
if (rxt > -1.0E-5D && rxt < 1.0E-5D) {
rxt = t * (this.Ax3 + this.Ax3) + this.Bx2;
if (rxt < -1.0E-5D || rxt > 1.0E-5D)
continue;
rxt = this.ax;
}
cross += (rxt > 0.0D) ? 1 : -1;
}
}
return cross;
}
int solvePoint(double[] res, double px) {
double[] eqn = { -px, this.Cx, this.Bx, this.Ax };
return Crossing.solveCubic(eqn, res);
}
int solveExtremX(double[] res) {
double[] eqn = { this.Cx, this.Bx2, this.Ax3 };
return Crossing.solveQuad(eqn, res);
}
int solveExtremY(double[] res) {
double[] eqn = { this.Cy, this.By + this.By, this.Ay + this.Ay + this.Ay };
return Crossing.solveQuad(eqn, res);
}
int addBound(double[] bound, int bc, double[] res, int rc, double minX, double maxX, boolean changeId, int id) {
for (int i = 0; i < rc; i++) {
double t = res[i];
if (t > -1.0E-5D && t < 1.00001D) {
double rx = t * (t * (t * this.Ax + this.Bx) + this.Cx);
if (minX <= rx && rx <= maxX) {
bound[bc++] = t;
bound[bc++] = rx;
bound[bc++] = t * (t * (t * this.Ay + this.By) + this.Cy);
bound[bc++] = (double)id;
if (changeId)
id++;
}
}
}
return bc;
}
}
public static int crossLine(double x1, double y1, double x2, double y2, double x, double y) {
if ((x < x1 && x < x2) || (x > x1 && x > x2) || (y > y1 && y > y2) || x1 == x2)
return 0;
if (y >= y1 || y >= y2)
if ((y2 - y1) * (x - x1) / (x2 - x1) <= y - y1)
return 0;
if (x == x1)
return (x1 < x2) ? 0 : -1;
if (x == x2)
return (x1 < x2) ? 1 : 0;
return (x1 < x2) ? 1 : -1;
}
public static int crossQuad(double x1, double y1, double cx, double cy, double x2, double y2, double x, double y) {
if ((x < x1 && x < cx && x < x2) || (x > x1 && x > cx && x > x2) || (y > y1 && y > cy && y > y2) || (x1 == cx && cx == x2))
return 0;
if (y < y1 && y < cy && y < y2 && x != x1 && x != x2) {
if (x1 < x2)
return (x1 < x && x < x2) ? 1 : 0;
return (x2 < x && x < x1) ? -1 : 0;
}
QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2);
double px = x - x1;
double py = y - y1;
double[] res = new double[3];
int rc = c.solvePoint(res, px);
return c.cross(res, rc, py, py);
}
public static int crossCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double x, double y) {
if ((x < x1 && x < cx1 && x < cx2 && x < x2) || (x > x1 && x > cx1 && x > cx2 && x > x2) || (y > y1 && y > cy1 && y > cy2 && y > y2) || (x1 == cx1 && cx1 == cx2 && cx2 == x2))
return 0;
if (y < y1 && y < cy1 && y < cy2 && y < y2 && x != x1 && x != x2) {
if (x1 < x2)
return (x1 < x && x < x2) ? 1 : 0;
return (x2 < x && x < x1) ? -1 : 0;
}
CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
double px = x - x1;
double py = y - y1;
double[] res = new double[3];
int rc = c.solvePoint(res, px);
return c.cross(res, rc, py, py);
}
public static int crossPath(PathIterator p, double x, double y) {
int cross = 0;
double cy = 0.0D, cx = cy, my = cx, mx = my;
double[] coords = new double[6];
while (!p.isDone()) {
switch (p.currentSegment(coords)) {
case 0:
if (cx != mx || cy != my)
cross += crossLine(cx, cy, mx, my, x, y);
mx = cx = coords[0];
my = cy = coords[1];
case 1:
cross += crossLine(cx, cy, cx = coords[0], cy = coords[1], x, y);
case 2:
cross += crossQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], x, y);
case 3:
cross += crossCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], x, y);
case 4:
if (cy != my || cx != mx)
cross += crossLine(cx, cy, cx = mx, cy = my, x, y);
break;
}
if (x == cx && y == cy) {
cross = 0;
cy = my;
break;
}
p.next();
}
if (cy != my)
cross += crossLine(cx, cy, mx, my, x, y);
return cross;
}
public static int crossShape(Shape s, double x, double y) {
if (!s.getBounds2D().contains(x, y))
return 0;
return crossPath(s.getPathIterator(null), x, y);
}
public static boolean isZero(double val) {
return (-1.0E-5D < val && val < 1.0E-5D);
}
static void sortBound(double[] bound, int bc) {
for (int i = 0; i < bc - 4; i += 4) {
int k = i;
for (int j = i + 4; j < bc; j += 4) {
if (bound[k] > bound[j])
k = j;
}
if (k != i) {
double tmp = bound[i];
bound[i] = bound[k];
bound[k] = tmp;
tmp = bound[i + 1];
bound[i + 1] = bound[k + 1];
bound[k + 1] = tmp;
tmp = bound[i + 2];
bound[i + 2] = bound[k + 2];
bound[k + 2] = tmp;
tmp = bound[i + 3];
bound[i + 3] = bound[k + 3];
bound[k + 3] = tmp;
}
}
}
static int crossBound(double[] bound, int bc, double py1, double py2) {
if (bc == 0)
return 0;
int up = 0;
int down = 0;
for (int i = 2; i < bc; i += 4) {
if (bound[i] < py1) {
up++;
} else if (bound[i] > py2) {
down++;
} else {
return 255;
}
}
if (down == 0)
return 0;
if (up != 0) {
sortBound(bound, bc);
boolean sign = (bound[2] > py2);
for (int j = 6; j < bc; j += 4) {
boolean sign2 = (bound[j] > py2);
if (sign != sign2 && bound[j + 1] != bound[j - 3])
return 255;
sign = sign2;
}
}
return 254;
}
public static int intersectLine(double x1, double y1, double x2, double y2, double rx1, double ry1, double rx2, double ry2) {
if ((rx2 < x1 && rx2 < x2) || (rx1 > x1 && rx1 > x2) || (ry1 > y1 && ry1 > y2))
return 0;
if (ry2 >= y1 || ry2 >= y2) {
double bx1, bx2;
if (x1 == x2)
return 255;
if (x1 < x2) {
bx1 = (x1 < rx1) ? rx1 : x1;
bx2 = (x2 < rx2) ? x2 : rx2;
} else {
bx1 = (x2 < rx1) ? rx1 : x2;
bx2 = (x1 < rx2) ? x1 : rx2;
}
double k = (y2 - y1) / (x2 - x1);
double by1 = k * (bx1 - x1) + y1;
double by2 = k * (bx2 - x1) + y1;
if (by1 < ry1 && by2 < ry1)
return 0;
if (by1 <= ry2 || by2 <= ry2)
return 255;
}
if (x1 == x2)
return 0;
if (rx1 == x1)
return (x1 < x2) ? 0 : -1;
if (rx1 == x2)
return (x1 < x2) ? 1 : 0;
if (x1 < x2)
return (x1 < rx1 && rx1 < x2) ? 1 : 0;
return (x2 < rx1 && rx1 < x1) ? -1 : 0;
}
public static int intersectQuad(double x1, double y1, double cx, double cy, double x2, double y2, double rx1, double ry1, double rx2, double ry2) {
if ((rx2 < x1 && rx2 < cx && rx2 < x2) || (rx1 > x1 && rx1 > cx && rx1 > x2) || (ry1 > y1 && ry1 > cy && ry1 > y2))
return 0;
if (ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2) {
if (x1 < x2)
return (x1 < rx1 && rx1 < x2) ? 1 : 0;
return (x2 < rx1 && rx1 < x1) ? -1 : 0;
}
QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2);
double px1 = rx1 - x1;
double py1 = ry1 - y1;
double px2 = rx2 - x1;
double py2 = ry2 - y1;
double[] res1 = new double[3];
double[] res2 = new double[3];
int rc1 = c.solvePoint(res1, px1);
int rc2 = c.solvePoint(res2, px2);
if (rc1 == 0 && rc2 == 0)
return 0;
double minX = px1 - 1.0E-5D;
double maxX = px2 + 1.0E-5D;
double[] bound = new double[28];
int bc = 0;
bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
rc2 = c.solveExtrem(res2);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
if (rx1 < x1 && x1 < rx2) {
bound[bc++] = 0.0D;
bound[bc++] = 0.0D;
bound[bc++] = 0.0D;
bound[bc++] = 4.0D;
}
if (rx1 < x2 && x2 < rx2) {
bound[bc++] = 1.0D;
bound[bc++] = c.ax;
bound[bc++] = c.ay;
bound[bc++] = 5.0D;
}
int cross = crossBound(bound, bc, py1, py2);
if (cross != 254)
return cross;
return c.cross(res1, rc1, py1, py2);
}
public static int intersectCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double rx1, double ry1, double rx2, double ry2) {
if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) || (rx1 > x1 && rx1 > cx1 && rx1 > cx2 && rx1 > x2) || (ry1 > y1 && ry1 > cy1 && ry1 > cy2 && ry1 > y2))
return 0;
if (ry2 < y1 && ry2 < cy1 && ry2 < cy2 && ry2 < y2 && rx1 != x1 && rx1 != x2) {
if (x1 < x2)
return (x1 < rx1 && rx1 < x2) ? 1 : 0;
return (x2 < rx1 && rx1 < x1) ? -1 : 0;
}
CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
double px1 = rx1 - x1;
double py1 = ry1 - y1;
double px2 = rx2 - x1;
double py2 = ry2 - y1;
double[] res1 = new double[3];
double[] res2 = new double[3];
int rc1 = c.solvePoint(res1, px1);
int rc2 = c.solvePoint(res2, px2);
if (rc1 == 0 && rc2 == 0)
return 0;
double minX = px1 - 1.0E-5D;
double maxX = px2 + 1.0E-5D;
double[] bound = new double[40];
int bc = 0;
bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
rc2 = c.solveExtremX(res2);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
rc2 = c.solveExtremY(res2);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 4);
if (rx1 < x1 && x1 < rx2) {
bound[bc++] = 0.0D;
bound[bc++] = 0.0D;
bound[bc++] = 0.0D;
bound[bc++] = 6.0D;
}
if (rx1 < x2 && x2 < rx2) {
bound[bc++] = 1.0D;
bound[bc++] = c.ax;
bound[bc++] = c.ay;
bound[bc++] = 7.0D;
}
int cross = crossBound(bound, bc, py1, py2);
if (cross != 254)
return cross;
return c.cross(res1, rc1, py1, py2);
}
public static int intersectPath(PathIterator p, double x, double y, double w, double h) {
int cross = 0;
double cy = 0.0D, cx = cy, my = cx, mx = my;
double[] coords = new double[6];
double rx1 = x;
double ry1 = y;
double rx2 = x + w;
double ry2 = y + h;
while (!p.isDone()) {
int count = 0;
switch (p.currentSegment(coords)) {
case 0:
if (cx != mx || cy != my)
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
mx = cx = coords[0];
my = cy = coords[1];
case 1:
count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
case 2:
count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], rx1, ry1, rx2, ry2);
case 3:
count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
case 4:
if (cy != my || cx != mx)
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
cx = mx;
cy = my;
break;
}
if (count == 255)
return 255;
cross += count;
p.next();
}
if (cy != my) {
int count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
if (count == 255)
return 255;
cross += count;
}
return cross;
}
public static int intersectShape(Shape s, double x, double y, double w, double h) {
if (!s.getBounds2D().intersects(x, y, w, h))
return 0;
return intersectPath(s.getPathIterator(null), x, y, w, h);
}
public static boolean isInsideNonZero(int cross) {
return (cross != 0);
}
public static boolean isInsideEvenOdd(int cross) {
return ((cross & 0x1) != 0);
}
}

View file

@ -0,0 +1,69 @@
package com.itextpdf.awt.geom.misc;
public final class HashCode {
public static final int EMPTY_HASH_CODE = 1;
private int hashCode = 1;
public final int hashCode() {
return this.hashCode;
}
public static int combine(int hashCode, boolean value) {
int v = value ? 1231 : 1237;
return combine(hashCode, v);
}
public static int combine(int hashCode, long value) {
int v = (int)(value ^ value >>> 32L);
return combine(hashCode, v);
}
public static int combine(int hashCode, float value) {
int v = Float.floatToIntBits(value);
return combine(hashCode, v);
}
public static int combine(int hashCode, double value) {
long v = Double.doubleToLongBits(value);
return combine(hashCode, v);
}
public static int combine(int hashCode, Object value) {
return combine(hashCode, value.hashCode());
}
public static int combine(int hashCode, int value) {
return 31 * hashCode + value;
}
public final HashCode append(int value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
public final HashCode append(long value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
public final HashCode append(float value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
public final HashCode append(double value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
public final HashCode append(boolean value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
public final HashCode append(Object value) {
this.hashCode = combine(this.hashCode, value);
return this;
}
}

View file

@ -0,0 +1,84 @@
package com.itextpdf.awt.geom.misc;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static ResourceBundle bundle = null;
public static String getString(String msg) {
if (bundle == null)
return msg;
try {
return bundle.getString(msg);
} catch (MissingResourceException e) {
return "Missing message: " + msg;
}
}
public static String getString(String msg, Object arg) {
return getString(msg, new Object[] { arg });
}
public static String getString(String msg, int arg) {
return getString(msg, new Object[] { Integer.toString(arg) });
}
public static String getString(String msg, char arg) {
return getString(msg, new Object[] { String.valueOf(arg) });
}
public static String getString(String msg, Object arg1, Object arg2) {
return getString(msg, new Object[] { arg1, arg2 });
}
public static String getString(String msg, Object[] args) {
String format = msg;
if (bundle != null)
try {
format = bundle.getString(msg);
} catch (MissingResourceException e) {}
return format(format, args);
}
public static String format(String format, Object[] args) {
StringBuilder answer = new StringBuilder(format.length() + args.length * 20);
String[] argStrings = new String[args.length];
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
argStrings[i] = "<null>";
} else {
argStrings[i] = args[i].toString();
}
}
int lastI = 0;
for (int j = format.indexOf('{', 0); j >= 0; j = format.indexOf('{', lastI)) {
if (j != 0 && format.charAt(j - 1) == '\\') {
if (j != 1)
answer.append(format.substring(lastI, j - 1));
answer.append('{');
lastI = j + 1;
} else if (j > format.length() - 3) {
answer.append(format.substring(lastI, format.length()));
lastI = format.length();
} else {
int argnum = (byte)Character.digit(format.charAt(j + 1), 10);
if (argnum < 0 || format.charAt(j + 2) != '}') {
answer.append(format.substring(lastI, j + 1));
lastI = j + 1;
} else {
answer.append(format.substring(lastI, j));
if (argnum >= argStrings.length) {
answer.append("<missing argument>");
} else {
answer.append(argStrings[argnum]);
}
lastI = j + 3;
}
}
}
if (lastI < format.length())
answer.append(format.substring(lastI, format.length()));
return answer.toString();
}
}

View file

@ -0,0 +1,236 @@
package com.itextpdf.awt.geom.misc;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class RenderingHints implements Map<Object, Object>, Cloneable {
public static final Key KEY_ALPHA_INTERPOLATION = new KeyImpl(1);
public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = new KeyValue(KEY_ALPHA_INTERPOLATION);
public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = new KeyValue(KEY_ALPHA_INTERPOLATION);
public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY = new KeyValue(KEY_ALPHA_INTERPOLATION);
public static final Key KEY_ANTIALIASING = new KeyImpl(2);
public static final Object VALUE_ANTIALIAS_DEFAULT = new KeyValue(KEY_ANTIALIASING);
public static final Object VALUE_ANTIALIAS_ON = new KeyValue(KEY_ANTIALIASING);
public static final Object VALUE_ANTIALIAS_OFF = new KeyValue(KEY_ANTIALIASING);
public static final Key KEY_COLOR_RENDERING = new KeyImpl(3);
public static final Object VALUE_COLOR_RENDER_DEFAULT = new KeyValue(KEY_COLOR_RENDERING);
public static final Object VALUE_COLOR_RENDER_SPEED = new KeyValue(KEY_COLOR_RENDERING);
public static final Object VALUE_COLOR_RENDER_QUALITY = new KeyValue(KEY_COLOR_RENDERING);
public static final Key KEY_DITHERING = new KeyImpl(4);
public static final Object VALUE_DITHER_DEFAULT = new KeyValue(KEY_DITHERING);
public static final Object VALUE_DITHER_DISABLE = new KeyValue(KEY_DITHERING);
public static final Object VALUE_DITHER_ENABLE = new KeyValue(KEY_DITHERING);
public static final Key KEY_FRACTIONALMETRICS = new KeyImpl(5);
public static final Object VALUE_FRACTIONALMETRICS_DEFAULT = new KeyValue(KEY_FRACTIONALMETRICS);
public static final Object VALUE_FRACTIONALMETRICS_ON = new KeyValue(KEY_FRACTIONALMETRICS);
public static final Object VALUE_FRACTIONALMETRICS_OFF = new KeyValue(KEY_FRACTIONALMETRICS);
public static final Key KEY_INTERPOLATION = new KeyImpl(6);
public static final Object VALUE_INTERPOLATION_BICUBIC = new KeyValue(KEY_INTERPOLATION);
public static final Object VALUE_INTERPOLATION_BILINEAR = new KeyValue(KEY_INTERPOLATION);
public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR = new KeyValue(KEY_INTERPOLATION);
public static final Key KEY_RENDERING = new KeyImpl(7);
public static final Object VALUE_RENDER_DEFAULT = new KeyValue(KEY_RENDERING);
public static final Object VALUE_RENDER_SPEED = new KeyValue(KEY_RENDERING);
public static final Object VALUE_RENDER_QUALITY = new KeyValue(KEY_RENDERING);
public static final Key KEY_STROKE_CONTROL = new KeyImpl(8);
public static final Object VALUE_STROKE_DEFAULT = new KeyValue(KEY_STROKE_CONTROL);
public static final Object VALUE_STROKE_NORMALIZE = new KeyValue(KEY_STROKE_CONTROL);
public static final Object VALUE_STROKE_PURE = new KeyValue(KEY_STROKE_CONTROL);
public static final Key KEY_TEXT_ANTIALIASING = new KeyImpl(9);
public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT = new KeyValue(KEY_TEXT_ANTIALIASING);
public static final Object VALUE_TEXT_ANTIALIAS_ON = new KeyValue(KEY_TEXT_ANTIALIASING);
public static final Object VALUE_TEXT_ANTIALIAS_OFF = new KeyValue(KEY_TEXT_ANTIALIASING);
private HashMap<Object, Object> map = new HashMap<Object, Object>();
public RenderingHints(Map<Key, ?> map) {
if (map != null)
putAll(map);
}
public RenderingHints(Key key, Object value) {
put(key, value);
}
public void add(RenderingHints hints) {
this.map.putAll(hints.map);
}
public Object put(Object key, Object value) {
if (!((Key)key).isCompatibleValue(value))
throw new IllegalArgumentException();
return this.map.put(key, value);
}
public Object remove(Object key) {
return this.map.remove(key);
}
public Object get(Object key) {
return this.map.get(key);
}
public Set<Object> keySet() {
return this.map.keySet();
}
public Set<Map.Entry<Object, Object>> entrySet() {
return this.map.entrySet();
}
public void putAll(Map<?, ?> m) {
if (m instanceof RenderingHints) {
this.map.putAll(((RenderingHints)m).map);
} else {
Set<?> entries = m.entrySet();
if (entries != null) {
Iterator<?> it = entries.iterator();
while (it.hasNext()) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)it.next();
Key key = (Key)entry.getKey();
Object val = entry.getValue();
put(key, val);
}
}
}
}
public Collection<Object> values() {
return this.map.values();
}
public boolean containsValue(Object value) {
return this.map.containsValue(value);
}
public boolean containsKey(Object key) {
if (key == null)
throw new NullPointerException();
return this.map.containsKey(key);
}
public boolean isEmpty() {
return this.map.isEmpty();
}
public void clear() {
this.map.clear();
}
public int size() {
return this.map.size();
}
public boolean equals(Object o) {
if (!(o instanceof Map))
return false;
Map<?, ?> m = (Map<?, ?>)o;
Set<?> keys = keySet();
if (!keys.equals(m.keySet()))
return false;
Iterator<?> it = keys.iterator();
while (it.hasNext()) {
Key key = (Key)it.next();
Object v1 = get(key);
Object v2 = m.get(key);
if ((v1 == null) ? (v2 == null) : v1.equals(v2))
continue;
return false;
}
return true;
}
public int hashCode() {
return this.map.hashCode();
}
public Object clone() {
RenderingHints clone = new RenderingHints(null);
clone.map = (HashMap<Object, Object>)this.map.clone();
return clone;
}
public String toString() {
return "RenderingHints[" + this.map.toString() + "]";
}
public static abstract class Key {
private final int key;
protected Key(int key) {
this.key = key;
}
public final boolean equals(Object o) {
return (this == o);
}
public final int hashCode() {
return System.identityHashCode(this);
}
protected final int intKey() {
return this.key;
}
public abstract boolean isCompatibleValue(Object param1Object);
}
private static class KeyImpl extends Key {
protected KeyImpl(int key) {
super(key);
}
public boolean isCompatibleValue(Object val) {
if (!(val instanceof RenderingHints.KeyValue))
return false;
return (((RenderingHints.KeyValue)val).key == this);
}
}
private static class KeyValue {
private final RenderingHints.Key key;
protected KeyValue(RenderingHints.Key key) {
this.key = key;
}
}
}