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.

RegionBody.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.pagination;
  19. // Java
  20. import java.awt.Rectangle;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.FODimension;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.datatypes.LengthBase;
  25. import org.apache.fop.datatypes.Numeric;
  26. import org.apache.fop.datatypes.PercentBaseContext;
  27. import org.apache.fop.fo.Constants;
  28. import org.apache.fop.fo.FONode;
  29. import org.apache.fop.fo.PropertyList;
  30. import org.apache.fop.fo.properties.CommonMarginBlock;
  31. /**
  32. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_region-body">
  33. * <code>fo:region-body</code></a> object.
  34. */
  35. public class RegionBody extends Region {
  36. // The value of properties relevant for fo:region-body.
  37. private CommonMarginBlock commonMarginBlock;
  38. private Numeric columnCount;
  39. private Length columnGap;
  40. // End of property values
  41. /**
  42. * Create a RegionBody instance that is a child of the
  43. * given parent {@link FONode}.
  44. * @param parent the {@link FONode} that is to be the parent
  45. */
  46. public RegionBody(FONode parent) {
  47. super(parent);
  48. }
  49. /** {@inheritDoc} */
  50. public void bind(PropertyList pList) throws FOPException {
  51. super.bind(pList);
  52. commonMarginBlock = pList.getMarginBlockProps();
  53. columnCount = pList.get(PR_COLUMN_COUNT).getNumeric();
  54. columnGap = pList.get(PR_COLUMN_GAP).getLength();
  55. if ((getColumnCount() > 1) && (getOverflow() == EN_SCROLL)) {
  56. /* This is an error (See XSL Rec, fo:region-body description).
  57. * The Rec allows for acting as if "1" is chosen in
  58. * these cases, but we will need to be able to change Numeric
  59. * values in order to do this.
  60. */
  61. getFOValidationEventProducer().columnCountErrorOnRegionBodyOverflowScroll(this,
  62. getName(), getLocator());
  63. }
  64. }
  65. /**
  66. * Return the {@link CommonMarginBlock} instance attached to
  67. * this instance.
  68. * @return the {@link CommonMarginBlock} instance
  69. */
  70. public CommonMarginBlock getCommonMarginBlock() {
  71. return commonMarginBlock;
  72. }
  73. /**
  74. * Return the value of the <code>column-count<code> property.
  75. * @return the "column-count" property.
  76. */
  77. public int getColumnCount() {
  78. return columnCount.getValue();
  79. }
  80. /**
  81. * Return the value of the <code>column-gap</code> property.
  82. * @return the "column-gap" property.
  83. */
  84. public int getColumnGap() {
  85. return columnGap.getValue();
  86. }
  87. /** {@inheritDoc} */
  88. public Rectangle getViewportRectangle(FODimension reldims) {
  89. /* Special rules apply to resolving margins in the page context.
  90. * Contrary to normal margins in this case top and bottom margin
  91. * are resolved relative to the height. In the property subsystem
  92. * all margin properties are configured to using BLOCK_WIDTH.
  93. * That's why we 'cheat' here and setup a context for the height but
  94. * use the LengthBase.BLOCK_WIDTH.
  95. * Also the values are resolved relative to the page size
  96. * and reference orientation.
  97. */
  98. PercentBaseContext pageWidthContext
  99. = getPageWidthContext(LengthBase.CONTAINING_BLOCK_WIDTH);
  100. PercentBaseContext pageHeightContext
  101. = getPageHeightContext(LengthBase.CONTAINING_BLOCK_WIDTH);
  102. int start;
  103. int end;
  104. // [TBD] WRITING MODE ALERT
  105. switch (getWritingMode().getEnumValue()) {
  106. case Constants.EN_RL_TB:
  107. start = commonMarginBlock.marginRight.getValue(pageWidthContext);
  108. end = commonMarginBlock.marginLeft.getValue(pageWidthContext);
  109. break;
  110. case Constants.EN_TB_LR:
  111. case Constants.EN_TB_RL:
  112. start = commonMarginBlock.marginTop.getValue(pageWidthContext);
  113. end = commonMarginBlock.marginBottom.getValue(pageWidthContext);
  114. break;
  115. case Constants.EN_LR_TB:
  116. default:
  117. start = commonMarginBlock.marginLeft.getValue(pageWidthContext);
  118. end = commonMarginBlock.marginRight.getValue(pageWidthContext);
  119. break;
  120. }
  121. int before = commonMarginBlock.spaceBefore.getOptimum(pageHeightContext)
  122. .getLength().getValue(pageHeightContext);
  123. int after = commonMarginBlock.spaceAfter.getOptimum(pageHeightContext)
  124. .getLength().getValue(pageHeightContext);
  125. return new Rectangle(start, before,
  126. reldims.ipd - start - end,
  127. reldims.bpd - before - after);
  128. }
  129. /** {@inheritDoc} */
  130. public String getDefaultRegionName() {
  131. return "xsl-region-body";
  132. }
  133. /** {@inheritDoc} */
  134. public String getLocalName() {
  135. return "region-body";
  136. }
  137. /**
  138. * {@inheritDoc}
  139. * @return {@link org.apache.fop.fo.Constants#FO_REGION_BODY}
  140. */
  141. public int getNameId() {
  142. return FO_REGION_BODY;
  143. }
  144. }