Lines 19-33
Link Here
|
19 |
|
19 |
|
20 |
package org.apache.fop.svg; |
20 |
package org.apache.fop.svg; |
21 |
|
21 |
|
22 |
import org.apache.batik.gvt.CompositeGraphicsNode; |
|
|
23 |
|
24 |
import java.awt.Graphics2D; |
22 |
import java.awt.Graphics2D; |
25 |
import java.awt.Shape; |
23 |
import java.awt.Shape; |
|
|
24 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.Rectangle2D; |
25 |
import java.awt.geom.Rectangle2D; |
27 |
import java.awt.geom.AffineTransform; |
|
|
28 |
|
29 |
import java.util.StringTokenizer; |
26 |
import java.util.StringTokenizer; |
30 |
|
27 |
|
|
|
28 |
import org.apache.batik.gvt.CompositeGraphicsNode; |
29 |
|
31 |
/** |
30 |
/** |
32 |
* A graphics node that represents an image described as a graphics node. |
31 |
* A graphics node that represents an image described as a graphics node. |
33 |
* |
32 |
* |
Lines 35-41
Link Here
|
35 |
*/ |
34 |
*/ |
36 |
public class PDFANode extends CompositeGraphicsNode { |
35 |
public class PDFANode extends CompositeGraphicsNode { |
37 |
private String destination; |
36 |
private String destination; |
38 |
private AffineTransform transform; |
37 |
private AffineTransform onPageTransform; |
39 |
|
38 |
|
40 |
/** |
39 |
/** |
41 |
* Constructs a new empty <tt>PDFANode</tt>. |
40 |
* Constructs a new empty <tt>PDFANode</tt>. |
Lines 52-65
Link Here
|
52 |
} |
51 |
} |
53 |
|
52 |
|
54 |
/** |
53 |
/** |
55 |
* Set the current transform of this node. |
54 |
* Returns the destination value for the node. |
|
|
55 |
* @return the destination |
56 |
*/ |
57 |
public String getDestination() { |
58 |
return this.destination; |
59 |
} |
60 |
|
61 |
/** |
62 |
* Set the "on-page" transform of this node. This corrects the placement of the link hot-zones |
63 |
* with respect of the SVG graphic on the page. |
56 |
* @param tf the transform |
64 |
* @param tf the transform |
57 |
*/ |
65 |
*/ |
58 |
public void setTransform(AffineTransform tf) { |
66 |
public void setOnPageTransform(AffineTransform tf) { |
59 |
transform = tf; |
67 |
this.onPageTransform = tf; |
60 |
} |
68 |
} |
61 |
|
69 |
|
62 |
/** |
70 |
/** |
|
|
71 |
* Returns the "on-page" transform of this node. |
72 |
* See {@code #setOnPageTransform(AffineTransform)} for details. |
73 |
* @return the "on-page" transform |
74 |
*/ |
75 |
public AffineTransform getOnPageTransform() { |
76 |
return this.onPageTransform; |
77 |
} |
78 |
|
79 |
/** |
63 |
* Paints this node if visible. |
80 |
* Paints this node if visible. |
64 |
* |
81 |
* |
65 |
* @param g2d the Graphics2D to use |
82 |
* @param g2d the Graphics2D to use |
Lines 104-112
Link Here
|
104 |
} catch (Exception e) { |
121 |
} catch (Exception e) { |
105 |
//TODO Move this to setDestination() and throw an IllegalArgumentException |
122 |
//TODO Move this to setDestination() and throw an IllegalArgumentException |
106 |
e.printStackTrace(); |
123 |
e.printStackTrace(); |
|
|
124 |
return; |
107 |
} |
125 |
} |
108 |
Rectangle2D destRect = new Rectangle2D.Float(x, y, width, height); |
126 |
Rectangle2D destRect = new Rectangle2D.Float(x, y, width, height); |
109 |
destRect = transform.createTransformedShape(destRect).getBounds(); |
127 |
destRect = getOnPageTransform().createTransformedShape(destRect).getBounds(); |
110 |
// these numbers need conversion to current |
128 |
// these numbers need conversion to current |
111 |
// svg position and scaled for the page |
129 |
// svg position and scaled for the page |
112 |
x = (float)destRect.getX(); |
130 |
x = (float)destRect.getX(); |
Lines 116-126
Link Here
|
116 |
|
134 |
|
117 |
destination = "" + x + " " + y + " " |
135 |
destination = "" + x + " " + y + " " |
118 |
+ (x + width) + " " + (y + height); |
136 |
+ (x + width) + " " + (y + height); |
|
|
137 |
} else if (destination.startsWith("#")) { |
138 |
if (generateFragmentLink(getBounds(), pdfg)) { |
139 |
return; //Returns early if the method indicated that it has generated a link |
140 |
} |
119 |
} |
141 |
} |
120 |
pdfg.addLink(getBounds(), transform, destination, type); |
142 |
pdfg.addLink(getBounds(), getOnPageTransform(), destination, type); |
121 |
} |
143 |
} |
122 |
} |
144 |
} |
123 |
} |
145 |
} |
124 |
|
146 |
|
|
|
147 |
/** |
148 |
* Generates a link for a fragment reference. By default, it does nothing. Subclasses can |
149 |
* generate links to objects (ex. in XSL-FO) identified by the fragment reference. |
150 |
* @param bounds the boundaries of the hot zone |
151 |
* @param pdfg the PDFGraphics2D object |
152 |
* @return true if it has generated a link for the fragment reference |
153 |
*/ |
154 |
protected boolean generateFragmentLink(Rectangle2D bounds, PDFGraphics2D pdfg) { |
155 |
//nop |
156 |
return false; |
157 |
} |
158 |
|
125 |
} |
159 |
} |
126 |
|
160 |
|