Browse Source

Merge branch 'feature/10.0' of ssh://cloud.finedevelop.com:7999/~zhouping/base-third into feature/10.0

research/11.0
zhouping 5 years ago
parent
commit
460c0b2cc8
  1. 15
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java
  2. 10
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java
  3. 8
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

15
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.setInterfaceProps(interfaceProps);
worker.objectList = new ArrayList(); worker.objectList = new ArrayList();
worker.parse(reader); worker.parse(reader);
return worker.objectList; return worker.objectList;
} }
@ -178,7 +179,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
try { try {
for (int k = 0; k < stack.size(); ++k) for (int k = 0; k < stack.size(); ++k)
document.add((Element) stack.elementAt(k)); document.add((Element) stack.elementAt(k));
if (currentParagraph != null) if (needAddLastParagraph())
document.add(currentParagraph); document.add(currentParagraph);
currentParagraph = null; currentParagraph = null;
} catch (Exception e) { } 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() { public void startDocument() {
HashMap h = new HashMap(); HashMap h = new HashMap();
style.applyStyle("body", h); style.applyStyle("body", h);

10
fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java

@ -103,6 +103,10 @@ public class PdfChunk {
return height; return height;
} }
public float getTextDescent() {
return textDescent;
}
public void setHeight(float height) { public void setHeight(float height) {
this.height = height; this.height = height;
} }
@ -112,6 +116,8 @@ public class PdfChunk {
private float height = 0; private float height = 0;
private float textDescent = 0;
private IndentAttribute indent = new IndentAttribute(); private IndentAttribute indent = new IndentAttribute();
public Map<String, String> background ; public Map<String, String> background ;
@ -228,6 +234,7 @@ public class PdfChunk {
if (splitCharacter == null) if (splitCharacter == null)
splitCharacter = DefaultSplitCharacter.DEFAULT; splitCharacter = DefaultSplitCharacter.DEFAULT;
this.height = other.getHeight(); this.height = other.getHeight();
this.textDescent = other.getTextDescent();
} }
/** /**
@ -240,6 +247,7 @@ public class PdfChunk {
public PdfChunk(Chunk chunk, PdfAction action) { public PdfChunk(Chunk chunk, PdfAction action) {
thisChunk[0] = this; thisChunk[0] = this;
value = chunk.getContent(); value = chunk.getContent();
updateBreakTag(); updateBreakTag();
Font f = chunk.getFont(); Font f = chunk.getFont();
float size = f.getSize(); float size = f.getSize();
@ -278,7 +286,9 @@ public class PdfChunk {
int fontSize = (int) (f.getSize() * FONT_SCALE * (getTextRise() != 0 ? SUB_PERCENT : 1)); 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)); FontMetrics metrics = FontDesignMetrics.getMetrics(new java.awt.Font(f.getFontName(), f.getStyle(), fontSize));
font = new PdfFont(f, f.getSize()); font = new PdfFont(f, f.getSize());
height = metrics.getHeight() / FONT_SCALE + indent.getTop() + indent.getBottom(); height = metrics.getHeight() / FONT_SCALE + indent.getTop() + indent.getBottom();
textDescent = metrics.getDescent() / FONT_SCALE;
if (f.isUnderlined()) { if (f.isUnderlined()) {
Object obj[] = {null, new float[]{0, 1f / 15, 0, -1f / 3, 0}}; Object obj[] = {null, new float[]{0, 1f / 15, 0, -1f / 3, 0}};
Object unders[][] = Utilities.addToArray((Object[][])attributes.get(Chunk.UNDERLINE), obj); Object unders[][] = Utilities.addToArray((Object[][])attributes.get(Chunk.UNDERLINE), obj);

8
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 maxTextHeight;
protected float maxTextDescent;
/** The left indentation of the line. */ /** The left indentation of the line. */
protected float left; protected float left;
@ -108,9 +110,8 @@ public class PdfLine {
protected boolean isRTL = false; protected boolean isRTL = false;
public float getHeight() { public float getHeight() {
return height; return height + (maxImgHeight != 0 ? maxTextDescent : 0);
} }
public void setHeight(float height) { public void setHeight(float height) {
@ -239,7 +240,7 @@ public class PdfLine {
if (textRise > 0) { if (textRise > 0) {
maxTextRise = Math.max(maxTextRise, textRise); maxTextRise = Math.max(maxTextRise, textRise);
} else { } else {
maxTextDrop = -Math.min(maxTextDrop, textRise); maxTextDrop = Math.max(maxTextDrop, -textRise);
} }
} else { } else {
//一行中只有上下标时,不需要浮动 //一行中只有上下标时,不需要浮动
@ -250,6 +251,7 @@ public class PdfLine {
maxImgHeight = Math.max(maxImgHeight, chunk.getImage().getScaledHeight()); maxImgHeight = Math.max(maxImgHeight, chunk.getImage().getScaledHeight());
} else { } else {
maxTextHeight = Math.max(maxTextHeight, chunk.getHeight() + maxTextRise + maxTextDrop); 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)); this.height = Math.max(this.height, chunk.getHeight() + (neddRiseOrDrop() && !imgBigThanText() ? maxTextRise + maxTextDrop : 0));
} }

Loading…
Cancel
Save