• R/O
  • SSH
  • HTTPS

copper: Commit


Commit MetaInfo

Revision1589 (tree)
Time2019-08-21 12:50:29
Authormiyabe

Log Message

(empty log message)

Change Summary

Incremental Difference

--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/StyleApplier.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/StyleApplier.java (revision 1589)
@@ -40,7 +40,7 @@
4040 private final HTMLStyle html;
4141
4242 public StyleApplier(UserAgent ua, StyleContext styleContext) {
43- this.html = new HTMLStyle(ua);
43+ this.html = new HTMLStyle();
4444 this.ua = ua;
4545 this.styleContext = styleContext;
4646
--- copper/trunk/homare/src/main/java/jp/cssj/homare/css/html/HTMLStyle.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/css/html/HTMLStyle.java (revision 1589)
@@ -592,12 +592,6 @@
592592 private ColorValue linkColor = null;
593593
594594 private ImageMap imageMap = null;
595-
596- private final boolean links;
597-
598- public HTMLStyle(final UserAgent ua) {
599- this.links = UAProps.OUTPUT_PDF_HYPERLINKS.getBoolean(ua);
600- }
601595
602596 public void applyStyle(CSSStyle style) {
603597 UserAgent ua = style.getUserAgent();
@@ -707,8 +701,8 @@
707701 }
708702 }
709703 try {
710- Area area = new Area(URIHelper.resolve(ua.getDocumentContext().getEncoding(),
711- ua.getDocumentContext().getBaseURI(), href), realShape);
704+ Area area = new Area(realShape, URIHelper.resolve(ua.getDocumentContext().getEncoding(),
705+ ua.getDocumentContext().getBaseURI(), href));
712706 this.imageMap.add(area);
713707 } catch (URISyntaxException e) {
714708 ua.message(MessageCodes.WARN_BAD_HTML_ATTRIBUTE, "AREA", "href", shape);
@@ -1428,12 +1422,8 @@
14281422 case HTMLCodes.MAP: {
14291423 // <MAP name>
14301424 style.set(Display.INFO, DisplayValue.INLINE_VALUE);
1431-
1432- if (!this.links) {
1433- break;
1434- }
14351425
1436- Map<String, ImageMap> imageMaps = style.getUserAgent().getUAContext().getImageMaps();
1426+ Map<Object, ImageMap> imageMaps = style.getUserAgent().getUAContext().getImageMaps();
14371427 String mapName = ce.atts.getValue("name");
14381428 if (mapName != null && !imageMaps.containsKey(mapName)) {
14391429 this.imageMap = new ImageMap();
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/objects/svg/SVGInlineObject.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/objects/svg/SVGInlineObject.java (revision 1589)
@@ -14,6 +14,7 @@
1414 import jp.cssj.homare.css.util.LengthUtils;
1515 import jp.cssj.homare.css.value.LengthValue;
1616 import jp.cssj.homare.impl.ua.svg.SVGImageLoader;
17+import jp.cssj.homare.ua.ImageMap;
1718 import jp.cssj.homare.ua.UserAgent;
1819 import jp.cssj.homare.xml.xerces.Xerces2Parser;
1920 import jp.cssj.sakae.gc.image.Image;
@@ -56,8 +57,11 @@
5657 Image image = this.loader.getImage(uri.toString(), doc, ua);
5758 double scale = LengthUtils.convert(ua, 1.0, LengthValue.UNIT_PX, LengthValue.UNIT_PT);
5859 if (scale != 1) {
60+ ImageMap map = ua.getUAContext().getImageMaps().remove(image);
5961 AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
6062 image = new TransformedImage(image, at);
63+ map = map.getTransformedImageMap(at);
64+ ua.getUAContext().getImageMaps().put(image, map);
6165 }
6266 return image;
6367 }
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/AbstractVisitor.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/AbstractVisitor.java (revision 1589)
@@ -12,6 +12,7 @@
1212 import jp.cssj.homare.css.value.LengthValue;
1313 import jp.cssj.homare.message.MessageCodes;
1414 import jp.cssj.homare.style.box.IBox;
15+import jp.cssj.homare.style.box.params.ReplacedParams;
1516 import jp.cssj.homare.style.visitor.Visitor;
1617 import jp.cssj.homare.ua.Counter;
1718 import jp.cssj.homare.ua.CounterScope;
@@ -66,7 +67,7 @@
6667
6768 protected abstract void addFragment(String id, Point2D location);
6869
69- protected abstract void addLink(Shape s, URI uri);
70+ protected abstract void addLink(Shape s, URI uri, CSSElement ce);
7071
7172 protected abstract void endBookmark();
7273
@@ -174,11 +175,11 @@
174175 if (!transform.isIdentity()) {
175176 s = transform.createTransformedShape(s);
176177 }
177- this.addLink(s, uri);
178+ this.addLink(s, uri, ce);
178179 }
179180
180- // Image map
181181 if (type == IBox.TYPE_REPLACED) {
182+ // Image map
182183 String usemap = XHTML.USEMAP_ATTR.getValue(ce.atts);
183184 if (usemap != null && usemap.startsWith("#")) {
184185 usemap = usemap.substring(1);
@@ -195,10 +196,28 @@
195196 if (!transform.isIdentity()) {
196197 s = transform.createTransformedShape(s);
197198 }
198- this.addLink(s, area.href);
199+ this.addLink(s, area.href, null);
199200 }
200201 }
201202 }
203+
204+ // SVG Links
205+ ReplacedParams params = (ReplacedParams)box.getParams();
206+ ImageMap imageMap = this.ua.getUAContext().getImageMaps().remove(params.image);
207+ if (imageMap != null) {
208+ AffineTransform t2 = AffineTransform.getTranslateInstance(x, y);
209+ t2.scale(box.getInnerWidth() / params.image.getWidth(), box.getInnerHeight() / params.image.getHeight());
210+ for(ImageMap.Area link : imageMap) {
211+ Shape s = link.shape;
212+ if (!t2.isIdentity()) {
213+ s = t2.createTransformedShape(s);
214+ }
215+ if (!transform.isIdentity()) {
216+ s = transform.createTransformedShape(s);
217+ }
218+ this.addLink(s, link.href, null);
219+ }
220+ }
202221 }
203222 }
204223
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/NopVisitor.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/NopVisitor.java (revision 1589)
@@ -4,6 +4,7 @@
44 import java.awt.geom.Point2D;
55 import java.net.URI;
66
7+import jp.cssj.homare.css.CSSElement;
78 import jp.cssj.homare.ua.UserAgent;
89
910 public class NopVisitor extends AbstractVisitor {
@@ -14,7 +15,7 @@
1415 protected void addFragment(String id, Point2D location) {
1516 }
1617
17- protected void addLink(Shape rect, URI uri) {
18+ protected void addLink(Shape rect, URI uri, CSSElement ce) {
1819 }
1920
2021 protected void endBookmark() {
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/pdf/PDFVisitor.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/pdf/PDFVisitor.java (revision 1589)
@@ -6,6 +6,7 @@
66 import java.io.IOException;
77 import java.net.URI;
88
9+import jp.cssj.homare.css.CSSElement;
910 import jp.cssj.homare.impl.ua.AbstractVisitor;
1011 import jp.cssj.homare.message.MessageCodes;
1112 import jp.cssj.homare.ua.UserAgent;
@@ -32,7 +33,7 @@
3233 this.setBookmarks(UAProps.OUTPUT_PDF_BOOKMARKS.getBoolean(this.ua));
3334 }
3435
35- protected void addLink(Shape s, URI uri) {
36+ protected void addLink(Shape s, URI uri, CSSElement ce) {
3637 PdfPageOutput pdfOut = (PdfPageOutput) this.gc.getPDFGraphicsOutput();
3738 AffineTransform at = this.gc.getTransform();
3839 if (at != null) {
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/MyBridgeContext.java (nonexistent)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/MyBridgeContext.java (revision 1589)
@@ -0,0 +1,48 @@
1+package jp.cssj.homare.impl.ua.svg;
2+
3+import java.awt.Shape;
4+import java.awt.geom.Dimension2D;
5+import java.net.URI;
6+
7+import org.apache.batik.bridge.BridgeContext;
8+import org.apache.batik.bridge.DocumentLoader;
9+import org.apache.batik.bridge.TextPainter;
10+import org.apache.batik.bridge.URIResolver;
11+import org.w3c.dom.svg.SVGDocument;
12+
13+import jp.cssj.homare.ua.ImageMap;
14+import jp.cssj.homare.ua.UserAgent;
15+
16+public class MyBridgeContext extends BridgeContext {
17+ protected final UserAgent ua;
18+ protected final SVGImageLoader loader;
19+ protected final ImageMap imageMap = new ImageMap();
20+
21+ public MyBridgeContext(String docURI, UserAgent ua, Dimension2D viewport, SVGImageLoader loader) {
22+ super(new MyUserAgent(docURI, ua, viewport));
23+ this.ua = ua;
24+ this.loader = loader;
25+ this.setDynamic(false);
26+ TextPainter textPainer = new MyTextPainter(ua);
27+ this.setTextPainter(textPainer);
28+ }
29+
30+ public ImageMap getImageMap() {
31+ return this.imageMap;
32+ }
33+
34+ public void addLink(Shape shape, URI uri) {
35+ this.imageMap.add(new ImageMap.Area(shape, uri));
36+ }
37+
38+ public void registerSVGBridges() {
39+ super.registerSVGBridges();
40+ this.putBridge(new MySVGTextElementBridge(this.ua));
41+ this.putBridge(new MySVGImageElementBridge(this.ua));
42+ this.putBridge(new MySVGAElementBridge(this.ua));
43+ }
44+
45+ public URIResolver createURIResolver(SVGDocument doc, DocumentLoader dl) {
46+ return new MyURIResolver(doc, dl, this.ua, this.loader);
47+ }
48+}
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/MySVGAElementBridge.java (nonexistent)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/MySVGAElementBridge.java (revision 1589)
@@ -0,0 +1,36 @@
1+package jp.cssj.homare.impl.ua.svg;
2+
3+import java.awt.Shape;
4+import java.net.URI;
5+
6+import org.apache.batik.anim.dom.SVGOMAElement;
7+import org.apache.batik.bridge.Bridge;
8+import org.apache.batik.bridge.BridgeContext;
9+import org.apache.batik.bridge.SVGAElementBridge;
10+import org.apache.batik.gvt.GraphicsNode;
11+import org.w3c.dom.Element;
12+
13+import jp.cssj.homare.ua.UserAgent;
14+
15+public class MySVGAElementBridge extends SVGAElementBridge {
16+ // private static final Logger LOG = Logger.getLogger(MySVGAElementBridge.class.getName());
17+ protected final UserAgent ua;
18+
19+ public MySVGAElementBridge(UserAgent ua) {
20+ this.ua = ua;
21+ }
22+
23+ public Bridge getInstance() {
24+ return new MySVGAElementBridge(this.ua);
25+ }
26+
27+ public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) {
28+ super.buildGraphicsNode(ctx, e, node);
29+ MyBridgeContext mctx = (MyBridgeContext)ctx;
30+ SVGOMAElement a = (SVGOMAElement) e;
31+ Shape s = node.getOutline();
32+ s = node.getGlobalTransform().createTransformedShape(s);
33+ mctx.addLink(s, URI.create(a.getHref().getBaseVal()));
34+ }
35+
36+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/SVGImageLoader.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/impl/ua/svg/SVGImageLoader.java (revision 1589)
@@ -1,5 +1,6 @@
11 package jp.cssj.homare.impl.ua.svg;
22
3+import java.awt.geom.AffineTransform;
34 import java.awt.geom.Dimension2D;
45 import java.io.BufferedInputStream;
56 import java.io.BufferedReader;
@@ -15,7 +16,6 @@
1516 import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
1617 import org.apache.batik.anim.dom.SVGOMDocument;
1718 import org.apache.batik.anim.dom.SVGOMSVGElement;
18-import org.apache.batik.bridge.BridgeContext;
1919 import org.apache.batik.bridge.BridgeException;
2020 import org.apache.batik.bridge.GVTBuilder;
2121 import org.apache.batik.gvt.GraphicsNode;
@@ -26,6 +26,7 @@
2626 import org.w3c.dom.svg.SVGRect;
2727
2828 import jp.cssj.homare.ua.ImageLoader;
29+import jp.cssj.homare.ua.ImageMap;
2930 import jp.cssj.homare.ua.UserAgent;
3031 import jp.cssj.resolver.Source;
3132 import jp.cssj.sakae.gc.image.Image;
@@ -134,7 +135,7 @@
134135 } catch (Exception e) {
135136 // ignore
136137 }
137- BridgeContext ctx = new BridgeContextImpl(docURI, ua, viewport, this);
138+ MyBridgeContext ctx = new MyBridgeContext(docURI, ua, viewport, this);
138139 GVTBuilder gvt = new GVTBuilderImpl();
139140 GraphicsNode gvtRoot = gvt.build(ctx, doc);
140141
@@ -153,7 +154,9 @@
153154 AbstractSVGAnimatedLength _height = (AbstractSVGAnimatedLength) root.getHeight();
154155 float h = _height.getCheckedValue();
155156
157+ ImageMap imageMap = ctx.imageMap;
156158 Image image = new SVGImage(gvtRoot, w, h);
159+ ua.getUAContext().getImageMaps().put(image, imageMap);
157160 return image;
158161 } catch (BridgeException e) {
159162 IOException ioe = new IOException("SVGを読み込めませんでした。");
--- copper/trunk/homare/src/main/java/jp/cssj/homare/ua/ImageMap.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/ua/ImageMap.java (revision 1589)
@@ -1,6 +1,7 @@
11 package jp.cssj.homare.ua;
22
33 import java.awt.Shape;
4+import java.awt.geom.AffineTransform;
45 import java.net.URI;
56 import java.util.ArrayList;
67
@@ -13,7 +14,7 @@
1314 public final URI href;
1415 public final Shape shape;
1516
16- public Area(final URI href, final Shape shape) {
17+ public Area(final Shape shape, final URI href) {
1718 this.href = href;
1819 this.shape = shape;
1920 }
@@ -25,4 +26,12 @@
2526 return buff.toString();
2627 }
2728 }
29+
30+ public ImageMap getTransformedImageMap(AffineTransform t) {
31+ ImageMap im = new ImageMap();
32+ for(Area area : this) {
33+ im.add(new Area(t.createTransformedShape(area.shape), area.href));
34+ }
35+ return im;
36+ }
2837 }
--- copper/trunk/homare/src/main/java/jp/cssj/homare/ua/UAContext.java (revision 1588)
+++ copper/trunk/homare/src/main/java/jp/cssj/homare/ua/UAContext.java (revision 1589)
@@ -15,7 +15,7 @@
1515
1616 private FontSourceManager fsm;
1717
18- private Map<String, ImageMap> maps = new HashMap<String, ImageMap> ();
18+ private Map<Object, ImageMap> maps = new HashMap<Object, ImageMap> ();
1919
2020 public FontSourceManager getFontSourceManager() {
2121 return this.fsm;
@@ -37,7 +37,7 @@
3737 return this.pageRef;
3838 }
3939
40- public Map<String, ImageMap> getImageMaps() {
40+ public Map<Object, ImageMap> getImageMaps() {
4141 return this.maps;
4242 }
4343 }
Show on old repository browser