Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SimpleSVGUserAgent.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.svg;
  19. import java.awt.Dimension;
  20. import java.awt.geom.AffineTransform;
  21. import java.awt.geom.Dimension2D;
  22. import javax.xml.parsers.ParserConfigurationException;
  23. import javax.xml.parsers.SAXParserFactory;
  24. import org.xml.sax.SAXException;
  25. import org.apache.batik.bridge.UserAgentAdapter;
  26. /**
  27. * A simple SVG user agent.
  28. * This is an implementation of the Batik SVG user agent. It ignores any message output sent
  29. * by Batik.
  30. */
  31. public class SimpleSVGUserAgent extends UserAgentAdapter {
  32. private AffineTransform currentTransform = null;
  33. private float pixelUnitToMillimeter = 0.0f;
  34. /**
  35. * Creates a new user agent.
  36. * @param pixelUnitToMM the pixel to millimeter conversion factor currently in effect
  37. * @param at the current transform
  38. */
  39. public SimpleSVGUserAgent(float pixelUnitToMM, AffineTransform at) {
  40. pixelUnitToMillimeter = pixelUnitToMM;
  41. currentTransform = at;
  42. }
  43. /**
  44. * Returns a customized the pixel to mm factor.
  45. * @return the pixel unit to millimeter conversion factor
  46. */
  47. public float getPixelUnitToMillimeter() {
  48. return pixelUnitToMillimeter;
  49. }
  50. /**
  51. * Returns the language settings.
  52. * @return the languages supported
  53. */
  54. public String getLanguages() {
  55. return "en"; // userLanguages;
  56. }
  57. /**
  58. * Returns the media type for this rendering.
  59. * @return the media for FO documents is "print"
  60. */
  61. public String getMedia() {
  62. return "print";
  63. }
  64. /**
  65. * Returns the user stylesheet URI.
  66. * @return null if no user style sheet was specified.
  67. */
  68. public String getUserStyleSheetURI() {
  69. return null; // userStyleSheetURI;
  70. }
  71. private static final String XML_PARSER_CLASS_NAME;
  72. static {
  73. String result;
  74. try {
  75. SAXParserFactory factory = SAXParserFactory.newInstance();
  76. result = factory.newSAXParser().getXMLReader().getClass().getName();
  77. } catch (SAXException e) {
  78. result = null;
  79. } catch (ParserConfigurationException e) {
  80. result = null;
  81. }
  82. XML_PARSER_CLASS_NAME = result;
  83. }
  84. /**
  85. * Returns the class name of the XML parser.
  86. * @return the XML parser class name
  87. */
  88. public String getXMLParserClassName() {
  89. return XML_PARSER_CLASS_NAME;
  90. }
  91. /**
  92. * Is the XML parser validating.
  93. * @return true if the XML parser is validating
  94. */
  95. public boolean isXMLParserValidating() {
  96. return false;
  97. }
  98. /**
  99. * Get the transform of the SVG document.
  100. * @return the transform
  101. */
  102. public AffineTransform getTransform() {
  103. return currentTransform;
  104. }
  105. /** {@inheritDoc} */
  106. public void setTransform(AffineTransform at) {
  107. this.currentTransform = at;
  108. }
  109. /**
  110. * Get the default viewport size for an SVG document.
  111. * This returns a default value of 100x100.
  112. * @return the default viewport size
  113. */
  114. public Dimension2D getViewportSize() {
  115. return new Dimension(100, 100);
  116. }
  117. }