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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * $Id: ContentLayoutManager.java,v 1.17 2003/03/07 07:58:51 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.layoutmgr;
  52. import org.apache.fop.fo.FObj;
  53. import org.apache.fop.apps.FOUserAgent;
  54. import org.apache.fop.fo.flow.Marker;
  55. import org.apache.fop.area.Area;
  56. import org.apache.fop.area.Resolveable;
  57. import org.apache.fop.area.PageViewport;
  58. import org.apache.avalon.framework.logger.Logger;
  59. import java.util.List;
  60. import java.util.Map;
  61. import java.util.ArrayList;
  62. import org.apache.fop.traits.MinOptMax;
  63. /**
  64. * Content Layout Manager.
  65. * For use with objects that contain inline areas such as
  66. * leader use-content and title.
  67. */
  68. public class ContentLayoutManager implements LayoutProcessor {
  69. private FOUserAgent userAgent;
  70. private Area holder;
  71. private int stackSize;
  72. private LayoutProcessor parentLM;
  73. /**
  74. * Constructs a new ContentLayoutManager
  75. *
  76. * @param area The parent area
  77. */
  78. public ContentLayoutManager(Area area) {
  79. holder = area;
  80. }
  81. /**
  82. * Set the FO object for this layout manager
  83. *
  84. * @param fo the fo for this layout manager
  85. */
  86. public void setFObj(FObj fo) {
  87. }
  88. public void fillArea(LayoutProcessor curLM) {
  89. List childBreaks = new ArrayList();
  90. MinOptMax stack = new MinOptMax();
  91. int ipd = 1000000;
  92. BreakPoss bp;
  93. LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
  94. childLC.setLeadingSpace(new SpaceSpecifier(false));
  95. childLC.setTrailingSpace(new SpaceSpecifier(false));
  96. // set stackLimit for lines
  97. childLC.setStackLimit(new MinOptMax(ipd));
  98. childLC.setRefIPD(ipd);
  99. int lineHeight = 14000;
  100. int lead = 12000;
  101. int follow = 2000;
  102. int halfLeading = (lineHeight - lead - follow) / 2;
  103. // height before baseline
  104. int lineLead = lead + halfLeading;
  105. // maximum size of top and bottom alignment
  106. int maxtb = follow + halfLeading;
  107. // max size of middle alignment below baseline
  108. int middlefollow = maxtb;
  109. while (!curLM.isFinished()) {
  110. MinOptMax lastSize = null;
  111. if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
  112. lastSize = bp.getStackingSize();
  113. childBreaks.add(bp);
  114. if (bp.getLead() > lineLead) {
  115. lineLead = bp.getLead();
  116. }
  117. if (bp.getTotal() > maxtb) {
  118. maxtb = bp.getTotal();
  119. }
  120. if (bp.getMiddle() > middlefollow) {
  121. middlefollow = bp.getMiddle();
  122. }
  123. }
  124. if (lastSize != null) {
  125. stack.add(lastSize);
  126. }
  127. }
  128. if (maxtb - lineLead > middlefollow) {
  129. middlefollow = maxtb - lineLead;
  130. }
  131. //if(holder instanceof InlineParent) {
  132. // ((InlineParent)holder).setHeight(lineHeight);
  133. //}
  134. LayoutContext lc = new LayoutContext(0);
  135. lc.setBaseline(lineLead);
  136. lc.setLineHeight(lineHeight);
  137. lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
  138. lc.setLeadingSpace(new SpaceSpecifier(false));
  139. lc.setTrailingSpace(new SpaceSpecifier(false));
  140. PositionIterator breakPosIter =
  141. new BreakPossPosIter(childBreaks, 0, childBreaks.size());
  142. curLM.addAreas(breakPosIter, lc);
  143. stackSize = stack.opt;
  144. }
  145. public int getStackingSize() {
  146. return stackSize;
  147. }
  148. /** @see org.apache.fop.layoutmgr.LayoutManager */
  149. public boolean generatesInlineAreas() {
  150. return true;
  151. }
  152. /** @see org.apache.fop.layoutmgr.LayoutManager */
  153. public Area getParentArea(Area childArea) {
  154. return holder;
  155. }
  156. /** @see org.apache.fop.layoutmgr.LayoutManager */
  157. public void addChild(Area childArea) {
  158. holder.addChild(childArea);
  159. }
  160. /**
  161. * Set the user agent.
  162. *
  163. * @param ua the user agent
  164. */
  165. public void setUserAgent(FOUserAgent ua) {
  166. userAgent = ua;
  167. }
  168. /**
  169. * @see org.apache.fop.layoutmgr.LayoutManager#getUserAgent()
  170. */
  171. public FOUserAgent getUserAgent() {
  172. return userAgent;
  173. }
  174. /**
  175. * Returns the logger
  176. * @return the logger
  177. */
  178. protected Logger getLogger() {
  179. return userAgent.getLogger();
  180. }
  181. /** @see org.apache.fop.layoutmgr.LayoutManager */
  182. public void setParent(LayoutProcessor lm) {
  183. parentLM = lm;
  184. }
  185. /** @see org.apache.fop.layoutmgr.LayoutManager */
  186. public boolean canBreakBefore(LayoutContext lc) {
  187. return false;
  188. }
  189. /** @see org.apache.fop.layoutmgr.LayoutManager */
  190. public BreakPoss getNextBreakPoss(LayoutContext context) {
  191. return null;
  192. }
  193. /** @see org.apache.fop.layoutmgr.LayoutManager */
  194. public boolean isFinished() {
  195. return false;
  196. }
  197. /** @see org.apache.fop.layoutmgr.LayoutManager */
  198. public void setFinished(boolean isFinished) {
  199. //to be done
  200. }
  201. /** @see org.apache.fop.layoutmgr.LayoutManager */
  202. public void addAreas(PositionIterator posIter, LayoutContext context) { }
  203. /** @see org.apache.fop.layoutmgr.LayoutManager */
  204. public void init() {
  205. //to be done
  206. }
  207. /** @see org.apache.fop.layoutmgr.LayoutManager */
  208. public void resetPosition(Position position) {
  209. //to be done
  210. }
  211. /** @see org.apache.fop.layoutmgr.LayoutManager */
  212. public void getWordChars(StringBuffer sbChars, Position bp1,
  213. Position bp2) { }
  214. /** @see org.apache.fop.layoutmgr.LayoutManager */
  215. public String getCurrentPageNumber() {
  216. return parentLM.getCurrentPageNumber();
  217. }
  218. /** @see org.apache.fop.layoutmgr.LayoutManager */
  219. public PageViewport resolveRefID(String ref) {
  220. return parentLM.resolveRefID(ref);
  221. }
  222. /** @see org.apache.fop.layoutmgr.LayoutManager */
  223. public void addIDToPage(String id) {
  224. parentLM.addIDToPage(id);
  225. }
  226. /** @see org.apache.fop.layoutmgr.LayoutManager */
  227. public void addUnresolvedArea(String id, Resolveable res) {
  228. parentLM.addUnresolvedArea(id, res);
  229. }
  230. /** @see org.apache.fop.layoutmgr.LayoutManager */
  231. public void addMarkerMap(Map marks, boolean start, boolean isfirst) {
  232. parentLM.addMarkerMap(marks, start, isfirst);
  233. }
  234. /** @see org.apache.fop.layoutmgr.LayoutManager */
  235. public Marker retrieveMarker(String name, int pos, int boundary) {
  236. return parentLM.retrieveMarker(name, pos, boundary);
  237. }
  238. }