Browse Source

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

release/10.0
zhouping 5 years ago
parent
commit
168bc9e78d
  1. 11
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java
  2. 44
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

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

@ -97,6 +97,8 @@ public class PdfChunk {
private boolean breakTag = false;
public final static float SUB_PERCENT = 5f/6;
public float getHeight() {
return height;
}
@ -254,9 +256,7 @@ public class PdfChunk {
// italic simulation
if ((style & Font.ITALIC) != 0)
attributes.put(Chunk.SKEW, new float[]{0, ITALIC_ANGLE});
FontMetrics metrics = FontDesignMetrics.getMetrics(new java.awt.Font(f.getFontName(), f.getStyle(), (int) (f.getSize() * FONT_SCALE)));
font = new PdfFont(f, f.getSize());
height = metrics.getHeight() / FONT_SCALE + indent.getTop() + indent.getBottom();
// other style possibilities
HashMap attr = chunk.getAttributes();
if (attr != null) {
@ -274,6 +274,11 @@ public class PdfChunk {
attributes.put(Chunk.GENERICTAG, chunk.getContent());
}
}
//考虑下上下标
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();
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);

44
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

@ -67,7 +67,16 @@ public class PdfLine {
/** The arraylist containing the chunks. */
protected ArrayList line;
/** 最大文字上浮距离 */
protected float maxTextRise;
/** 最大文字下沉距离 */
protected float maxTextDrop;
/** true : 存在常规标签(非上下标) */
protected boolean existNormalTag;
/** The left indentation of the line. */
protected float left;
@ -211,18 +220,41 @@ public class PdfLine {
}
return overflow;
}
private void addToLine(PdfChunk chunk) {
//添加到line上处理计算line高度
if (chunk.changeLeading && chunk.isImage()) {
float f = chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() + chunk.getImage().getBorderWidthTop();
if (f > height) height = f;
float f = chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() + chunk.getImage().getBorderWidthTop();
if (f > height) height = f;
}else{
height = Math.max(height, chunk.getHeight());
float textRise = chunk.getTextRise();
if (textRise != 0) {
if (textRise > 0) {
maxTextRise = Math.max(maxTextRise, textRise);
} else {
maxTextDrop = -Math.min(maxTextDrop, textRise);
}
} else {
existNormalTag = true;
}
this.height = Math.max(this.height, chunk.getHeight() + (neddRiseOrDrop() ? maxTextRise + maxTextDrop : 0));
}
line.add(chunk);
}
public float getMaxTextRise() {
return maxTextRise;
}
public float getMaxTextDrop() {
return maxTextDrop;
}
public boolean neddRiseOrDrop() {
return existNormalTag && (maxTextRise > 0 || maxTextDrop > 0);
}
// methods to retrieve information
/**

Loading…
Cancel
Save