(empty log message)
@@ -1,28 +0,0 @@ | ||
1 | -package jp.cssj.homare.impl.ua.svg; | |
2 | - | |
3 | -import java.awt.geom.Dimension2D; | |
4 | - | |
5 | -public class Dimension2DImpl extends Dimension2D { | |
6 | - protected double width, height; | |
7 | - | |
8 | - public Dimension2DImpl(double width, double height) { | |
9 | - this.setSize(width, height); | |
10 | - } | |
11 | - | |
12 | - public double getHeight() { | |
13 | - return this.height; | |
14 | - } | |
15 | - | |
16 | - public double getWidth() { | |
17 | - return this.width; | |
18 | - } | |
19 | - | |
20 | - public void setSize(double width, double height) { | |
21 | - this.width = width; | |
22 | - this.height = height; | |
23 | - } | |
24 | - | |
25 | - public String toString() { | |
26 | - return super.toString() + "[" + this.width + "," + this.height + "]"; | |
27 | - } | |
28 | -} |
@@ -4,21 +4,20 @@ | ||
4 | 4 | |
5 | 5 | import org.apache.batik.bridge.NoLoadScriptSecurity; |
6 | 6 | import org.apache.batik.bridge.ScriptSecurity; |
7 | -import org.apache.batik.bridge.UserAgentAdapter; | |
8 | 7 | import org.apache.batik.util.ParsedURL; |
9 | 8 | |
10 | 9 | import jp.cssj.homare.message.MessageCodes; |
11 | 10 | import jp.cssj.homare.ua.UserAgent; |
11 | +import jp.cssj.sakae.svg.UserAgentImpl; | |
12 | 12 | |
13 | -class MyUserAgent extends UserAgentAdapter { | |
13 | +class MyUserAgent extends UserAgentImpl { | |
14 | 14 | protected final String docURI; |
15 | 15 | protected final UserAgent ua; |
16 | - protected final Dimension2D viewport; | |
17 | 16 | |
18 | 17 | public MyUserAgent(String docURI, UserAgent ua, Dimension2D viewport) { |
18 | + super(viewport); | |
19 | 19 | this.docURI = docURI; |
20 | 20 | this.ua = ua; |
21 | - this.viewport = viewport; | |
22 | 21 | this.addStdFeatures(); |
23 | 22 | } |
24 | 23 |
@@ -17,6 +17,7 @@ | ||
17 | 17 | import org.apache.batik.anim.dom.SVGOMSVGElement; |
18 | 18 | import org.apache.batik.bridge.BridgeContext; |
19 | 19 | import org.apache.batik.bridge.BridgeException; |
20 | +import org.apache.batik.bridge.DocumentLoader; | |
20 | 21 | import org.apache.batik.bridge.GVTBuilder; |
21 | 22 | import org.apache.batik.gvt.GraphicsNode; |
22 | 23 | import org.apache.batik.util.ParsedURL; |
@@ -29,8 +30,10 @@ | ||
29 | 30 | import jp.cssj.homare.ua.UserAgent; |
30 | 31 | import jp.cssj.resolver.Source; |
31 | 32 | import jp.cssj.sakae.gc.image.Image; |
33 | +import jp.cssj.sakae.svg.Dimension2DImpl; | |
32 | 34 | import jp.cssj.sakae.svg.GVTBuilderImpl; |
33 | 35 | import jp.cssj.sakae.svg.SVGImage; |
36 | +import jp.cssj.sakae.svg.UserAgentImpl; | |
34 | 37 | |
35 | 38 | public class SVGImageLoader implements ImageLoader { |
36 | 39 | private static final Logger LOG = Logger.getLogger(SVGImageLoader.class.getName()); |
@@ -121,12 +124,11 @@ | ||
121 | 124 | return doc; |
122 | 125 | } |
123 | 126 | |
124 | - public static final Dimension2D VIEWPORT = new Dimension2DImpl(400, 400); | |
127 | + private static final Dimension2D VIEWPORT = new Dimension2DImpl(400, 400); | |
125 | 128 | |
126 | 129 | public Image getImage(String docURI, final Document doc, final UserAgent ua) throws IOException { |
127 | 130 | try { |
128 | 131 | SVGOMSVGElement root = (SVGOMSVGElement) doc.getDocumentElement(); |
129 | - | |
130 | 132 | Dimension2D viewport = VIEWPORT; |
131 | 133 | try { |
132 | 134 | SVGRect r = root.getViewBox().getBaseVal(); |
@@ -134,7 +136,9 @@ | ||
134 | 136 | } catch (Exception e) { |
135 | 137 | // ignore |
136 | 138 | } |
137 | - BridgeContext ctx = new BridgeContextImpl(docURI, ua, viewport, this); | |
139 | + UserAgentImpl uax = new UserAgentImpl(viewport); | |
140 | + DocumentLoader loader = new DocumentLoader(uax); | |
141 | + BridgeContext ctx = new BridgeContext(uax, loader); | |
138 | 142 | GVTBuilder gvt = new GVTBuilderImpl(); |
139 | 143 | GraphicsNode gvtRoot = gvt.build(ctx, doc); |
140 | 144 |
@@ -69,6 +69,7 @@ | ||
69 | 69 | * @param text |
70 | 70 | */ |
71 | 71 | public static void drawText(GC gc, DrawableFont font, Text text) throws GraphicsException { |
72 | + gc.begin(); | |
72 | 73 | FontStyle fontStyle = text.getFontStyle(); |
73 | 74 | byte direction = fontStyle.getDirection(); |
74 | 75 | double fontSize = fontStyle.getSize(); |
@@ -219,6 +220,7 @@ | ||
219 | 220 | gc.setLineWidth(xlineWidth); |
220 | 221 | gc.setStrokePaint(xstrokePaint); |
221 | 222 | } |
223 | + gc.end(); | |
222 | 224 | } |
223 | 225 | |
224 | 226 | private static void drawPath(GC gc, GeneralPath path, short textMode) { |
@@ -2,6 +2,7 @@ | ||
2 | 2 | |
3 | 3 | import java.awt.Graphics2D; |
4 | 4 | import java.awt.geom.AffineTransform; |
5 | +import java.awt.geom.Dimension2D; | |
5 | 6 | import java.io.IOException; |
6 | 7 | import java.io.InputStream; |
7 | 8 | import java.util.HashMap; |
@@ -13,7 +14,6 @@ | ||
13 | 14 | import org.apache.batik.bridge.DocumentLoader; |
14 | 15 | import org.apache.batik.bridge.GVTBuilder; |
15 | 16 | import org.apache.batik.bridge.UserAgent; |
16 | -import org.apache.batik.bridge.UserAgentAdapter; | |
17 | 17 | import org.apache.batik.gvt.GraphicsNode; |
18 | 18 | import org.apache.batik.util.XMLResourceDescriptor; |
19 | 19 |
@@ -24,8 +24,10 @@ | ||
24 | 24 | import jp.cssj.sakae.gc.GraphicsException; |
25 | 25 | import jp.cssj.sakae.gc.font.util.FontUtils; |
26 | 26 | import jp.cssj.sakae.gc.text.Text; |
27 | +import jp.cssj.sakae.svg.Dimension2DImpl; | |
27 | 28 | import jp.cssj.sakae.svg.GVTBuilderImpl; |
28 | 29 | import jp.cssj.sakae.svg.SVGBridgeGraphics2D; |
30 | +import jp.cssj.sakae.svg.UserAgentImpl; | |
29 | 31 | |
30 | 32 | class EmojiFont implements ImageFont { |
31 | 33 | private static final long serialVersionUID = 2L; |
@@ -69,20 +71,22 @@ | ||
69 | 71 | FontUtils.drawText(gc, this, text); |
70 | 72 | } |
71 | 73 | |
72 | - private final SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory( | |
73 | - XMLResourceDescriptor.getXMLParserClassName()); | |
74 | - private final GVTBuilder builder = new GVTBuilderImpl(true); | |
75 | - private final UserAgent ua = new UserAgentAdapter(); | |
76 | - private final DocumentLoader loader = new DocumentLoader(ua); | |
77 | 74 | private final Map<Integer, GraphicsNode> gidToEmoji = new HashMap<Integer, GraphicsNode>(); |
78 | - | |
75 | + private static final Dimension2D VIEWPORT = new Dimension2DImpl(128, 128); | |
76 | + | |
79 | 77 | public void drawGlyphForGid(GC gc, int gid, AffineTransform at) { |
80 | 78 | GraphicsNode gvtRoot = this.gidToEmoji.get(gid); |
81 | 79 | if (gvtRoot == null) { |
82 | - try (InputStream in = EmojiFont.class | |
80 | + try (InputStream in = EmojiFontSource.class | |
83 | 81 | .getResourceAsStream("emoji_u" + Integer.toHexString(gid).toLowerCase() + ".svg")) { |
84 | - SVGOMDocument doc = (SVGOMDocument) this.factory.createDocument(null, in); | |
85 | - gvtRoot = this.builder.build(new BridgeContext(this.ua, this.loader), doc); | |
82 | + SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName()); | |
83 | + SVGOMDocument doc = (SVGOMDocument) factory.createDocument(null, in); | |
84 | + UserAgent ua = new UserAgentImpl(VIEWPORT); | |
85 | + DocumentLoader loader = new DocumentLoader(ua); | |
86 | + BridgeContext ctx = new BridgeContext(ua, loader); | |
87 | + ctx.setDynamic(false); | |
88 | + GVTBuilder gvt = new GVTBuilderImpl(); | |
89 | + gvtRoot = gvt.build(ctx, doc); | |
86 | 90 | this.gidToEmoji.put(gid, gvtRoot); |
87 | 91 | } catch (Exception e) { |
88 | 92 | e.printStackTrace(); |
@@ -91,18 +95,18 @@ | ||
91 | 95 | if (gvtRoot == null) { |
92 | 96 | return; |
93 | 97 | } |
94 | - | |
95 | 98 | |
96 | 99 | gc.begin(); |
97 | - Graphics2D g2d = new SVGBridgeGraphics2D(gc); | |
98 | 100 | if (at != null) { |
99 | - g2d.transform(at); | |
101 | + gc.transform(at); | |
100 | 102 | } |
101 | - AffineTransform t = AffineTransform.getTranslateInstance(0, -this.source.getAscent()); | |
102 | - t.scale(1000, 1000); | |
103 | - g2d.transform(t); | |
103 | + gc.transform(AffineTransform.getTranslateInstance(0, -this.source.getAscent())); | |
104 | + gc.transform(AffineTransform.getScaleInstance(1000.0/VIEWPORT.getWidth(), 1000.0/VIEWPORT.getHeight())); | |
105 | + gc.begin(); | |
106 | + Graphics2D g2d = new SVGBridgeGraphics2D(gc); | |
104 | 107 | gvtRoot.paint(g2d); |
105 | 108 | g2d.dispose(); |
106 | 109 | gc.end(); |
110 | + gc.end(); | |
107 | 111 | } |
108 | 112 | } |
@@ -66,7 +66,7 @@ | ||
66 | 66 | } |
67 | 67 | |
68 | 68 | public boolean canDisplay(int c) { |
69 | - return EmojiFont.class.getResource("emoji_u"+Integer.toHexString(c).toLowerCase()+".svg") != null; | |
69 | + return EmojiFontSource.class.getResource("emoji_u"+Integer.toHexString(c).toLowerCase()+".svg") != null; | |
70 | 70 | } |
71 | 71 | |
72 | 72 | public Panose getPanose() { |
@@ -0,0 +1,28 @@ | ||
1 | +package jp.cssj.sakae.svg; | |
2 | + | |
3 | +import java.awt.geom.Dimension2D; | |
4 | + | |
5 | +public class Dimension2DImpl extends Dimension2D { | |
6 | + protected double width, height; | |
7 | + | |
8 | + public Dimension2DImpl(double width, double height) { | |
9 | + this.setSize(width, height); | |
10 | + } | |
11 | + | |
12 | + public double getHeight() { | |
13 | + return this.height; | |
14 | + } | |
15 | + | |
16 | + public double getWidth() { | |
17 | + return this.width; | |
18 | + } | |
19 | + | |
20 | + public void setSize(double width, double height) { | |
21 | + this.width = width; | |
22 | + this.height = height; | |
23 | + } | |
24 | + | |
25 | + public String toString() { | |
26 | + return super.toString() + "[" + this.width + "," + this.height + "]"; | |
27 | + } | |
28 | +} |
@@ -38,11 +38,11 @@ | ||
38 | 38 | } |
39 | 39 | |
40 | 40 | public void drawTo(GC gc) throws GraphicsException { |
41 | - gc.begin(); | |
42 | - Graphics2D g2d = new SVGBridgeGraphics2D(gc); | |
43 | - this.gvtRoot.paint(g2d); | |
44 | - g2d.dispose(); | |
45 | - gc.end(); | |
41 | + gc.begin(); | |
42 | + Graphics2D g2d = new SVGBridgeGraphics2D(gc); | |
43 | + this.gvtRoot.paint(g2d); | |
44 | + g2d.dispose(); | |
45 | + gc.end(); | |
46 | 46 | } |
47 | 47 | |
48 | 48 | public String getAltString() { |
@@ -0,0 +1,18 @@ | ||
1 | +package jp.cssj.sakae.svg; | |
2 | + | |
3 | +import java.awt.geom.Dimension2D; | |
4 | + | |
5 | +import org.apache.batik.bridge.UserAgentAdapter; | |
6 | + | |
7 | +public class UserAgentImpl extends UserAgentAdapter { | |
8 | + protected final Dimension2D viewport; | |
9 | + | |
10 | + public UserAgentImpl(Dimension2D viewport) { | |
11 | + this.viewport = viewport; | |
12 | + this.addStdFeatures(); | |
13 | + } | |
14 | + | |
15 | + public Dimension2D getViewportSize() { | |
16 | + return this.viewport; | |
17 | + } | |
18 | +} | |
\ No newline at end of file |