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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fo.pagination;
  18. // Java
  19. import java.awt.Rectangle;
  20. // XML
  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.Locator;
  23. // FOP
  24. import org.apache.fop.datatypes.ColorType;
  25. import org.apache.fop.datatypes.FODimension;
  26. import org.apache.fop.fo.FONode;
  27. import org.apache.fop.fo.FOTreeVisitor;
  28. import org.apache.fop.fo.FObj;
  29. import org.apache.fop.fo.PropertyList;
  30. import org.apache.fop.fo.properties.CommonMarginBlock;
  31. import org.apache.fop.fo.properties.Property;
  32. import org.apache.fop.fo.FOPropertyMapping;
  33. /**
  34. * The fo:region-body element.
  35. */
  36. public class RegionBody extends Region {
  37. private ColorType backgroundColor;
  38. /**
  39. * @see org.apache.fop.fo.FONode#FONode(FONode)
  40. */
  41. public RegionBody(FONode parent) {
  42. super(parent, Region.BODY_CODE);
  43. }
  44. /**
  45. * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
  46. * XSL/FOP Content Model: empty
  47. */
  48. protected void validateChildNode(Locator loc, String nsURI, String localName) {
  49. invalidChildError(loc, nsURI, localName);
  50. }
  51. /**
  52. * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension)
  53. */
  54. public Rectangle getViewportRectangle (FODimension reldims) {
  55. /*
  56. * Use space-before and space-after which will use corresponding
  57. * absolute margin properties if specified. For indents:
  58. * try to get corresponding absolute margin property using the
  59. * writing-mode on the page (not on the region-body!). If that's not
  60. * set but indent is explicitly set, it will return that.
  61. */
  62. CommonMarginBlock mProps = propMgr.getMarginProps();
  63. int start = getRelMargin(PropertyList.START, PR_START_INDENT);
  64. Rectangle vpRect;
  65. if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) {
  66. vpRect = new Rectangle(start, mProps.spaceBefore,
  67. reldims.ipd - start
  68. - getRelMargin(PropertyList.END, PR_END_INDENT),
  69. reldims.bpd - mProps.spaceBefore - mProps.spaceAfter);
  70. } else {
  71. vpRect = new Rectangle(start, mProps.spaceBefore,
  72. reldims.bpd - mProps.spaceBefore - mProps.spaceAfter,
  73. reldims.ipd - start
  74. - getRelMargin(PropertyList.END, PR_END_INDENT));
  75. }
  76. return vpRect;
  77. }
  78. /**
  79. * Get the relative margin using parent's writing mode, not own
  80. * writing mode.
  81. */
  82. private int getRelMargin(int reldir, int relPropId) {
  83. FObj parent = (FObj) getParent();
  84. String sPropName = "margin-"
  85. + parent.getPropertyList().getAbsoluteWritingMode(reldir);
  86. int propId = FOPropertyMapping.getPropertyId(sPropName);
  87. Property prop = propertyList.getExplicitOrShorthand(propId);
  88. if (prop == null) {
  89. prop = propertyList.getExplicitOrShorthand(relPropId);
  90. }
  91. return ((prop != null) ? prop.getLength().getValue() : 0);
  92. }
  93. /**
  94. * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName()
  95. */
  96. protected String getDefaultRegionName() {
  97. return "xsl-region-body";
  98. }
  99. /**
  100. * @see org.apache.fop.fo.pagination.Region#getRegionClassCode()
  101. */
  102. public int getRegionClassCode() {
  103. return Region.BODY_CODE;
  104. }
  105. /**
  106. * This is a hook for an FOTreeVisitor subclass to be able to access
  107. * this object.
  108. * @param fotv the FOTreeVisitor subclass that can access this object.
  109. * @see org.apache.fop.fo.FOTreeVisitor
  110. */
  111. public void acceptVisitor(FOTreeVisitor fotv) {
  112. fotv.serveRegionBody(this);
  113. }
  114. public String getName() {
  115. return "fo:region-body";
  116. }
  117. }