Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ContentLayoutManager.java 9.1KB

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