001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: LayoutManager.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.layoutmgr;
021:
022: import java.util.LinkedList;
023: import java.util.List;
024:
025: import org.apache.fop.area.Area;
026: import org.apache.fop.datatypes.PercentBaseContext;
027: import org.apache.fop.fo.FObj;
028:
029: /**
030: * The interface for all LayoutManagers.
031: */
032: public interface LayoutManager extends PercentBaseContext {
033:
034: /**
035: * Set the parent layout manager.
036: * The parent layout manager is required for adding areas.
037: *
038: * @param lm the parent layout manager
039: */
040: void setParent(LayoutManager lm);
041:
042: /**
043: * Get the parent layout manager.
044: * @return the parent layout manager.
045: */
046: LayoutManager getParent();
047:
048: /**
049: * initialize the layout manager. Allows each layout manager
050: * to calculate often used values.
051: */
052: void initialize();
053:
054: /**
055: * Get the active PageSequenceLayoutManager instance for this
056: * layout process.
057: * @return the PageSequenceLayoutManager
058: */
059: PageSequenceLayoutManager getPSLM();
060:
061: /**
062: * Reset to the position.
063: *
064: * @param position the Position to reset to
065: */
066: void resetPosition(Position position);
067:
068: /**
069: * Return a value indicating whether this LayoutManager has laid out
070: * all its content (or generated BreakPossibilities for all content.)
071: *
072: * @return true if this layout manager is finished
073: */
074: boolean isFinished();
075:
076: /**
077: * Set a flag indicating whether the LayoutManager has laid out all
078: * its content. This is generally called by the LM itself, but can
079: * be called by a parentLM when backtracking.
080: *
081: * @param isFinished the value to set the finished flag to
082: */
083: void setFinished(boolean isFinished);
084:
085: /**
086: * Get the parent area for an area.
087: * This should get the parent depending on the class of the
088: * area passed in.
089: *
090: * @param childArea the child area to get the parent for
091: * @return the parent Area
092: */
093: Area getParentArea(Area childArea);
094:
095: /**
096: * Add the area as a child of the current area.
097: * This is called by child layout managers to add their
098: * areas as children of the current area.
099: *
100: * @param childArea the child area to add
101: */
102: void addChildArea(Area childArea);
103:
104: /**
105: * Tell the layout manager to add all the child areas implied
106: * by Position objects which will be returned by the
107: * Iterator.
108: *
109: * @param posIter the position iterator
110: * @param context the context
111: */
112: void addAreas(PositionIterator posIter, LayoutContext context);
113:
114: /**
115: * Create more child LMs of the parent, up to child LM index pos
116: * @param pos index up to which child LMs are requested
117: * @return true if requested index does exist
118: */
119: boolean createNextChildLMs(int pos);
120:
121: /**
122: * @return the list of child LMs
123: */
124: List getChildLMs();
125:
126: /**
127: * Add the LM in the argument to the list of child LMs;
128: * set this LM as the parent;
129: * initialize the LM.
130: * @param lm the LM to be added
131: */
132: void addChildLM(LayoutManager lm);
133:
134: /**
135: * Add the LMs in the argument to the list of child LMs;
136: * @param newLMs the list of LMs to be added
137: */
138: void addChildLMs(List newLMs);
139:
140: /**
141: * Get a sequence of KnuthElements representing the content
142: * of the node assigned to the LM
143: *
144: * @param context the LayoutContext used to store layout information
145: * @param alignment the desired text alignement
146: * @return the list of KnuthElements
147: */
148: LinkedList getNextKnuthElements(LayoutContext context, int alignment);
149:
150: /**
151: * Get a sequence of KnuthElements representing the content
152: * of the node assigned to the LM, after changes have been applied
153: *
154: * In the context of line breaking, this method is called after hyphenation has
155: * been performed, in order to receive the sequence of elements representing the
156: * text together with all possibile hyphenation points.
157: * For example, if the text "representation" originates a single box element
158: * when getNextKnuthElements() is called, it will be now split in syllables
159: * (rep-re-sen-ta-tion) each one originating a box and divided by additional
160: * elements allowing a line break.
161: *
162: * In the context of page breaking, this method is called only if the pages need
163: * to be "vertically justified" modifying (also) the quantity of lines created by
164: * the paragraphs, and after a first page breaking has been performed.
165: * According to the result of the first page breaking, each paragraph now knows
166: * how many lines it must create (among the existing layout possibilities) and
167: * has to create a sequence of elements representing this layout; in particular,
168: * each box, representing a line, will contain a LineBreakPositions that will be
169: * used in the addAreas() phase.
170: *
171: * LMs having children look at the old list of elements in order to know which
172: * ones they must get the new elements from, as break conditions of preserved
173: * linefeeds can divide children into smaller groups (page sequences or
174: * paragraphs).
175: * LMs having no children can simply return the old elements if they have nothing
176: * to change.
177: *
178: * Inline LMs need to know the text alignment because it affects the elements
179: * representing feasible breaks between syllables.
180: *
181: * @param oldList the elements to replace
182: * @param alignment the desired text alignment
183: * @return the updated list of KnuthElements
184: */
185: LinkedList getChangedKnuthElements(List oldList, int alignment);
186:
187: /**
188: * Returns the IPD of the content area
189: * @return the IPD of the content area
190: */
191: int getContentAreaIPD();
192:
193: /**
194: * Returns the BPD of the content area
195: * @return the BPD of the content area
196: */
197: int getContentAreaBPD();
198:
199: /**
200: * Returns an indication if the layout manager generates a reference area.
201: * @return True if the layout manager generates a reference area
202: */
203: boolean getGeneratesReferenceArea();
204:
205: /**
206: * Returns an indication if the layout manager generates a block area.
207: * @return True if the layout manager generates a block area
208: */
209: boolean getGeneratesBlockArea();
210:
211: /**
212: * Returns an indication if the layout manager generates a line area.
213: * @return True if the layout manager generates a line area
214: */
215: boolean getGeneratesLineArea();
216:
217: /**
218: * Returns the fo this layout manager is associated with.
219: * @return The fo for this layout manager or null.
220: */
221: FObj getFObj();
222:
223: /**
224: * Adds a Position to the Position participating in the first|last determination by assigning
225: * it a unique position index.
226: * @param pos the Position
227: * @return the same Position but with a position index
228: */
229: Position notifyPos(Position pos);
230: }
|