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.

SimpleSVGUserAgent.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.SAXParserFactory;
  23. import org.apache.batik.bridge.UserAgentAdapter;
  24. import org.apache.batik.gvt.font.FontFamilyResolver;
  25. /**
  26. * A simple SVG user agent.
  27. * This is an implementation of the Batik SVG user agent. It ignores any message output sent
  28. * by Batik.
  29. */
  30. public class SimpleSVGUserAgent extends UserAgentAdapter {
  31. private AffineTransform currentTransform = null;
  32. private float pixelUnitToMillimeter = 0.0f;
  33. private final FontFamilyResolver fontFamilyResolver;
  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, FontFamilyResolver fontFamilyResolver) {
  40. this.fontFamilyResolver = fontFamilyResolver;
  41. pixelUnitToMillimeter = pixelUnitToMM;
  42. currentTransform = at;
  43. }
  44. /**
  45. * Returns a customized the pixel to mm factor.
  46. * @return the pixel unit to millimeter conversion factor
  47. */
  48. public float getPixelUnitToMillimeter() {
  49. return pixelUnitToMillimeter;
  50. }
  51. /**
  52. * Returns the language settings.
  53. * @return the languages supported
  54. */
  55. public String getLanguages() {
  56. return "en"; // userLanguages;
  57. }
  58. /**
  59. * Returns the media type for this rendering.
  60. * @return the media for FO documents is "print"
  61. */
  62. public String getMedia() {
  63. return "print";
  64. }
  65. /**
  66. * Returns the user stylesheet URI.
  67. * @return null if no user style sheet was specified.
  68. */
  69. public String getUserStyleSheetURI() {
  70. return null; // userStyleSheetURI;
  71. }
  72. /**
  73. * Returns the class name of the XML parser.
  74. * @return the XML parser class name
  75. */
  76. public String getXMLParserClassName() {
  77. try {
  78. SAXParserFactory factory = SAXParserFactory.newInstance();
  79. return factory.newSAXParser().getXMLReader().getClass().getName();
  80. } catch (Exception e) {
  81. return null;
  82. }
  83. }
  84. /**
  85. * Is the XML parser validating.
  86. * @return true if the XML parser is validating
  87. */
  88. public boolean isXMLParserValidating() {
  89. return false;
  90. }
  91. /**
  92. * Get the transform of the SVG document.
  93. * @return the transform
  94. */
  95. public AffineTransform getTransform() {
  96. return currentTransform;
  97. }
  98. /** {@inheritDoc} */
  99. public void setTransform(AffineTransform at) {
  100. this.currentTransform = at;
  101. }
  102. /**
  103. * Get the default viewport size for an SVG document.
  104. * This returns a default value of 100x100.
  105. * @return the default viewport size
  106. */
  107. public Dimension2D getViewportSize() {
  108. return new Dimension(100, 100);
  109. }
  110. @Override
  111. public FontFamilyResolver getFontFamilyResolver() {
  112. return fontFamilyResolver;
  113. }
  114. }