Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

IFPainter.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.render.intermediate;
  19. import java.awt.Color;
  20. import java.awt.Dimension;
  21. import java.awt.Paint;
  22. import java.awt.Point;
  23. import java.awt.Rectangle;
  24. import java.awt.geom.AffineTransform;
  25. import org.w3c.dom.Document;
  26. import org.apache.fop.traits.BorderProps;
  27. import org.apache.fop.traits.RuleStyle;
  28. /**
  29. * Interface used to paint whole documents layouted by Apache FOP.
  30. * <p>
  31. * Call sequence:
  32. * <p>
  33. * <pre>
  34. * startDocument()
  35. * startDocumentHeader()
  36. * [handleExtension()]*
  37. * endDocumentHeader()
  38. * [
  39. * startPageSequence()
  40. * [
  41. * startPage()
  42. * startPageHeader()
  43. * [handleExtension()]*
  44. * endPageHeader()
  45. * startPageContent()
  46. * (#pageContent)+
  47. * endPageContent()
  48. * startPageTrailer()
  49. * (addTarget())*
  50. * endPageTrailer()
  51. * endPage()
  52. * ]*
  53. * endPageSequence()
  54. * ]*
  55. * startDocumentTrailer()
  56. * [handleExtension()]*
  57. * endDocumentTrailer()
  58. * endDocument()
  59. *
  60. * #box:
  61. * startBox()
  62. * (#pageContent)+
  63. * endBox()
  64. *
  65. * #pageContent:
  66. * (
  67. * setFont() |
  68. * drawText() |
  69. * drawRect() |
  70. * drawImage() |
  71. * TODO etc. etc. |
  72. * handleExtensionObject()
  73. * )
  74. * </pre>
  75. */
  76. public interface IFPainter {
  77. /**
  78. * Starts a new viewport, establishing a new coordinate system. A viewport has a size and
  79. * can optionally be clipped. Corresponds to SVG's svg element.
  80. * @param transform the transformation matrix establishing the new coordinate system
  81. * @param size the size of the viewport
  82. * @param clipRect the clipping rectangle (may be null)
  83. * @throws IFException if an error occurs while handling this element
  84. */
  85. void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
  86. throws IFException;
  87. /**
  88. * Starts a new viewport, establishing a new coordinate system. A viewport has a size and
  89. * can optionally be clipped. Corresponds to SVG's svg element.
  90. * @param transforms a series of transformation matrices establishing the new coordinate system
  91. * @param size the size of the viewport
  92. * @param clipRect the clipping rectangle (may be null)
  93. * @throws IFException if an error occurs while handling this element
  94. */
  95. void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect)
  96. throws IFException;
  97. //For transform, Batik's org.apache.batik.parser.TransformListHandler/Parser can be used
  98. /**
  99. * Ends the current viewport and restores the previous coordinate system.
  100. * @throws IFException if an error occurs while handling this element
  101. */
  102. void endViewport() throws IFException;
  103. /**
  104. * Starts a new group of graphical elements. Corresponds to SVG's g element.
  105. * @param transforms a series of transformation matrices establishing the new coordinate system
  106. * @param layer an optional layer label (or null if none)
  107. * @throws IFException if an error occurs while handling this element
  108. */
  109. void startGroup(AffineTransform[] transforms, String layer) throws IFException;
  110. /**
  111. * Starts a new group of graphical elements. Corresponds to SVG's g element.
  112. * @param transform the transformation matrix establishing the new coordinate system
  113. * @param layer an optional layer label (or null if none)
  114. * @throws IFException if an error occurs while handling this element
  115. */
  116. void startGroup(AffineTransform transform, String layer) throws IFException;
  117. /**
  118. * Ends the current group and restores the previous coordinate system (and layer).
  119. * @throws IFException if an error occurs while handling this element
  120. */
  121. void endGroup() throws IFException;
  122. /**
  123. * Updates the current font.
  124. * @param family the font family (or null if there's no change)
  125. * @param style the font style (or null if there's no change)
  126. * @param weight the font weight (or null if there's no change)
  127. * @param variant the font variant (or null if there's no change)
  128. * @param size the font size (or null if there's no change)
  129. * @param color the text color (or null if there's no change)
  130. * @throws IFException if an error occurs while handling this event
  131. */
  132. void setFont(String family, String style, Integer weight, String variant, Integer size,
  133. Color color) throws IFException;
  134. /**
  135. * Draws text. The initial coordinates (x and y) point to the starting point at the normal
  136. * baseline of the font. The parameters letterSpacing, wordSpacing and the array dx are
  137. * optional and can be used to influence character positioning (for example, for kerning).
  138. * @param x X-coordinate of the starting point of the text
  139. * @param y Y-coordinate of the starting point of the text
  140. * @param letterSpacing additional spacing between characters (may be 0)
  141. * @param wordSpacing additional spacing between words (may be 0)
  142. * @param dp an array of 4-tuples, expressing [X,Y] placment
  143. * adjustments and [X,Y] advancement adjustments, in that order (may be null); if
  144. * not null, then adjustments.length must be the same as text.length()
  145. * @param text the text
  146. * @throws IFException if an error occurs while handling this event
  147. */
  148. void drawText(int x, int y, int letterSpacing, int wordSpacing,
  149. int[][] dp, String text) throws IFException;
  150. /**
  151. * Restricts the current clipping region with the given rectangle.
  152. * @param rect the rectangle's coordinates and extent
  153. * @throws IFException if an error occurs while handling this event
  154. */
  155. void clipRect(Rectangle rect) throws IFException;
  156. //TODO clipRect() shall be considered temporary until verified with SVG and PCL
  157. /**
  158. * Restricts the current clipping region to the inner border.
  159. * @param rect the rectangle's coordinates and extent
  160. * @param bpsBefore the border segment on the before-side (top)
  161. * @param bpsAfter the border segment on the after-side (bottom)
  162. * @param bpsStart the border segment on the start-side (left)
  163. * @param bpsEnd the border segment on the end-side (right)
  164. * @throws IFException if an error occurs while handling this event
  165. */
  166. void clipBackground(Rectangle rect,
  167. BorderProps bpsBefore, BorderProps bpsAfter,
  168. BorderProps bpsStart, BorderProps bpsEnd) throws IFException;
  169. /**
  170. * TODO Painter-specific rounded borders logic required background drawing to be
  171. * made optional. A future refactoring of the rounded borders code should aim to make
  172. * the need for this abstraction obsolete
  173. * @param bpsBefore the before border
  174. * @param bpsAfter the after border
  175. * @param bpsStart the start border
  176. * @param bpsEnd the end border
  177. * @return true if and only if background drawing is required
  178. */
  179. boolean isBackgroundRequired(BorderProps bpsBefore, BorderProps bpsAfter,
  180. BorderProps bpsStart, BorderProps bpsEnd);
  181. /**
  182. * Fills a rectangular area.
  183. * @param rect the rectangle's coordinates and extent
  184. * @param fill the fill paint
  185. * @throws IFException if an error occurs while handling this event
  186. */
  187. void fillRect(Rectangle rect, Paint fill) throws IFException;
  188. /**
  189. * Draws a border rectangle. The border segments are specified through {@link BorderProps}
  190. * instances.
  191. * @param rect the rectangle's coordinates and extent
  192. * @param top the border segment on the top edge
  193. * @param bottom the border segment on the bottom edge
  194. * @param left the border segment on the left edge
  195. * @param right the border segment on the right edge
  196. * @param innerBackgroundColor the color of the inner background
  197. * @throws IFException if an error occurs while handling this event
  198. */
  199. void drawBorderRect(Rectangle rect,
  200. BorderProps top, BorderProps bottom,
  201. BorderProps left, BorderProps right, Color innerBackgroundColor) throws IFException;
  202. /**
  203. * Draws a line. NOTE: Currently, only horizontal lines are implemented!
  204. * @param start the start point of the line
  205. * @param end the end point of the line
  206. * @param width the line width
  207. * @param color the line color
  208. * @param style the line style (using the Constants.EN_* constants for the rule-style property)
  209. * @throws IFException if an error occurs while handling this event
  210. */
  211. void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
  212. throws IFException;
  213. /**
  214. * Draws an image identified by a URI inside a given rectangle. This is the equivalent to
  215. * an fo:external-graphic in XSL-FO.
  216. * @param uri the image's URI
  217. * @param rect the rectangle in which the image shall be painted
  218. * @throws IFException if an error occurs while handling this event
  219. */
  220. void drawImage(String uri, Rectangle rect) throws IFException;
  221. /**
  222. * Draws an image (represented by a DOM document) inside a given rectangle. This is the
  223. * equivalent to an fo:instream-foreign-object in XSL-FO.
  224. * @param doc the DOM document containing the foreign object
  225. * @param rect the rectangle in which the image shall be painted
  226. * @throws IFException if an error occurs while handling this event
  227. */
  228. void drawImage(Document doc, Rectangle rect) throws IFException;
  229. //Note: For now, all foreign objects are handled as DOM documents. At the moment, all known
  230. //implementations use a DOM anyway, so optimizing this to work with SAX wouldn't result in
  231. //any performance benefits. The IFRenderer itself has a DOM anyway. Only the IFParser could
  232. //potentially profit if there's an image handler that can efficiently deal with the foreign
  233. //object without building a DOM.
  234. //etc. etc.
  235. }