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.

AbstractGraphics.java 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.util.Stack;
  20. import org.apache.fop.accessibility.StructureTreeElement;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.FObj;
  26. import org.apache.fop.fo.GraphicsProperties;
  27. import org.apache.fop.fo.PropertyList;
  28. import org.apache.fop.fo.properties.CommonAccessibility;
  29. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  30. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  31. import org.apache.fop.fo.properties.KeepProperty;
  32. import org.apache.fop.fo.properties.LengthRangeProperty;
  33. import org.apache.fop.fo.properties.SpaceProperty;
  34. import org.apache.fop.fo.properties.StructureTreeElementHolder;
  35. import org.apache.fop.util.CharUtilities;
  36. /**
  37. * Common base class for the <a href="http://www.w3.org/TR/xsl/#fo_instream-foreign-object">
  38. * <code>fo:instream-foreign-object</code></a>
  39. * and <a href="http://www.w3.org/TR/xsl/#fo_external-graphic">
  40. * <code>fo:external-graphic</code></a> flow formatting objects.
  41. */
  42. public abstract class AbstractGraphics extends FObj
  43. implements GraphicsProperties, StructureTreeElementHolder, CommonAccessibilityHolder {
  44. // The value of properties relevant for fo:instream-foreign-object
  45. // and external-graphics.
  46. private CommonAccessibility commonAccessibility;
  47. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  48. private Length alignmentAdjust;
  49. private int alignmentBaseline;
  50. private Length baselineShift;
  51. private LengthRangeProperty blockProgressionDimension;
  52. // private ToBeImplementedProperty clip;
  53. private Length contentHeight;
  54. private Length contentWidth;
  55. private int displayAlign;
  56. private int dominantBaseline;
  57. private Length height;
  58. private String id;
  59. private LengthRangeProperty inlineProgressionDimension;
  60. private KeepProperty keepWithNext;
  61. private KeepProperty keepWithPrevious;
  62. private SpaceProperty lineHeight;
  63. private int overflow;
  64. private int scaling;
  65. private int textAlign;
  66. private Length width;
  67. private String altText;
  68. private StructureTreeElement structureTreeElement;
  69. // Unused but valid items, commented out for performance:
  70. // private CommonAccessibility commonAccessibility;
  71. // private CommonAural commonAural;
  72. // private CommonMarginInline commonMarginInline;
  73. // private CommonRelativePosition commonRelativePosition;
  74. // private String contentType;
  75. // private int scalingMethod;
  76. // End of property values
  77. /**
  78. * constructs an instream-foreign-object object (called by Maker).
  79. *
  80. * @param parent the parent formatting object
  81. */
  82. public AbstractGraphics(FONode parent) {
  83. super(parent);
  84. }
  85. /** {@inheritDoc} */
  86. public void bind(PropertyList pList) throws FOPException {
  87. commonAccessibility = CommonAccessibility.getInstance(pList);
  88. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  89. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  90. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  91. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  92. blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  93. // clip = pList.get(PR_CLIP);
  94. contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength();
  95. contentWidth = pList.get(PR_CONTENT_WIDTH).getLength();
  96. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  97. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  98. height = pList.get(PR_HEIGHT).getLength();
  99. id = pList.get(PR_ID).getString();
  100. inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
  101. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  102. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  103. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  104. overflow = pList.get(PR_OVERFLOW).getEnum();
  105. scaling = pList.get(PR_SCALING).getEnum();
  106. textAlign = pList.get(PR_TEXT_ALIGN).getEnum();
  107. width = pList.get(PR_WIDTH).getLength();
  108. if (getUserAgent().isAccessibilityEnabled()) {
  109. altText = pList.get(PR_X_ALT_TEXT).getString();
  110. if (altText.equals("")) {
  111. getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator());
  112. }
  113. }
  114. }
  115. /** {@inheritDoc} */
  116. public CommonAccessibility getCommonAccessibility() {
  117. return commonAccessibility;
  118. }
  119. /**
  120. * @return the "id" property.
  121. */
  122. public String getId() {
  123. return id;
  124. }
  125. /** @return the {@link CommonBorderPaddingBackground} */
  126. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  127. return commonBorderPaddingBackground;
  128. }
  129. /** @return the "line-height" property */
  130. public SpaceProperty getLineHeight() {
  131. return lineHeight;
  132. }
  133. /** @return the "inline-progression-dimension" property */
  134. public LengthRangeProperty getInlineProgressionDimension() {
  135. return inlineProgressionDimension;
  136. }
  137. /** @return the "block-progression-dimension" property */
  138. public LengthRangeProperty getBlockProgressionDimension() {
  139. return blockProgressionDimension;
  140. }
  141. /** @return the "height" property */
  142. public Length getHeight() {
  143. return height;
  144. }
  145. /** @return the "width" property */
  146. public Length getWidth() {
  147. return width;
  148. }
  149. /** @return the "content-height" property */
  150. public Length getContentHeight() {
  151. return contentHeight;
  152. }
  153. /** @return the "content-width" property */
  154. public Length getContentWidth() {
  155. return contentWidth;
  156. }
  157. /** @return the "scaling" property */
  158. public int getScaling() {
  159. return scaling;
  160. }
  161. /** @return the "overflow" property */
  162. public int getOverflow() {
  163. return overflow;
  164. }
  165. /** {@inheritDoc} */
  166. public int getDisplayAlign() {
  167. return displayAlign;
  168. }
  169. /** {@inheritDoc} */
  170. public int getTextAlign() {
  171. return textAlign;
  172. }
  173. /** @return the "alignment-adjust" property */
  174. public Length getAlignmentAdjust() {
  175. if (alignmentAdjust.getEnum() == EN_AUTO) {
  176. final Length intrinsicAlignmentAdjust = this.getIntrinsicAlignmentAdjust();
  177. if (intrinsicAlignmentAdjust != null) {
  178. return intrinsicAlignmentAdjust;
  179. }
  180. }
  181. return alignmentAdjust;
  182. }
  183. /** @return the "alignment-baseline" property */
  184. public int getAlignmentBaseline() {
  185. return alignmentBaseline;
  186. }
  187. /** @return the "baseline-shift" property */
  188. public Length getBaselineShift() {
  189. return baselineShift;
  190. }
  191. /** @return the "dominant-baseline" property */
  192. public int getDominantBaseline() {
  193. return dominantBaseline;
  194. }
  195. /** @return the "keep-with-next" property */
  196. public KeepProperty getKeepWithNext() {
  197. return keepWithNext;
  198. }
  199. /** @return the "keep-with-previous" property */
  200. public KeepProperty getKeepWithPrevious() {
  201. return keepWithPrevious;
  202. }
  203. @Override
  204. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  205. this.structureTreeElement = structureTreeElement;
  206. }
  207. @Override
  208. public StructureTreeElement getStructureTreeElement() {
  209. return structureTreeElement;
  210. }
  211. /** @return the alternative text property. */
  212. public String getAltText() {
  213. return altText;
  214. }
  215. /** @return the graphic's intrinsic width in millipoints */
  216. public abstract int getIntrinsicWidth();
  217. /** @return the graphic's intrinsic height in millipoints */
  218. public abstract int getIntrinsicHeight();
  219. /** @return the graphic's intrinsic alignment-adjust */
  220. public abstract Length getIntrinsicAlignmentAdjust();
  221. @Override
  222. public boolean isDelimitedTextRangeBoundary(int boundary) {
  223. return false;
  224. }
  225. @Override
  226. protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
  227. DelimitedTextRange currentRange) {
  228. if (currentRange != null) {
  229. currentRange.append(CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this);
  230. }
  231. return ranges;
  232. }
  233. }