Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

IFState.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 org.apache.xmlgraphics.java2d.color.ColorUtil;
  21. /** a state class for intermediate format data */
  22. public final class IFState {
  23. private IFState parent;
  24. private String fontFamily;
  25. private int fontSize;
  26. private String fontStyle;
  27. private int fontWeight;
  28. private String fontVariant;
  29. private boolean fontChanged = true;
  30. private Color textColor;
  31. private IFState() {
  32. //nop
  33. }
  34. private IFState(IFState parent) {
  35. this.parent = parent;
  36. this.fontFamily = parent.fontFamily;
  37. this.fontSize = parent.fontSize;
  38. this.fontStyle = parent.fontStyle;
  39. this.fontWeight = parent.fontWeight;
  40. this.fontVariant = parent.fontVariant;
  41. this.textColor = parent.textColor;
  42. }
  43. /** @return create state */
  44. public static IFState create() {
  45. return new IFState();
  46. }
  47. /** @return push state */
  48. public IFState push() {
  49. return new IFState(this);
  50. }
  51. /** @return pop state */
  52. public IFState pop() {
  53. return this.parent;
  54. }
  55. /** @return true if font changed */
  56. public boolean isFontChanged() {
  57. return this.fontChanged;
  58. }
  59. /** reset font changed */
  60. public void resetFontChanged() {
  61. this.fontChanged = false;
  62. }
  63. /**
  64. * Returns the font family.
  65. * @return the font family
  66. */
  67. public String getFontFamily() {
  68. return fontFamily;
  69. }
  70. /**
  71. * Sets the font family.
  72. * @param family the new font family
  73. */
  74. public void setFontFamily(String family) {
  75. if (!family.equals(this.fontFamily)) {
  76. this.fontChanged = true;
  77. }
  78. this.fontFamily = family;
  79. }
  80. /**
  81. * Returns the font size.
  82. * @return the font size (in mpt)
  83. */
  84. public int getFontSize() {
  85. return fontSize;
  86. }
  87. /**
  88. * Sets the font size.
  89. * @param size the new font size (in mpt)
  90. */
  91. public void setFontSize(int size) {
  92. if (size != this.fontSize) {
  93. this.fontChanged = true;
  94. }
  95. this.fontSize = size;
  96. }
  97. /**
  98. * Returns the font style.
  99. * @return the font style
  100. */
  101. public String getFontStyle() {
  102. return fontStyle;
  103. }
  104. /**
  105. * Set the font style
  106. * @param style the new font style
  107. */
  108. public void setFontStyle(String style) {
  109. if (!style.equals(this.fontStyle)) {
  110. this.fontChanged = true;
  111. }
  112. this.fontStyle = style;
  113. }
  114. /**
  115. * Returns the font weight.
  116. * @return the font weight
  117. */
  118. public int getFontWeight() {
  119. return fontWeight;
  120. }
  121. /**
  122. * Sets the font weight
  123. * @param weight the new font weight
  124. */
  125. public void setFontWeight(int weight) {
  126. if (weight != this.fontWeight) {
  127. this.fontChanged = true;
  128. }
  129. this.fontWeight = weight;
  130. }
  131. /**
  132. * Returns the font variant.
  133. * @return the font variant
  134. */
  135. public String getFontVariant() {
  136. return fontVariant;
  137. }
  138. /**
  139. * Sets the font variant.
  140. * @param variant the new font variant
  141. */
  142. public void setFontVariant(String variant) {
  143. if (!variant.equals(this.fontVariant)) {
  144. this.fontChanged = true;
  145. }
  146. this.fontVariant = variant;
  147. }
  148. /**
  149. * Returns the text color.
  150. * @return the text color
  151. */
  152. public Color getTextColor() {
  153. return textColor;
  154. }
  155. /**
  156. * Sets the text color.
  157. * @param color the new text color
  158. */
  159. public void setTextColor(Color color) {
  160. if (!ColorUtil.isSameColor(color, this.textColor)) {
  161. this.fontChanged = true;
  162. }
  163. this.textColor = color;
  164. }
  165. }