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.

AbstractPageNumberCitation.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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.flow;
  19. import java.awt.Color;
  20. import java.util.Stack;
  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.Locator;
  23. import org.apache.fop.accessibility.StructureTreeElement;
  24. import org.apache.fop.apps.FOPException;
  25. import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
  26. import org.apache.fop.datatypes.Length;
  27. import org.apache.fop.fo.Constants;
  28. import org.apache.fop.fo.FONode;
  29. import org.apache.fop.fo.FObj;
  30. import org.apache.fop.fo.PropertyList;
  31. import org.apache.fop.fo.ValidationException;
  32. import org.apache.fop.fo.properties.CommonAccessibility;
  33. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  34. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  35. import org.apache.fop.fo.properties.CommonFont;
  36. import org.apache.fop.fo.properties.CommonTextDecoration;
  37. import org.apache.fop.fo.properties.SpaceProperty;
  38. import org.apache.fop.fo.properties.StructureTreeElementHolder;
  39. import org.apache.fop.util.CharUtilities;
  40. /**
  41. * Common base class for the <a href="http://www.w3.org/TR/xsl/#fo_page-number-citation">
  42. * <code>fo:page-number-citation</code></a> and
  43. * <a href="http://www.w3.org/TR/xsl/#fo_page-number-citation-last">
  44. * <code>fo:page-number-citation-last</code></a> objects.
  45. */
  46. public abstract class AbstractPageNumberCitation extends FObj
  47. implements StructureTreeElementHolder, CommonAccessibilityHolder {
  48. // The value of properties relevant for fo:page-number-citation(-last).
  49. private CommonAccessibility commonAccessibility;
  50. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  51. private CommonFont commonFont;
  52. private Length alignmentAdjust;
  53. private int alignmentBaseline;
  54. private Length baselineShift;
  55. private int dominantBaseline;
  56. private StructureTreeElement structureTreeElement;
  57. // private ToBeImplementedProperty letterSpacing;
  58. private SpaceProperty lineHeight;
  59. private String refId;
  60. /** Holds the text decoration values. May be null */
  61. private CommonTextDecoration textDecoration;
  62. // private ToBeImplementedProperty textShadow;
  63. // Unused but valid items, commented out for performance:
  64. // private CommonAural commonAural;
  65. // private CommonMarginInline commonMarginInline;
  66. // private CommonRelativePosition commonRelativePosition;
  67. // private KeepProperty keepWithNext;
  68. // private KeepProperty keepWithPrevious;
  69. // private int scoreSpaces;
  70. // private Length textAltitude;
  71. // private Length textDepth;
  72. // private int textTransform;
  73. // private int visibility;
  74. // private SpaceProperty wordSpacing;
  75. // private int wrapOption;
  76. // End of property values
  77. // Properties which are not explicitely listed but are still applicable
  78. private Color color;
  79. /**
  80. * Base constructor
  81. *
  82. * @param parent {@link FONode} that is the parent of this object
  83. */
  84. public AbstractPageNumberCitation(FONode parent) {
  85. super(parent);
  86. }
  87. /** {@inheritDoc} */
  88. public void bind(PropertyList pList) throws FOPException {
  89. super.bind(pList);
  90. commonAccessibility = CommonAccessibility.getInstance(pList);
  91. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  92. commonFont = pList.getFontProps();
  93. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  94. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  95. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  96. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  97. // letterSpacing = pList.get(PR_LETTER_SPACING);
  98. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  99. refId = pList.get(PR_REF_ID).getString();
  100. textDecoration = pList.getTextDecorationProps();
  101. // textShadow = pList.get(PR_TEXT_SHADOW);
  102. // implicit properties
  103. color = pList.get(Constants.PR_COLOR).getColor(getUserAgent());
  104. }
  105. /** {@inheritDoc} */
  106. public void processNode(
  107. String elementName, Locator locator, Attributes attlist, PropertyList pList)
  108. throws FOPException {
  109. super.processNode(elementName, locator, attlist, pList);
  110. if (!inMarker() && (refId == null || "".equals(refId))) {
  111. missingPropertyError("ref-id");
  112. }
  113. }
  114. /**
  115. * {@inheritDoc}
  116. * <br>XSL Content Model: empty
  117. */
  118. protected void validateChildNode(Locator loc, String nsURI, String localName)
  119. throws ValidationException {
  120. if (FO_URI.equals(nsURI)) {
  121. invalidChildError(loc, nsURI, localName);
  122. }
  123. }
  124. /** {@inheritDoc} */
  125. public CommonAccessibility getCommonAccessibility() {
  126. return commonAccessibility;
  127. }
  128. /** @return the {@link CommonFont} */
  129. public CommonFont getCommonFont() {
  130. return commonFont;
  131. }
  132. /** @return the "color" property. */
  133. public Color getColor() {
  134. return color;
  135. }
  136. /** @return the "text-decoration" property. */
  137. public CommonTextDecoration getTextDecoration() {
  138. return textDecoration;
  139. }
  140. @Override
  141. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  142. this.structureTreeElement = structureTreeElement;
  143. }
  144. @Override
  145. public StructureTreeElement getStructureTreeElement() {
  146. return structureTreeElement;
  147. }
  148. /** @return the "alignment-adjust" property */
  149. public Length getAlignmentAdjust() {
  150. return alignmentAdjust;
  151. }
  152. /** @return the "alignment-baseline" property */
  153. public int getAlignmentBaseline() {
  154. return alignmentBaseline;
  155. }
  156. /** @return the "baseline-shift" property */
  157. public Length getBaselineShift() {
  158. return baselineShift;
  159. }
  160. /** @return the "dominant-baseline" property */
  161. public int getDominantBaseline() {
  162. return dominantBaseline;
  163. }
  164. /** @return the {@link CommonBorderPaddingBackground} */
  165. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  166. return commonBorderPaddingBackground;
  167. }
  168. /** @return the "line-height" property */
  169. public SpaceProperty getLineHeight() {
  170. return lineHeight;
  171. }
  172. /** @return the "ref-id" property. */
  173. public String getRefId() {
  174. return refId;
  175. }
  176. @Override
  177. public boolean isDelimitedTextRangeBoundary(int boundary) {
  178. return false;
  179. }
  180. @Override
  181. protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
  182. DelimitedTextRange currentRange) {
  183. if (currentRange != null) {
  184. currentRange.append(CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this);
  185. }
  186. return ranges;
  187. }
  188. }