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.

AFPState.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 java.awt.Color;
  20. import java.util.Arrays;
  21. /**
  22. * This keeps information about the current state when writing to pdf.
  23. */
  24. public class AFPState {
  25. /**
  26. * The current color
  27. */
  28. private Color color = null;
  29. /**
  30. * The current background color
  31. */
  32. private Color backColor = null;
  33. /**
  34. * The current font name
  35. */
  36. private String fontName = null;
  37. /**
  38. * The current font size
  39. */
  40. private int fontSize = 0;
  41. /**
  42. * The current line width
  43. */
  44. private float lineWidth = 0;
  45. /**
  46. * The dash array for the current basic stroke (line type)
  47. */
  48. private float[] dashArray = null;
  49. /**
  50. * The current fill status
  51. */
  52. private boolean filled = false;
  53. /**
  54. * The fonts on the current page
  55. */
  56. private AFPPageFonts pageFonts = null;
  57. /**
  58. * Set the current color.
  59. * Check if the new color is a change and then set the current color.
  60. *
  61. * @param col the color to set
  62. * @return true if the color has changed
  63. */
  64. protected boolean setColor(Color col) {
  65. if (!col.equals(this.color)) {
  66. this.color = col;
  67. return true;
  68. }
  69. return false;
  70. }
  71. /**
  72. * Sets if the current painted shape is to be filled
  73. * @param fill true if the current painted shape is to be filled
  74. * @return true if the fill value has changed
  75. */
  76. protected boolean setFill(boolean fill) {
  77. if (fill != this.filled) {
  78. this.filled = fill;
  79. return true;
  80. }
  81. return false;
  82. }
  83. /**
  84. * Get the color.
  85. * @return the color
  86. */
  87. protected Color getColor() {
  88. if (this.color == null) {
  89. this.color = Color.black;
  90. }
  91. return this.color;
  92. }
  93. /**
  94. * Set the current line width.
  95. * @param width the line width in points
  96. * @return true if the line width has changed
  97. */
  98. protected boolean setLineWidth(float width) {
  99. if (this.lineWidth != width) {
  100. this.lineWidth = width;
  101. return true;
  102. }
  103. return false;
  104. }
  105. /**
  106. * Sets the dash array (line type) for the current basic stroke
  107. * @param dash the line dash array
  108. * @return true if the dash array has changed
  109. */
  110. public boolean setDashArray(float[] dash) {
  111. if (!Arrays.equals(dash, this.dashArray)) {
  112. this.dashArray = dash;
  113. return true;
  114. }
  115. return false;
  116. }
  117. /**
  118. * Gets the current line width
  119. * @return the current line width
  120. */
  121. protected float getLineWidth() {
  122. return lineWidth;
  123. }
  124. /**
  125. * Get the background color.
  126. * @return the background color
  127. */
  128. protected Color getBackColor() {
  129. if (this.backColor == null) {
  130. this.backColor = Color.white;
  131. }
  132. return backColor;
  133. }
  134. /**
  135. * Set the current background color.
  136. * Check if the new background color is a change and then set the current background color.
  137. *
  138. * @param col the background color to set
  139. * @return true if the color has changed
  140. */
  141. protected boolean setBackColor(Color col) {
  142. if (!col.equals(this.backColor)) {
  143. this.backColor = col;
  144. return true;
  145. }
  146. return false;
  147. }
  148. /**
  149. * Set the current font name
  150. * @param internalFontName the internal font name
  151. * @return true if the font name has changed
  152. */
  153. protected boolean setFontName(String internalFontName) {
  154. if (!internalFontName.equals(this.fontName)) {
  155. this.fontName = internalFontName;
  156. return true;
  157. }
  158. return false;
  159. }
  160. /**
  161. * Gets the current font name
  162. * @return the current font name
  163. */
  164. protected String getFontName() {
  165. return this.fontName;
  166. }
  167. /**
  168. * Gets the current font size
  169. * @return the current font size
  170. */
  171. protected int getFontSize() {
  172. return this.fontSize;
  173. }
  174. /**
  175. * Set the current font size.
  176. * Check if the font size is a change and then set the current font size.
  177. *
  178. * @param size the font size to set
  179. * @return true if the font size has changed
  180. */
  181. protected boolean setFontSize(int size) {
  182. if (size != this.fontSize) {
  183. this.fontSize = size;
  184. return true;
  185. }
  186. return false;
  187. }
  188. /**
  189. * Gets the current page fonts
  190. * @return the current page fonts
  191. */
  192. protected AFPPageFonts getPageFonts() {
  193. if (this.pageFonts == null) {
  194. this.pageFonts = new AFPPageFonts();
  195. }
  196. return this.pageFonts;
  197. }
  198. /**
  199. * Resets the current state
  200. */
  201. protected void reset() {
  202. this.color = null;
  203. this.backColor = null;
  204. this.fontName = null;
  205. this.fontSize = 0;
  206. this.lineWidth = 0;
  207. this.dashArray = null;
  208. this.filled = false;
  209. if (this.pageFonts != null) {
  210. this.pageFonts.clear();
  211. }
  212. }
  213. }