|
|
@ -55,8 +55,6 @@ 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. |
|
|
@ -74,6 +72,7 @@ import java.awt.geom.AffineTransform; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public class PdfFont implements Comparable { |
|
|
|
public class PdfFont implements Comparable { |
|
|
|
|
|
|
|
|
|
|
|
private static final int ONE_THOUSAND = 1000 ; |
|
|
|
private static final int ONE_THOUSAND = 1000 ; |
|
|
|
|
|
|
|
|
|
|
|
private Font oriFont; |
|
|
|
private Font oriFont; |
|
|
@ -153,6 +152,8 @@ public class PdfFont implements Comparable { |
|
|
|
return width(' '); |
|
|
|
return width(' '); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private FontMetrics metrics; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the width of a certain character of this font. |
|
|
|
* Returns the width of a certain character of this font. |
|
|
|
* |
|
|
|
* |
|
|
@ -161,31 +162,20 @@ public class PdfFont implements Comparable { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
float width(int character) { |
|
|
|
float width(int character) { |
|
|
|
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
return image == null ? getMetrics().charWidth(character) : image.getScaledWidth(); |
|
|
|
if (image == null) |
|
|
|
|
|
|
|
return metrics.charWidth(character) * hScale; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return image.getScaledWidth(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public float width(String s) { |
|
|
|
float width(String s) { |
|
|
|
double width = 0.0d; |
|
|
|
return image == null ? getMetrics().stringWidth(s) : image.getScaledWidth(); |
|
|
|
java.awt.Font font = this.getAwtFont(); |
|
|
|
|
|
|
|
if (font.getSize2D() > 0) { |
|
|
|
|
|
|
|
float scale = ONE_THOUSAND / font.getSize2D(); |
|
|
|
|
|
|
|
java.awt.Font derivedFont = font.deriveFont(AffineTransform.getScaleInstance(scale, scale)); |
|
|
|
|
|
|
|
width = derivedFont.getStringBounds(s, new FontRenderContext(new AffineTransform(), true, true)).getWidth(); |
|
|
|
|
|
|
|
if (derivedFont.isTransformed()){ |
|
|
|
|
|
|
|
width /= scale; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private FontMetrics getMetrics() { |
|
|
|
|
|
|
|
if (null == metrics) { |
|
|
|
|
|
|
|
metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (image == null) |
|
|
|
return metrics; |
|
|
|
return (float) width * hScale; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return image.getScaledWidth(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BaseFont getFont() { |
|
|
|
BaseFont getFont() { |
|
|
|
return oriFont.getCalculatedBaseFont(false); |
|
|
|
return oriFont.getCalculatedBaseFont(false); |
|
|
|
} |
|
|
|
} |
|
|
|