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.

TableContentLayoutManager.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.layoutmgr.table;
  19. import java.util.Iterator;
  20. import java.util.LinkedList;
  21. import java.util.List;
  22. import java.util.ListIterator;
  23. import java.util.Map;
  24. import org.apache.commons.logging.Log;
  25. import org.apache.commons.logging.LogFactory;
  26. import org.apache.fop.datatypes.PercentBaseContext;
  27. import org.apache.fop.fo.Constants;
  28. import org.apache.fop.fo.FObj;
  29. import org.apache.fop.fo.flow.Marker;
  30. import org.apache.fop.fo.flow.table.EffRow;
  31. import org.apache.fop.fo.flow.table.PrimaryGridUnit;
  32. import org.apache.fop.fo.flow.table.Table;
  33. import org.apache.fop.fo.flow.table.TableBody;
  34. import org.apache.fop.fo.flow.table.TablePart;
  35. import org.apache.fop.layoutmgr.BreakElement;
  36. import org.apache.fop.layoutmgr.ElementListUtils;
  37. import org.apache.fop.layoutmgr.FootenoteUtil;
  38. import org.apache.fop.layoutmgr.FootnoteBodyLayoutManager;
  39. import org.apache.fop.layoutmgr.Keep;
  40. import org.apache.fop.layoutmgr.KnuthBlockBox;
  41. import org.apache.fop.layoutmgr.KnuthBox;
  42. import org.apache.fop.layoutmgr.KnuthElement;
  43. import org.apache.fop.layoutmgr.KnuthGlue;
  44. import org.apache.fop.layoutmgr.KnuthPossPosIter;
  45. import org.apache.fop.layoutmgr.LayoutContext;
  46. import org.apache.fop.layoutmgr.ListElement;
  47. import org.apache.fop.layoutmgr.PageBreaker;
  48. import org.apache.fop.layoutmgr.Position;
  49. import org.apache.fop.layoutmgr.PositionIterator;
  50. import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition;
  51. import org.apache.fop.util.BreakUtil;
  52. /**
  53. * Layout manager for table contents, particularly managing the creation of combined element lists.
  54. */
  55. public class TableContentLayoutManager implements PercentBaseContext {
  56. /** Logger **/
  57. private static final Log LOG = LogFactory.getLog(TableContentLayoutManager.class);
  58. private TableLayoutManager tableLM;
  59. private TableRowIterator bodyIter;
  60. private TableRowIterator headerIter;
  61. private TableRowIterator footerIter;
  62. private LinkedList headerList;
  63. private LinkedList footerList;
  64. private int headerNetHeight;
  65. private int footerNetHeight;
  66. private int startXOffset;
  67. private int usedBPD;
  68. private TableStepper stepper;
  69. private boolean headerIsBeingRepeated;
  70. private boolean atLeastOnce;
  71. /**
  72. * Main constructor
  73. * @param parent Parent layout manager
  74. */
  75. TableContentLayoutManager(TableLayoutManager parent) {
  76. this.tableLM = parent;
  77. Table table = getTableLM().getTable();
  78. this.bodyIter = new TableRowIterator(table, TableRowIterator.BODY);
  79. if (table.getTableHeader() != null) {
  80. headerIter = new TableRowIterator(table, TableRowIterator.HEADER);
  81. }
  82. if (table.getTableFooter() != null) {
  83. footerIter = new TableRowIterator(table, TableRowIterator.FOOTER);
  84. }
  85. stepper = new TableStepper(this);
  86. }
  87. /**
  88. * @return the table layout manager
  89. */
  90. TableLayoutManager getTableLM() {
  91. return this.tableLM;
  92. }
  93. /** @return true if the table uses the separate border model. */
  94. boolean isSeparateBorderModel() {
  95. return getTableLM().getTable().isSeparateBorderModel();
  96. }
  97. /**
  98. * @return the column setup of this table
  99. */
  100. ColumnSetup getColumns() {
  101. return getTableLM().getColumns();
  102. }
  103. /** @return the net header height */
  104. protected int getHeaderNetHeight() {
  105. return this.headerNetHeight;
  106. }
  107. /** @return the net footer height */
  108. protected int getFooterNetHeight() {
  109. return this.footerNetHeight;
  110. }
  111. /** @return the header element list */
  112. protected LinkedList getHeaderElements() {
  113. return this.headerList;
  114. }
  115. /** @return the footer element list */
  116. protected LinkedList getFooterElements() {
  117. return this.footerList;
  118. }
  119. /**
  120. * Get a sequence of KnuthElements representing the content
  121. * of the node assigned to the LM.
  122. *
  123. * @param context the LayoutContext used to store layout information
  124. * @param alignment the desired text alignment
  125. * @return the list of KnuthElements
  126. * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int)
  127. */
  128. public List getNextKnuthElements(LayoutContext context, int alignment) {
  129. if (LOG.isDebugEnabled()) {
  130. LOG.debug("==> Columns: " + getTableLM().getColumns());
  131. }
  132. KnuthBox headerAsFirst = null;
  133. KnuthBox headerAsSecondToLast = null;
  134. KnuthBox footerAsLast = null;
  135. LinkedList returnList = new LinkedList();
  136. int headerFootnoteBPD = 0;
  137. if (headerIter != null && headerList == null) {
  138. this.headerList = getKnuthElementsForRowIterator(
  139. headerIter, context, alignment, TableRowIterator.HEADER);
  140. this.headerNetHeight
  141. = ElementListUtils.calcContentLength(this.headerList);
  142. if (LOG.isDebugEnabled()) {
  143. LOG.debug("==> Header: "
  144. + headerNetHeight + " - " + this.headerList);
  145. }
  146. TableHeaderFooterPosition pos = new TableHeaderFooterPosition(
  147. getTableLM(), true, this.headerList);
  148. List<FootnoteBodyLayoutManager> footnoteList = FootenoteUtil.getFootnotes(headerList);
  149. KnuthBox box = (footnoteList.isEmpty() || !getTableLM().getTable().omitHeaderAtBreak())
  150. ? new KnuthBox(headerNetHeight, pos, false)
  151. : new KnuthBlockBox(headerNetHeight, footnoteList, pos, false);
  152. if (getTableLM().getTable().omitHeaderAtBreak()) {
  153. //We can simply add the table header at the start
  154. //of the whole list
  155. headerAsFirst = box;
  156. } else {
  157. if (!footnoteList.isEmpty()) {
  158. List<List<KnuthElement>> footnotes = PageBreaker.getFootnoteKnuthElements(
  159. getTableLM().getPSLM().getFlowLayoutManager(), context, footnoteList);
  160. getTableLM().setHeaderFootnotes(footnotes);
  161. headerFootnoteBPD = getFootnotesBPD(footnotes);
  162. returnList.add(new KnuthBlockBox(-headerFootnoteBPD, footnoteList,
  163. new Position(getTableLM()), true));
  164. headerNetHeight += headerFootnoteBPD;
  165. }
  166. headerAsSecondToLast = box;
  167. }
  168. }
  169. if (footerIter != null && footerList == null) {
  170. this.footerList = getKnuthElementsForRowIterator(
  171. footerIter, context, alignment, TableRowIterator.FOOTER);
  172. this.footerNetHeight
  173. = ElementListUtils.calcContentLength(this.footerList);
  174. if (LOG.isDebugEnabled()) {
  175. LOG.debug("==> Footer: "
  176. + footerNetHeight + " - " + this.footerList);
  177. }
  178. //We can simply add the table footer at the end of the whole list
  179. TableHeaderFooterPosition pos = new TableHeaderFooterPosition(
  180. getTableLM(), false, this.footerList);
  181. List<FootnoteBodyLayoutManager> footnoteList = FootenoteUtil.getFootnotes(footerList);
  182. footerAsLast = footnoteList.isEmpty()
  183. ? new KnuthBox(footerNetHeight, pos, false)
  184. : new KnuthBlockBox(footerNetHeight, footnoteList, pos, false);
  185. if (!(getTableLM().getTable().omitFooterAtBreak() || footnoteList.isEmpty())) {
  186. List<List<KnuthElement>> footnotes = PageBreaker.getFootnoteKnuthElements(
  187. getTableLM().getPSLM().getFlowLayoutManager(), context, footnoteList);
  188. getTableLM().setFooterFootnotes(footnotes);
  189. footerNetHeight += getFootnotesBPD(footnotes);
  190. }
  191. }
  192. returnList.addAll(getKnuthElementsForRowIterator(
  193. bodyIter, context, alignment, TableRowIterator.BODY));
  194. if (headerAsFirst != null) {
  195. int insertionPoint = 0;
  196. if (returnList.size() > 0 && ((ListElement)returnList.getFirst()).isForcedBreak()) {
  197. insertionPoint++;
  198. }
  199. returnList.add(insertionPoint, headerAsFirst);
  200. } else if (headerAsSecondToLast != null) {
  201. int insertionPoint = returnList.size();
  202. if (returnList.size() > 0 && ((ListElement)returnList.getLast()).isForcedBreak()) {
  203. insertionPoint--;
  204. }
  205. returnList.add(insertionPoint, headerAsSecondToLast);
  206. }
  207. if (footerAsLast != null) {
  208. int insertionPoint = returnList.size();
  209. if (returnList.size() > 0 && ((ListElement)returnList.getLast()).isForcedBreak()) {
  210. insertionPoint--;
  211. }
  212. returnList.add(insertionPoint, footerAsLast);
  213. }
  214. if (headerFootnoteBPD != 0) {
  215. returnList.add(new KnuthBox(headerFootnoteBPD, new Position(getTableLM()), true));
  216. }
  217. return returnList;
  218. }
  219. private int getFootnotesBPD(List<List<KnuthElement>> footnotes) {
  220. int bpd = 0;
  221. for (List<KnuthElement> footnote : footnotes) {
  222. bpd += ElementListUtils.calcContentLength(footnote);
  223. }
  224. return bpd;
  225. }
  226. /**
  227. * Creates Knuth elements by iterating over a TableRowIterator.
  228. * @param iter TableRowIterator instance to fetch rows from
  229. * @param context Active LayoutContext
  230. * @param alignment alignment indicator
  231. * @param bodyType Indicates what kind of body is being processed
  232. * (BODY, HEADER or FOOTER)
  233. * @return An element list
  234. */
  235. private LinkedList getKnuthElementsForRowIterator(TableRowIterator iter,
  236. LayoutContext context, int alignment, int bodyType) {
  237. LinkedList returnList = new LinkedList();
  238. EffRow[] rowGroup = iter.getNextRowGroup();
  239. // TODO homogenize the handling of keeps and breaks
  240. context.clearKeepsPending();
  241. context.setBreakBefore(Constants.EN_AUTO);
  242. context.setBreakAfter(Constants.EN_AUTO);
  243. Keep keepWithPrevious = Keep.KEEP_AUTO;
  244. int breakBefore = Constants.EN_AUTO;
  245. if (rowGroup != null) {
  246. RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup,
  247. stepper);
  248. List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
  249. keepWithPrevious = keepWithPrevious.compare(context.getKeepWithPreviousPending());
  250. breakBefore = context.getBreakBefore();
  251. int breakBetween = context.getBreakAfter();
  252. returnList.addAll(nextRowGroupElems);
  253. while ((rowGroup = iter.getNextRowGroup()) != null) {
  254. rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup, stepper);
  255. //Note previous pending keep-with-next and clear the strength
  256. //(as the layout context is reused)
  257. Keep keepWithNextPending = context.getKeepWithNextPending();
  258. context.clearKeepWithNextPending();
  259. //Get elements for next row group
  260. nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
  261. /*
  262. * The last break element produced by TableStepper (for the previous row
  263. * group) may be used to represent the break between the two row groups.
  264. * Its penalty value and break class must just be overridden by the
  265. * characteristics of the keep or break between the two.
  266. *
  267. * However, we mustn't forget that if the after border of the last row of
  268. * the row group is thicker in the normal case than in the trailing case,
  269. * an additional glue will be appended to the element list. So we may have
  270. * to go two steps backwards in the list.
  271. */
  272. //Determine keep constraints
  273. Keep keep = keepWithNextPending.compare(context.getKeepWithPreviousPending());
  274. context.clearKeepWithPreviousPending();
  275. keep = keep.compare(getTableLM().getKeepTogether());
  276. int penaltyValue = keep.getPenalty();
  277. int breakClass = keep.getContext();
  278. breakBetween = BreakUtil.compareBreakClasses(breakBetween,
  279. context.getBreakBefore());
  280. if (breakBetween != Constants.EN_AUTO) {
  281. penaltyValue = -KnuthElement.INFINITE;
  282. breakClass = breakBetween;
  283. }
  284. BreakElement breakElement;
  285. ListIterator elemIter = returnList.listIterator(returnList.size());
  286. ListElement elem = (ListElement) elemIter.previous();
  287. if (elem instanceof KnuthGlue) {
  288. breakElement = (BreakElement) elemIter.previous();
  289. } else {
  290. breakElement = (BreakElement) elem;
  291. }
  292. breakElement.setPenaltyValue(penaltyValue);
  293. breakElement.setBreakClass(breakClass);
  294. returnList.addAll(nextRowGroupElems);
  295. breakBetween = context.getBreakAfter();
  296. }
  297. }
  298. /*
  299. * The last break produced for the last row-group of this table part must be
  300. * removed, because the breaking after the table will be handled by TableLM.
  301. * Unless the element list ends with a glue, which must be kept to accurately
  302. * represent the content. In such a case the break is simply disabled by setting
  303. * its penalty to infinite.
  304. */
  305. if (!returnList.isEmpty()) {
  306. ListIterator elemIter = returnList.listIterator(returnList.size());
  307. ListElement elem = (ListElement) elemIter.previous();
  308. if (elem instanceof KnuthGlue) {
  309. BreakElement breakElement = (BreakElement) elemIter.previous();
  310. breakElement.setPenaltyValue(KnuthElement.INFINITE);
  311. } else {
  312. elemIter.remove();
  313. }
  314. }
  315. context.updateKeepWithPreviousPending(keepWithPrevious);
  316. context.setBreakBefore(breakBefore);
  317. //fox:widow-content-limit
  318. int widowContentLimit = getTableLM().getTable().getWidowContentLimit().getValue();
  319. if (widowContentLimit != 0 && bodyType == TableRowIterator.BODY) {
  320. ElementListUtils.removeLegalBreaks(returnList, widowContentLimit);
  321. }
  322. //fox:orphan-content-limit
  323. int orphanContentLimit = getTableLM().getTable().getOrphanContentLimit().getValue();
  324. if (orphanContentLimit != 0 && bodyType == TableRowIterator.BODY) {
  325. ElementListUtils.removeLegalBreaksFromEnd(returnList, orphanContentLimit);
  326. }
  327. return returnList;
  328. }
  329. /**
  330. * Returns the X offset of the given grid unit.
  331. * @param gu the grid unit
  332. * @return the requested X offset
  333. */
  334. protected int getXOffsetOfGridUnit(PrimaryGridUnit gu) {
  335. return getXOffsetOfGridUnit(gu.getColIndex(), gu.getCell().getNumberColumnsSpanned());
  336. }
  337. /**
  338. * Returns the X offset of the grid unit in the given column.
  339. * @param colIndex the column index (zero-based)
  340. * @param nrColSpan number columns spanned
  341. * @return the requested X offset
  342. */
  343. protected int getXOffsetOfGridUnit(int colIndex, int nrColSpan) {
  344. return startXOffset + getTableLM().getColumns().getXOffset(colIndex + 1, nrColSpan, getTableLM());
  345. }
  346. /**
  347. * Adds the areas generated by this layout manager to the area tree.
  348. * @param parentIter the position iterator
  349. * @param layoutContext the layout context for adding areas
  350. */
  351. void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
  352. this.usedBPD = 0;
  353. RowPainter painter = new RowPainter(this, layoutContext);
  354. List tablePositions = new java.util.ArrayList();
  355. List headerElements = null;
  356. List footerElements = null;
  357. Position firstPos = null;
  358. Position lastPos = null;
  359. Position lastCheckPos = null;
  360. while (parentIter.hasNext()) {
  361. Position pos = parentIter.next();
  362. if (pos instanceof SpaceHandlingBreakPosition) {
  363. //This position has only been needed before addAreas was called, now we need the
  364. //original one created by the layout manager.
  365. pos = ((SpaceHandlingBreakPosition)pos).getOriginalBreakPosition();
  366. }
  367. if (pos == null) {
  368. continue;
  369. }
  370. if (firstPos == null) {
  371. firstPos = pos;
  372. }
  373. lastPos = pos;
  374. if (pos.getIndex() >= 0) {
  375. lastCheckPos = pos;
  376. }
  377. if (pos instanceof TableHeaderFooterPosition) {
  378. TableHeaderFooterPosition thfpos = (TableHeaderFooterPosition)pos;
  379. //these positions need to be unpacked
  380. if (thfpos.header) {
  381. //Positions for header will be added first
  382. headerElements = thfpos.nestedElements;
  383. } else {
  384. //Positions for footers are simply added at the end
  385. footerElements = thfpos.nestedElements;
  386. }
  387. } else if (pos instanceof TableHFPenaltyPosition) {
  388. //ignore for now, see special handling below if break is at a penalty
  389. //Only if the last position in this part/page us such a position it will be used
  390. } else if (pos instanceof TableContentPosition) {
  391. tablePositions.add(pos);
  392. } else {
  393. if (LOG.isDebugEnabled()) {
  394. LOG.debug("Ignoring position: " + pos);
  395. }
  396. }
  397. }
  398. boolean treatFooterAsArtifact = layoutContext.treatAsArtifact();
  399. if (lastPos instanceof TableHFPenaltyPosition) {
  400. TableHFPenaltyPosition penaltyPos = (TableHFPenaltyPosition)lastPos;
  401. LOG.debug("Break at penalty!");
  402. if (penaltyPos.headerElements != null) {
  403. //Header positions for the penalty position are in the last element and need to
  404. //be handled first before all other TableContentPositions
  405. headerElements = penaltyPos.headerElements;
  406. }
  407. if (penaltyPos.footerElements != null) {
  408. footerElements = penaltyPos.footerElements;
  409. treatFooterAsArtifact = true;
  410. }
  411. }
  412. // there may be table fragment markers stored; clear them since we are starting a new fragment
  413. tableLM.clearTableFragmentMarkers();
  414. // note: markers at table level are to be retrieved by the page, not by the table itself
  415. Map<String, Marker> markers = getTableLM().getTable().getMarkers();
  416. if (markers != null) {
  417. getTableLM().getCurrentPV().registerMarkers(markers,
  418. true, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
  419. }
  420. if (headerElements != null) {
  421. boolean ancestorTreatAsArtifact = layoutContext.treatAsArtifact();
  422. if (headerIsBeingRepeated) {
  423. layoutContext.setTreatAsArtifact(true);
  424. if (!getTableLM().getHeaderFootnotes().isEmpty()) {
  425. getTableLM().getPSLM().addTableHeaderFootnotes(getTableLM().getHeaderFootnotes());
  426. }
  427. }
  428. //header positions for the last part are the second-to-last element and need to
  429. //be handled first before all other TableContentPositions
  430. addHeaderFooterAreas(headerElements, tableLM.getTable().getTableHeader(), painter,
  431. false);
  432. if (!ancestorTreatAsArtifact) {
  433. headerIsBeingRepeated = true;
  434. }
  435. layoutContext.setTreatAsArtifact(ancestorTreatAsArtifact);
  436. }
  437. if (tablePositions.isEmpty()) {
  438. // TODO make sure this actually never happens
  439. LOG.error("tablePositions empty."
  440. + " Please send your FO file to fop-users@xmlgraphics.apache.org");
  441. } else {
  442. // Here we are sure that posIter iterates only over TableContentPosition instances
  443. addBodyAreas(tablePositions.iterator(), painter, footerElements == null);
  444. }
  445. // if there are TCLMs saved because they have a RetrieveTableMarker, we repeat the header areas now;
  446. // this can also be done after the areas for the footer are added but should be the same as here
  447. tableLM.setRepeateHeader(atLeastOnce);
  448. tableLM.repeatAddAreasForSavedTableHeaderTableCellLayoutManagers();
  449. atLeastOnce = true;
  450. if (footerElements != null && !footerElements.isEmpty()) {
  451. boolean ancestorTreatAsArtifact = layoutContext.treatAsArtifact();
  452. layoutContext.setTreatAsArtifact(treatFooterAsArtifact);
  453. //Positions for footers are simply added at the end
  454. addHeaderFooterAreas(footerElements, tableLM.getTable().getTableFooter(), painter, true);
  455. if (lastPos instanceof TableHFPenaltyPosition && !tableLM.getFooterFootnotes().isEmpty()) {
  456. tableLM.getPSLM().addTableFooterFootnotes(getTableLM().getFooterFootnotes());
  457. }
  458. layoutContext.setTreatAsArtifact(ancestorTreatAsArtifact);
  459. }
  460. this.usedBPD += painter.getAccumulatedBPD();
  461. if (markers != null) {
  462. getTableLM().getCurrentPV().registerMarkers(markers,
  463. false, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
  464. }
  465. }
  466. private void addHeaderFooterAreas(List elements, TablePart part, RowPainter painter,
  467. boolean lastOnPage) {
  468. List lst = new java.util.ArrayList(elements.size());
  469. for (Iterator iter = new KnuthPossPosIter(elements); iter.hasNext();) {
  470. Position pos = (Position) iter.next();
  471. /*
  472. * Unlike for the body the Positions associated to the glues generated by
  473. * TableStepper haven't been removed yet.
  474. */
  475. if (pos instanceof TableContentPosition) {
  476. lst.add((TableContentPosition) pos);
  477. }
  478. }
  479. addTablePartAreas(lst, painter, part, true, true, true, lastOnPage);
  480. }
  481. /**
  482. * Iterates over the positions corresponding to the table's body (which may contain
  483. * several table-body elements!) and adds the corresponding areas.
  484. *
  485. * @param iterator iterator over TableContentPosition elements. Those positions
  486. * correspond to the elements of the body present on the current page
  487. * @param painter
  488. * @param lastOnPage true if the table has no footer (then the last line of the table
  489. * that will be present on the page belongs to the body)
  490. */
  491. private void addBodyAreas(Iterator iterator, RowPainter painter,
  492. boolean lastOnPage) {
  493. painter.startBody();
  494. List lst = new java.util.ArrayList();
  495. TableContentPosition pos = (TableContentPosition) iterator.next();
  496. boolean isFirstPos = pos.getFlag(TableContentPosition.FIRST_IN_ROWGROUP)
  497. && pos.getRow().getFlag(EffRow.FIRST_IN_PART);
  498. TablePart part = pos.getTablePart();
  499. lst.add(pos);
  500. while (iterator.hasNext()) {
  501. pos = (TableContentPosition) iterator.next();
  502. if (pos.getTablePart() != part) {
  503. addTablePartAreas(lst, painter, part, isFirstPos, true, false, false);
  504. isFirstPos = true;
  505. lst.clear();
  506. part = pos.getTablePart();
  507. }
  508. lst.add(pos);
  509. }
  510. boolean isLastPos = pos.getFlag(TableContentPosition.LAST_IN_ROWGROUP)
  511. && pos.getRow().getFlag(EffRow.LAST_IN_PART);
  512. addTablePartAreas(lst, painter, part, isFirstPos, isLastPos, true, lastOnPage);
  513. painter.endBody();
  514. }
  515. /**
  516. * Adds the areas corresponding to a single fo:table-header/footer/body element.
  517. */
  518. private void addTablePartAreas(List positions, RowPainter painter, TablePart body,
  519. boolean isFirstPos, boolean isLastPos, boolean lastInBody, boolean lastOnPage) {
  520. getTableLM().getCurrentPV().registerMarkers(body.getMarkers(),
  521. true, isFirstPos, isLastPos);
  522. if (body instanceof TableBody) {
  523. getTableLM().registerMarkers(body.getMarkers(), true, isFirstPos, isLastPos);
  524. }
  525. painter.startTablePart(body);
  526. for (Object position : positions) {
  527. painter.handleTableContentPosition((TableContentPosition) position);
  528. }
  529. getTableLM().getCurrentPV().registerMarkers(body.getMarkers(),
  530. false, isFirstPos, isLastPos);
  531. if (body instanceof TableBody) {
  532. getTableLM().registerMarkers(body.getMarkers(), false, isFirstPos, isLastPos);
  533. }
  534. painter.endTablePart(lastInBody, lastOnPage);
  535. }
  536. /**
  537. * Sets the overall starting x-offset. Used for proper placement of cells.
  538. * @param startXOffset starting x-offset (table's start-indent)
  539. */
  540. void setStartXOffset(int startXOffset) {
  541. this.startXOffset = startXOffset;
  542. }
  543. /**
  544. * @return the amount of block-progression-dimension used by the content
  545. */
  546. int getUsedBPD() {
  547. return this.usedBPD;
  548. }
  549. // --------- Property Resolution related functions --------- //
  550. /**
  551. * {@inheritDoc}
  552. */
  553. public int getBaseLength(int lengthBase, FObj fobj) {
  554. return tableLM.getBaseLength(lengthBase, fobj);
  555. }
  556. }