diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java index 6137f1326..a059dd05a 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java @@ -53,7 +53,10 @@ package com.fr.third.v2.lowagie.text.html; import java.awt.Color; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; +import java.util.StringTokenizer; /** * A class that contains all the possible tagnames and their attributes. @@ -510,4 +513,47 @@ public class Markup { return result.toString(); } + /** + * 解析类似于 margin: 10px 5px 15px 20px,中的值 + * NESW:北东南西(上右下左) + * + * @param attr 如10px 5px 15px 20px + * @return list: 按上左下右的顺序存放 ,要么四个方位的值都存在,要么都不存在(返回null) + */ + public static List parseNESW(String attr) { + if (null == attr) { + return null; + } + List list = new ArrayList(4); + StringTokenizer st = new StringTokenizer(attr); + while (st.hasMoreElements()) { + list.add(st.nextToken()); + } + switch (list.size()) { + case 1: + //如 margin:1px ,代表上下左右 的margin值都是 1px + for (int i = 0; i < 3; i++) { + list.add(list.get(0)); + } + break; + case 2: + //如 margin:1px 2px ,代表上下方位的margin值为1px, 左右方位的margin值为 2px + list.add(list.get(0)); + list.add(list.get(1)); + break; + case 3: + //如 margin:1px 2px 3px ,代表上下方位的margin值分别为1px、3px, 左右方位的margin值为 2px + list.add(list.get(1)); + break; + case 4: + //如 margin:1px 2px 3px 4px,就不用管了 + break; + default: + //如 margin:1px 2px 3px 4px 5px,超了就违反了规则,在浏览器中该属性失效 + list = null; + break; + } + return list; + } + } \ No newline at end of file diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index a8a89b93d..0b29f4d01 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -53,6 +53,7 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; import java.awt.Color; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Properties; import java.util.StringTokenizer; import com.fr.third.v2.lowagie.text.Chunk; @@ -143,18 +144,9 @@ public class FactoryProperties { if (props.hasProperty("noexist-attrid")) { p.setAttribute("noexist-attrid", props.getProperty("noexist-attrid")); } - for(String margin : HtmlConstants.MARGIN){ - if(props.hasPropertyInChain("div", margin)){ - String ss = props.getPropertyFromChain("div", margin); - p.setAttribute(margin, ss); - } - } - for(String padding : HtmlConstants.PADDING){ - if(props.hasPropertyInChain("div", padding)){ - String ss = props.getPropertyFromChain("div", padding); - p.setAttribute(padding, ss); - } - } + + parseMarginAttr( p, props); + parsePaddingAttr( p, props); if(props.hasPropertyInChain("div", "text-indent")){ String ss = props.getPropertyFromChain("div", "text-indent"); @@ -190,6 +182,52 @@ public class FactoryProperties { } } + /** + * 解析margin属性 + * + * @param p + * @param props + */ + private static void parseMarginAttr(Paragraph p, ChainedProperties props) { + if (props.hasPropertyInChain("div", Markup.CSS_KEY_MARGIN)) { + List list = Markup.parseNESW(props.getPropertyFromChain("div", Markup.CSS_KEY_MARGIN)); + if (null != list && 4 == list.size()) { + for (int i = 0; i < HtmlConstants.MARGIN.size() && i < list.size(); i++) { + p.setAttribute(HtmlConstants.MARGIN.get(i), list.get(i)); + } + } + } + for (String margin : HtmlConstants.MARGIN) { + if (props.hasPropertyInChain("div", margin)) { + String ss = props.getPropertyFromChain("div", margin); + p.setAttribute(margin, ss); + } + } + } + + /** + * 解析padding属性 + * + * @param p + * @param props + */ + private static void parsePaddingAttr(Paragraph p, ChainedProperties props) { + if (props.hasPropertyInChain("div", Markup.CSS_KEY_PADDING)) { + List list = Markup.parseNESW(props.getPropertyFromChain("div", Markup.CSS_KEY_PADDING)); + if (null != list && 4 == list.size()) { + for (int i = 0; i < HtmlConstants.PADDING.size() && i < list.size(); i++) { + p.setAttribute(HtmlConstants.PADDING.get(i), list.get(i)); + } + } + } + for (String padding : HtmlConstants.PADDING) { + if (props.hasPropertyInChain("div", padding)) { + String ss = props.getPropertyFromChain("div", padding); + p.setAttribute(padding, ss); + } + } + } + public static Paragraph createParagraph(ChainedProperties props) { Paragraph p = new Paragraph(); createParagraph(p, props); diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java index 7a94e1d51..a86cb9205 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java @@ -33,13 +33,15 @@ public class HtmlConstants { 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_PADDINGRIGHT); PADDING.add(Markup.CSS_KEY_PADDINGBOTTOM); - MARGIN.add(Markup.CSS_KEY_MARGINLEFT); - MARGIN.add(Markup.CSS_KEY_MARGINRIGHT); + PADDING.add(Markup.CSS_KEY_PADDINGLEFT); + MARGIN.add(Markup.CSS_KEY_MARGINTOP); + MARGIN.add(Markup.CSS_KEY_MARGINRIGHT); MARGIN.add(Markup.CSS_KEY_MARGINBOTTOM); + MARGIN.add(Markup.CSS_KEY_MARGINLEFT); } } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java index 44a02083e..c666a1093 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java @@ -872,6 +872,9 @@ public class PdfChunk { if (font.isUnderlined()) { s.append("text-decoration :underline;"); } + if (font.isStrikethru()) { + s.append("text-decoration :line-through;"); + } } public String javaColor2JSColorWithAlpha(Color var0) {