Browse Source

Merge pull request #397 in CORE/base-third from ~HUGH.C/base-third:release/10.0 to release/10.0

* commit '48c82fc848db6b9b76adcacf31b2610515be30cd':
  REPORT-28245 review 改进
  REPORT-28245 图片与文本在同一行时绘制高度和位置不对
  REPORT-28245 <img>标签不属于块级元素
release/10.0
ju.ju 5 years ago
parent
commit
f241fa8f27
  1. 2
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java
  2. 23
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

2
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;
}

23
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
/**

Loading…
Cancel
Save