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.

SpacedBorderedPaddedBlockLayoutManager.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.layoutmgr;
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.apache.fop.fo.FObj;
  22. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  23. import org.apache.fop.traits.MinOptMax;
  24. /**
  25. * A block-stacking layout manager for an FO that supports spaces, border and padding.
  26. */
  27. public abstract class SpacedBorderedPaddedBlockLayoutManager extends BlockStackingLayoutManager
  28. implements ConditionalElementListener {
  29. private static final Log LOG = LogFactory.getLog(BlockLayoutManager.class);
  30. protected MinOptMax effSpaceBefore;
  31. protected MinOptMax effSpaceAfter;
  32. protected boolean discardBorderBefore;
  33. protected boolean discardBorderAfter;
  34. protected boolean discardPaddingBefore;
  35. protected boolean discardPaddingAfter;
  36. public SpacedBorderedPaddedBlockLayoutManager(FObj node) {
  37. super(node);
  38. }
  39. public void notifySpace(RelSide side, MinOptMax effectiveLength) {
  40. if (RelSide.BEFORE == side) {
  41. if (LOG.isDebugEnabled()) {
  42. LOG.debug(this + ": Space " + side + ", "
  43. + this.effSpaceBefore + "-> " + effectiveLength);
  44. }
  45. this.effSpaceBefore = effectiveLength;
  46. } else {
  47. if (LOG.isDebugEnabled()) {
  48. LOG.debug(this + ": Space " + side + ", "
  49. + this.effSpaceAfter + "-> " + effectiveLength);
  50. }
  51. this.effSpaceAfter = effectiveLength;
  52. }
  53. }
  54. public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
  55. if (effectiveLength == null) {
  56. if (RelSide.BEFORE == side) {
  57. this.discardBorderBefore = true;
  58. } else {
  59. this.discardBorderAfter = true;
  60. }
  61. }
  62. if (LOG.isDebugEnabled()) {
  63. LOG.debug(this + ": Border " + side + " -> " + effectiveLength);
  64. }
  65. }
  66. public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
  67. if (effectiveLength == null) {
  68. if (RelSide.BEFORE == side) {
  69. this.discardPaddingBefore = true;
  70. } else {
  71. this.discardPaddingAfter = true;
  72. }
  73. }
  74. if (LOG.isDebugEnabled()) {
  75. LOG.debug(this + ": Padding " + side + " -> " + effectiveLength);
  76. }
  77. }
  78. @Override
  79. public int getBaselineOffset() {
  80. int baselineOffset = super.getBaselineOffset();
  81. if (effSpaceBefore != null) {
  82. baselineOffset += effSpaceBefore.getOpt();
  83. }
  84. if (!discardBorderBefore) {
  85. baselineOffset += getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
  86. }
  87. if (!discardPaddingBefore) {
  88. baselineOffset += getCommonBorderPaddingBackground().getPaddingBefore(false, this);
  89. }
  90. return baselineOffset;
  91. }
  92. /**
  93. * Returns the {@link CommonBorderPaddingBackground} instance from the FO handled by this layout manager.
  94. */
  95. protected abstract CommonBorderPaddingBackground getCommonBorderPaddingBackground();
  96. }