From 3babdf48a278faa18e1a47fd519709017186e6d1 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 24 Mar 2020 09:42:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-28589=20html=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E8=A1=8C=E4=B8=8D=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E5=85=A8=E6=98=AF=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/HTMLWorker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index e8f3f1406..a3558dab3 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java @@ -171,6 +171,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { worker.setInterfaceProps(interfaceProps); worker.objectList = new ArrayList(); worker.parse(reader); + return worker.objectList; } @@ -178,7 +179,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { try { for (int k = 0; k < stack.size(); ++k) document.add((Element) stack.elementAt(k)); - if (currentParagraph != null) + if (needAddLastParagraph()) document.add(currentParagraph); currentParagraph = null; } catch (Exception e) { @@ -186,6 +187,18 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { } } + private boolean needAddLastParagraph() { + if (currentParagraph == null) { + return false; + } + ArrayList list = currentParagraph.getChunks(); + if (!(list.size() == 1 && list.get(0) instanceof Chunk)) { + return true; + } + Chunk c = (Chunk) list.get(0); + return c.getImage() != null || c.getContent().trim().length() != 0; + } + public void startDocument() { HashMap h = new HashMap(); style.applyStyle("body", h); From f94bea200400df721cd53758a8854b1324c51a38 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Wed, 25 Mar 2020 15:06:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-28245=20HTML=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=EF=BC=8C=E5=9B=BE=E7=89=87=E5=92=8C=E6=96=87=E5=AD=97=E5=9C=A8?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E8=A1=8C=E6=97=B6=E5=8E=8B=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java | 10 ++++++++++ .../src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java index f9800c56b..44a02083e 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java @@ -103,6 +103,10 @@ public class PdfChunk { return height; } + public float getTextDescent() { + return textDescent; + } + public void setHeight(float height) { this.height = height; } @@ -112,6 +116,8 @@ public class PdfChunk { private float height = 0; + private float textDescent = 0; + private IndentAttribute indent = new IndentAttribute(); public Map background ; @@ -228,6 +234,7 @@ public class PdfChunk { if (splitCharacter == null) splitCharacter = DefaultSplitCharacter.DEFAULT; this.height = other.getHeight(); + this.textDescent = other.getTextDescent(); } /** @@ -240,6 +247,7 @@ public class PdfChunk { public PdfChunk(Chunk chunk, PdfAction action) { thisChunk[0] = this; value = chunk.getContent(); + updateBreakTag(); Font f = chunk.getFont(); float size = f.getSize(); @@ -278,7 +286,9 @@ public class PdfChunk { int fontSize = (int) (f.getSize() * FONT_SCALE * (getTextRise() != 0 ? SUB_PERCENT : 1)); FontMetrics metrics = FontDesignMetrics.getMetrics(new java.awt.Font(f.getFontName(), f.getStyle(), fontSize)); font = new PdfFont(f, f.getSize()); + height = metrics.getHeight() / FONT_SCALE + indent.getTop() + indent.getBottom(); + textDescent = metrics.getDescent() / FONT_SCALE; if (f.isUnderlined()) { Object obj[] = {null, new float[]{0, 1f / 15, 0, -1f / 3, 0}}; Object unders[][] = Utilities.addToArray((Object[][])attributes.get(Chunk.UNDERLINE), obj); diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java index 220ae2c8a..72ae7d640 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java @@ -81,6 +81,8 @@ public class PdfLine { protected float maxTextHeight; + protected float maxTextDescent; + /** The left indentation of the line. */ protected float left; @@ -108,9 +110,8 @@ public class PdfLine { protected boolean isRTL = false; - public float getHeight() { - return height; + return height + (maxImgHeight != 0 ? maxTextDescent : 0); } public void setHeight(float height) { @@ -239,7 +240,7 @@ public class PdfLine { if (textRise > 0) { maxTextRise = Math.max(maxTextRise, textRise); } else { - maxTextDrop = -Math.min(maxTextDrop, textRise); + maxTextDrop = Math.max(maxTextDrop, -textRise); } } else { //一行中只有上下标时,不需要浮动 @@ -250,6 +251,7 @@ public class PdfLine { maxImgHeight = Math.max(maxImgHeight, chunk.getImage().getScaledHeight()); } else { maxTextHeight = Math.max(maxTextHeight, chunk.getHeight() + maxTextRise + maxTextDrop); + maxTextDescent = Math.max(maxTextDescent, chunk.getTextDescent()); } this.height = Math.max(this.height, chunk.getHeight() + (neddRiseOrDrop() && !imgBigThanText() ? maxTextRise + maxTextDrop : 0)); }