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.4KB

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