You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SVGUserAgent.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id: SVGUserAgent.java,v 1.2 2004/02/27 17:43:22 jeremias Exp $ */
  17. package org.apache.fop.svg;
  18. import org.apache.fop.apps.FOFileHandler;
  19. import org.apache.batik.bridge.UserAgentAdapter;
  20. import org.apache.avalon.framework.logger.Logger;
  21. // Java
  22. import java.awt.geom.AffineTransform;
  23. import java.awt.geom.Dimension2D;
  24. import java.awt.Dimension;
  25. /**
  26. * The SVG user agent.
  27. * This is an implementation of the batik svg user agent
  28. * for handling errors and getting user agent values.
  29. */
  30. public class SVGUserAgent extends UserAgentAdapter {
  31. private AffineTransform currentTransform = null;
  32. private Logger logger;
  33. private float pixelUnitToMillimeter = 0.0f;
  34. /**
  35. * Creates a new SVGUserAgent.
  36. * @param log an Avalon logging instance
  37. * @param pixelUnitToMM The pixel to millimeter conversion factor
  38. * currently in effect
  39. * @param at the current transform
  40. */
  41. public SVGUserAgent(Logger log, float pixelUnitToMM, AffineTransform at) {
  42. logger = log;
  43. pixelUnitToMillimeter = pixelUnitToMM;
  44. currentTransform = at;
  45. }
  46. /**
  47. * Returns the logger associated with this user agent.
  48. * @return Logger the logger
  49. */
  50. protected final Logger getLogger() {
  51. return logger;
  52. }
  53. /**
  54. * Displays an error message.
  55. * @param message the message to display
  56. */
  57. public void displayError(String message) {
  58. logger.error(message);
  59. }
  60. /**
  61. * Displays an error resulting from the specified Exception.
  62. * @param ex the exception to display
  63. */
  64. public void displayError(Exception ex) {
  65. logger.error("SVG Error" + ex.getMessage(), ex);
  66. }
  67. /**
  68. * Displays a message in the User Agent interface.
  69. * The given message is typically displayed in a status bar.
  70. * @param message the message to display
  71. */
  72. public void displayMessage(String message) {
  73. logger.info(message);
  74. }
  75. /**
  76. * Shows an alert dialog box.
  77. * @param message the message to display
  78. */
  79. public void showAlert(String message) {
  80. logger.warn(message);
  81. }
  82. /**
  83. * Returns a customized the pixel to mm factor.
  84. * @return the pixel unit to millimeter conversion factor
  85. */
  86. public float getPixelUnitToMillimeter() {
  87. return pixelUnitToMillimeter;
  88. }
  89. /**
  90. * Returns the language settings.
  91. * @return the languages supported
  92. */
  93. public String getLanguages() {
  94. return "en"; // userLanguages;
  95. }
  96. /**
  97. * Returns the media type for this rendering.
  98. * @return the media for fo documents is "print"
  99. */
  100. public String getMedia() {
  101. return "print";
  102. }
  103. /**
  104. * Returns the user stylesheet uri.
  105. * @return null if no user style sheet was specified.
  106. */
  107. public String getUserStyleSheetURI() {
  108. return null; // userStyleSheetURI;
  109. }
  110. /**
  111. * Returns the class name of the XML parser.
  112. * @return the XML parser class name
  113. */
  114. public String getXMLParserClassName() {
  115. return FOFileHandler.getParserClassName();
  116. }
  117. /**
  118. * Is the XML parser validating.
  119. * @return true if the xml parser is validating
  120. */
  121. public boolean isXMLParserValidating() {
  122. return false;
  123. }
  124. /**
  125. * Get the transform of the svg document.
  126. * @return the transform
  127. */
  128. public AffineTransform getTransform() {
  129. return currentTransform;
  130. }
  131. /**
  132. * Get the default viewport size for an svg document.
  133. * This returns a default value of 100x100.
  134. * @return the default viewport size
  135. */
  136. public Dimension2D getViewportSize() {
  137. return new Dimension(100, 100);
  138. }
  139. }