Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RegionBody.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.pagination;
  8. import java.awt.Rectangle;
  9. import java.awt.geom.Rectangle2D;
  10. // FOP
  11. import org.apache.fop.fo.FONode;
  12. import org.apache.fop.fo.FObj;
  13. import org.apache.fop.fo.PropertyList;
  14. import org.apache.fop.fo.Property;
  15. import org.apache.fop.fo.properties.Overflow;
  16. import org.apache.fop.datatypes.ColorType;
  17. import org.apache.fop.datatypes.FODimension;
  18. import org.apache.fop.apps.FOPException;
  19. import org.apache.fop.area.RegionReference;
  20. import org.apache.fop.area.BodyRegion;
  21. import org.apache.fop.layout.MarginProps;
  22. public class RegionBody extends Region {
  23. ColorType backgroundColor;
  24. public RegionBody(FONode parent) {
  25. super(parent);
  26. }
  27. protected Rectangle getViewportRectangle (FODimension reldims)
  28. {
  29. /*
  30. * Use space-before and space-after which will use corresponding
  31. * absolute margin properties if specified. For indents:
  32. * try to get corresponding absolute margin property using the
  33. * writing-mode on the page (not on the region-body!). If that's not
  34. * set but indent is explicitly set, it will return that.
  35. */
  36. MarginProps mProps = propMgr.getMarginProps();
  37. int start = getRelMargin(PropertyList.START, "start-indent");
  38. return new Rectangle( start, mProps.spaceBefore,
  39. reldims.ipd - start -
  40. getRelMargin(PropertyList.END, "end-indent"),
  41. reldims.bpd - mProps.spaceBefore -
  42. mProps.spaceAfter);
  43. }
  44. /**
  45. * Get the relative margin using parent's writing mode, not own
  46. * writing mode.
  47. */
  48. private int getRelMargin(int reldir, String sRelPropName) {
  49. FObj parent = (FObj) getParent();
  50. String sPropName = "margin-" +
  51. parent.properties.wmRelToAbs(reldir);
  52. Property prop = properties.getExplicitBaseProp(sPropName);
  53. if (prop == null) {
  54. prop = properties.getExplicitBaseProp(sRelPropName);
  55. }
  56. return ((prop != null)? prop.getLength().mvalue() : 0);
  57. }
  58. protected void setRegionTraits(RegionReference r, Rectangle2D absRegVPRect) {
  59. super.setRegionTraits(r, absRegVPRect);
  60. // r.setBackgroundColor(backgroundColor);
  61. }
  62. protected String getDefaultRegionName() {
  63. return "xsl-region-body";
  64. }
  65. public String getRegionClass() {
  66. return Region.BODY;
  67. }
  68. public int getRegionAreaClass() {
  69. return RegionReference.BODY;
  70. }
  71. /**
  72. * Override the inherited method.
  73. */
  74. public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) {
  75. // Should set some column stuff here I think, or put it elsewhere
  76. BodyRegion body = new BodyRegion();
  77. setRegionTraits(body, absRegVPRect);
  78. int columnCount=
  79. this.properties.get("column-count").getNumber().intValue();
  80. if ((columnCount > 1) && (overflow == Overflow.SCROLL)) {
  81. // recover by setting 'column-count' to 1. This is allowed but
  82. // not required by the spec.
  83. getLogger().error("Setting 'column-count' to 1 because "
  84. + "'overflow' is set to 'scroll'");
  85. columnCount = 1;
  86. }
  87. body.setColumnCount(columnCount);
  88. int columnGap =
  89. this.properties.get("column-gap").getLength().mvalue();
  90. body.setColumnGap(columnGap);
  91. return body;
  92. }
  93. }