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 4ccf4aaff..e8f3f1406 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 @@ -526,7 +526,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { cprops.removeChain(follow); return; } - if (tag.equals("font") || tag.equals("span")) { + if (tag.equals("font") || tag.equals("span") || tag.equals("img")) { cprops.removeChain(tag); return; } 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 db519ecc8..220ae2c8a 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 @@ -77,6 +77,10 @@ public class PdfLine { /** true : 存在常规标签(非上下标) */ protected boolean existNormalTag; + protected float maxImgHeight; + + protected float maxTextHeight; + /** The left indentation of the line. */ protected float left; @@ -225,7 +229,10 @@ public class PdfLine { //添加到line上处理计算line高度 if (chunk.changeLeading && chunk.isImage()) { float f = chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() + chunk.getImage().getBorderWidthTop(); - if (f > height) height = f; + if (f > height){ + height = f; + } + maxImgHeight = Math.max(maxImgHeight, f); }else{ float textRise = chunk.getTextRise(); if (textRise != 0) { @@ -234,11 +241,17 @@ public class PdfLine { } else { maxTextDrop = -Math.min(maxTextDrop, textRise); } - } else { + //一行中只有上下标时,不需要浮动 existNormalTag = true; } - this.height = Math.max(this.height, chunk.getHeight() + (neddRiseOrDrop() ? maxTextRise + maxTextDrop : 0)); + //图片存在且高度足够大,整体高度就不考虑上下标的浮动距离了 + if (chunk.isImage()) { + maxImgHeight = Math.max(maxImgHeight, chunk.getImage().getScaledHeight()); + } else { + maxTextHeight = Math.max(maxTextHeight, chunk.getHeight() + maxTextRise + maxTextDrop); + } + this.height = Math.max(this.height, chunk.getHeight() + (neddRiseOrDrop() && !imgBigThanText() ? maxTextRise + maxTextDrop : 0)); } line.add(chunk); } @@ -255,6 +268,10 @@ public class PdfLine { return existNormalTag && (maxTextRise > 0 || maxTextDrop > 0); } + public boolean imgBigThanText() { + return maxImgHeight > maxTextHeight; + } + // methods to retrieve information /**