Browse Source
* commit '0d859e400ec56ca509a14633d6c98f8e37a811d2': 删除无用代码 删除无用代码 REPORT-11624 Excel和Word导出的html解析(third部分)research/11.0
ju
6 years ago
24 changed files with 2844 additions and 1871 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,200 @@
|
||||
package com.fr.third.com.lowagie.text.html; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/5/11 |
||||
*/ |
||||
public class CSS { |
||||
public final class Value { |
||||
private Value(){}; |
||||
public static final String THIN = "thin"; |
||||
public static final String MEDIUM = "medium"; |
||||
public static final String THICK = "thick"; |
||||
public static final String NONE = "none"; |
||||
public static final String HIDDEN = "hidden"; |
||||
public static final String DOTTED = "dotted"; |
||||
public static final String DASHED = "dashed"; |
||||
public static final String SOLID = "solid"; |
||||
public static final String DOUBLE = "double"; |
||||
public static final String GROOVE = "groove"; |
||||
public static final String RIDGE = "ridge"; |
||||
public static final String INSET = "inset"; |
||||
public static final String OUTSET = "outset"; |
||||
public static final String LEFT = "left"; |
||||
public static final String CENTER = "center"; |
||||
public static final String JUSTIFY = "justify"; |
||||
public static final String BOTTOM = "bottom"; |
||||
public static final String TOP = "top"; |
||||
public static final String RIGHT = "right"; |
||||
public static final String REPEAT = "repeat"; |
||||
public static final String NO_REPEAT = "no-repeat"; |
||||
public static final String REPEAT_X = "repeat-x"; |
||||
public static final String REPEAT_Y = "repeat-y"; |
||||
public static final String FIXED = "fixed"; |
||||
public static final String SCROLL = "scroll"; |
||||
public static final String DISC = "disc"; |
||||
public static final String SQUARE = "square"; |
||||
public static final String CIRCLE = "circle"; |
||||
public static final String DECIMAL = "decimal"; |
||||
public static final String LOWER_ROMAN = "lower-roman"; |
||||
public static final String UPPER_ROMAN = "upper-roman"; |
||||
public static final String LOWER_GREEK = "lower-greek"; |
||||
public static final String UPPER_GREEK = "upper-greek"; |
||||
public static final String LOWER_ALPHA = "lower-alpha"; |
||||
public static final String UPPER_ALPHA = "upper-alpha"; |
||||
public static final String LOWER_LATIN = "lower-latin"; |
||||
public static final String UPPER_LATIN = "upper-latin"; |
||||
public static final String INSIDE = "inside"; |
||||
public static final String OUTSIDE = "outside"; |
||||
public static final String INHERIT = "inherit"; |
||||
public static final String UNDERLINE = "underline"; |
||||
public static final String BOLD = "bold"; |
||||
public static final String ITALIC = "italic"; |
||||
public static final String OBLIQUE = "oblique"; |
||||
public static final String SUPER = "super"; |
||||
public static final String SUB = "sub"; |
||||
public static final String TEXT_TOP = "text-top"; |
||||
public static final String TEXT_BOTTOM = "text-bottom"; |
||||
public static final String LINE_THROUGH = "line-through"; |
||||
public static final String RELATIVE = "relative"; |
||||
public static final String HIDE = "hide"; |
||||
public static final String XX_SMALL = "xx-small"; |
||||
public static final String X_SMALL = "x-small"; |
||||
public static final String SMALL = "small"; |
||||
public static final String LARGE = "large"; |
||||
public static final String X_LARGE = "x-large"; |
||||
public static final String XX_LARGE = "xx-large"; |
||||
public static final String SMALLER = "smaller"; |
||||
public static final String LARGER = "larger"; |
||||
public static final String PX = "px"; |
||||
public static final String IN = "in"; |
||||
public static final String CM = "cm"; |
||||
public static final String MM = "mm"; |
||||
public static final String PT = "pt"; |
||||
public static final String PC = "pc"; |
||||
public static final String PERCENTAGE = "%"; |
||||
public static final String EM = "em"; |
||||
public static final String EX = "ex"; |
||||
public static final String ALWAYS = "always"; |
||||
public static final String AVOID = "avoid"; |
||||
public static final String ABSOLUTE = "absolute"; |
||||
public static final String AUTO = "auto"; |
||||
public static final String INLINE = "inline"; |
||||
public static final String BLOCK = "block"; |
||||
public static final String SEPARATE = "separate"; |
||||
public static final String COLLAPSE = "collapse"; |
||||
public static final String RTL = "rtl"; |
||||
public static final String LTR = "ltr"; |
||||
public static final String INLINE_BLOCK = "inline-block"; |
||||
public static final String INLINE_TABLE = "inline-table"; |
||||
public static final String LIST_ITEM = "list-item"; |
||||
public static final String RUN_IN = "run-in"; |
||||
public static final String TABLE = "table"; |
||||
public static final String TABLE_CAPTION = "table-caption"; |
||||
public static final String TABLE_CELL = "table-cell"; |
||||
public static final String TABLE_COLUMN_GROUP = "table-column-group"; |
||||
public static final String TABLE_COLUMN = "table-column"; |
||||
public static final String TABLE_FOOTER_GROUP = "table-footer-group"; |
||||
public static final String TABLE_HEADER_GROUP = "table-header-group"; |
||||
public static final String TABLE_ROW = "table-row"; |
||||
public static final String TABLE_ROW_GROUP = "table-row-group"; |
||||
} |
||||
|
||||
public final class Property { |
||||
|
||||
private Property() {}; |
||||
public static final String BACKGROUND = "background"; |
||||
public static final String BACKGROUND_IMAGE = "background-image"; |
||||
public static final String BACKGROUND_REPEAT = "background-repeat"; |
||||
public static final String BACKGROUND_ATTACHMENT = "background-attachment"; |
||||
public static final String BACKGROUND_POSITION = "background-position"; |
||||
public static final String BACKGROUND_COLOR = "background-color"; |
||||
public static final String BACKGROUND_SIZE = "background-size"; |
||||
public static final String LIST_STYLE = "list-style"; |
||||
public static final String LIST_STYLE_TYPE = "list-style-type"; |
||||
public static final String LIST_STYLE_POSITION = "list-style-position"; |
||||
public static final String LIST_STYLE_IMAGE = "list-style-image"; |
||||
public static final String MARGIN = "margin"; |
||||
public static final String TOP = "top"; |
||||
public static final String MARGIN_LEFT = "margin-left"; |
||||
public static final String MARGIN_RIGHT = "margin-right"; |
||||
public static final String MARGIN_TOP = "margin-top"; |
||||
public static final String MARGIN_BOTTOM = "margin-bottom"; |
||||
public static final String BORDER = "border"; |
||||
public static final String BORDER_LEFT = "border-left"; |
||||
public static final String BORDER_TOP = "border-top"; |
||||
public static final String BORDER_RIGHT = "border-right"; |
||||
public static final String BORDER_BOTTOM = "border-bottom"; |
||||
public static final String BORDER_WIDTH = "border-width"; |
||||
public static final String BORDER_STYLE = "border-style"; |
||||
public static final String BORDER_COLOR = "border-color"; |
||||
public static final String BORDER_COLLAPSE = "border-collapse"; |
||||
public static final String BORDER_SPACING = "border-spacing"; |
||||
public static final String BORDER_TOP_WIDTH = "border-top-width"; |
||||
public static final String BORDER_BOTTOM_WIDTH = "border-bottom-width"; |
||||
public static final String BORDER_LEFT_WIDTH = "border-left-width"; |
||||
public static final String BORDER_RIGHT_WIDTH = "border-right-width"; |
||||
public static final String BORDER_TOP_COLOR = "border-top-color"; |
||||
public static final String BORDER_BOTTOM_COLOR = "border-bottom-color"; |
||||
public static final String BORDER_LEFT_COLOR = "border-left-color"; |
||||
public static final String BORDER_RIGHT_COLOR = "border-right-color"; |
||||
public static final String BORDER_TOP_STYLE = "border-top-style"; |
||||
public static final String BORDER_BOTTOM_STYLE = "border-bottom-style"; |
||||
public static final String BORDER_LEFT_STYLE = "border-left-style"; |
||||
public static final String BORDER_RIGHT_STYLE = "border-right-style"; |
||||
public static final String PADDING = "padding"; |
||||
public static final String PADDING_TOP = "padding-top"; |
||||
public static final String PADDING_BOTTOM = "padding-bottom"; |
||||
public static final String PADDING_LEFT = "padding-left"; |
||||
public static final String PADDING_RIGHT = "padding-right"; |
||||
public static final String FONT = "font"; |
||||
public static final String FONT_WEIGHT = "font-weight"; |
||||
public static final String FONT_SIZE = "font-size"; |
||||
public static final String FONT_STYLE = "font-style"; |
||||
public static final String FONT_FAMILY = "font-family"; |
||||
public static final String TEXT_DECORATION = "text-decoration"; |
||||
public static final String COLOR = "color"; |
||||
public static final String TAB_INTERVAL = "tab-interval"; |
||||
public static final String XFA_TAB_COUNT = "xfa-tab-count"; |
||||
public static final String XFA_FONT_HORIZONTAL_SCALE = "xfa-font-horizontal-scale"; |
||||
public static final String XFA_FONT_VERTICAL_SCALE = "xfa-font-vertical-scale"; |
||||
public static final String BEFORE = "before"; |
||||
public static final String AFTER = "after"; |
||||
public static final String HEIGHT = "height"; |
||||
public static final String WIDTH = "width"; |
||||
public static final String LETTER_SPACING = "letter-spacing"; |
||||
public static final String VERTICAL_ALIGN = "vertical-align"; |
||||
public static final String LINE_HEIGHT = "line-height"; |
||||
public static final String TEXT_ALIGN = "text-align"; |
||||
public static final String TEXT_VALIGN = "text-valign"; |
||||
public static final String TEXT_INDENT = "text-indent"; |
||||
public static final String POSITION = "position"; |
||||
public static final String EMPTY_CELLS = "empty-cells"; |
||||
public static final String CELLPADDING = "cellpadding"; |
||||
//deprecated
|
||||
public static final String CELLPADDING_LEFT = "cellpadding-left"; |
||||
public static final String CELLPADDING_TOP = "cellpadding-top"; |
||||
public static final String CELLPADDING_RIGHT = "cellpadding-right"; |
||||
public static final String CELLPADDING_BOTTOM = "cellpadding-bottom"; |
||||
|
||||
public static final String CAPTION_SIDE = "caption-side"; |
||||
public static final String TAB_STOPS = "tab-stops"; |
||||
public static final String XFA_TAB_STOPS = "xfa-tab-stops"; |
||||
public static final String PAGE_BREAK_BEFORE = "page-break-before"; |
||||
public static final String PAGE_BREAK_INSIDE = "page-break-inside"; |
||||
public static final String PAGE_BREAK_AFTER = "page-break-after"; |
||||
public static final String REPEAT_HEADER = "repeat-header"; |
||||
public static final String REPEAT_FOOTER = "repeat-footer"; |
||||
public static final String LEFT = "left"; |
||||
public static final String DISPLAY = "display"; |
||||
public static final String MIN_WIDTH = "min-width"; |
||||
public static final String MAX_WIDTH = "max-width"; |
||||
public static final String MIN_HEIGHT = "min-height"; |
||||
public static final String MAX_HEIGHT = "max-height"; |
||||
public static final String RIGHT = "right"; |
||||
public static final String BOTTOM = "bottom"; |
||||
public static final String FLOAT = "float"; |
||||
public static final String DIRECTION = "direction"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,105 @@
|
||||
package com.fr.third.com.lowagie.text.html; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/4/9 |
||||
*/ |
||||
public class CSSUtils { |
||||
|
||||
|
||||
private static final Set<String> backgroundPositions = new HashSet<String>( |
||||
Arrays.asList(new String[] { CSS.Value.LEFT, CSS.Value.CENTER, CSS.Value.BOTTOM, CSS.Value.TOP, CSS.Value.RIGHT })); |
||||
|
||||
public static Map<String, String> processBackground(final String background) { |
||||
Map<String, String> rules = new HashMap<String, String>(); |
||||
String[] styles = splitComplexCssStyle(background); |
||||
for(String style : styles) { |
||||
if (style.contains("url(")) { |
||||
rules.put(CSS.Property.BACKGROUND_IMAGE, style); |
||||
} else if (style.equalsIgnoreCase(CSS.Value.REPEAT) |
||||
|| style.equalsIgnoreCase(CSS.Value.NO_REPEAT) |
||||
|| style.equalsIgnoreCase(CSS.Value.REPEAT_X) |
||||
|| style.equalsIgnoreCase(CSS.Value.REPEAT_Y)) { |
||||
rules.put(CSS.Property.BACKGROUND_REPEAT, style); |
||||
} else if (style.equalsIgnoreCase(CSS.Value.FIXED) || style.equalsIgnoreCase(CSS.Value.SCROLL)) { |
||||
rules.put(CSS.Property.BACKGROUND_ATTACHMENT, style); |
||||
} else if (backgroundPositions.contains(style)) { |
||||
if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) { |
||||
rules.put(CSS.Property.BACKGROUND_POSITION, style); |
||||
} else { |
||||
style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION)); |
||||
rules.put(CSS.Property.BACKGROUND_POSITION, style); |
||||
} |
||||
} else if (isNumericValue(style) || isMetricValue(style) || isRelativeValue(style)) { |
||||
if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) { |
||||
rules.put(CSS.Property.BACKGROUND_POSITION, style); |
||||
} else { |
||||
style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION)); |
||||
rules.put(CSS.Property.BACKGROUND_POSITION, style); |
||||
} |
||||
} else if(style.contains("rgb(") || style.contains("rgba(") || style.contains("#") || WebColors.NAMES.containsKey(style.toLowerCase())) { |
||||
rules.put(CSS.Property.BACKGROUND_COLOR, style); |
||||
} |
||||
} |
||||
return rules; |
||||
} |
||||
public static String[] splitComplexCssStyle(String s) { |
||||
s = s.replaceAll("\\s*,\\s*", ",") ; |
||||
return s.split("\\s"); |
||||
} |
||||
|
||||
|
||||
public static boolean isMetricValue(final String value) { |
||||
return value.contains(CSS.Value.PX) || value.contains(CSS.Value.IN) || value.contains(CSS.Value.CM) |
||||
|| value.contains(CSS.Value.MM) || value.contains(CSS.Value.PC) || value.contains(CSS.Value.PT); |
||||
|
||||
} |
||||
|
||||
public static boolean isRelativeValue(final String value) { |
||||
return value.contains(CSS.Value.PERCENTAGE) || value.contains(CSS.Value.EM) || value.contains(CSS.Value.EX); |
||||
|
||||
} |
||||
|
||||
public static boolean isNumericValue(final String value) { |
||||
return value.matches("^-?\\d\\d*\\.\\d*$") || value.matches("^-?\\d\\d*$") || value.matches("^-?\\.\\d\\d*$"); |
||||
|
||||
} |
||||
|
||||
|
||||
public static String extractUrl(final String url) { |
||||
String str = null; |
||||
if (url.startsWith("url")) { |
||||
String urlString = url.substring(3).trim().replace("(", "").replace(")", "").trim(); |
||||
if (urlString.startsWith("'") && urlString.endsWith("'")) { |
||||
str = urlString.substring(urlString.indexOf("'")+1, urlString.lastIndexOf("'")); |
||||
} else if ( urlString.startsWith("\"") && urlString.endsWith("\"") ) { |
||||
str = urlString.substring(urlString.indexOf('"')+1, urlString.lastIndexOf('"')); |
||||
} else { |
||||
str = urlString; |
||||
} |
||||
} else { |
||||
str = url; |
||||
} |
||||
return str; |
||||
} |
||||
|
||||
public static Float parseFloat(String str){ |
||||
float result = 0.0f; |
||||
try { |
||||
if(str.endsWith("px") || str.endsWith("pt")){ |
||||
result = Float.parseFloat(str.substring(0, str.length() - 2)); |
||||
}else{ |
||||
result = Float.parseFloat(str); |
||||
} |
||||
}catch (NumberFormatException e){ |
||||
|
||||
} |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.fr.third.com.lowagie.text.html; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/5/9 |
||||
*/ |
||||
public class IndentAttribute { |
||||
private float top = 0.0f; |
||||
private float bottom = 0.0f; |
||||
private float left = 0.0f; |
||||
private float right = 0.0f; |
||||
|
||||
public float getTop() { |
||||
return top; |
||||
} |
||||
|
||||
public void setTop(float top) { |
||||
this.top = top; |
||||
} |
||||
|
||||
public float getBottom() { |
||||
return bottom; |
||||
} |
||||
|
||||
public void setBottom(float bottom) { |
||||
this.bottom = bottom; |
||||
} |
||||
|
||||
public float getLeft() { |
||||
return left; |
||||
} |
||||
|
||||
public void setLeft(float left) { |
||||
this.left = left; |
||||
} |
||||
|
||||
public float getRight() { |
||||
return right; |
||||
} |
||||
|
||||
public void setRight(float right) { |
||||
this.right = right; |
||||
} |
||||
|
||||
public IndentAttribute(float top, float left, float bottom, float right){ |
||||
this.top = top; |
||||
this.left = left; |
||||
this.bottom = bottom; |
||||
this.right = right; |
||||
} |
||||
|
||||
public IndentAttribute(){ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
package com.fr.third.com.lowagie.text.html; |
||||
|
||||
import com.fr.third.com.lowagie.text.html.CSS; |
||||
import com.fr.third.com.lowagie.text.html.IndentAttribute; |
||||
import com.fr.third.com.lowagie.text.html.Markup; |
||||
|
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/5/14 |
||||
*/ |
||||
public class ParseIndentAttrUtils { |
||||
public static IndentAttribute parseSpace(String indent){ |
||||
String[] a = indent.split(" "); |
||||
if(a.length == 0){ |
||||
return new IndentAttribute(); |
||||
} |
||||
float indentTop = Markup.parseLength(a[0]); |
||||
if(a.length == 1){ |
||||
return new IndentAttribute(indentTop, indentTop, indentTop, indentTop); |
||||
} |
||||
float indentLeft = Markup.parseLength(a[1]); |
||||
if(a.length == 2){ |
||||
return new IndentAttribute(indentTop, indentLeft, indentTop, indentLeft); |
||||
} |
||||
float indentBottom = Markup.parseLength(a[2]); |
||||
if(a.length == 3){ |
||||
return new IndentAttribute(indentTop, indentLeft, indentBottom, indentLeft); |
||||
} |
||||
float indentRight = Markup.parseLength(a[3]); |
||||
return new IndentAttribute(indentTop, indentLeft, indentBottom, indentRight); |
||||
} |
||||
|
||||
public static IndentAttribute parsePaddingAttribute(Map map){ |
||||
if (map == null){ |
||||
return new IndentAttribute(); |
||||
} |
||||
IndentAttribute indentAttribute = new IndentAttribute(); |
||||
Iterator iter = map.entrySet().iterator(); |
||||
while (iter.hasNext()) { |
||||
Map.Entry entry = (Map.Entry) iter.next(); |
||||
String key = (String) entry.getKey(); |
||||
if (CSS.Property.PADDING_LEFT.equals(key)) { |
||||
indentAttribute.setLeft(Markup.parseLength((String) entry.getValue())); |
||||
} else if (CSS.Property.PADDING_RIGHT.equals(key)) { |
||||
indentAttribute.setRight(Markup.parseLength((String) entry.getValue())); |
||||
} else if (CSS.Property.PADDING_TOP.equals(key)) { |
||||
indentAttribute.setTop(Markup.parseLength((String) entry.getValue())); |
||||
} else if (CSS.Property.PADDING_BOTTOM.equals(key)) { |
||||
indentAttribute.setBottom(Markup.parseLength((String) entry.getValue())); |
||||
} |
||||
} |
||||
return indentAttribute; |
||||
} |
||||
|
||||
public static IndentAttribute parseMarginAttribute(Map map){ |
||||
IndentAttribute indentAttribute = new IndentAttribute(); |
||||
Iterator iter = map.entrySet().iterator(); |
||||
while (iter.hasNext()) { |
||||
Map.Entry entry = (Map.Entry) iter.next(); |
||||
String key = (String) entry.getKey(); |
||||
float val = Markup.parseLength((String) entry.getValue()); |
||||
if (CSS.Property.MARGIN_LEFT.equals(key)) { |
||||
indentAttribute.setLeft(val); |
||||
} else if (CSS.Property.MARGIN_RIGHT.equals(key)) { |
||||
indentAttribute.setRight(val); |
||||
} else if (CSS.Property.MARGIN_TOP.equals(key)) { |
||||
indentAttribute.setTop(val); |
||||
} else if (CSS.Property.MARGIN_BOTTOM.equals(key)) { |
||||
indentAttribute.setBottom(val); |
||||
} |
||||
} |
||||
return indentAttribute; |
||||
} |
||||
|
||||
public static void createIndent(StringBuffer stringBuffer, String attr, IndentAttribute indentAttribute){ |
||||
stringBuffer.append(attr).append("-").append("left").append(":").append(indentAttribute.getLeft()).append("px;") |
||||
.append(attr).append("-").append("right").append(":").append(indentAttribute.getRight()).append("px;") |
||||
.append(attr).append("-").append("top").append(":").append(indentAttribute.getTop()).append("px;") |
||||
.append(attr).append("-").append("bottom").append(":").append(indentAttribute.getBottom()).append("px;"); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fr.third.com.lowagie.text.html.simpleparser; |
||||
|
||||
import com.fr.third.com.lowagie.text.html.HtmlTags; |
||||
import com.fr.third.com.lowagie.text.html.Markup; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/5/2 |
||||
*/ |
||||
public class HtmlConstants { |
||||
//块级元素集合
|
||||
public static final List<String> BLOCK_ELEMENTS = new ArrayList<String>(); |
||||
//行内元素集合
|
||||
public static final List<String> INLINE_ELEMENTS = new ArrayList<String>(); |
||||
//支持解析的属性
|
||||
public static final List<String> PADDING = new ArrayList<String>(); |
||||
public static final List<String> MARGIN = new ArrayList<String>(); |
||||
static { |
||||
BLOCK_ELEMENTS.add(HtmlTags.DIV); |
||||
BLOCK_ELEMENTS.add(HtmlTags.UNORDEREDLIST); |
||||
BLOCK_ELEMENTS.add(HtmlTags.PARAGRAPH); |
||||
BLOCK_ELEMENTS.add(HtmlTags.ORDEREDLIST); |
||||
BLOCK_ELEMENTS.add(HtmlTags.TABLE); |
||||
INLINE_ELEMENTS.add(HtmlTags.SPAN); |
||||
INLINE_ELEMENTS.add(HtmlTags.IMAGE); |
||||
INLINE_ELEMENTS.add(HtmlTags.STRONG); |
||||
INLINE_ELEMENTS.add(HtmlTags.ANCHOR); |
||||
INLINE_ELEMENTS.add(HtmlTags.SUB); |
||||
INLINE_ELEMENTS.add(HtmlTags.SUP); |
||||
INLINE_ELEMENTS.add(HtmlTags.I); |
||||
INLINE_ELEMENTS.add(HtmlTags.U); |
||||
INLINE_ELEMENTS.add(HtmlTags.EM); |
||||
PADDING.add(Markup.CSS_KEY_PADDINGLEFT); |
||||
PADDING.add(Markup.CSS_KEY_PADDINGRIGHT); |
||||
PADDING.add(Markup.CSS_KEY_PADDINGTOP); |
||||
PADDING.add(Markup.CSS_KEY_PADDINGBOTTOM); |
||||
MARGIN.add(Markup.CSS_KEY_MARGINLEFT); |
||||
MARGIN.add(Markup.CSS_KEY_MARGINRIGHT); |
||||
MARGIN.add(Markup.CSS_KEY_MARGINTOP); |
||||
MARGIN.add(Markup.CSS_KEY_MARGINBOTTOM); |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
package com.fr.third.com.lowagie.text.pdf; |
||||
|
||||
import com.fr.third.com.lowagie.text.DocumentException; |
||||
import com.fr.third.com.lowagie.text.html.CSSUtils; |
||||
import com.fr.third.com.lowagie.text.html.Markup; |
||||
|
||||
import java.awt.Color; |
||||
|
||||
public class BorderStyle { |
||||
private float borderWidth = 0.0f; |
||||
private Color borderColor = Color.black; |
||||
private String borderPattern = "solid"; |
||||
|
||||
public float getBorderWidth() { |
||||
return borderWidth; |
||||
} |
||||
|
||||
public void setBorderWidth(float borderWidth) { |
||||
this.borderWidth = borderWidth; |
||||
} |
||||
|
||||
public Color getBorderColor() { |
||||
return borderColor; |
||||
} |
||||
|
||||
public void setBorderColor(Color borderColor) { |
||||
this.borderColor = borderColor; |
||||
} |
||||
|
||||
public String getBorderPattern() { |
||||
return borderPattern; |
||||
} |
||||
|
||||
public void setBorderPattern(String borderPattern) { |
||||
this.borderPattern = borderPattern; |
||||
} |
||||
|
||||
public BorderStyle() { |
||||
|
||||
} |
||||
|
||||
public BorderStyle(int borderWidth, String borderPattern, Color borderColor) { |
||||
this.borderWidth = borderWidth; |
||||
this.borderPattern = borderPattern; |
||||
this.borderWidth = borderWidth; |
||||
} |
||||
|
||||
public static BorderStyle parseBorderStyle(String borderString) throws DocumentException { |
||||
BorderStyle borderStyle = new BorderStyle(); |
||||
String[] borderPros = borderString.split(" "); |
||||
borderStyle.setBorderWidth(CSSUtils.parseFloat(borderPros[0])); |
||||
borderStyle.setBorderPattern(borderPros[1]); |
||||
borderStyle.setBorderColor(Markup.decodeColor(borderPros[2])); |
||||
return borderStyle; |
||||
|
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,54 @@
|
||||
package com.fr.third.com.lowagie.text.pdf; |
||||
|
||||
import com.fr.third.com.lowagie.text.pdf.BorderStyle; |
||||
|
||||
/** |
||||
* 描述table的属性类 |
||||
* 包括cellspacing、cellpadding、border等 |
||||
*/ |
||||
public class TableProperties { |
||||
private BorderStyle borderStyle = new BorderStyle(); |
||||
private float cellspacing = 2.0f; |
||||
private float cellpadding = 1.0f; |
||||
private boolean collapse = false; |
||||
|
||||
public BorderStyle getBorderStyle() { |
||||
return borderStyle; |
||||
} |
||||
|
||||
public void setBorderStyle(BorderStyle borderStyle) { |
||||
this.borderStyle = borderStyle; |
||||
} |
||||
|
||||
public float getCellspacing() { |
||||
return isCollapse() ? 0 : cellspacing; |
||||
} |
||||
|
||||
public void setCellspacing(float cellspacing) { |
||||
this.cellspacing = cellspacing; |
||||
} |
||||
|
||||
public float getCellpadding() { |
||||
return cellpadding; |
||||
} |
||||
|
||||
public void setCellpadding(float cellpadding) { |
||||
this.cellpadding = cellpadding; |
||||
} |
||||
|
||||
public boolean isCollapse() { |
||||
return collapse; |
||||
} |
||||
|
||||
public void setCollapse(boolean collapse) { |
||||
this.collapse = collapse; |
||||
} |
||||
|
||||
public String toHtmlString(){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
sb.append("cellspacing").append("=").append(cellspacing).append(" "); |
||||
sb.append("cellpadding").append("=").append(cellpadding).append(" "); |
||||
sb.append("border").append("=").append(borderStyle.getBorderWidth()).append(" "); |
||||
return sb.toString(); |
||||
} |
||||
} |
Loading…
Reference in new issue