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.

Region.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.datatypes.FODimension;
  12. import org.apache.fop.fo.FObj;
  13. import org.apache.fop.fo.FONode;
  14. import org.apache.fop.fo.PropertyList;
  15. import org.apache.fop.layout.BorderAndPadding;
  16. import org.apache.fop.layout.BackgroundProps;
  17. import org.apache.fop.apps.FOPException;
  18. import org.apache.fop.area.CTM;
  19. import org.apache.fop.area.RegionViewport;
  20. import org.apache.fop.area.RegionReference;
  21. import org.xml.sax.Attributes;
  22. /**
  23. * This is an abstract base class for pagination regions
  24. */
  25. public abstract class Region extends FObj {
  26. public static final String PROP_REGION_NAME = "region-name";
  27. public static final String BEFORE = "before";
  28. public static final String START = "start";
  29. public static final String END = "end";
  30. public static final String AFTER = "after";
  31. public static final String BODY = "body";
  32. private SimplePageMaster _layoutMaster;
  33. private String _regionName;
  34. protected int overflow;
  35. protected Region(FONode parent) {
  36. super(parent);
  37. }
  38. public void handleAttrs(Attributes attlist) throws FOPException {
  39. super.handleAttrs(attlist);
  40. // regions may have name, or default
  41. if (null == this.properties.get(PROP_REGION_NAME)) {
  42. setRegionName(getDefaultRegionName());
  43. } else if (this.properties.get(PROP_REGION_NAME).getString().equals("")) {
  44. setRegionName(getDefaultRegionName());
  45. } else {
  46. setRegionName(this.properties.get(PROP_REGION_NAME).getString());
  47. // check that name is OK. Not very pretty.
  48. if (isReserved(getRegionName())
  49. &&!getRegionName().equals(getDefaultRegionName())) {
  50. throw new FOPException(PROP_REGION_NAME + " '" + _regionName
  51. + "' for " + this.name
  52. + " not permitted.");
  53. }
  54. }
  55. if (parent instanceof SimplePageMaster) {
  56. _layoutMaster = (SimplePageMaster)parent;
  57. } else {
  58. throw new FOPException(this.name + " must be child "
  59. + "of simple-page-master, not "
  60. + parent.getName());
  61. }
  62. }
  63. /**
  64. * Creates a RegionViewport Area object for this pagination Region.
  65. */
  66. public RegionViewport makeRegionViewport(FODimension reldims, CTM pageCTM) {
  67. Rectangle2D relRegionRect = getViewportRectangle(reldims);
  68. Rectangle2D absRegionRect = pageCTM.transform(relRegionRect);
  69. // Get the region viewport rectangle in absolute coords by
  70. // transforming it using the page CTM
  71. return new RegionViewport(absRegionRect);
  72. }
  73. protected abstract Rectangle getViewportRectangle(FODimension pageRefRect);
  74. /**
  75. * Create the region reference area for this region master.
  76. * @param absRegVPRect The region viewport rectangle is "absolute" coordinates
  77. * where x=distance from left, y=distance from bottom, width=right-left
  78. * height=top-bottom
  79. */
  80. public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) {
  81. RegionReference r = new RegionReference(getRegionAreaClass());
  82. setRegionTraits(r, absRegVPRect);
  83. return r;
  84. }
  85. protected void setRegionTraits(RegionReference r, Rectangle2D absRegVPRect) {
  86. // Common Border, Padding, and Background Properties
  87. BorderAndPadding bap = propMgr.getBorderAndPadding();
  88. BackgroundProps bProps = propMgr.getBackgroundProps();
  89. /* backgroundColor = properties.get("background-color").getColorType();*/
  90. // this.properties.get("clip");
  91. // this.properties.get("display-align");
  92. this.overflow = this.properties.get("overflow").getEnum();
  93. FODimension reldims = new FODimension(0,0);
  94. r.setCTM(propMgr.getCTMandRelDims(absRegVPRect, reldims));
  95. //r.setBackground(bProps);
  96. }
  97. /**
  98. * Return the enumerated value designating this type of region in the
  99. * Area tree.
  100. */
  101. protected abstract int getRegionAreaClass();
  102. /**
  103. * Returns the default region name (xsl-region-before, xsl-region-start,
  104. * etc.)
  105. */
  106. protected abstract String getDefaultRegionName();
  107. public abstract String getRegionClass();
  108. /**
  109. * Returns the name of this region
  110. */
  111. public String getRegionName() {
  112. return _regionName;
  113. }
  114. private void setRegionName(String name) {
  115. _regionName = name;
  116. }
  117. protected SimplePageMaster getPageMaster() {
  118. return _layoutMaster;
  119. }
  120. /**
  121. * Checks to see if a given region name is one of the reserved names
  122. *
  123. * @param name a region name to check
  124. * @return true if the name parameter is a reserved region name
  125. */
  126. protected boolean isReserved(String name) throws FOPException {
  127. return (name.equals("xsl-region-before")
  128. || name.equals("xsl-region-start")
  129. || name.equals("xsl-region-end")
  130. || name.equals("xsl-region-after")
  131. || name.equals("xsl-before-float-separator")
  132. || name.equals("xsl-footnote-separator"));
  133. }
  134. public boolean generatesReferenceAreas() {
  135. return true;
  136. }
  137. protected Region getSiblingRegion(String regionClass) {
  138. // Ask parent for region
  139. return _layoutMaster.getRegion(regionClass);
  140. }
  141. boolean getPrecedence() {
  142. return false;
  143. }
  144. int getExtent() {
  145. return 0;
  146. }
  147. }