• R/O
  • SSH
  • HTTPS

copper: Commit


Commit MetaInfo

Revision1608 (tree)
Time2021-04-18 12:57:50
Authormiyabe

Log Message

(empty log message)

Change Summary

Incremental Difference

--- copper/trunk/homare/pom.xml (revision 1607)
+++ copper/trunk/homare/pom.xml (revision 1608)
@@ -9,7 +9,7 @@
99 <groupId>net.zamasoft</groupId>
1010 <artifactId>homare</artifactId>
1111 <packaging>jar</packaging>
12- <version>3.2.11</version>
12+ <version>3.2.12</version>
1313 <name>Homare</name>
1414 <description>印刷向けのHTML/CSSレンダリングエンジンです。</description>
1515 <url>https://copper.osdn.jp/homare/</url>
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/CSSProcessor.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/CSSProcessor.java (revision 1608)
@@ -446,7 +446,7 @@
446446 }
447447
448448 void _startElement(int charOffset, String uri, String lName, String qName, Attributes atts) throws SAXException {
449- // System.err.println("CSSP_: "+lName+"/"+this.ignoreIndex);
449+ // System.err.println("CSSP_: "+lName+"/"+qName);
450450
451451 // None
452452 if (this.noneStack > 0) {
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/StyleApplier.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/StyleApplier.java (revision 1608)
@@ -17,6 +17,7 @@
1717 import jp.cssj.homare.style.box.params.Length;
1818 import jp.cssj.homare.style.util.StyleUtils;
1919 import jp.cssj.homare.ua.UserAgent;
20+import jp.cssj.homare.ua.props.UAProps;
2021 import jp.cssj.homare.xml.xhtml.XHTML;
2122 import jp.cssj.sakae.sac.css.CSSException;
2223 import jp.cssj.sakae.sac.css.InputSource;
@@ -39,6 +40,8 @@
3940
4041 private final HTMLStyle html;
4142
43+ private final boolean changeDefaultNamespace;
44+
4245 public StyleApplier(UserAgent ua, StyleContext styleContext) {
4346 this.html = new HTMLStyle();
4447 this.ua = ua;
@@ -50,6 +53,8 @@
5053 this.declParser = new Parser();
5154 this.declParser.setDocumentHandler(this.declBuilder);
5255
56+ this.changeDefaultNamespace = UAProps.INPUT_CHANGE_DEFAULT_NAMESPACE.getBoolean(ua);
57+
5358 this.setBaseURI(ua.getDocumentContext().getBaseURI());
5459 }
5560
@@ -74,7 +79,12 @@
7479
7580 // インラインスタイル宣言
7681 this.declBuilder.setDeclaration(declaration);
77- String inlineStyleDecl = ce.atts.getValue(XHTML.URI, XHTML.STYLE_ATTR.lName);
82+ String inlineStyleDecl;
83+ if (this.changeDefaultNamespace) {
84+ inlineStyleDecl = ce.atts.getValue(XHTML.STYLE_ATTR.lName);
85+ } else {
86+ inlineStyleDecl = ce.atts.getValue(XHTML.URI, XHTML.STYLE_ATTR.lName);
87+ }
7888 if (inlineStyleDecl != null) {
7989 try {
8090 this.declParser.parseStyleDeclaration(new InputSource(new StringReader(inlineStyleDecl)));
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/html/HTMLStyleUtils.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/html/HTMLStyleUtils.java (revision 1608)
@@ -8,8 +8,8 @@
88 import jp.cssj.homare.css.CSSStyle;
99 import jp.cssj.homare.css.util.ColorValueUtils;
1010 import jp.cssj.homare.css.util.GeneratedValueUtils;
11-import jp.cssj.homare.css.util.LengthUtils;
1211 import jp.cssj.homare.css.util.URIUtils;
12+import jp.cssj.homare.css.util.ValueUtils;
1313 import jp.cssj.homare.css.value.AbsoluteLengthValue;
1414 import jp.cssj.homare.css.value.AutoValue;
1515 import jp.cssj.homare.css.value.BorderStyleValue;
@@ -698,7 +698,7 @@
698698 return PercentageValue.create(percentage);
699699 }
700700 try {
701- return LengthUtils.parseLength(ua, str);
701+ return ValueUtils.toLength(ua, true, str);
702702 } catch (Exception e) {
703703 // ignore
704704 }
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/objects/svg/SVGInlineObject.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/objects/svg/SVGInlineObject.java (revision 1608)
@@ -9,6 +9,9 @@
99 import org.apache.batik.util.ParsedURL;
1010 import org.apache.batik.util.XMLConstants;
1111 import org.apache.batik.util.XMLResourceDescriptor;
12+import org.xml.sax.Attributes;
13+import org.xml.sax.SAXException;
14+import org.xml.sax.helpers.AttributesImpl;
1215
1316 import jp.cssj.homare.css.InlineObject;
1417 import jp.cssj.homare.css.util.LengthUtils;
@@ -37,7 +40,20 @@
3740 }
3841 this.setValidating(false);
3942 }
43+ @Override
44+ public void startElement(String uri, String lName, String qName, Attributes atts) throws SAXException {
45+ // HACK
46+ int viewbox = atts.getIndex("viewbox");
47+ if (viewbox != -1) {
48+ AttributesImpl attsi = new AttributesImpl(atts);
49+ attsi.setLocalName(viewbox, "viewBox");
50+ attsi.setQName(viewbox, attsi.getQName(viewbox).replace("viewbox", "viewBox"));
51+ atts = attsi;
52+ }
53+ super.startElement(uri, lName, qName, atts);
54+ }
4055
56+
4157 public Image getImage(UserAgent ua) throws IOException {
4258 SVGOMDocument doc = (SVGOMDocument) this.document;
4359 this.document = null;
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/SVGImageLoader.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/SVGImageLoader.java (revision 1608)
@@ -1,6 +1,5 @@
11 package jp.cssj.homare.impl.ua.svg;
22
3-import java.awt.geom.AffineTransform;
43 import java.awt.geom.Dimension2D;
54 import java.io.BufferedInputStream;
65 import java.io.BufferedReader;
--- copper/trunk/homare/src/main/java/jp/cssj/homare/ua/props/UAProps.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/ua/props/UAProps.java (revision 1608)
@@ -19,6 +19,12 @@
1919 "xslt default-to-xhtml loose-html");
2020
2121 /**
22+ * Support change default namespace.
23+ */
24+ public static final BooleanPropManager INPUT_CHANGE_DEFAULT_NAMESPACE = new BooleanPropManager("input.html.change-default-namespace",
25+ false);
26+
27+ /**
2228 * 選択するalternateスタイルシートのタイトルです。
2329 */
2430 public static final StringPropManager INPUT_STYLESHEET_TITLES = new StringPropManager("input.stylesheet.titles",
--- copper/trunk/homare/src/main/java/jp/cssj/homare/xml/html/HTMLParser.java (revision 1607)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/xml/html/HTMLParser.java (revision 1608)
@@ -47,6 +47,8 @@
4747 parser.setFeature("http://cyberneko.org/html/features/scanner/cdata-sections", true);
4848 parser.setFeature("http://cyberneko.org/html/features/balance-tags", false);
4949
50+ final boolean chageDefaultNamespace = UAProps.INPUT_CHANGE_DEFAULT_NAMESPACE.getBoolean(ua);
51+
5052 final TagBalancer balancer = new TagBalancer();
5153 XMLDocumentFilter[] filters = { new DefaultFilter() {
5254 private boolean firstElement = true;
@@ -58,8 +60,10 @@
5860 }
5961
6062 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
61- if (element.uri != null && (element.prefix == null || element.prefix.length() == 0)) {
62- element.uri = null;
63+ if (!chageDefaultNamespace) {
64+ if (element.uri != null && (element.prefix == null || element.prefix.length() == 0)) {
65+ element.uri = null;
66+ }
6367 }
6468 super.startElement(element, attributes, augs);
6569 if (this.firstElement && element.localpart.equalsIgnoreCase("body")) {
@@ -72,8 +76,10 @@
7276 }
7377
7478 public void endElement(QName element, Augmentations augs) throws XNIException {
75- if (element.uri != null && (element.prefix == null || element.prefix.length() == 0)) {
76- element.uri = null;
79+ if (!chageDefaultNamespace) {
80+ if (element.uri != null && (element.prefix == null || element.prefix.length() == 0)) {
81+ element.uri = null;
82+ }
7783 }
7884 super.endElement(element, augs);
7985 }
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFont.java (revision 1607)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFont.java (revision 1608)
@@ -25,6 +25,9 @@
2525 import jp.cssj.sakae.gc.GraphicsException;
2626 import jp.cssj.sakae.gc.font.util.FontUtils;
2727 import jp.cssj.sakae.gc.text.Text;
28+import jp.cssj.sakae.pdf.gc.PdfGC;
29+import jp.cssj.sakae.pdf.gc.PdfGroupImage;
30+import jp.cssj.sakae.pdf.params.PdfParams;
2831 import jp.cssj.sakae.svg.Dimension2DImpl;
2932 import jp.cssj.sakae.svg.GVTBuilderImpl;
3033 import jp.cssj.sakae.svg.SVGBridgeGraphics2D;
@@ -33,7 +36,8 @@
3336 class EmojiFont implements ImageFont {
3437 private static final long serialVersionUID = 2L;
3538 protected final EmojiFontSource source;
36- protected final Map<Integer, GraphicsNode> gidToEmoji = new HashMap<Integer, GraphicsNode>();
39+ protected final Map<Integer, GraphicsNode> gidToNode = new HashMap<Integer, GraphicsNode>();
40+ protected final Map<Integer, PdfGroupImage> gidToImage = new HashMap<Integer, PdfGroupImage>();
3741 protected static final Dimension2D VIEWPORT = new Dimension2DImpl(128, 128);
3842
3943 public EmojiFont(EmojiFontSource source) {
@@ -88,30 +92,47 @@
8892 }
8993
9094 public void drawGlyphForGid(GC gc, int gid, AffineTransform at) {
91- GraphicsNode gvtRoot = this.gidToEmoji.get(gid);
92- if (gvtRoot == null) {
93- String code = EmojiFontSource.fgidToCode.get(gid);
94- if (code.endsWith("_200d")) {
95- code = code.substring(0, code.length() - 5);
95+ GraphicsNode gvtRoot = null;
96+ PdfGroupImage image = this.gidToImage.get(gid);
97+ if (image == null) {
98+ gvtRoot = this.gidToNode.get(gid);
99+ if (gvtRoot == null) {
100+ String code = EmojiFontSource.fgidToCode.get(gid);
101+ if (code.endsWith("_200d")) {
102+ code = code.substring(0, code.length() - 5);
103+ }
104+ URL url = EmojiFontSource.class.getResource("emoji_u" + code + ".svg");
105+ if (url == null) {
106+ return;
107+ }
108+ try (InputStream in = url.openStream()) {
109+ SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
110+ XMLResourceDescriptor.getXMLParserClassName());
111+ SVGOMDocument doc = (SVGOMDocument) factory.createDocument(null, in);
112+ UserAgent ua = new UserAgentImpl(VIEWPORT);
113+ DocumentLoader loader = new DocumentLoader(ua);
114+ BridgeContext ctx = new BridgeContext(ua, loader);
115+ ctx.setDynamic(false);
116+ GVTBuilder gvt = new GVTBuilderImpl();
117+ gvtRoot = gvt.build(ctx, doc);
118+ if (gc instanceof PdfGC && ((PdfGC) gc).getPDFGraphicsOutput().getPdfWriter().getParams().getVersion() >= PdfParams.VERSION_1_4) {
119+ image = ((PdfGC) gc).getPDFGraphicsOutput().getPdfWriter().createGroupImage(1000, 1000);
120+ PdfGC gc2 = new PdfGC(image);
121+ gc2.transform(AffineTransform.getScaleInstance(1000.0 / VIEWPORT.getWidth(), 1000.0 / VIEWPORT.getHeight()));
122+ gc2.begin();
123+ Graphics2D g2d = new SVGBridgeGraphics2D(gc2);
124+ gvtRoot.paint(g2d);
125+ g2d.dispose();
126+ gc2.end();
127+ image.close();
128+ this.gidToImage.put(gid, image);
129+ } else {
130+ this.gidToNode.put(gid, gvtRoot);
131+ }
132+ } catch (Exception e) {
133+ throw new RuntimeException(e);
134+ }
96135 }
97- URL url = EmojiFontSource.class.getResource("emoji_u" + code + ".svg");
98- if (url == null) {
99- return;
100- }
101- try (InputStream in = url.openStream()) {
102- SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
103- XMLResourceDescriptor.getXMLParserClassName());
104- SVGOMDocument doc = (SVGOMDocument) factory.createDocument(null, in);
105- UserAgent ua = new UserAgentImpl(VIEWPORT);
106- DocumentLoader loader = new DocumentLoader(ua);
107- BridgeContext ctx = new BridgeContext(ua, loader);
108- ctx.setDynamic(false);
109- GVTBuilder gvt = new GVTBuilderImpl();
110- gvtRoot = gvt.build(ctx, doc);
111- this.gidToEmoji.put(gid, gvtRoot);
112- } catch (Exception e) {
113- throw new RuntimeException(e);
114- }
115136 }
116137
117138 gc.begin();
@@ -119,11 +140,16 @@
119140 gc.transform(at);
120141 }
121142 gc.transform(AffineTransform.getTranslateInstance(0, -this.source.getAscent()));
122- gc.transform(AffineTransform.getScaleInstance(1000.0 / VIEWPORT.getWidth(), 1000.0 / VIEWPORT.getHeight()));
123- gc.begin();
124- Graphics2D g2d = new SVGBridgeGraphics2D(gc);
125- gvtRoot.paint(g2d);
126- g2d.dispose();
143+ if (image != null) {
144+ gc.begin();
145+ gc.drawImage(image);
146+ } else {
147+ gc.transform(AffineTransform.getScaleInstance(1000.0 / VIEWPORT.getWidth(), 1000.0 / VIEWPORT.getHeight()));
148+ gc.begin();
149+ Graphics2D g2d = new SVGBridgeGraphics2D(gc);
150+ gvtRoot.paint(g2d);
151+ g2d.dispose();
152+ }
127153 gc.end();
128154 gc.end();
129155 }
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/CIDTable.java (revision 1607)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/CIDTable.java (revision 1608)
@@ -43,7 +43,7 @@
4343 this.javaEncoding = javaEncoding;
4444 }
4545
46- private IntMap getToCid() {
46+ private synchronized IntMap getToCid() {
4747 IntMap toCid = null;
4848 if (this.toCID != null) {
4949 toCid = this.toCID.get();
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/WArray.java (revision 1607)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/WArray.java (revision 1608)
@@ -88,6 +88,7 @@
8888 boolean run = false;
8989 int cid = widths.key();
9090 while (widths.next()) {
91+ cid = widths.key();
9192 short advance = widths.value();
9293 // Short.MIN_VALUEはデフォルトの幅とする
9394 if (advance == Short.MIN_VALUE) {
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/gc/PdfGC.java (revision 1607)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/gc/PdfGC.java (revision 1608)
@@ -281,7 +281,7 @@
281281 }
282282 }
283283
284- private List<GraphicsState> stack = new ArrayList<GraphicsState>();
284+ public List<GraphicsState> stack = new ArrayList<GraphicsState>();
285285
286286 private AffineTransform transform = null;
287287
@@ -1124,7 +1124,7 @@
11241124 }
11251125 case Paint.LINEAR_GRADIENT: {
11261126 // PDF Axial(Type 2) Shading
1127- if (this.out.getPdfWriter().getParams().getVersion() < PdfParams.VERSION_1_3) {
1127+ if (this.pdfVersion < PdfParams.VERSION_1_3) {
11281128 return null;
11291129 }
11301130 LinearGradient gradient = (LinearGradient) paint;
@@ -1162,7 +1162,7 @@
11621162 }
11631163 case Paint.RADIAL_GRADIENT: {
11641164 // PDF Radial(Type 3) Shading
1165- if (this.out.getPdfWriter().getParams().getVersion() < PdfParams.VERSION_1_3) {
1165+ if (this.pdfVersion < PdfParams.VERSION_1_3) {
11661166 return null;
11671167 }
11681168 RadialGradient gp = (RadialGradient) paint;
@@ -1510,9 +1510,8 @@
15101510 }
15111511
15121512 // 不透明度
1513- int pdfVersion = this.out.getPdfWriter().getParams().getVersion();
1514- boolean supportAlpha = pdfVersion >= PdfParams.VERSION_1_4 && pdfVersion != PdfParams.VERSION_PDFA1B
1515- && pdfVersion != PdfParams.VERSION_PDFX1A;
1513+ boolean supportAlpha = this.pdfVersion >= PdfParams.VERSION_1_4 && this.pdfVersion != PdfParams.VERSION_PDFA1B
1514+ && this.pdfVersion != PdfParams.VERSION_PDFX1A;
15161515 // 透明化処理がサポートされる場合。
15171516 if ((supportAlpha && (this.strokeAlpha != this.xstrokeAlpha || this.fillAlpha != this.xfillAlpha))
15181517 || (this.strokeOverprint != this.xstrokeOverprint || this.fillOverprint != this.xfillOverprint)) {
Show on old repository browser