1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.xmlgraphics;
20
21 import java.awt.Dimension;
22 import java.awt.Graphics2D;
23 import java.awt.Image;
24 import java.awt.geom.Rectangle2D;
25 import java.awt.image.BufferedImage;
26
27 import net.sourceforge.jeuclid.MutableLayoutContext;
28 import net.sourceforge.jeuclid.context.LayoutContextImpl;
29 import net.sourceforge.jeuclid.layout.JEuclidView;
30
31 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
32 import org.w3c.dom.Document;
33
34
35
36
37
38
39 public class Graphics2DImagePainterMathML implements Graphics2DImagePainter {
40
41 private final Dimension dimension;
42
43 private final JEuclidView view;
44
45 private final float ascent;
46
47
48
49
50
51
52
53
54
55
56
57 public Graphics2DImagePainterMathML(final JEuclidView theView,
58 final Dimension dim, final float asc) {
59 this.view = theView;
60 this.dimension = dim;
61 this.ascent = asc;
62 }
63
64
65
66
67
68
69
70
71 public static Graphics2DImagePainter createGraphics2DImagePainter(
72 final Document document) {
73 final MutableLayoutContext layoutContext = new LayoutContextImpl(
74 LayoutContextImpl.getDefaultLayoutContext());
75
76 final Image tempimage = new BufferedImage(1, 1,
77 BufferedImage.TYPE_INT_ARGB);
78 final Graphics2D tempg = (Graphics2D) tempimage.getGraphics();
79 final JEuclidView view = new JEuclidView(document, layoutContext,
80 tempg);
81 final int w = (int) Math.ceil(view.getWidth()
82 * PreloaderMathML.MPT_FACTOR);
83 final float ascent = view.getAscentHeight();
84 final int h = (int) Math.ceil((ascent + view.getDescentHeight())
85 * PreloaderMathML.MPT_FACTOR);
86 return new Graphics2DImagePainterMathML(view, new Dimension(w, h),
87 ascent);
88 }
89
90
91 public Dimension getImageSize() {
92 return this.dimension;
93 }
94
95
96 public void paint(final Graphics2D graphics2d,
97 final Rectangle2D rectangle2d) {
98 this.view.draw(graphics2d, 0, this.ascent);
99 }
100 }