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.

RegionBA.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.PercentBaseContext;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.PropertyList;
  25. /**
  26. * Abstract base class for <a href="http://www.w3.org/TR/xsl/#fo_region-before">
  27. * <code>fo:region-before</code></a> and <a href="http://www.w3.org/TR/xsl/#fo_region-after">
  28. * <code>fo:region-after</code></a>.
  29. */
  30. public abstract class RegionBA extends SideRegion {
  31. // The value of properties relevant for fo:region-[before|after].
  32. private int precedence;
  33. // End of property values
  34. /**
  35. * Create a RegionBA instance that is a child of the
  36. * given parent {@link FONode}.
  37. * @param parent the {@link FONode} that is to be the parent
  38. */
  39. protected RegionBA(FONode parent) {
  40. super(parent);
  41. }
  42. /** {@inheritDoc} */
  43. public void bind(PropertyList pList) throws FOPException {
  44. super.bind(pList);
  45. precedence = pList.get(PR_PRECEDENCE).getEnum();
  46. }
  47. /**
  48. * Get the value of the <code>precedence</code> property.
  49. * @return the "precedence" property
  50. */
  51. public int getPrecedence() {
  52. return precedence;
  53. }
  54. /**
  55. * Adjust the viewport reference rectangle for a region as a function
  56. * of precedence.
  57. * If precedence is false on a before or after region, its
  58. * inline-progression-dimension is limited by the extent of the start
  59. * and end regions if they are present.
  60. * @param vpRefRect viewport reference rectangle
  61. * @param wm writing mode
  62. * @param siblingContext the context to use to resolve extent on siblings
  63. */
  64. protected void adjustIPD(Rectangle vpRefRect, int wm, PercentBaseContext siblingContext) {
  65. int offset = 0;
  66. RegionStart start = (RegionStart) getSiblingRegion(FO_REGION_START);
  67. if (start != null) {
  68. offset = start.getExtent().getValue(siblingContext);
  69. vpRefRect.translate(offset, 0); // move (x, y) units
  70. }
  71. RegionEnd end = (RegionEnd) getSiblingRegion(FO_REGION_END);
  72. if (end != null) {
  73. offset += end.getExtent().getValue(siblingContext);
  74. }
  75. if (offset > 0) {
  76. if (wm == EN_LR_TB || wm == EN_RL_TB) {
  77. vpRefRect.width -= offset;
  78. } else {
  79. vpRefRect.height -= offset;
  80. }
  81. }
  82. }
  83. }