|
|
@ -55,6 +55,8 @@ import com.fr.third.v2.lowagie.text.Image; |
|
|
|
import sun.font.FontDesignMetrics; |
|
|
|
import sun.font.FontDesignMetrics; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
|
|
|
import java.awt.font.FontRenderContext; |
|
|
|
|
|
|
|
import java.awt.geom.AffineTransform; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* <CODE>PdfFont</CODE> is the Pdf Font object. |
|
|
|
* <CODE>PdfFont</CODE> is the Pdf Font object. |
|
|
@ -72,36 +74,37 @@ import java.awt.FontMetrics; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public class PdfFont implements Comparable { |
|
|
|
public class PdfFont implements Comparable { |
|
|
|
|
|
|
|
private static final int ONE_THOUSAND = 1000 ; |
|
|
|
|
|
|
|
|
|
|
|
private Font oriFont; |
|
|
|
private Font oriFont; |
|
|
|
|
|
|
|
|
|
|
|
/** the font metrics. */ |
|
|
|
/** the font metrics. */ |
|
|
|
// private BaseFont font;
|
|
|
|
// private BaseFont font;
|
|
|
|
|
|
|
|
|
|
|
|
/** the size. */ |
|
|
|
/** the size. */ |
|
|
|
private float size; |
|
|
|
private float size; |
|
|
|
|
|
|
|
|
|
|
|
/** an image. */ |
|
|
|
/** an image. */ |
|
|
|
protected Image image; |
|
|
|
protected Image image; |
|
|
|
|
|
|
|
|
|
|
|
protected float hScale = 1; |
|
|
|
protected float hScale = 1; |
|
|
|
|
|
|
|
|
|
|
|
// constructors
|
|
|
|
// constructors
|
|
|
|
|
|
|
|
|
|
|
|
PdfFont(Font oriFont, float size) { |
|
|
|
PdfFont(Font oriFont, float size) { |
|
|
|
this.size = size; |
|
|
|
this.size = size; |
|
|
|
this.oriFont = oriFont; |
|
|
|
this.oriFont = oriFont; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// methods
|
|
|
|
// methods
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Compares this <CODE>PdfFont</CODE> with another |
|
|
|
* Compares this <CODE>PdfFont</CODE> with another |
|
|
|
* |
|
|
|
* |
|
|
|
* @param object the other <CODE>PdfFont</CODE> |
|
|
|
* @param object the other <CODE>PdfFont</CODE> |
|
|
|
* @return a value |
|
|
|
* @return a value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public int compareTo(Object object) { |
|
|
|
public int compareTo(Object object) { |
|
|
|
if (image != null) |
|
|
|
if (image != null) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -125,13 +128,13 @@ public class PdfFont implements Comparable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the size of this font. |
|
|
|
* Returns the size of this font. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return a size |
|
|
|
* @return a size |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
float size() { |
|
|
|
float size() { |
|
|
|
if (image == null) |
|
|
|
if (image == null) |
|
|
|
return size; |
|
|
|
return size; |
|
|
@ -139,24 +142,24 @@ public class PdfFont implements Comparable { |
|
|
|
return image.getScaledHeight(); |
|
|
|
return image.getScaledHeight(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the approximative width of 1 character of this font. |
|
|
|
* Returns the approximative width of 1 character of this font. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return a width in Text Space |
|
|
|
* @return a width in Text Space |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
float width() { |
|
|
|
float width() { |
|
|
|
return width(' '); |
|
|
|
return width(' '); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the width of a certain character of this font. |
|
|
|
* Returns the width of a certain character of this font. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param character a certain character |
|
|
|
* @param character a certain character |
|
|
|
* @return a width in Text Space |
|
|
|
* @return a width in Text Space |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
float width(int character) { |
|
|
|
float width(int character) { |
|
|
|
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
if (image == null) |
|
|
|
if (image == null) |
|
|
@ -164,15 +167,21 @@ public class PdfFont implements Comparable { |
|
|
|
else |
|
|
|
else |
|
|
|
return image.getScaledWidth(); |
|
|
|
return image.getScaledWidth(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float width(String s) { |
|
|
|
float width(String s) { |
|
|
|
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
java.awt.Font font = this.getAwtFont(); |
|
|
|
|
|
|
|
float scale = ONE_THOUSAND / font.getSize2D(); |
|
|
|
|
|
|
|
java.awt.Font derivedFont = font.deriveFont(AffineTransform.getScaleInstance(scale, scale)); |
|
|
|
|
|
|
|
double width = derivedFont.getStringBounds(s, new FontRenderContext(new AffineTransform(), true, true)).getWidth(); |
|
|
|
|
|
|
|
if (derivedFont.isTransformed()){ |
|
|
|
|
|
|
|
width /= scale; |
|
|
|
|
|
|
|
} |
|
|
|
if (image == null) |
|
|
|
if (image == null) |
|
|
|
return metrics.stringWidth(s) * hScale; |
|
|
|
return (float) width * hScale; |
|
|
|
else |
|
|
|
else |
|
|
|
return image.getScaledWidth(); |
|
|
|
return image.getScaledWidth(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BaseFont getFont() { |
|
|
|
BaseFont getFont() { |
|
|
|
return oriFont.getCalculatedBaseFont(false); |
|
|
|
return oriFont.getCalculatedBaseFont(false); |
|
|
|
} |
|
|
|
} |
|
|
@ -195,7 +204,7 @@ public class PdfFont implements Comparable { |
|
|
|
void setImage(Image image) { |
|
|
|
void setImage(Image image) { |
|
|
|
this.image = image; |
|
|
|
this.image = image; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static PdfFont getDefaultFont() { |
|
|
|
static PdfFont getDefaultFont() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
|
|
|
|
// BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
|
|
|
|