From 5b87243654a59025b4b29098e5b8b781b019e982 Mon Sep 17 00:00:00 2001 From: kerry Date: Sun, 30 Sep 2018 10:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=89=93=E5=8C=85=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/v2/lowagie/text/pdf/PdfFont.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 0f80b75aa..d81d3c878 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 @@ -169,12 +169,15 @@ public class PdfFont implements Comparable { } float width(String s) { + double width = 0.0d; 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 (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; + } } if (image == null) return (float) width * hScale; @@ -182,6 +185,7 @@ public class PdfFont implements Comparable { return image.getScaledWidth(); } + BaseFont getFont() { return oriFont.getCalculatedBaseFont(false); }