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.

AFPInfo.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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.afp;
  19. import org.apache.fop.afp.AFPGraphics2D;
  20. import org.apache.fop.afp.AFPPaintingState;
  21. import org.apache.fop.afp.AFPResourceInfo;
  22. import org.apache.fop.afp.AFPResourceManager;
  23. import org.apache.fop.configuration.Configuration;
  24. import org.apache.fop.fonts.FontInfo;
  25. /**
  26. * AFP information structure for drawing the XML document.
  27. */
  28. public final class AFPInfo {
  29. /** see WIDTH */
  30. private int width;
  31. /** see HEIGHT */
  32. private int height;
  33. /** see XPOS */
  34. private int x;
  35. /** see YPOS */
  36. private int y;
  37. /** see HANDLER_CONFIGURATION */
  38. private Configuration handlerConfiguration;
  39. /** see AFP_FONT_INFO */
  40. private FontInfo fontInfo;
  41. /** See AFP_PAINTING_STATE */
  42. private AFPPaintingState paintingState;
  43. /** See AFP_RESOURCE_MANAGER */
  44. private AFPResourceManager resourceManager;
  45. /** See AFP_RESOURCE_INFO */
  46. private AFPResourceInfo resourceInfo;
  47. /** true if SVG should be rendered as a bitmap instead of natively */
  48. private boolean paintAsBitmap;
  49. /**
  50. * Returns the width.
  51. *
  52. * @return the width
  53. */
  54. public int getWidth() {
  55. return width;
  56. }
  57. /**
  58. * Sets the width.
  59. *
  60. * @param width The pageWidth to set
  61. */
  62. public void setWidth(int width) {
  63. this.width = width;
  64. }
  65. /**
  66. * Returns the height.
  67. *
  68. * @return the height
  69. */
  70. public int getHeight() {
  71. return height;
  72. }
  73. /**
  74. * Sets the height.
  75. *
  76. * @param height The height to set
  77. */
  78. public void setHeight(int height) {
  79. this.height = height;
  80. }
  81. /**
  82. * Returns the handler configuration
  83. *
  84. * @return the handler configuration
  85. */
  86. public Configuration getHandlerConfiguration() {
  87. return this.handlerConfiguration;
  88. }
  89. /**
  90. * Sets the handler configuration
  91. *
  92. * @param cfg the handler configuration
  93. */
  94. public void setHandlerConfiguration(Configuration cfg) {
  95. this.handlerConfiguration = cfg;
  96. }
  97. /**
  98. * Return the font info
  99. *
  100. * @return the font info
  101. */
  102. public FontInfo getFontInfo() {
  103. return this.fontInfo;
  104. }
  105. /**
  106. * Returns the current AFP state
  107. *
  108. * @return the current AFP state
  109. */
  110. public AFPPaintingState getPaintingState() {
  111. return this.paintingState;
  112. }
  113. /**
  114. * Returns the AFPResourceManager
  115. *
  116. * @return the AFPResourceManager
  117. */
  118. public AFPResourceManager getResourceManager() {
  119. return this.resourceManager;
  120. }
  121. /**
  122. * Returns true if supports color
  123. *
  124. * @return true if supports color
  125. */
  126. public boolean isColorSupported() {
  127. return getPaintingState().isColorImages();
  128. }
  129. /**
  130. * Returns the current x position coordinate
  131. *
  132. * @return the current x position coordinate
  133. */
  134. protected int getX() {
  135. return x;
  136. }
  137. /**
  138. * Returns the current y position coordinate
  139. *
  140. * @return the current y position coordinate
  141. */
  142. protected int getY() {
  143. return y;
  144. }
  145. /**
  146. * Returns the resolution
  147. *
  148. * @return the resolution
  149. */
  150. protected int getResolution() {
  151. return getPaintingState().getResolution();
  152. }
  153. /**
  154. * Returns the number of bits per pixel to use
  155. * @return the number of bits per pixel to use
  156. */
  157. protected int getBitsPerPixel() {
  158. return getPaintingState().getBitsPerPixel();
  159. }
  160. /**
  161. * Sets the current x position coordinate
  162. *
  163. * @param x the current x position coordinate
  164. */
  165. protected void setX(int x) {
  166. this.x = x;
  167. }
  168. /**
  169. * Sets the current y position coordinate
  170. *
  171. * @param y the current y position coordinate
  172. */
  173. protected void setY(int y) {
  174. this.y = y;
  175. }
  176. /**
  177. * Sets the current font info
  178. *
  179. * @param fontInfo the current font info
  180. */
  181. protected void setFontInfo(FontInfo fontInfo) {
  182. this.fontInfo = fontInfo;
  183. }
  184. /**
  185. * Sets the AFP state
  186. *
  187. * @param paintingState the AFP state
  188. */
  189. public void setPaintingState(AFPPaintingState paintingState) {
  190. this.paintingState = paintingState;
  191. }
  192. /**
  193. * Sets the AFPResourceManager
  194. *
  195. * @param resourceManager the AFPResourceManager
  196. */
  197. public void setResourceManager(AFPResourceManager resourceManager) {
  198. this.resourceManager = resourceManager;
  199. }
  200. /**
  201. * Sets true if SVG should be rendered as a bitmap instead of natively
  202. *
  203. * @param b boolean value
  204. */
  205. public void setPaintAsBitmap(boolean b) {
  206. this.paintAsBitmap = b;
  207. }
  208. /**
  209. * Returns true if SVG should be rendered as a bitmap instead of natively
  210. *
  211. * @return true if SVG should be rendered as a bitmap instead of natively
  212. */
  213. public boolean paintAsBitmap() {
  214. return this.paintAsBitmap;
  215. }
  216. /**
  217. * Returns true if text should be stroked when painted
  218. *
  219. * @return true if text should be stroked when painted
  220. */
  221. public boolean strokeText() {
  222. boolean strokeText = false;
  223. if (handlerConfiguration != null) {
  224. strokeText
  225. = handlerConfiguration.getChild("stroke-text", true).getValueAsBoolean(strokeText);
  226. }
  227. return strokeText;
  228. }
  229. /**
  230. * Sets the resource information
  231. *
  232. * @param resourceInfo the resource information
  233. */
  234. public void setResourceInfo(AFPResourceInfo resourceInfo) {
  235. this.resourceInfo = resourceInfo;
  236. }
  237. /**
  238. * Returns the resource information
  239. *
  240. * @return the resource information
  241. */
  242. public AFPResourceInfo getResourceInfo() {
  243. return resourceInfo;
  244. }
  245. /**
  246. * Creates an AFPGraphics2D implementation
  247. *
  248. * @param textAsShapes true when text is painted as shapes
  249. * @return a newly created AFPGraphics2D
  250. */
  251. public AFPGraphics2D createGraphics2D(boolean textAsShapes) {
  252. AFPGraphics2D g2d
  253. = new AFPGraphics2D(
  254. textAsShapes, paintingState, resourceManager, resourceInfo, fontInfo);
  255. g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
  256. return g2d;
  257. }
  258. /** {@inheritDoc} */
  259. public String toString() {
  260. return "AFPInfo{width=" + width
  261. + ", height=" + height
  262. + ", x=" + x
  263. + ", y=" + y
  264. + ", cfg=" + handlerConfiguration
  265. + ", fontInfo=" + fontInfo
  266. + ", resourceManager=" + resourceManager
  267. + ", paintingState=" + paintingState
  268. + ", paintAsBitmap=" + paintAsBitmap
  269. + ", resourceInfo=" + resourceInfo
  270. + "}";
  271. }
  272. }