diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfFont.java b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfFont.java
index da9d4743d..b1d2183b7 100644
--- a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfFont.java
+++ b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfFont.java
@@ -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;
/**
* PdfFont
is the Pdf Font object.
@@ -77,31 +79,31 @@ public class PdfFont implements Comparable {
/** the font metrics. */
// private BaseFont font;
-
+
/** the size. */
private float size;
-
+
/** an image. */
protected Image image;
protected float hScale = 1;
-
+
// constructors
-
+
PdfFont(Font oriFont, float size) {
this.size = size;
this.oriFont = oriFont;
}
// methods
-
+
/**
* Compares this PdfFont
with another
*
* @param object the other PdfFont
* @return a value
*/
-
+
public int compareTo(Object object) {
if (image != null)
return 0;
@@ -125,13 +127,13 @@ public class PdfFont implements Comparable {
}
-
+
/**
* Returns the size of this font.
*
* @return a size
*/
-
+
float size() {
if (image == null)
return size;
@@ -139,24 +141,24 @@ public class PdfFont implements Comparable {
return image.getScaledHeight();
}
}
-
+
/**
* Returns the approximative width of 1 character of this font.
*
* @return a width in Text Space
*/
-
+
float width() {
return width(' ');
}
-
+
/**
* Returns the width of a certain character of this font.
*
* @param character a certain character
* @return a width in Text Space
*/
-
+
float width(int character) {
FontMetrics metrics = FontDesignMetrics.getMetrics(getAwtFont());
if (image == null)
@@ -164,15 +166,21 @@ public class PdfFont implements Comparable {
else
return image.getScaledWidth();
}
-
+
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();
}
-
+
BaseFont getFont() {
return oriFont.getCalculatedBaseFont(false);
}
@@ -195,7 +203,7 @@ public class PdfFont implements Comparable {
void setImage(Image image) {
this.image = image;
}
-
+
static PdfFont getDefaultFont() {
try {
// BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);