|
|
|
@ -55,6 +55,8 @@ import com.fr.third.v2.lowagie.text.Image;
|
|
|
|
|
import sun.font.FontDesignMetrics; |
|
|
|
|
|
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
import java.awt.font.FontRenderContext; |
|
|
|
|
import java.awt.geom.AffineTransform; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <CODE>PdfFont</CODE> is the Pdf Font object. |
|
|
|
@ -72,6 +74,7 @@ import java.awt.FontMetrics;
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
public class PdfFont implements Comparable { |
|
|
|
|
private static final int ONE_THOUSAND = 1000 ; |
|
|
|
|
|
|
|
|
|
private Font oriFont; |
|
|
|
|
|
|
|
|
@ -166,9 +169,15 @@ public class PdfFont implements Comparable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
return metrics.stringWidth(s) * hScale; |
|
|
|
|
return (float) width * hScale; |
|
|
|
|
else |
|
|
|
|
return image.getScaledWidth(); |
|
|
|
|
} |
|
|
|
|