From df46b151f6fabaca61e35933ceb68a19081f6905 Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 26 Nov 2019 17:32:08 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E2=80=9CREPORT-23134=20=E8=B0=83=E7=94=A8d?= =?UTF-8?q?oURLPrint=E6=89=93=E5=8D=B0\n=E4=BC=9A=E8=A2=AB=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E6=88=90=E7=A9=BA=E6=A0=BC=20by=20Bruce.Deng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/third/javax/xml/stream/XMLEntityReaderImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fine-third-default/src/com/fr/third/javax/xml/stream/XMLEntityReaderImpl.java b/fine-third-default/src/com/fr/third/javax/xml/stream/XMLEntityReaderImpl.java index 90649414f..512f82fb9 100644 --- a/fine-third-default/src/com/fr/third/javax/xml/stream/XMLEntityReaderImpl.java +++ b/fine-third-default/src/com/fr/third/javax/xml/stream/XMLEntityReaderImpl.java @@ -39,6 +39,7 @@ public class XMLEntityReaderImpl extends XMLEntityReader XMLEntityReaderImpl.validContent[i] = true; } XMLEntityReaderImpl.validContent[9] = true; + XMLEntityReaderImpl.validContent[10] = true; XMLEntityReaderImpl.validContent[38] = false; XMLEntityReaderImpl.validContent[60] = false; for (int j = 65; j <= 90; ++j) { From 72ee15206300064f37b2217c41b30849d5cb1066 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 9 Dec 2019 16:16:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?REPORT-24915=20REPORT-24809=20PDF=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=B2=97=E4=BD=93=E5=AD=97=E4=BD=93=E8=BF=87=E7=B2=97?= =?UTF-8?q?;html=E6=98=BE=E7=A4=BA=20=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=87=BAp?= =?UTF-8?q?df=E6=B2=A1=E6=9C=89=E5=8A=A0=E7=B2=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/com/lowagie/text/pdf/PdfGraphics2D.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java index 5a13315c3..ee5a7cfcf 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java @@ -382,7 +382,10 @@ public class PdfGraphics2D extends Graphics2D { // value. When they are the same value then we are normally dealing // with a single font that has been made into an italic or bold // font. - if (font.isItalic() && font.getFontName().equals(font.getName())) { + if (font.isItalic()) + //awt.font只要样式,不验证是否安装,真实绘制的字体是 baseFont + // && font.getFontName().equals(font.getName())) + { float angle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, 1000); float angle2 = font.getItalicAngle(); // We don't have an italic version of this font so we need @@ -419,10 +422,13 @@ public class PdfGraphics2D extends Graphics2D { weight = (font.isBold()) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR; } - if ((font.isBold() || (weight.floatValue() >= TextAttribute.WEIGHT_SEMIBOLD.floatValue())) - && (font.getFontName().equals(font.getName()))) { + if ((font.isBold() || (weight.floatValue() >= TextAttribute.WEIGHT_SEMIBOLD.floatValue()))) + //awt.font只要样式,不验证是否安装,真实绘制的字体是 baseFont + // && (font.getFontName().equals(font.getName()))) + { // Simulate a bold font. - float strokeWidth = font.getSize2D() * (weight.floatValue() - TextAttribute.WEIGHT_REGULAR.floatValue()) / 30f; + // 30有点粗 ,换成40 + float strokeWidth = font.getSize2D() * (weight.floatValue() - TextAttribute.WEIGHT_REGULAR.floatValue()) / 40f; if (strokeWidth != 1) { if(realPaint instanceof Color){ cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); From 4f71896be84d6e4264e5a03c94e5bea252180598 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 17 Dec 2019 13:52:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?REPORT-25253=20Html=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=B0=8F=E4=BA=8E=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/HTMLWorker.java | 9 ++++-- .../xml/simpleparser/SimpleXMLParser.java | 30 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index ade85f5cf..968747ecf 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java @@ -804,10 +804,15 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { public static final HashMap tagsSupported = new HashMap(); + public static final HashMap tagsPrefixSupported = new HashMap(); + static { StringTokenizer tok = new StringTokenizer(tagsSupportedString); - while (tok.hasMoreTokens()) - tagsSupported.put(tok.nextToken(), null); + while (tok.hasMoreTokens()){ + String s = tok.nextToken(); + tagsSupported.put(s, null); + tagsPrefixSupported.put(s.charAt(0), null); + } } } diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/xml/simpleparser/SimpleXMLParser.java b/fine-itext/src/com/fr/third/v2/lowagie/text/xml/simpleparser/SimpleXMLParser.java index 2a15f56ff..0642a11e7 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/xml/simpleparser/SimpleXMLParser.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/xml/simpleparser/SimpleXMLParser.java @@ -75,6 +75,8 @@ */ package com.fr.third.v2.lowagie.text.xml.simpleparser; +import com.fr.third.v2.lowagie.text.html.simpleparser.HTMLWorker; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -229,16 +231,13 @@ public final class SimpleXMLParser { // we are in an unknown state before there's actual content case UNKNOWN: if(character == '<') { - saveState(TEXT); - state = TAG_ENCOUNTERED; + beginnOfTag((char) reader.read(), UNKNOWN); } break; // we can encounter any content case TEXT: if(character == '<') { - flush(); - saveState(state); - state = TAG_ENCOUNTERED; + beginnOfTag((char) reader.read(), TEXT); } else if(character == '&') { saveState(state); entity.setLength(0); @@ -481,6 +480,27 @@ public final class SimpleXMLParser { } } + + /** + * 处理标签的开头,若不在支持标签范围内,将<符号作为文本处理,例:<1111 (仿造浏览器的处理方式) + */ + public void beginnOfTag(char c, int type) { + previousCharacter = c; + if (c == -1) { + return; + } + if (c == '/' || HTMLWorker.tagsPrefixSupported.containsKey(c)) { + if (type == TEXT) { + flush(); + } + saveState(TEXT); + state = TAG_ENCOUNTERED; + return; + } + text.append((char) character); + nowhite = true; + } + /** * Gets a state from the stack * @return the previous state From 6fff6aaeaf21b76c70e425fcf0e303623514acb9 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 24 Dec 2019 09:28:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?REPORT-25477=20HTML=E8=A7=A3=E6=9E=90color?= =?UTF-8?q?=20=E9=94=99=E8=AF=AF=EF=BC=8816=E8=BF=9B=E5=88=B6=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=86=99=E9=94=99=E4=BA=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/v2/lowagie/text/html/WebColors.java | 307 ++++++++++-------- 1 file changed, 165 insertions(+), 142 deletions(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/WebColors.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/WebColors.java index 1004d2414..512def96d 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/WebColors.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/WebColors.java @@ -66,147 +66,170 @@ public class WebColors extends HashMap { /** HashMap containing all the names and corresponding color values. */ public static final WebColors NAMES = new WebColors(); static { - NAMES.put("aliceblue", new int[] { 0xf0, 0xf8, 0xff, 0x00 }); - NAMES.put("antiquewhite", new int[] { 0xfa, 0xeb, 0xd7, 0x00 }); - NAMES.put("aqua", new int[] { 0x00, 0xff, 0xff, 0x00 }); - NAMES.put("aquamarine", new int[] { 0x7f, 0xff, 0xd4, 0x00 }); - NAMES.put("azure", new int[] { 0xf0, 0xff, 0xff, 0x00 }); - NAMES.put("beige", new int[] { 0xf5, 0xf5, 0xdc, 0x00 }); - NAMES.put("bisque", new int[] { 0xff, 0xe4, 0xc4, 0x00 }); - NAMES.put("black", new int[] { 0x00, 0x00, 0x00, 0x00 }); - NAMES.put("blanchedalmond", new int[] { 0xff, 0xeb, 0xcd, 0x00 }); - NAMES.put("blue", new int[] { 0x00, 0x00, 0xff, 0x00 }); - NAMES.put("blueviolet", new int[] { 0x8a, 0x2b, 0xe2, 0x00 }); - NAMES.put("brown", new int[] { 0xa5, 0x2a, 0x2a, 0x00 }); - NAMES.put("burlywood", new int[] { 0xde, 0xb8, 0x87, 0x00 }); - NAMES.put("cadetblue", new int[] { 0x5f, 0x9e, 0xa0, 0x00 }); - NAMES.put("chartreuse", new int[] { 0x7f, 0xff, 0x00, 0x00 }); - NAMES.put("chocolate", new int[] { 0xd2, 0x69, 0x1e, 0x00 }); - NAMES.put("coral", new int[] { 0xff, 0x7f, 0x50, 0x00 }); - NAMES.put("cornflowerblue", new int[] { 0x64, 0x95, 0xed, 0x00 }); - NAMES.put("cornsilk", new int[] { 0xff, 0xf8, 0xdc, 0x00 }); - NAMES.put("crimson", new int[] { 0xdc, 0x14, 0x3c, 0x00 }); - NAMES.put("cyan", new int[] { 0x00, 0xff, 0xff, 0x00 }); - NAMES.put("darkblue", new int[] { 0x00, 0x00, 0x8b, 0x00 }); - NAMES.put("darkcyan", new int[] { 0x00, 0x8b, 0x8b, 0x00 }); - NAMES.put("darkgoldenrod", new int[] { 0xb8, 0x86, 0x0b, 0x00 }); - NAMES.put("darkgray", new int[] { 0xa9, 0xa9, 0xa9, 0x00 }); - NAMES.put("darkgreen", new int[] { 0x00, 0x64, 0x00, 0x00 }); - NAMES.put("darkkhaki", new int[] { 0xbd, 0xb7, 0x6b, 0x00 }); - NAMES.put("darkmagenta", new int[] { 0x8b, 0x00, 0x8b, 0x00 }); - NAMES.put("darkolivegreen", new int[] { 0x55, 0x6b, 0x2f, 0x00 }); - NAMES.put("darkorange", new int[] { 0xff, 0x8c, 0x00, 0x00 }); - NAMES.put("darkorchid", new int[] { 0x99, 0x32, 0xcc, 0x00 }); - NAMES.put("darkred", new int[] { 0x8b, 0x00, 0x00, 0x00 }); - NAMES.put("darksalmon", new int[] { 0xe9, 0x96, 0x7a, 0x00 }); - NAMES.put("darkseagreen", new int[] { 0x8f, 0xbc, 0x8f, 0x00 }); - NAMES.put("darkslateblue", new int[] { 0x48, 0x3d, 0x8b, 0x00 }); - NAMES.put("darkslategray", new int[] { 0x2f, 0x4f, 0x4f, 0x00 }); - NAMES.put("darkturquoise", new int[] { 0x00, 0xce, 0xd1, 0x00 }); - NAMES.put("darkviolet", new int[] { 0x94, 0x00, 0xd3, 0x00 }); - NAMES.put("deeppink", new int[] { 0xff, 0x14, 0x93, 0x00 }); - NAMES.put("deepskyblue", new int[] { 0x00, 0xbf, 0xff, 0x00 }); - NAMES.put("dimgray", new int[] { 0x69, 0x69, 0x69, 0x00 }); - NAMES.put("dodgerblue", new int[] { 0x1e, 0x90, 0xff, 0x00 }); - NAMES.put("firebrick", new int[] { 0xb2, 0x22, 0x22, 0x00 }); - NAMES.put("floralwhite", new int[] { 0xff, 0xfa, 0xf0, 0x00 }); - NAMES.put("forestgreen", new int[] { 0x22, 0x8b, 0x22, 0x00 }); - NAMES.put("fuchsia", new int[] { 0xff, 0x00, 0xff, 0x00 }); - NAMES.put("gainsboro", new int[] { 0xdc, 0xdc, 0xdc, 0x00 }); - NAMES.put("ghostwhite", new int[] { 0xf8, 0xf8, 0xff, 0x00 }); - NAMES.put("gold", new int[] { 0xff, 0xd7, 0x00, 0x00 }); - NAMES.put("goldenrod", new int[] { 0xda, 0xa5, 0x20, 0x00 }); - NAMES.put("gray", new int[] { 0x80, 0x80, 0x80, 0x00 }); - NAMES.put("green", new int[] { 0x00, 0x80, 0x00, 0x00 }); - NAMES.put("greenyellow", new int[] { 0xad, 0xff, 0x2f, 0x00 }); - NAMES.put("honeydew", new int[] { 0xf0, 0xff, 0xf0, 0x00 }); - NAMES.put("hotpink", new int[] { 0xff, 0x69, 0xb4, 0x00 }); - NAMES.put("indianred", new int[] { 0xcd, 0x5c, 0x5c, 0x00 }); - NAMES.put("indigo", new int[] { 0x4b, 0x00, 0x82, 0x00 }); - NAMES.put("ivory", new int[] { 0xff, 0xff, 0xf0, 0x00 }); - NAMES.put("khaki", new int[] { 0xf0, 0xe6, 0x8c, 0x00 }); - NAMES.put("lavender", new int[] { 0xe6, 0xe6, 0xfa, 0x00 }); - NAMES.put("lavenderblush", new int[] { 0xff, 0xf0, 0xf5, 0x00 }); - NAMES.put("lawngreen", new int[] { 0x7c, 0xfc, 0x00, 0x00 }); - NAMES.put("lemonchiffon", new int[] { 0xff, 0xfa, 0xcd, 0x00 }); - NAMES.put("lightblue", new int[] { 0xad, 0xd8, 0xe6, 0x00 }); - NAMES.put("lightcoral", new int[] { 0xf0, 0x80, 0x80, 0x00 }); - NAMES.put("lightcyan", new int[] { 0xe0, 0xff, 0xff, 0x00 }); - NAMES.put("lightgoldenrodyellow", new int[] { 0xfa, 0xfa, 0xd2, 0x00 }); - NAMES.put("lightgreen", new int[] { 0x90, 0xee, 0x90, 0x00 }); - NAMES.put("lightgrey", new int[] { 0xd3, 0xd3, 0xd3, 0x00 }); - NAMES.put("lightpink", new int[] { 0xff, 0xb6, 0xc1, 0x00 }); - NAMES.put("lightsalmon", new int[] { 0xff, 0xa0, 0x7a, 0x00 }); - NAMES.put("lightseagreen", new int[] { 0x20, 0xb2, 0xaa, 0x00 }); - NAMES.put("lightskyblue", new int[] { 0x87, 0xce, 0xfa, 0x00 }); - NAMES.put("lightslategray", new int[] { 0x77, 0x88, 0x99, 0x00 }); - NAMES.put("lightsteelblue", new int[] { 0xb0, 0xc4, 0xde, 0x00 }); - NAMES.put("lightyellow", new int[] { 0xff, 0xff, 0xe0, 0x00 }); - NAMES.put("lime", new int[] { 0x00, 0xff, 0x00, 0x00 }); - NAMES.put("limegreen", new int[] { 0x32, 0xcd, 0x32, 0x00 }); - NAMES.put("linen", new int[] { 0xfa, 0xf0, 0xe6, 0x00 }); - NAMES.put("magenta", new int[] { 0xff, 0x00, 0xff, 0x00 }); - NAMES.put("maroon", new int[] { 0x80, 0x00, 0x00, 0x00 }); - NAMES.put("mediumaquamarine", new int[] { 0x66, 0xcd, 0xaa, 0x00 }); - NAMES.put("mediumblue", new int[] { 0x00, 0x00, 0xcd, 0x00 }); - NAMES.put("mediumorchid", new int[] { 0xba, 0x55, 0xd3, 0x00 }); - NAMES.put("mediumpurple", new int[] { 0x93, 0x70, 0xdb, 0x00 }); - NAMES.put("mediumseagreen", new int[] { 0x3c, 0xb3, 0x71, 0x00 }); - NAMES.put("mediumslateblue", new int[] { 0x7b, 0x68, 0xee, 0x00 }); - NAMES.put("mediumspringgreen", new int[] { 0x00, 0xfa, 0x9a, 0x00 }); - NAMES.put("mediumturquoise", new int[] { 0x48, 0xd1, 0xcc, 0x00 }); - NAMES.put("mediumvioletred", new int[] { 0xc7, 0x15, 0x85, 0x00 }); - NAMES.put("midnightblue", new int[] { 0x19, 0x19, 0x70, 0x00 }); - NAMES.put("mintcream", new int[] { 0xf5, 0xff, 0xfa, 0x00 }); - NAMES.put("mistyrose", new int[] { 0xff, 0xe4, 0xe1, 0x00 }); - NAMES.put("moccasin", new int[] { 0xff, 0xe4, 0xb5, 0x00 }); - NAMES.put("navajowhite", new int[] { 0xff, 0xde, 0xad, 0x00 }); - NAMES.put("navy", new int[] { 0x00, 0x00, 0x80, 0x00 }); - NAMES.put("oldlace", new int[] { 0xfd, 0xf5, 0xe6, 0x00 }); - NAMES.put("olive", new int[] { 0x80, 0x80, 0x00, 0x00 }); - NAMES.put("olivedrab", new int[] { 0x6b, 0x8e, 0x23, 0x00 }); - NAMES.put("orange", new int[] { 0xff, 0xa5, 0x00, 0x00 }); - NAMES.put("orangered", new int[] { 0xff, 0x45, 0x00, 0x00 }); - NAMES.put("orchid", new int[] { 0xda, 0x70, 0xd6, 0x00 }); - NAMES.put("palegoldenrod", new int[] { 0xee, 0xe8, 0xaa, 0x00 }); - NAMES.put("palegreen", new int[] { 0x98, 0xfb, 0x98, 0x00 }); - NAMES.put("paleturquoise", new int[] { 0xaf, 0xee, 0xee, 0x00 }); - NAMES.put("palevioletred", new int[] { 0xdb, 0x70, 0x93, 0x00 }); - NAMES.put("papayawhip", new int[] { 0xff, 0xef, 0xd5, 0x00 }); - NAMES.put("peachpuff", new int[] { 0xff, 0xda, 0xb9, 0x00 }); - NAMES.put("peru", new int[] { 0xcd, 0x85, 0x3f, 0x00 }); - NAMES.put("pink", new int[] { 0xff, 0xc0, 0xcb, 0x00 }); - NAMES.put("plum", new int[] { 0xdd, 0xa0, 0xdd, 0x00 }); - NAMES.put("powderblue", new int[] { 0xb0, 0xe0, 0xe6, 0x00 }); - NAMES.put("purple", new int[] { 0x80, 0x00, 0x80, 0x00 }); - NAMES.put("red", new int[] { 0xff, 0x00, 0x00, 0x00 }); - NAMES.put("rosybrown", new int[] { 0xbc, 0x8f, 0x8f, 0x00 }); - NAMES.put("royalblue", new int[] { 0x41, 0x69, 0xe1, 0x00 }); - NAMES.put("saddlebrown", new int[] { 0x8b, 0x45, 0x13, 0x00 }); - NAMES.put("salmon", new int[] { 0xfa, 0x80, 0x72, 0x00 }); - NAMES.put("sandybrown", new int[] { 0xf4, 0xa4, 0x60, 0x00 }); - NAMES.put("seagreen", new int[] { 0x2e, 0x8b, 0x57, 0x00 }); - NAMES.put("seashell", new int[] { 0xff, 0xf5, 0xee, 0x00 }); - NAMES.put("sienna", new int[] { 0xa0, 0x52, 0x2d, 0x00 }); - NAMES.put("silver", new int[] { 0xc0, 0xc0, 0xc0, 0x00 }); - NAMES.put("skyblue", new int[] { 0x87, 0xce, 0xeb, 0x00 }); - NAMES.put("slateblue", new int[] { 0x6a, 0x5a, 0xcd, 0x00 }); - NAMES.put("slategray", new int[] { 0x70, 0x80, 0x90, 0x00 }); - NAMES.put("snow", new int[] { 0xff, 0xfa, 0xfa, 0x00 }); - NAMES.put("springgreen", new int[] { 0x00, 0xff, 0x7f, 0x00 }); - NAMES.put("steelblue", new int[] { 0x46, 0x82, 0xb4, 0x00 }); - NAMES.put("tan", new int[] { 0xd2, 0xb4, 0x8c, 0x00 }); - NAMES.put("transparent", new int[] { 0x00, 0x00, 0x00, 0xff }); - NAMES.put("teal", new int[] { 0x00, 0x80, 0x80, 0x00 }); - NAMES.put("thistle", new int[] { 0xd8, 0xbf, 0xd8, 0x00 }); - NAMES.put("tomato", new int[] { 0xff, 0x63, 0x47, 0x00 }); - NAMES.put("turquoise", new int[] { 0x40, 0xe0, 0xd0, 0x00 }); - NAMES.put("violet", new int[] { 0xee, 0x82, 0xee, 0x00 }); - NAMES.put("wheat", new int[] { 0xf5, 0xde, 0xb3, 0x00 }); - NAMES.put("white", new int[] { 0xff, 0xff, 0xff, 0x00 }); - NAMES.put("whitesmoke", new int[] { 0xf5, 0xf5, 0xf5, 0x00 }); - NAMES.put("yellow", new int[] { 0xff, 0xff, 0x00, 0x00 }); - NAMES.put("yellowgreen", new int[] { 0x9, 0xacd, 0x32, 0x00 }); + //比对 https://html-color-codes.info/color-names/ + //Red color names + NAMES.put("indianred", new int[]{0xcd, 0x5c, 0x5c, 0xff}); + NAMES.put("lightcoral", new int[]{0xf0, 0x80, 0x80, 0xff}); + NAMES.put("salmon", new int[]{0xfa, 0x80, 0x72, 0xff}); + NAMES.put("darksalmon", new int[]{0xe9, 0x96, 0x7a, 0xff}); + NAMES.put("lightsalmon", new int[]{0xff, 0xa0, 0x7a, 0xff}); + NAMES.put("crimson", new int[]{0xdc, 0x14, 0x3c, 0xff}); + NAMES.put("firebrick", new int[]{0xb2, 0x22, 0x22, 0xff}); + NAMES.put("darkred", new int[]{0x8b, 0x00, 0x00, 0xff}); + NAMES.put("red", new int[]{0xff, 0x00, 0x00, 0xff}); + + //Pink color names + NAMES.put("pink", new int[]{0xff, 0xc0, 0xcb, 0xff}); + NAMES.put("lightpink", new int[]{0xff, 0xb6, 0xc1, 0xff}); + NAMES.put("hotpink", new int[]{0xff, 0x69, 0xb4, 0xff}); + NAMES.put("deeppink", new int[]{0xff, 0x14, 0x93, 0xff}); + NAMES.put("mediumvioletred", new int[]{0xc7, 0x15, 0x85, 0xff}); + NAMES.put("palevioletred", new int[]{0xdb, 0x70, 0x93, 0xff}); + + //Orange color names + NAMES.put("coral", new int[]{0xff, 0x7f, 0x50, 0xff}); + NAMES.put("tomato", new int[]{0xff, 0x63, 0x47, 0xff}); + NAMES.put("orangered", new int[]{0xff, 0x45, 0x00, 0xff}); + NAMES.put("darkorange", new int[]{0xff, 0x8c, 0x00, 0xff}); + NAMES.put("orange", new int[]{0xff, 0xa5, 0x00, 0xff}); + + //Orange color names + NAMES.put("gold", new int[]{0xff, 0xd7, 0x00, 0xff}); + NAMES.put("yellow", new int[]{0xff, 0xff, 0x00, 0xff}); + NAMES.put("lightyellow", new int[]{0xff, 0xff, 0xefe, 0xff}); + NAMES.put("lemonchiffon", new int[]{0xff, 0xfa, 0xcd, 0xff}); + NAMES.put("lightgoldenrodyellow", new int[]{0xfa, 0xfa, 0xd2, 0xff}); + NAMES.put("papayawhip", new int[]{0xff, 0xef, 0xd5, 0xff}); + NAMES.put("moccasin", new int[]{0xff, 0xe4, 0xb5, 0xff}); + NAMES.put("peachpuff", new int[]{0xff, 0xda, 0xb9, 0xff}); + NAMES.put("palegoldenrod", new int[]{0xee, 0xe8, 0xaa, 0xff}); + NAMES.put("khaki", new int[]{0xf0, 0xe6, 0x8c, 0xff}); + NAMES.put("darkkhaki", new int[]{0xbd, 0xb7, 0x6b, 0xff}); + + //Purple color names + NAMES.put("lavender", new int[]{0xe6, 0xe6, 0xfa, 0xff}); + NAMES.put("thistle", new int[]{0xd8, 0xbf, 0xd8, 0xff}); + NAMES.put("plum", new int[]{0xdd, 0xa0, 0xdd, 0xff}); + NAMES.put("violet", new int[]{0xee, 0x82, 0xee, 0xff}); + NAMES.put("orchid", new int[]{0xda, 0x70, 0xd6, 0xff}); + NAMES.put("fuchsia", new int[]{0xff, 0x00, 0xff, 0xff}); + NAMES.put("magenta", new int[]{0xff, 0x00, 0xff, 0xff}); + NAMES.put("mediumorchid", new int[]{0xba, 0x55, 0xd3, 0xff}); + NAMES.put("mediumpurple", new int[]{0x93, 0x70, 0xdb, 0xff}); + NAMES.put("amethyst", new int[]{0x99, 0x66, 0xcc, 0xff}); + NAMES.put("blueviolet", new int[]{0x8a, 0x2b, 0xe2, 0xff}); + NAMES.put("darkviolet", new int[]{0x94, 0x00, 0xd3, 0xff}); + NAMES.put("darkorchid", new int[]{0x99, 0x32, 0xcc, 0xff}); + NAMES.put("darkmagenta", new int[]{0x8b, 0x00, 0x8b, 0xff}); + NAMES.put("purple", new int[]{0x80, 0x00, 0x80, 0xff}); + NAMES.put("indigo", new int[]{0x4b, 0x00, 0x82, 0xff}); + NAMES.put("slateblue", new int[]{0x6a, 0x5a, 0xcd, 0xff}); + NAMES.put("darkslateblue", new int[]{0x48, 0x3d, 0x8b, 0xff}); + NAMES.put("mediumslateblue", new int[]{0x7b, 0x68, 0xee, 0xff}); + + //Green color names + NAMES.put("greenyellow", new int[]{0xad, 0xff, 0x2f, 0xff}); + NAMES.put("chartreuse", new int[]{0x7f, 0xff, 0x00, 0xff}); + NAMES.put("lawngreen", new int[]{0x7c, 0xfc, 0x00, 0xff}); + NAMES.put("lime", new int[]{0x00, 0xff, 0x00, 0xff}); + NAMES.put("limegreen", new int[]{0x32, 0xcd, 0x32, 0xff}); + NAMES.put("palegreen", new int[]{0x98, 0xfb, 0x98, 0xff}); + NAMES.put("lightgreen", new int[]{0x90, 0xee, 0x90, 0xff}); + NAMES.put("mediumspringgreen", new int[]{0x00, 0xfa, 0x9a, 0xff}); + NAMES.put("springgreen", new int[]{0x00, 0xff, 0x7f, 0xff}); + NAMES.put("mediumseagreen", new int[]{0x3c, 0xb3, 0x71, 0xff}); + NAMES.put("seagreen", new int[]{0x2e, 0x8b, 0x57, 0xff}); + NAMES.put("forestgreen", new int[]{0x22, 0x8b, 0x22, 0xff}); + NAMES.put("green", new int[]{0x00, 0x80, 0x00, 0xff}); + NAMES.put("darkgreen", new int[]{0x00, 0x64, 0x00, 0xff}); + NAMES.put("yellowgreen", new int[]{0x9a, 0xcd, 0x32, 0xff}); + NAMES.put("olivedrab", new int[]{0x6b, 0x8e, 0x23, 0xff}); + NAMES.put("olive", new int[]{0x80, 0x80, 0x00, 0xff}); + NAMES.put("darkolivegreen", new int[]{0x55, 0x6b, 0x2f, 0xff}); + NAMES.put("mediumaquamarine", new int[]{0x66, 0xcd, 0xaa, 0xff}); + NAMES.put("darkseagreen", new int[]{0x8f, 0xbc, 0x8f, 0xff}); + NAMES.put("lightseagreen", new int[]{0x20, 0xb2, 0xaa, 0xff}); + NAMES.put("darkcyan", new int[]{0x00, 0x8b, 0x8b, 0xff}); + NAMES.put("teal", new int[]{0x00, 0x80, 0x80, 0xff}); + + //Blue color names + NAMES.put("aqua", new int[]{0x00, 0xff, 0xff, 0xff}); + NAMES.put("cyan", new int[]{0x00, 0xff, 0xff, 0xff}); + NAMES.put("lightcyan", new int[]{0xe0, 0xff, 0xff, 0xff}); + NAMES.put("paleturquoise", new int[]{0xaf, 0xee, 0xee, 0xff}); + NAMES.put("aquamarine", new int[]{0x7f, 0xff, 0xd4, 0xff}); + NAMES.put("turquoise", new int[]{0x40, 0xe0, 0xd0, 0xff}); + NAMES.put("mediumturquoise", new int[]{0x48, 0xd1, 0xcc, 0xff}); + NAMES.put("darkturquoise", new int[]{0x00, 0xce, 0xd1, 0xff}); + NAMES.put("cadetblue", new int[]{0x5f, 0x9e, 0xa0, 0xff}); + NAMES.put("steelblue", new int[]{0x46, 0x82, 0xb4, 0xff}); + NAMES.put("lightsteelblue", new int[]{0xb0, 0xc4, 0xde, 0xff}); + NAMES.put("powderblue", new int[]{0xb0, 0xe0, 0xe6, 0xff}); + NAMES.put("lightblue", new int[]{0xad, 0xd8, 0xe6, 0xff}); + NAMES.put("skyblue", new int[]{0x87, 0xce, 0xeb, 0xff}); + NAMES.put("lightskyblue", new int[]{0x87, 0xce, 0xfa, 0xff}); + NAMES.put("deepskyblue", new int[]{0x00, 0xbf, 0xff, 0xff}); + NAMES.put("dodgerblue", new int[]{0x1e, 0x90, 0xff, 0xff}); + NAMES.put("cornflowerblue", new int[]{0x64, 0x95, 0xed, 0xff}); + NAMES.put("royalblue", new int[]{0x41, 0x69, 0xe1, 0xff}); + NAMES.put("blue", new int[]{0x00, 0x00, 0xff, 0xff}); + NAMES.put("mediumblue", new int[]{0x00, 0x00, 0xcd, 0xff}); + NAMES.put("darkblue", new int[]{0x00, 0x00, 0x8b, 0xff}); + NAMES.put("navy", new int[]{0x00, 0x00, 0x80, 0xff}); + NAMES.put("midnightblue", new int[]{0x19, 0x19, 0x70, 0xff}); + + //Brown color names + NAMES.put("cornsilk", new int[]{0xff, 0xf8, 0xdc, 0xff}); + NAMES.put("blanchedalmond", new int[]{0xff, 0xeb, 0xcd, 0xff}); + NAMES.put("bisque", new int[]{0xff, 0xe4, 0xc4, 0xff}); + NAMES.put("navajowhite", new int[]{0xff, 0xde, 0xad, 0xff}); + NAMES.put("wheat", new int[]{0xf5, 0xde, 0xb3, 0xff}); + NAMES.put("burlywood", new int[]{0xde, 0xb8, 0x87, 0xff}); + NAMES.put("tan", new int[]{0xd2, 0xb4, 0x8c, 0xff}); + NAMES.put("rosybrown", new int[]{0xbc, 0x8f, 0x8f, 0xff}); + NAMES.put("sandybrown", new int[]{0xf4, 0xa4, 0x60, 0xff}); + NAMES.put("goldenrod", new int[]{0xda, 0xa5, 0x20, 0xff}); + NAMES.put("darkgoldenrod", new int[]{0xb8, 0x86, 0x0b, 0xff}); + NAMES.put("peru", new int[]{0xcd, 0x85, 0x3f, 0xff}); + NAMES.put("chocolate", new int[]{0xd2, 0x69, 0x1e, 0xff}); + NAMES.put("saddlebrown", new int[]{0x8b, 0x45, 0x13, 0xff}); + NAMES.put("sienna", new int[]{0xa0, 0x52, 0x2d, 0xff}); + NAMES.put("brown", new int[]{0xa5, 0x2a, 0x2a, 0xff}); + NAMES.put("maroon", new int[]{0x80, 0x00, 0x00, 0xff}); + + //White color names + NAMES.put("white", new int[]{0xff, 0xff, 0xff, 0xff}); + NAMES.put("snow", new int[]{0xff, 0xfa, 0xfa, 0xff}); + NAMES.put("honeydew", new int[]{0xf0, 0xff, 0xf0, 0xff}); + NAMES.put("mintcream", new int[]{0xf5, 0xff, 0xfa, 0xff}); + NAMES.put("azure", new int[]{0xf0, 0xff, 0xff, 0xff}); + NAMES.put("aliceblue", new int[]{0xf0, 0xf8, 0xff, 0xff}); + NAMES.put("ghostwhite", new int[]{0xf8, 0xf8, 0xff, 0xff}); + NAMES.put("whitesmoke", new int[]{0xf5, 0xf5, 0xf5, 0xff}); + NAMES.put("seashell", new int[]{0xff, 0xf5, 0xee, 0xff}); + NAMES.put("beige", new int[]{0xf5, 0xf5, 0xdc, 0xff}); + NAMES.put("oldlace", new int[]{0xfd, 0xf5, 0xe6, 0xff}); + NAMES.put("floralwhite", new int[]{0xff, 0xfa, 0xf0, 0xff}); + NAMES.put("ivory", new int[]{0xff, 0xff, 0xf0, 0xff}); + NAMES.put("antiquewhite", new int[]{0xfa, 0xeb, 0xd7, 0xff}); + NAMES.put("linen", new int[]{0xfa, 0xf0, 0xe6, 0xff}); + NAMES.put("lavenderblush", new int[]{0xff, 0xf0, 0xf5, 0xff}); + NAMES.put("mistyrose", new int[]{0xff, 0xe4, 0xe1, 0xff}); + + //Grey color names + NAMES.put("gainsboro", new int[]{0xdc, 0xdc, 0xdc, 0xff}); + NAMES.put("lightgrey", new int[]{0xd3, 0xd3, 0xd3, 0xff}); + NAMES.put("silver", new int[]{0xc0, 0xc0, 0xc0, 0xff}); + NAMES.put("darkgray", new int[]{0xa9, 0xa9, 0xa9, 0xff}); + NAMES.put("gray", new int[]{0x80, 0x80, 0x80, 0xff}); + NAMES.put("dimgray", new int[]{0x69, 0x69, 0x69, 0xff}); + NAMES.put("lightslategray", new int[]{0x77, 0x88, 0x99, 0xff}); + NAMES.put("slategray", new int[]{0x70, 0x80, 0x90, 0xff}); + NAMES.put("darkslategray", new int[]{0x2f, 0x4f, 0x4f, 0xff}); + NAMES.put("black", new int[]{0x00, 0x00, 0x00, 0xff}); + + //Transparent color names + NAMES.put("transparent", new int[]{0xff, 0xff, 0xff, 0x00}); } /** @@ -258,6 +281,6 @@ public class WebColors extends HashMap { throw new IllegalArgumentException("Color '" + name + "' not found."); c = (int[]) NAMES.get(name); - return new Color(c[0], c[1], c[2], 255); + return new Color(c[0], c[1], c[2], c[3]); } } \ No newline at end of file From e847825b7a93278f8cf65a21aefcb8a5a49d9ac9 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 24 Dec 2019 09:48:44 +0800 Subject: [PATCH 5/5] =?UTF-8?q?REPORT-25504=20=20=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=86=85=E5=AE=B9=E4=B8=8D=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E5=88=97=E5=AE=BD=E8=BF=9B=E8=A1=8C=E6=8D=A2=E8=A1=8C=EF=BC=8C?= =?UTF-8?q?=E8=A1=8C=E9=AB=98=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/HTMLWorker.java | 14 +++-- .../text/html/simpleparser/IncTable.java | 54 ++++++++++++++-- .../fr/third/v2/lowagie/text/pdf/PdfPRow.java | 61 +++++++++++++++++++ 3 files changed, 121 insertions(+), 8 deletions(-) diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java index ade85f5cf..74a7a3af7 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java @@ -63,6 +63,7 @@ import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; +import com.fr.third.v2.lowagie.text.Cell; import com.fr.third.v2.lowagie.text.DocumentException; import com.fr.third.v2.lowagie.text.Element; import com.fr.third.v2.lowagie.text.ExceptionConverter; @@ -74,6 +75,8 @@ import com.fr.third.v2.lowagie.text.Rectangle; import com.fr.third.v2.lowagie.text.TextElementArray; import com.fr.third.v2.lowagie.text.html.CSSUtils; import com.fr.third.v2.lowagie.text.html.HtmlTags; +import com.fr.third.v2.lowagie.text.pdf.PdfCell; +import com.fr.third.v2.lowagie.text.pdf.PdfPCell; import com.fr.third.v2.lowagie.text.pdf.draw.LineSeparator; import com.fr.third.v2.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.fr.third.v2.lowagie.text.html.Markup; @@ -661,10 +664,13 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { cprops.removeChain("tr"); ArrayList cells = new ArrayList(); IncTable table = null; + float maxHeight = 0; while (true) { Object obj = stack.pop(); - if (obj instanceof IncCell) { - cells.add(((IncCell) obj).getCell()); + if (obj instanceof IncCell) { + PdfPCell cell = ((IncCell) obj).getCell(); + cells.add(cell); + maxHeight = Math.max(maxHeight, cell.getStyleHeight()); } if (obj instanceof IncTable) { table = (IncTable) obj; @@ -672,11 +678,11 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { } } float rowHeight = 0.0f; - if(rowHeightPx!=null){ + if (rowHeightPx != null) { rowHeight = CSSUtils.parseFloat(rowHeightPx); } table.addCols(cells); - table.endRow(rowHeight); + table.endRow(Math.max(rowHeight, maxHeight)); stack.push(table); skipText = true; diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java index 5da1eb4ca..9c99d6370 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java @@ -50,6 +50,7 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.List; import com.fr.third.v2.lowagie.text.html.CSSUtils; import com.fr.third.v2.lowagie.text.html.Markup; @@ -66,6 +67,7 @@ public class IncTable { private HashMap props = new HashMap(); private ArrayList rows = new ArrayList(); private ArrayList cols; + private List rowIndex4ZeroHeight = new ArrayList(); private ArrayList rowHeights = new ArrayList(); private ArrayList relativeColWidths = new ArrayList(); @@ -88,6 +90,9 @@ public class IncTable { } public void endRow(float rowHeight) { + if (rowHeight == 0) { + rowIndex4ZeroHeight.add(rowHeights.size()); + } rowHeights.add(rowHeight); if (cols != null) { Collections.reverse(cols); @@ -204,12 +209,53 @@ public class IncTable { } public void processRowHeight(PdfPTable table) { - Float height = CSSUtils.parseFloat((String) props.get("height")); - Float eachHeight = height / table.getRows().size(); + adjustRowHeight(CSSUtils.parseFloat((String) props.get("height"))); //调整行高 - for (int a = 0; a < rowHeights.size(); a++) { - table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a))); + for (int i = 0; i < rowHeights.size(); i++) { + table.getRow(i).setStyleHeight(rowHeights.get(i)); + } + } + + /** + * 调整行高 + * 1、若 tableHeight < rowHeightSum , return ,每行扔取取指定的 height (该行的最大值) + * 2、若 tableHeight > rowHeightSum ,每行都有指定 height (该行的最大值),则按比例平分tableHeight + * 3、若 tableHeight > rowHeightSum ,有些行没有指定 height ,则将tableHeight - rowHeightSum ,平分给这些行 + * 最后,若计算出的内容高度大于上述计算出的行高,则取内容高度 + * + * @param tableHeight + */ + private void adjustRowHeight(Float tableHeight) { + if (0 > tableHeight) { + return; + } + float totalHeight = getRowHeightSum(); + if (tableHeight < totalHeight) { + return; + } + float extraHeight = tableHeight - totalHeight; + int size = rowIndex4ZeroHeight.size(); + //多出来的高度平分给没有设置高度的行 + if (size > 0) { + float eachHeight = extraHeight / size; + for (int i = 0; i < size; i++) { + rowHeights.set(rowIndex4ZeroHeight.get(i), eachHeight); + } + } + //按比例分 + else { + for (int i = 0; i < rowHeights.size(); i++) { + rowHeights.set(i, tableHeight * rowHeights.get(i) / totalHeight); + } + } + } + + private float getRowHeightSum() { + float sum = 0; + for (int i = 0; i < rowHeights.size(); i++) { + sum += rowHeights.get(i); } + return sum; } public TableProperties parseTableProperties(){ diff --git a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java index ed4a6b24a..466ee0df8 100644 --- a/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java +++ b/fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java @@ -50,12 +50,19 @@ package com.fr.third.v2.lowagie.text.pdf; import java.awt.Color; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import com.fr.third.v2.lowagie.text.ExceptionConverter; import com.fr.third.v2.lowagie.text.DocumentException; import com.fr.third.v2.lowagie.text.Element; import com.fr.third.v2.lowagie.text.Image; +import com.fr.third.v2.lowagie.text.ListItem; +import com.fr.third.v2.lowagie.text.Paragraph; import com.fr.third.v2.lowagie.text.Rectangle; +import com.fr.third.v2.lowagie.text.html.CSS; /** * A row in a PdfPTable. @@ -155,10 +162,64 @@ public class PdfPRow { --k; cell.setRight(total); cell.setTop(0); + processColWidth(cell.getColumn().getCompositeElements(), cell.getWidth()); } return true; } + /** + * @param list + * @param width + */ + private void processColWidth(List list, float width) { + if (null == list) { + return; + } + String widthStr = String.valueOf(width); + //调整列宽,不然内容换行任取指定的width + for (int i = 0; i < list.size(); i++) { + setStyleWidth(list.get(i), widthStr); + } + } + + private void setStyleWidth(Element element, String width) { + if (null == element) { + return; + } + try { + switch (element.type()) { + case Element.PARAGRAPH: { + HashMap attr = ((Paragraph) element).getAttributes(); + attr.put(CSS.Property.WIDTH, width); + break; + } + case Element.LIST: { + com.fr.third.v2.lowagie.text.List list = (com.fr.third.v2.lowagie.text.List) element; + for (Iterator i = list.getList().iterator(); i.hasNext(); ) { + setStyleWidth((Element) i.next(), width); + } + break; + } + case Element.LISTITEM: { + ListItem listItem = (ListItem) element; + for (Iterator i = listItem.iterator(); i.hasNext(); ) { + setStyleWidth((Element) i.next(), width); + } + break; + } + case Element.PTABLE: { + PdfPTable table = (PdfPTable) element; + table.setTotalWidth(Float.parseFloat(width)); + break; + } + default: + return; + } + } catch (Exception e) { + throw new ExceptionConverter(e); + } + } + /** * Initializes the extra heights array. * @since 2.1.6