Browse Source

REPORT-23453 html切割时,丢失<br> 标签

bugfix/10.0
Hugh.C 5 years ago
parent
commit
de740d5754
  1. 21
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java
  2. 10
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

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

@ -88,6 +88,12 @@ public class PdfChunk {
private static final float FONT_SCALE = 100f;
private static final String BREAK = "\n";
private static final String BREAK_TAG = "<br>";
private boolean breakTag = false;
public float getHeight() {
return height;
}
@ -200,6 +206,7 @@ public class PdfChunk {
PdfChunk(String string, PdfChunk other) {
thisChunk[0] = this;
value = string;
updateBreakTag();
this.font = other.font;
this.attributes = other.attributes;
this.noStroke = other.noStroke;
@ -218,7 +225,7 @@ public class PdfChunk {
this.height = other.getHeight();
}
/**
/**
* Constructs a <CODE>PdfChunk</CODE>-object.
*
* @param chunk the original <CODE>Chunk</CODE>-object
@ -228,7 +235,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();
if (size == Font.UNDEFINED)
@ -798,7 +805,7 @@ public class PdfChunk {
htmlString.append("<span style='");
htmlString.append(getStyleAttributes()).append("'");
htmlString.append(">");
htmlString.append(value);
htmlString.append(breakTag ? BREAK_TAG : value);
htmlString.append("</span>");
return htmlString.toString();
}
@ -856,4 +863,12 @@ public class PdfChunk {
return indent.getLeft();
}
private void updateBreakTag() {
breakTag = BREAK.equals(value);
}
public boolean isBreakTag() {
return breakTag;
}
}

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

@ -94,6 +94,8 @@ public class PdfLine {
protected boolean isRTL = false;
public float getHeight() {
return height;
}
@ -155,7 +157,13 @@ public class PdfLine {
public PdfChunk add(PdfChunk chunk) {
// nothing happens if the chunk is null.
if (chunk == null || chunk.toString().equals("")) {
return null;
return null;
}
// add to line if the chunk is break tag ("\n")
if (chunk.isBreakTag()) {
addToLine(chunk);
width = 0;
return null;
}
// we split the chunk to be added

Loading…
Cancel
Save