diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index e8f3f1406..a3558dab3 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/main/java/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); diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java index f9800c56b..44a02083e 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java +++ b/fine-itext/src/main/java/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/main/java/com/fr/third/v2/lowagie/text/pdf/PdfLine.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfLine.java index 220ae2c8a..72ae7d640 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfLine.java +++ b/fine-itext/src/main/java/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)); }