From ed074335555bdd8e5c17bb0089396a4a66982711 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Thu, 11 Jun 2020 18:37:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-33491=20=E6=97=A0=E6=8F=92=E4=BB=B6P?= =?UTF-8?q?DF=E5=AF=BC=E5=87=BA-HTML=E8=A7=A3=E6=9E=90=EF=BC=9A=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=A0=87=E7=AD=BE=E5=8A=A0=E7=B2=97=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java | 1 + .../third/v2/lowagie/text/html/simpleparser/HTMLWorker.java | 3 +++ .../fr/third/v2/lowagie/text/html/simpleparser/IncCell.java | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java b/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java index 39f566cb1..b69457ff6 100644 --- a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java +++ b/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java @@ -433,6 +433,7 @@ public class PdfGraphics2D extends Graphics2D { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); if (strokeWidth != 1) { cb.setLineWidth(strokeWidth); + oldStroke = new BasicStroke(strokeWidth); if(realPaint instanceof Color){ Color color = (Color)realPaint; int alpha = color.getAlpha(); diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index 166f27f3e..18f5b59eb 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java @@ -491,6 +491,9 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { endElement(tag); skipText = false; pendingTD = true; + if (tag.equals("th")) { + h.put("b", null); + } cprops.addToChain("td", h); stack.push(new IncCell(tag, cprops)); return; diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java index eaf6ec573..cd0f7a572 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java @@ -74,8 +74,8 @@ public class IncCell implements TextElementArray { if (value != null) cell.setColspan(Integer.parseInt(value)); value = props.getProperty("align"); - if (tag.equals("th")) - cell.setHorizontalAlignment(Element.ALIGN_CENTER); +// if (tag.equals("th")) +// cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (value != null) { if ("center".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); From d213b85dd5558559fdba23d55b3c56dcac54cf32 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Fri, 12 Jun 2020 10:48:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-33029=20=E6=97=A0=E6=8F=92=E4=BB=B6P?= =?UTF-8?q?DF=E5=AF=BC=E5=87=BA-HTML=E8=A7=A3=E6=9E=90=EF=BC=9A=E5=9D=97?= =?UTF-8?q?=E5=85=83=E7=B4=A0=EF=BC=88=E5=A6=82=EF=BC=9Adiv=E3=80=81p?= =?UTF-8?q?=EF=BC=89=E6=94=AF=E6=8C=81align=E3=80=81text-align=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/lowagie/text/html/Markup.java | 3 ++ .../html/simpleparser/FactoryProperties.java | 40 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) 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 a059dd05a..09cd4d8ac 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 @@ -203,6 +203,9 @@ public class Markup { /** the CSS tag for the horizontal alignment of an object */ public static final String CSS_KEY_TEXTALIGN = "text-align"; + /** the CSS tag for the horizontal alignment of an object */ + public static final String CSS_KEY_ALIGN = "align"; + /** the CSS tag for text decorations */ public static final String CSS_KEY_TEXTDECORATION = "text-decoration"; 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 853a09b8c..28deb3e61 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 @@ -154,15 +154,6 @@ public class FactoryProperties { } public static void createParagraph(Paragraph p, ChainedProperties props) { - String value = props.getProperty("align"); - if (value != null) { - if (value.equalsIgnoreCase("center")) - p.setAlignment(Element.ALIGN_CENTER); - else if (value.equalsIgnoreCase("right")) - p.setAlignment(Element.ALIGN_RIGHT); - else if (value.equalsIgnoreCase("justify")) - p.setAlignment(Element.ALIGN_JUSTIFIED); - } if(props.hasPropertyInChain("div", "background")){ p.setBackground(props.getPropertyFromChain("div", "background")); } @@ -173,8 +164,9 @@ public class FactoryProperties { p.setAttribute("noexist-attrid", props.getProperty("noexist-attrid")); } - parseMarginAttr( p, props); - parsePaddingAttr( p, props); + parseAlignAttr(p, props); + parseMarginAttr(p, props); + parsePaddingAttr(p, props); if(props.hasPropertyInChain("div", "text-indent")){ String ss = props.getPropertyFromChain("div", "text-indent"); @@ -187,7 +179,7 @@ public class FactoryProperties { p.setHyphenation(getHyphenation(props)); setParagraphLeading(p, props.getProperty("leading")); - value = props.getProperty("before"); + String value = props.getProperty("before"); if (value != null) { try { p.setSpacingBefore(Float.parseFloat(value)); @@ -210,6 +202,30 @@ public class FactoryProperties { } } + /** + * 解析align属性 + * + * @param p + * @param props + */ + private static void parseAlignAttr(Paragraph p, ChainedProperties props) { + String[] keys = new String[]{Markup.CSS_KEY_ALIGN, Markup.CSS_KEY_TEXTALIGN}; + for (String key : keys) { + String value = props.getPropertyFromChain("div", key); + if (null == value) { + continue; + } + if (value.equalsIgnoreCase("center")) + p.setAlignment(Element.ALIGN_CENTER); + else if (value.equalsIgnoreCase("right")) + p.setAlignment(Element.ALIGN_RIGHT); + else if (value.equalsIgnoreCase("left")) + p.setAlignment(Element.ALIGN_LEFT); + else if (value.equalsIgnoreCase("justify")) + p.setAlignment(Element.ALIGN_JUSTIFIED); + } + } + /** * 解析margin属性 *