Browse Source

REPORT-11624 Excel和Word导出的html解析支持

research/11.0
kerry 6 years ago
parent
commit
ea82a6fc62
  1. 72
      fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java
  2. 59
      fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java

72
fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java

@ -49,11 +49,13 @@
package com.fr.third.com.lowagie.text;
import java.awt.Color;
import com.fr.third.com.lowagie.text.ExceptionConverter;
import com.fr.third.com.lowagie.text.FontFactory;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.pdf.BaseFont;
import java.awt.Color;
/**
* Contains all the specifications of a font: fontfamily, size, style and color.
* <P>
@ -133,6 +135,14 @@ public class Font implements Comparable {
/** the external font */
private BaseFont baseFont = null;
private String fontName = "";
public String getFontName(){
return fontName;
}
// constructors
/**
@ -141,7 +151,7 @@ public class Font implements Comparable {
* @param other
* the font that has to be copied
*/
public Font(Font other) {
public Font(com.fr.third.com.lowagie.text.Font other) {
this.family = other.family;
this.size = other.size;
this.style = other.style;
@ -169,6 +179,13 @@ public class Font implements Comparable {
this.color = color;
}
public Font(String face, float size, int style, Color color) {
this.fontName = face;
this.size =size;
this.style = style;
this.color = color;
}
/**
* Constructs a Font.
*
@ -285,9 +302,9 @@ public class Font implements Comparable {
if (object == null) {
return -1;
}
Font font;
com.fr.third.com.lowagie.text.Font font;
try {
font = (Font) object;
font = (com.fr.third.com.lowagie.text.Font) object;
if (baseFont != null && !baseFont.equals(font.getBaseFont())) {
return -2;
}
@ -335,35 +352,7 @@ public class Font implements Comparable {
* @return the familyname
*/
public String getFamilyname() {
String tmp = "unknown";
switch (getFamily()) {
case Font.COURIER:
return FontFactory.COURIER;
case Font.HELVETICA:
return FontFactory.HELVETICA;
case Font.TIMES_ROMAN:
return FontFactory.TIMES_ROMAN;
case Font.SYMBOL:
return FontFactory.SYMBOL;
case Font.ZAPFDINGBATS:
return FontFactory.ZAPFDINGBATS;
default:
if (baseFont != null) {
String[][] names = baseFont.getFamilyFontName();
for (int i = 0; i < names.length; i++) {
if ("0".equals(names[i][2])) {
return names[i][3];
}
if ("1033".equals(names[i][2])) {
tmp = names[i][3];
}
if ("".equals(names[i][2])) {
tmp = names[i][3];
}
}
}
}
return tmp;
return getFontName();
}
/**
@ -374,9 +363,10 @@ public class Font implements Comparable {
* A <CODE>String</CODE> representing a certain font-family.
*/
public void setFamily(String family) {
this.family = getFamilyIndex(family);
this.fontName = family;
}
/**
* Translates a <CODE>String</CODE> -value of a certain family into the
* index that is used for this family in this class.
@ -697,7 +687,7 @@ public class Font implements Comparable {
encoding = BaseFont.ZAPFDINGBATS;
break;
default:
case Font.HELVETICA:
case com.fr.third.com.lowagie.text.Font.HELVETICA:
switch (style & BOLDITALIC) {
case BOLD:
fontName = BaseFont.HELVETICA_BOLD;
@ -746,7 +736,7 @@ public class Font implements Comparable {
* the font of a bigger element class
* @return a <CODE>Font</CODE>
*/
public Font difference(Font font) {
public com.fr.third.com.lowagie.text.Font difference(com.fr.third.com.lowagie.text.Font font) {
if (font == null) return this;
// size
float dSize = font.size;
@ -771,20 +761,20 @@ public class Font implements Comparable {
}
// family
if (font.baseFont != null) {
return new Font(font.baseFont, dSize, dStyle, dColor);
return new com.fr.third.com.lowagie.text.Font(font.baseFont, dSize, dStyle, dColor);
}
if (font.getFamily() != UNDEFINED) {
return new Font(font.family, dSize, dStyle, dColor);
return new com.fr.third.com.lowagie.text.Font(font.family, dSize, dStyle, dColor);
}
if (this.baseFont != null) {
if (dStyle == style1) {
return new Font(this.baseFont, dSize, dStyle, dColor);
return new com.fr.third.com.lowagie.text.Font(this.baseFont, dSize, dStyle, dColor);
} else {
return FontFactory.getFont(this.getFamilyname(), dSize, dStyle,
dColor);
}
}
return new Font(this.family, dSize, dStyle, dColor);
return new com.fr.third.com.lowagie.text.Font(this.family, dSize, dStyle, dColor);
}
}

59
fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java

@ -49,6 +49,17 @@
package com.fr.third.com.lowagie.text;
import com.fr.third.com.lowagie.text.Chunk;
import com.fr.third.com.lowagie.text.Element;
import com.fr.third.com.lowagie.text.ElementTags;
import com.fr.third.com.lowagie.text.Font;
import com.fr.third.com.lowagie.text.Image;
import com.fr.third.com.lowagie.text.List;
import com.fr.third.com.lowagie.text.ListItem;
import com.fr.third.com.lowagie.text.Phrase;
import java.util.HashMap;
/**
* A <CODE>Paragraph</CODE> is a series of <CODE>Chunk</CODE>s and/or <CODE>Phrases</CODE>.
* <P>
@ -78,7 +89,7 @@ public class Paragraph extends Phrase {
// membervariables
/** The alignment of the text. */
protected int alignment = Element.ALIGN_UNDEFINED;
protected int alignment = ALIGN_UNDEFINED;
/** The text leading that is multiplied by the biggest font size in the line. */
protected float multipliedLeading = 0;
@ -104,6 +115,24 @@ public class Paragraph extends Phrase {
/** Does the paragraph has to be kept together on 1 page. */
protected boolean keeptogether = false;
protected String background;
protected HashMap attributes = new HashMap();
public HashMap getAttributes() {
return attributes;
}
public void setAttributes(HashMap attributes) {
this.attributes = attributes;
}
public void setAttribute(String name, Object obj) {
if (attributes == null)
attributes = new HashMap();
attributes.put(name, obj);
}
// constructors
/**
@ -192,8 +221,8 @@ public class Paragraph extends Phrase {
*/
public Paragraph(Phrase phrase) {
super(phrase);
if (phrase instanceof Paragraph) {
Paragraph p = (Paragraph)phrase;
if (phrase instanceof com.fr.third.com.lowagie.text.Paragraph) {
com.fr.third.com.lowagie.text.Paragraph p = (com.fr.third.com.lowagie.text.Paragraph)phrase;
setAlignment(p.alignment);
setLeading(phrase.getLeading(), p.multipliedLeading);
setIndentationLeft(p.getIndentationLeft());
@ -213,7 +242,7 @@ public class Paragraph extends Phrase {
* @return a type
*/
public int type() {
return Element.PARAGRAPH;
return PARAGRAPH;
}
// methods
@ -235,7 +264,7 @@ public class Paragraph extends Phrase {
super.addSpecial(o);
return true;
}
else if (o instanceof Paragraph) {
else if (o instanceof com.fr.third.com.lowagie.text.Paragraph) {
super.add(o);
java.util.List chunks = getChunks();
if (!chunks.isEmpty()) {
@ -268,26 +297,26 @@ public class Paragraph extends Phrase {
*/
public void setAlignment(String alignment) {
if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_CENTER;
this.alignment = ALIGN_CENTER;
return;
}
if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_RIGHT;
this.alignment = ALIGN_RIGHT;
return;
}
if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_JUSTIFIED;
this.alignment = ALIGN_JUSTIFIED;
return;
}
if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_JUSTIFIED_ALL;
this.alignment = ALIGN_JUSTIFIED_ALL;
return;
}
this.alignment = Element.ALIGN_LEFT;
this.alignment = ALIGN_LEFT;
}
/**
* @see com.fr.third.com.lowagie.text.Phrase#setLeading(float)
* @see Phrase#setLeading(float)
*/
public void setLeading(float fixedLeading) {
this.leading = fixedLeading;
@ -499,4 +528,12 @@ public class Paragraph extends Phrase {
return spacingAfter;
}
public void setBackground(String background){
this.background = background;
}
public String getBackground(){
return this.background;
}
}

Loading…
Cancel
Save