|
|
|
@ -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. |
|
|
|
@ -166,9 +168,15 @@ public class PdfFont implements Comparable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float width(String s) { |
|
|
|
|
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont()); |
|
|
|
|
java.awt.Font font = this.getAwtFont(); |
|
|
|
|
float scale = 1000 / 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(); |
|
|
|
|
} |
|
|
|
|