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.

ContentLayoutManager.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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.layoutmgr;
  18. import org.apache.fop.fo.FObj;
  19. import org.apache.fop.apps.FOUserAgent;
  20. import org.apache.fop.fo.flow.Marker;
  21. import org.apache.fop.area.Area;
  22. import org.apache.fop.area.Resolveable;
  23. import org.apache.fop.area.PageViewport;
  24. import org.apache.avalon.framework.logger.Logger;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.ArrayList;
  28. import org.apache.fop.traits.MinOptMax;
  29. /**
  30. * Content Layout Manager.
  31. * For use with objects that contain inline areas such as
  32. * leader use-content and title.
  33. */
  34. public class ContentLayoutManager implements LayoutProcessor {
  35. private FOUserAgent userAgent;
  36. private Area holder;
  37. private int stackSize;
  38. private LayoutProcessor parentLM;
  39. /**
  40. * Constructs a new ContentLayoutManager
  41. *
  42. * @param area The parent area
  43. */
  44. public ContentLayoutManager(Area area) {
  45. holder = area;
  46. }
  47. /**
  48. * Set the FO object for this layout manager
  49. *
  50. * @param fo the fo for this layout manager
  51. */
  52. public void setFObj(FObj fo) {
  53. }
  54. public void fillArea(LayoutProcessor curLM) {
  55. List childBreaks = new ArrayList();
  56. MinOptMax stack = new MinOptMax();
  57. int ipd = 1000000;
  58. BreakPoss bp;
  59. LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
  60. childLC.setLeadingSpace(new SpaceSpecifier(false));
  61. childLC.setTrailingSpace(new SpaceSpecifier(false));
  62. // set stackLimit for lines
  63. childLC.setStackLimit(new MinOptMax(ipd));
  64. childLC.setRefIPD(ipd);
  65. int lineHeight = 14000;
  66. int lead = 12000;
  67. int follow = 2000;
  68. int halfLeading = (lineHeight - lead - follow) / 2;
  69. // height before baseline
  70. int lineLead = lead + halfLeading;
  71. // maximum size of top and bottom alignment
  72. int maxtb = follow + halfLeading;
  73. // max size of middle alignment below baseline
  74. int middlefollow = maxtb;
  75. while (!curLM.isFinished()) {
  76. MinOptMax lastSize = null;
  77. if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
  78. lastSize = bp.getStackingSize();
  79. childBreaks.add(bp);
  80. if (bp.getLead() > lineLead) {
  81. lineLead = bp.getLead();
  82. }
  83. if (bp.getTotal() > maxtb) {
  84. maxtb = bp.getTotal();
  85. }
  86. if (bp.getMiddle() > middlefollow) {
  87. middlefollow = bp.getMiddle();
  88. }
  89. }
  90. if (lastSize != null) {
  91. stack.add(lastSize);
  92. }
  93. }
  94. if (maxtb - lineLead > middlefollow) {
  95. middlefollow = maxtb - lineLead;
  96. }
  97. //if(holder instanceof InlineParent) {
  98. // ((InlineParent)holder).setHeight(lineHeight);
  99. //}
  100. LayoutContext lc = new LayoutContext(0);
  101. lc.setBaseline(lineLead);
  102. lc.setLineHeight(lineHeight);
  103. lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
  104. lc.setLeadingSpace(new SpaceSpecifier(false));
  105. lc.setTrailingSpace(new SpaceSpecifier(false));
  106. PositionIterator breakPosIter =
  107. new BreakPossPosIter(childBreaks, 0, childBreaks.size());
  108. curLM.addAreas(breakPosIter, lc);
  109. stackSize = stack.opt;
  110. }
  111. public int getStackingSize() {
  112. return stackSize;
  113. }
  114. /** @see org.apache.fop.layoutmgr.LayoutManager */
  115. public boolean generatesInlineAreas() {
  116. return true;
  117. }
  118. /** @see org.apache.fop.layoutmgr.LayoutManager */
  119. public Area getParentArea(Area childArea) {
  120. return holder;
  121. }
  122. /** @see org.apache.fop.layoutmgr.LayoutManager */
  123. public void addChild(Area childArea) {
  124. holder.addChild(childArea);
  125. }
  126. /**
  127. * Set the user agent.
  128. *
  129. * @param ua the user agent
  130. */
  131. public void setUserAgent(FOUserAgent ua) {
  132. userAgent = ua;
  133. }
  134. /**
  135. * @see org.apache.fop.layoutmgr.LayoutManager#getUserAgent()
  136. */
  137. public FOUserAgent getUserAgent() {
  138. return userAgent;
  139. }
  140. /**
  141. * Returns the logger
  142. * @return the logger
  143. */
  144. protected Logger getLogger() {
  145. return userAgent.getLogger();
  146. }
  147. /** @see org.apache.fop.layoutmgr.LayoutManager */
  148. public void setParent(LayoutProcessor lm) {
  149. parentLM = lm;
  150. }
  151. public LayoutProcessor getParent() {
  152. return this.parentLM;
  153. }
  154. public LayoutManagerLS getLayoutManagerLS() {
  155. return getParent().getLayoutManagerLS();
  156. }
  157. /** @see org.apache.fop.layoutmgr.LayoutManager */
  158. public boolean canBreakBefore(LayoutContext lc) {
  159. return false;
  160. }
  161. /** @see org.apache.fop.layoutmgr.LayoutManager */
  162. public BreakPoss getNextBreakPoss(LayoutContext context) {
  163. return null;
  164. }
  165. /** @see org.apache.fop.layoutmgr.LayoutManager */
  166. public boolean isFinished() {
  167. return false;
  168. }
  169. /** @see org.apache.fop.layoutmgr.LayoutManager */
  170. public void setFinished(boolean isFinished) {
  171. //to be done
  172. }
  173. /** @see org.apache.fop.layoutmgr.LayoutManager */
  174. public void addAreas(PositionIterator posIter, LayoutContext context) { }
  175. /** @see org.apache.fop.layoutmgr.LayoutManager */
  176. public void init() {
  177. //to be done
  178. }
  179. /** @see org.apache.fop.layoutmgr.LayoutManager */
  180. public void resetPosition(Position position) {
  181. //to be done
  182. }
  183. /** @see org.apache.fop.layoutmgr.LayoutManager */
  184. public void getWordChars(StringBuffer sbChars, Position bp1,
  185. Position bp2) { }
  186. /** @see org.apache.fop.layoutmgr.LayoutManager */
  187. public String getCurrentPageNumber() {
  188. return parentLM.getCurrentPageNumber();
  189. }
  190. /** @see org.apache.fop.layoutmgr.LayoutManager */
  191. public PageViewport resolveRefID(String ref) {
  192. return parentLM.resolveRefID(ref);
  193. }
  194. /** @see org.apache.fop.layoutmgr.LayoutManager */
  195. public void addIDToPage(String id) {
  196. parentLM.addIDToPage(id);
  197. }
  198. /** @see org.apache.fop.layoutmgr.LayoutManager */
  199. public void addUnresolvedArea(String id, Resolveable res) {
  200. parentLM.addUnresolvedArea(id, res);
  201. }
  202. /** @see org.apache.fop.layoutmgr.LayoutManager */
  203. public void addMarkerMap(Map marks, boolean start, boolean isfirst) {
  204. parentLM.addMarkerMap(marks, start, isfirst);
  205. }
  206. /** @see org.apache.fop.layoutmgr.LayoutManager */
  207. public Marker retrieveMarker(String name, int pos, int boundary) {
  208. return parentLM.retrieveMarker(name, pos, boundary);
  209. }
  210. }