1 51 package org.apache.fop.svg; 52 53 import org.apache.batik.gvt.*; 54 55 import java.awt.Graphics2D ; 56 import java.awt.Shape ; 57 import java.awt.geom.AffineTransform ; 58 59 import java.util.StringTokenizer ; 60 61 66 public class PDFANode extends CompositeGraphicsNode { 67 String destination; 68 AffineTransform transform; 69 70 73 public PDFANode() {} 74 75 78 public void setDestination(String dest) { 79 destination = dest; 80 } 81 82 public void setTransform(AffineTransform tf) { 83 transform = tf; 84 } 85 86 92 public void paint(Graphics2D g2d) { 93 if (isVisible) { 94 super.paint(g2d); 95 if(g2d instanceof PDFGraphics2D) { 96 PDFGraphics2D pdfg = (PDFGraphics2D)g2d; 97 int type = org.apache.fop.layout.LinkSet.EXTERNAL; 98 Shape outline = getOutline(); 99 if(destination.startsWith("#svgView(viewBox(")) { 100 type = org.apache.fop.layout.LinkSet.INTERNAL; 101 String nums = destination.substring(18, destination.length() - 2); 102 float x = 0; 103 float y = 0; 104 float width = 0; 105 float height; 106 int count = 0; 107 try { 108 StringTokenizer st = new StringTokenizer (nums, ","); 109 while(st.hasMoreTokens()) { 110 String tok = st.nextToken(); 111 count++; 112 switch(count) { 113 case 1: 114 x = Float.parseFloat(tok); 115 break; 116 case 2: 117 y = Float.parseFloat(tok); 118 break; 119 case 3: 120 width = Float.parseFloat(tok); 121 break; 122 case 4: 123 height = Float.parseFloat(tok); 124 break; 125 default: 126 break; 127 } 128 } 129 } catch(Exception e) { 130 } 131 destination = "" + x + " " + y + " " + 200 / width; 134 } 135 pdfg.addLink(outline, transform, destination, type); 136 } 137 } 138 } 139 140 } 141 142 | Popular Tags |