Browse Source

REPORT-10262 html大文本精确分页

final/10.0.3
kerry 6 years ago
parent
commit
6a959c0b33
  1. 12
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfFont.java

12
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;
/**
* <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();
}

Loading…
Cancel
Save