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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * $Id: SVGUserAgent.java,v 1.14 2003/03/07 09:51:25 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.svg;
  52. import org.apache.fop.fo.FOUserAgent;
  53. import org.apache.batik.bridge.UserAgentAdapter;
  54. import org.apache.avalon.framework.logger.Logger;
  55. // Java
  56. import java.awt.geom.AffineTransform;
  57. import java.awt.geom.Dimension2D;
  58. import java.awt.Dimension;
  59. /**
  60. * The SVG user agent.
  61. * This is an implementation of the batik svg user agent
  62. * for handling errors and getting user agent values.
  63. */
  64. public class SVGUserAgent extends UserAgentAdapter {
  65. private AffineTransform currentTransform = null;
  66. private FOUserAgent userAgent;
  67. /**
  68. * Creates a new SVGUserAgent.
  69. * @param ua the FO user agent
  70. * @param at the current transform
  71. */
  72. public SVGUserAgent(FOUserAgent ua, AffineTransform at) {
  73. currentTransform = at;
  74. userAgent = ua;
  75. }
  76. /**
  77. * Returns the logger associated with this user agent.
  78. * @return Logger the logger
  79. */
  80. protected final Logger getLogger() {
  81. return this.userAgent.getLogger();
  82. }
  83. /**
  84. * Displays an error message.
  85. * @param message the message to display
  86. */
  87. public void displayError(String message) {
  88. getLogger().error(message);
  89. }
  90. /**
  91. * Displays an error resulting from the specified Exception.
  92. * @param ex the exception to display
  93. */
  94. public void displayError(Exception ex) {
  95. getLogger().error("SVG Error" + ex.getMessage(), ex);
  96. }
  97. /**
  98. * Displays a message in the User Agent interface.
  99. * The given message is typically displayed in a status bar.
  100. * @param message the message to display
  101. */
  102. public void displayMessage(String message) {
  103. getLogger().info(message);
  104. }
  105. /**
  106. * Shows an alert dialog box.
  107. * @param message the message to display
  108. */
  109. public void showAlert(String message) {
  110. getLogger().warn(message);
  111. }
  112. /**
  113. * Returns a customized the pixel to mm factor.
  114. * @return the pixel unit to millimeter conversion factor
  115. */
  116. public float getPixelUnitToMillimeter() {
  117. return userAgent.getPixelUnitToMillimeter();
  118. }
  119. /**
  120. * Returns the language settings.
  121. * @return the languages supported
  122. */
  123. public String getLanguages() {
  124. return "en"; // userLanguages;
  125. }
  126. /**
  127. * Returns the media type for this rendering.
  128. * @return the media for fo documents is "print"
  129. */
  130. public String getMedia() {
  131. return "print";
  132. }
  133. /**
  134. * Returns the user stylesheet uri.
  135. * @return null if no user style sheet was specified.
  136. */
  137. public String getUserStyleSheetURI() {
  138. return null; // userStyleSheetURI;
  139. }
  140. /**
  141. * Returns the class name of the XML parser.
  142. * @return the XML parser class name
  143. */
  144. public String getXMLParserClassName() {
  145. return org.apache.fop.apps.Session.getParserClassName();
  146. }
  147. /**
  148. * Is the XML parser validating.
  149. * @return true if the xml parser is validating
  150. */
  151. public boolean isXMLParserValidating() {
  152. return false;
  153. }
  154. /**
  155. * Get the transform of the svg document.
  156. * @return the transform
  157. */
  158. public AffineTransform getTransform() {
  159. return currentTransform;
  160. }
  161. /**
  162. * Get the default viewport size for an svg document.
  163. * This returns a default value of 100x100.
  164. * @return the default viewport size
  165. */
  166. public Dimension2D getViewportSize() {
  167. return new Dimension(100, 100);
  168. }
  169. }