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.

CommonTextDecoration.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.fo.properties;
  19. import java.awt.Color;
  20. import java.util.List;
  21. import org.apache.fop.apps.FOUserAgent;
  22. import org.apache.fop.fo.Constants;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.expr.PropertyException;
  25. /**
  26. * Stores all information concerning text-decoration.
  27. */
  28. public class CommonTextDecoration {
  29. //using a bit-mask here
  30. private static final int UNDERLINE = 1;
  31. private static final int OVERLINE = 2;
  32. private static final int LINE_THROUGH = 4;
  33. private static final int BLINK = 8;
  34. private int decoration;
  35. private Color underColor;
  36. private Color overColor;
  37. private Color throughColor;
  38. /**
  39. * Creates a new CommonTextDecoration object with default values.
  40. */
  41. public CommonTextDecoration() {
  42. }
  43. /**
  44. * Creates a CommonTextDecoration object from a property list.
  45. * @param pList the property list to build the object for
  46. * @return a CommonTextDecoration object or null if the obj would only have default values
  47. * @throws PropertyException if there's a problem while processing the property
  48. */
  49. public static CommonTextDecoration createFromPropertyList(PropertyList pList)
  50. throws PropertyException {
  51. return calcTextDecoration(pList);
  52. }
  53. private static CommonTextDecoration calcTextDecoration(PropertyList pList)
  54. throws PropertyException {
  55. assert pList != null;
  56. CommonTextDecoration deco = null;
  57. PropertyList parentList = pList.getParentPropertyList();
  58. if (parentList != null) {
  59. //Parent is checked first
  60. deco = calcTextDecoration(parentList);
  61. }
  62. //For rules, see XSL 1.0, chapters 5.5.6 and 7.16.4
  63. Property textDecoProp = pList.getExplicit(Constants.PR_TEXT_DECORATION);
  64. if (textDecoProp != null) {
  65. List list = textDecoProp.getList();
  66. for (Object aList : list) {
  67. Property prop = (Property) aList;
  68. int propEnum = prop.getEnum();
  69. FOUserAgent ua = pList.getFObj() == null ? null : pList.getFObj().getUserAgent();
  70. if (propEnum == Constants.EN_NONE) {
  71. if (deco != null) {
  72. deco.decoration = 0;
  73. }
  74. return deco;
  75. } else if (propEnum == Constants.EN_UNDERLINE) {
  76. if (deco == null) {
  77. deco = new CommonTextDecoration();
  78. }
  79. deco.decoration |= UNDERLINE;
  80. deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua);
  81. } else if (propEnum == Constants.EN_NO_UNDERLINE) {
  82. if (deco != null) {
  83. deco.decoration &= OVERLINE | LINE_THROUGH | BLINK;
  84. deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua);
  85. }
  86. } else if (propEnum == Constants.EN_OVERLINE) {
  87. if (deco == null) {
  88. deco = new CommonTextDecoration();
  89. }
  90. deco.decoration |= OVERLINE;
  91. deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua);
  92. } else if (propEnum == Constants.EN_NO_OVERLINE) {
  93. if (deco != null) {
  94. deco.decoration &= UNDERLINE | LINE_THROUGH | BLINK;
  95. deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua);
  96. }
  97. } else if (propEnum == Constants.EN_LINE_THROUGH) {
  98. if (deco == null) {
  99. deco = new CommonTextDecoration();
  100. }
  101. deco.decoration |= LINE_THROUGH;
  102. deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua);
  103. } else if (propEnum == Constants.EN_NO_LINE_THROUGH) {
  104. if (deco != null) {
  105. deco.decoration &= UNDERLINE | OVERLINE | BLINK;
  106. deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua);
  107. }
  108. } else if (propEnum == Constants.EN_BLINK) {
  109. if (deco == null) {
  110. deco = new CommonTextDecoration();
  111. }
  112. deco.decoration |= BLINK;
  113. } else if (propEnum == Constants.EN_NO_BLINK) {
  114. if (deco != null) {
  115. deco.decoration &= UNDERLINE | OVERLINE | LINE_THROUGH;
  116. }
  117. } else {
  118. throw new PropertyException("Illegal value encountered: " + prop.getString());
  119. }
  120. }
  121. }
  122. return deco;
  123. }
  124. /** @return true if underline is active */
  125. public boolean hasUnderline() {
  126. return (this.decoration & UNDERLINE) != 0;
  127. }
  128. /** @return true if overline is active */
  129. public boolean hasOverline() {
  130. return (this.decoration & OVERLINE) != 0;
  131. }
  132. /** @return true if line-through is active */
  133. public boolean hasLineThrough() {
  134. return (this.decoration & LINE_THROUGH) != 0;
  135. }
  136. /** @return true if blink is active */
  137. public boolean isBlinking() {
  138. return (this.decoration & BLINK) != 0;
  139. }
  140. /** @return the color of the underline mark */
  141. public Color getUnderlineColor() {
  142. return this.underColor;
  143. }
  144. /** @return the color of the overline mark */
  145. public Color getOverlineColor() {
  146. return this.overColor;
  147. }
  148. /** @return the color of the line-through mark */
  149. public Color getLineThroughColor() {
  150. return this.throughColor;
  151. }
  152. }