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.

GraphicElement.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "FOP" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.dom.svg;
  41. import java.util.Enumeration;
  42. import org.apache.fop.datatypes.*;
  43. import org.w3c.dom.svg.*;
  44. import org.w3c.dom.*;
  45. import org.w3c.dom.events.*;
  46. /**
  47. * base class for SVG graphic objects.
  48. *
  49. * Graphic objects include rectangles, lines and text
  50. *
  51. */
  52. public abstract class GraphicElement extends SVGElementImpl implements SVGTransformable, SVGLangSpace, SVGTests, EventTarget {
  53. protected SVGList reqFeatures;
  54. protected SVGList reqExtensions;
  55. protected SVGList sysLanguage;
  56. SVGAnimatedTransformList transform;
  57. String xmlspace = "default";
  58. public SVGElement getNearestViewportElement( )
  59. {
  60. return null;
  61. }
  62. public SVGElement getFarthestViewportElement( )
  63. {
  64. return null;
  65. }
  66. public SVGAnimatedTransformList getTransform()
  67. {
  68. if(transform != null) {
  69. return transform;
  70. }
  71. SVGTransformList stl = new SVGTransformListImpl();
  72. SVGTransform transform = new SVGTransformImpl();
  73. stl.appendItem(transform);
  74. SVGAnimatedTransformList atl = new SVGAnimatedTransformListImpl();
  75. atl.setBaseVal(stl);
  76. return atl;
  77. }
  78. public void setTransform(SVGAnimatedTransformList transform)
  79. {
  80. this.transform = transform;
  81. }
  82. public SVGRect getBBox()
  83. {
  84. return null;
  85. }
  86. public SVGMatrix getCTM()
  87. {
  88. return null;
  89. }
  90. public SVGMatrix getScreenCTM()
  91. {
  92. return null;
  93. }
  94. public SVGMatrix getTransformToElement(SVGElement element)
  95. throws SVGException
  96. {
  97. return null;
  98. }
  99. public String getXMLlang()
  100. {
  101. return null;
  102. }
  103. public void setXMLlang(String xmllang)
  104. {
  105. }
  106. public String getXMLspace()
  107. {
  108. return xmlspace;
  109. }
  110. public void setXMLspace(String xmlspace)
  111. {
  112. this.xmlspace = xmlspace;
  113. }
  114. public SVGList getRequiredFeatures( )
  115. {
  116. return reqFeatures;
  117. }
  118. public void setRequiredFeatures( SVGList requiredFeatures )
  119. throws DOMException
  120. {
  121. reqFeatures = requiredFeatures;
  122. }
  123. public SVGList getRequiredExtensions( )
  124. {
  125. return reqExtensions;
  126. }
  127. public void setRequiredExtensions( SVGList requiredExtensions )
  128. throws DOMException
  129. {
  130. reqExtensions = requiredExtensions;
  131. }
  132. public boolean hasExtension ( String extension )
  133. {
  134. return false;
  135. }
  136. public SVGList getSystemLanguage()
  137. {
  138. return sysLanguage;
  139. }
  140. public void setSystemLanguage(SVGList systemLanguage)
  141. {
  142. sysLanguage = systemLanguage;
  143. }
  144. public void addEventListener(String type,
  145. EventListener listener,
  146. boolean useCapture)
  147. {
  148. }
  149. public void removeEventListener(String type,
  150. EventListener listener,
  151. boolean useCapture)
  152. {
  153. }
  154. public boolean dispatchEvent(Event evt)
  155. // throws EventException
  156. {
  157. return false;
  158. }
  159. /**
  160. * Convenience method for implementations of SVGTransformable
  161. * that have children that represents the bounding box
  162. */
  163. protected SVGRect getChildrenBBox()
  164. {
  165. float minX = 10000000; // a big number
  166. float maxX = -10000000; // a low number
  167. float minY = 10000000; // a big number
  168. float maxY = -10000000; // a low number
  169. NodeList nl = getChildNodes();
  170. // can width and height be negative??
  171. for(int count = 0; count < nl.getLength(); count++) {
  172. Node n = nl.item(count);
  173. if(n instanceof SVGTransformable) {
  174. SVGRect r = ((SVGTransformable)n).getBBox();
  175. if(r != null) {
  176. if(minX > r.getX())
  177. minX = r.getX();
  178. if(minY > r.getY())
  179. minY = r.getY();
  180. if(maxX < r.getX() + r.getWidth())
  181. maxX = r.getX() + r.getWidth();
  182. if(maxY > r.getY() + r.getHeight())
  183. maxY = r.getY() + r.getHeight();
  184. }
  185. }
  186. }
  187. SVGRect rect = new SVGRectImpl();
  188. rect.setX(minX);
  189. rect.setY(minY);
  190. rect.setWidth(maxX - minX);
  191. rect.setHeight(maxY - minY);
  192. return rect;
  193. }
  194. }