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 8.6KB

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