1 18 package org.apache.batik.bridge; 19 20 import java.awt.Cursor ; 21 import java.awt.Dimension ; 22 import java.awt.Point ; 23 import java.awt.geom.AffineTransform ; 24 import java.awt.geom.Dimension2D ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Set ; 28 29 import org.apache.batik.gvt.event.EventDispatcher; 30 import org.apache.batik.gvt.text.Mark; 31 import org.apache.batik.util.ParsedURL; 32 import org.apache.batik.util.SVGConstants; 33 import org.apache.batik.util.XMLResourceDescriptor; 34 import org.w3c.dom.Element ; 35 import org.w3c.dom.svg.SVGAElement; 36 37 44 public class UserAgentAdapter implements UserAgent { 45 protected Set FEATURES = new HashSet (); 46 protected Set extensions = new HashSet (); 47 48 public UserAgentAdapter() { 49 } 50 51 public void addStdFeatures() { 52 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_FEATURE); 53 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_LANG_FEATURE); 54 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_STATIC_FEATURE); 55 } 56 57 58 61 public Dimension2D getViewportSize() { 62 return new Dimension (1, 1); 63 } 64 65 68 public void displayMessage(String message) { 69 } 70 71 74 public void displayError(String message) { 75 displayMessage(message); 76 } 77 78 81 public void displayError(Exception e) { 82 displayError(e.getMessage()); 83 } 84 85 88 public void showAlert(String message) { 89 } 90 91 94 public String showPrompt(String message) { 95 return null; 96 } 97 98 101 public String showPrompt(String message, String defaultValue) { 102 return null; 103 } 104 105 108 public boolean showConfirm(String message) { 109 return false; 110 } 111 112 115 public float getPixelUnitToMillimeter() { 116 return 0.26458333333333333333333333333333f; } 118 119 124 public float getPixelToMM() { 125 return getPixelUnitToMillimeter(); 126 127 } 128 129 132 public String getDefaultFontFamily() { 133 return "Arial, Helvetica, sans-serif"; 134 } 135 136 139 public float getMediumFontSize() { 140 return 9f * 25.4f / (72f * getPixelUnitToMillimeter()); 142 } 143 144 147 public float getLighterFontWeight(float f) { 148 return getStandardLighterFontWeight(f); 149 } 150 151 154 public float getBolderFontWeight(float f) { 155 return getStandardBolderFontWeight(f); 156 } 157 158 159 162 public String getLanguages() { 163 return "en"; 164 } 165 166 169 public String getMedia() { 170 return "all"; 171 } 172 173 176 public String getAlternateStyleSheet() { 177 return null; 178 } 179 180 183 public String getUserStyleSheetURI() { 184 return null; 185 } 186 187 190 public String getXMLParserClassName() { 191 return XMLResourceDescriptor.getXMLParserClassName(); 192 } 193 194 197 public boolean isXMLParserValidating() { 198 return false; 199 } 200 201 204 public EventDispatcher getEventDispatcher() { 205 return null; 206 } 207 208 211 public void openLink(SVGAElement elt) { } 212 213 216 public void setSVGCursor(Cursor cursor) { } 217 218 221 public void setTextSelection(Mark start, Mark end) { } 222 223 226 public void deselectAll() { } 227 228 231 public void runThread(Thread t) { } 232 233 236 public AffineTransform getTransform() { 237 return null; 238 } 239 240 243 public void setTransform(AffineTransform at) { 244 } 246 247 250 public Point getClientAreaLocationOnScreen() { 251 return new Point (); 252 } 253 254 258 public boolean hasFeature(String s) { 259 return FEATURES.contains(s); 260 } 261 262 266 public boolean supportExtension(String s) { 267 return extensions.contains(s); 268 } 269 270 274 public void registerExtension(BridgeExtension ext) { 275 Iterator i = ext.getImplementedExtensions(); 276 while (i.hasNext()) 277 extensions.add(i.next()); 278 } 279 280 281 288 public void handleElement(Element elt, Object data){ 289 } 290 291 304 public ScriptSecurity getScriptSecurity(String scriptType, 305 ParsedURL scriptURL, 306 ParsedURL docURL){ 307 return new DefaultScriptSecurity(scriptType, scriptURL, docURL); 308 } 309 310 328 public void checkLoadScript(String scriptType, 329 ParsedURL scriptURL, 330 ParsedURL docURL) throws SecurityException { 331 ScriptSecurity s = getScriptSecurity(scriptType, 332 scriptURL, 333 docURL); 334 if (s != null) { 335 s.checkLoadScript(); 336 } 337 } 338 339 350 public ExternalResourceSecurity 351 getExternalResourceSecurity(ParsedURL resourceURL, 352 ParsedURL docURL) { 353 return new RelaxedExternalResourceSecurity(resourceURL, docURL); 354 } 355 356 372 public void 373 checkLoadExternalResource(ParsedURL resourceURL, 374 ParsedURL docURL) throws SecurityException { 375 ExternalResourceSecurity s 376 = getExternalResourceSecurity(resourceURL, docURL); 377 378 if (s != null) { 379 s.checkLoadExternalResource(); 380 } 381 } 382 383 386 public static float getStandardLighterFontWeight(float f) { 387 int weight = ((int)((f+50)/100))*100; 389 switch (weight) { 390 case 100: return 100; 391 case 200: return 100; 392 case 300: return 200; 393 case 400: return 300; 394 case 500: return 400; 395 case 600: return 400; 396 case 700: return 400; 397 case 800: return 400; 398 case 900: return 400; 399 default: 400 throw new IllegalArgumentException ("Bad Font Weight: " + f); 401 } 402 } 403 404 407 public static float getStandardBolderFontWeight(float f) { 408 int weight = ((int)((f+50)/100))*100; 410 switch (weight) { 411 case 100: return 600; 412 case 200: return 600; 413 case 300: return 600; 414 case 400: return 600; 415 case 500: return 600; 416 case 600: return 700; 417 case 700: return 800; 418 case 800: return 900; 419 case 900: return 900; 420 default: 421 throw new IllegalArgumentException ("Bad Font Weight: " + f); 422 } 423 } 424 425 } 426 427 | Popular Tags |