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.

TableLayoutManager.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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.ArrayList;
  20. import java.util.Collections;
  21. import java.util.Iterator;
  22. import java.util.LinkedList;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.apache.commons.logging.Log;
  26. import org.apache.commons.logging.LogFactory;
  27. import org.apache.fop.area.Area;
  28. import org.apache.fop.area.Block;
  29. import org.apache.fop.datatypes.LengthBase;
  30. import org.apache.fop.fo.Constants;
  31. import org.apache.fop.fo.FONode;
  32. import org.apache.fop.fo.FObj;
  33. import org.apache.fop.fo.flow.Marker;
  34. import org.apache.fop.fo.flow.Markers;
  35. import org.apache.fop.fo.flow.RetrieveTableMarker;
  36. import org.apache.fop.fo.flow.table.Table;
  37. import org.apache.fop.fo.flow.table.TableColumn;
  38. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  39. import org.apache.fop.fo.properties.KeepProperty;
  40. import org.apache.fop.layoutmgr.BlockLevelEventProducer;
  41. import org.apache.fop.layoutmgr.BreakElement;
  42. import org.apache.fop.layoutmgr.BreakOpportunity;
  43. import org.apache.fop.layoutmgr.KnuthElement;
  44. import org.apache.fop.layoutmgr.KnuthGlue;
  45. import org.apache.fop.layoutmgr.LayoutContext;
  46. import org.apache.fop.layoutmgr.LeafPosition;
  47. import org.apache.fop.layoutmgr.ListElement;
  48. import org.apache.fop.layoutmgr.Position;
  49. import org.apache.fop.layoutmgr.PositionIterator;
  50. import org.apache.fop.layoutmgr.SpacedBorderedPaddedBlockLayoutManager;
  51. import org.apache.fop.layoutmgr.TraitSetter;
  52. import org.apache.fop.traits.MinOptMax;
  53. import org.apache.fop.traits.SpaceVal;
  54. import org.apache.fop.util.BreakUtil;
  55. /**
  56. * LayoutManager for a table FO.
  57. * A table consists of columns, table header, table footer and multiple
  58. * table bodies.
  59. * The header, footer and body add the areas created from the table cells.
  60. * The table then creates areas for the columns, bodies and rows
  61. * the render background.
  62. */
  63. public class TableLayoutManager extends SpacedBorderedPaddedBlockLayoutManager
  64. implements BreakOpportunity {
  65. /**
  66. * logging instance
  67. */
  68. private static Log log = LogFactory.getLog(TableLayoutManager.class);
  69. private TableContentLayoutManager contentLM;
  70. private ColumnSetup columns;
  71. private Block curBlockArea;
  72. private double tableUnit;
  73. private boolean autoLayout = true;
  74. private int halfBorderSeparationBPD;
  75. private int halfBorderSeparationIPD;
  76. /** See {@link TableLayoutManager#registerColumnBackgroundArea(TableColumn, Block, int)}. */
  77. private List columnBackgroundAreas;
  78. private Position auxiliaryPosition;
  79. // this holds a possible list of TCLMs that needed to have their addAreas() repeated
  80. private List<TableCellLayoutManager> savedTCLMs;
  81. private boolean areAllTCLMsSaved;
  82. private Markers tableMarkers;
  83. private Markers tableFragmentMarkers;
  84. private boolean hasRetrieveTableMarker;
  85. private boolean repeatedHeader;
  86. private List<List<KnuthElement>> headerFootnotes = Collections.emptyList();
  87. private List<List<KnuthElement>> footerFootnotes = Collections.emptyList();
  88. /**
  89. * Temporary holder of column background informations for a table-cell's area.
  90. *
  91. * @see TableLayoutManager#registerColumnBackgroundArea(TableColumn, Block, int)
  92. */
  93. private static final class ColumnBackgroundInfo {
  94. private TableColumn column;
  95. private Block backgroundArea;
  96. private int xShift;
  97. private ColumnBackgroundInfo(TableColumn column, Block backgroundArea, int xShift) {
  98. this.column = column;
  99. this.backgroundArea = backgroundArea;
  100. this.xShift = xShift;
  101. }
  102. }
  103. /**
  104. * Create a new table layout manager.
  105. * @param node the table FO
  106. */
  107. public TableLayoutManager(Table node) {
  108. super(node);
  109. this.columns = new ColumnSetup(node);
  110. }
  111. @Override
  112. protected CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  113. return getTable().getCommonBorderPaddingBackground();
  114. }
  115. /** @return the table FO */
  116. public Table getTable() {
  117. return (Table)this.fobj;
  118. }
  119. /**
  120. * @return the column setup for this table.
  121. */
  122. public ColumnSetup getColumns() {
  123. return this.columns;
  124. }
  125. /** {@inheritDoc} */
  126. public void initialize() {
  127. foSpaceBefore = new SpaceVal(
  128. getTable().getCommonMarginBlock().spaceBefore, this).getSpace();
  129. foSpaceAfter = new SpaceVal(
  130. getTable().getCommonMarginBlock().spaceAfter, this).getSpace();
  131. startIndent = getTable().getCommonMarginBlock().startIndent.getValue(this);
  132. endIndent = getTable().getCommonMarginBlock().endIndent.getValue(this);
  133. if (getTable().isSeparateBorderModel()) {
  134. this.halfBorderSeparationBPD = getTable().getBorderSeparation().getBPD().getLength()
  135. .getValue(this) / 2;
  136. this.halfBorderSeparationIPD = getTable().getBorderSeparation().getIPD().getLength()
  137. .getValue(this) / 2;
  138. } else {
  139. this.halfBorderSeparationBPD = 0;
  140. this.halfBorderSeparationIPD = 0;
  141. }
  142. if (!getTable().isAutoLayout()
  143. && getTable().getInlineProgressionDimension().getOptimum(this).getEnum()
  144. != EN_AUTO) {
  145. autoLayout = false;
  146. }
  147. }
  148. private void resetSpaces() {
  149. this.discardBorderBefore = false;
  150. this.discardBorderAfter = false;
  151. this.discardPaddingBefore = false;
  152. this.discardPaddingAfter = false;
  153. this.effSpaceBefore = null;
  154. this.effSpaceAfter = null;
  155. }
  156. /**
  157. * @return half the value of border-separation.block-progression-dimension, or 0 if
  158. * border-collapse="collapse".
  159. */
  160. public int getHalfBorderSeparationBPD() {
  161. return halfBorderSeparationBPD;
  162. }
  163. /**
  164. * @return half the value of border-separation.inline-progression-dimension, or 0 if
  165. * border-collapse="collapse".
  166. */
  167. public int getHalfBorderSeparationIPD() {
  168. return halfBorderSeparationIPD;
  169. }
  170. /** {@inheritDoc} */
  171. public List getNextKnuthElements(LayoutContext context, int alignment) {
  172. List returnList = new LinkedList();
  173. /*
  174. * Compute the IPD and adjust it if necessary (overconstrained)
  175. */
  176. referenceIPD = context.getRefIPD();
  177. if (getTable().getInlineProgressionDimension().getOptimum(this).getEnum() != EN_AUTO) {
  178. int contentIPD = getTable().getInlineProgressionDimension().getOptimum(this)
  179. .getLength().getValue(this);
  180. updateContentAreaIPDwithOverconstrainedAdjust(contentIPD);
  181. } else {
  182. if (!getTable().isAutoLayout()) {
  183. BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
  184. getTable().getUserAgent().getEventBroadcaster());
  185. eventProducer.tableFixedAutoWidthNotSupported(this, getTable().getLocator());
  186. }
  187. updateContentAreaIPDwithOverconstrainedAdjust();
  188. }
  189. int sumOfColumns = columns.getSumOfColumnWidths(this);
  190. if (!autoLayout && sumOfColumns > getContentAreaIPD()) {
  191. log.debug(FONode.decorateWithContextInfo(
  192. "The sum of all column widths is larger than the specified table width.",
  193. getTable()));
  194. updateContentAreaIPDwithOverconstrainedAdjust(sumOfColumns);
  195. }
  196. int availableIPD = referenceIPD - getIPIndents();
  197. if (getContentAreaIPD() > availableIPD) {
  198. BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
  199. getTable().getUserAgent().getEventBroadcaster());
  200. eventProducer.objectTooWide(this, getTable().getName(),
  201. getContentAreaIPD(), context.getRefIPD(),
  202. getTable().getLocator());
  203. }
  204. /* initialize unit to determine computed values
  205. * for proportional-column-width()
  206. */
  207. if (tableUnit == 0.0) {
  208. this.tableUnit = columns.computeTableUnit(this);
  209. }
  210. if (!firstVisibleMarkServed) {
  211. addKnuthElementsForSpaceBefore(returnList, alignment);
  212. }
  213. if (getTable().isSeparateBorderModel()) {
  214. addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
  215. firstVisibleMarkServed = true;
  216. // Border and padding to be repeated at each break
  217. // This must be done only in the separate-border model, as in collapsing
  218. // tables have no padding and borders are determined at the cell level
  219. addPendingMarks(context);
  220. }
  221. // Elements for the table-header/footer/body
  222. List contentKnuthElements;
  223. contentLM = new TableContentLayoutManager(this);
  224. LayoutContext childLC = LayoutContext.newInstance();
  225. /*
  226. childLC.setStackLimit(
  227. MinOptMax.subtract(context.getStackLimit(),
  228. stackSize));*/
  229. childLC.setRefIPD(context.getRefIPD());
  230. childLC.copyPendingMarksFrom(context);
  231. contentKnuthElements = contentLM.getNextKnuthElements(childLC, alignment);
  232. //Set index values on elements coming from the content LM
  233. Iterator iter = contentKnuthElements.iterator();
  234. while (iter.hasNext()) {
  235. ListElement el = (ListElement)iter.next();
  236. notifyPos(el.getPosition());
  237. }
  238. log.debug(contentKnuthElements);
  239. wrapPositionElements(contentKnuthElements, returnList);
  240. context.updateKeepWithPreviousPending(getKeepWithPrevious());
  241. context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
  242. context.updateKeepWithNextPending(getKeepWithNext());
  243. context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
  244. if (getTable().isSeparateBorderModel()) {
  245. addKnuthElementsForBorderPaddingAfter(returnList, true);
  246. }
  247. addKnuthElementsForSpaceAfter(returnList, alignment);
  248. if (!context.suppressBreakBefore()) {
  249. //addKnuthElementsForBreakBefore(returnList, context);
  250. int breakBefore = BreakUtil.compareBreakClasses(getTable().getBreakBefore(),
  251. childLC.getBreakBefore());
  252. if (breakBefore != Constants.EN_AUTO) {
  253. returnList.add(0, new BreakElement(new LeafPosition(getParent(), 0), 0,
  254. -KnuthElement.INFINITE, breakBefore, context));
  255. }
  256. }
  257. //addKnuthElementsForBreakAfter(returnList, context);
  258. int breakAfter = BreakUtil.compareBreakClasses(getTable().getBreakAfter(),
  259. childLC.getBreakAfter());
  260. if (breakAfter != Constants.EN_AUTO) {
  261. returnList.add(new BreakElement(new LeafPosition(getParent(), 0),
  262. 0, -KnuthElement.INFINITE, breakAfter, context));
  263. }
  264. setFinished(true);
  265. resetSpaces();
  266. return returnList;
  267. }
  268. /** {@inheritDoc} */
  269. public Position getAuxiliaryPosition() {
  270. /*
  271. * Redefined to return a LeafPosition instead of a NonLeafPosition. The
  272. * SpaceResolver.SpaceHandlingBreakPosition constructors unwraps all
  273. * NonLeafPositions, which can lead to a NPE when a break in a table occurs at a
  274. * page with different ipd.
  275. */
  276. if (auxiliaryPosition == null) {
  277. auxiliaryPosition = new LeafPosition(this, 0);
  278. }
  279. return auxiliaryPosition;
  280. }
  281. /**
  282. * Registers the given area, that will be used to render the part of column background
  283. * covered by a table-cell. If percentages are used to place the background image, the
  284. * final bpd of the (fraction of) table that will be rendered on the current page must
  285. * be known. The traits can't then be set when the areas for the cell are created
  286. * since at that moment this bpd is yet unknown. So they will instead be set in
  287. * TableLM's {@link #addAreas(PositionIterator, LayoutContext)} method.
  288. *
  289. * @param column the table-column element from which the cell gets background
  290. * informations
  291. * @param backgroundArea the block of the cell's dimensions that will hold the column
  292. * background
  293. * @param xShift additional amount by which the image must be shifted to be correctly
  294. * placed (to counterbalance the cell's start border)
  295. */
  296. void registerColumnBackgroundArea(TableColumn column, Block backgroundArea, int xShift) {
  297. addBackgroundArea(backgroundArea);
  298. if (columnBackgroundAreas == null) {
  299. columnBackgroundAreas = new ArrayList();
  300. }
  301. columnBackgroundAreas.add(new ColumnBackgroundInfo(column, backgroundArea, xShift));
  302. }
  303. /**
  304. * The table area is a reference area that contains areas for
  305. * columns, bodies, rows and the contents are in cells.
  306. *
  307. * @param parentIter the position iterator
  308. * @param layoutContext the layout context for adding areas
  309. */
  310. public void addAreas(PositionIterator parentIter,
  311. LayoutContext layoutContext) {
  312. getParentArea(null);
  313. addId();
  314. // add space before, in order to implement display-align = "center" or "after"
  315. if (layoutContext.getSpaceBefore() != 0) {
  316. addBlockSpacing(0.0, MinOptMax.getInstance(layoutContext.getSpaceBefore()));
  317. }
  318. int startXOffset = getTable().getCommonMarginBlock().startIndent.getValue(this);
  319. // add column, body then row areas
  320. // BPD of the table, i.e., height of its content; table's borders and paddings not counted
  321. int tableHeight = 0;
  322. //Body childLM;
  323. LayoutContext lc = LayoutContext.offspringOf(layoutContext);
  324. lc.setRefIPD(getContentAreaIPD());
  325. contentLM.setStartXOffset(startXOffset);
  326. contentLM.addAreas(parentIter, lc);
  327. tableHeight += contentLM.getUsedBPD();
  328. curBlockArea.setBPD(tableHeight);
  329. if (columnBackgroundAreas != null) {
  330. for (Iterator iter = columnBackgroundAreas.iterator(); iter.hasNext();) {
  331. ColumnBackgroundInfo b = (ColumnBackgroundInfo) iter.next();
  332. TraitSetter.addBackground(b.backgroundArea,
  333. b.column.getCommonBorderPaddingBackground(), this,
  334. b.xShift, -b.backgroundArea.getYOffset(),
  335. b.column.getColumnWidth().getValue(this), tableHeight);
  336. }
  337. columnBackgroundAreas.clear();
  338. }
  339. if (getTable().isSeparateBorderModel()) {
  340. TraitSetter.addBorders(curBlockArea,
  341. getTable().getCommonBorderPaddingBackground(),
  342. discardBorderBefore, discardBorderAfter, false, false, this);
  343. TraitSetter.addPadding(curBlockArea,
  344. getTable().getCommonBorderPaddingBackground(),
  345. discardPaddingBefore, discardPaddingAfter, false, false, this);
  346. }
  347. TraitSetter.addBackground(curBlockArea,
  348. getTable().getCommonBorderPaddingBackground(),
  349. this);
  350. TraitSetter.addMargins(curBlockArea,
  351. getTable().getCommonBorderPaddingBackground(),
  352. startIndent, endIndent,
  353. this);
  354. TraitSetter.addBreaks(curBlockArea,
  355. getTable().getBreakBefore(), getTable().getBreakAfter());
  356. TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(),
  357. effSpaceBefore, effSpaceAfter);
  358. flush();
  359. resetSpaces();
  360. curBlockArea = null;
  361. notifyEndOfLayout();
  362. }
  363. /**
  364. * Return an Area which can contain the passed childArea. The childArea
  365. * may not yet have any content, but it has essential traits set.
  366. * In general, if the LayoutManager already has an Area it simply returns
  367. * it. Otherwise, it makes a new Area of the appropriate class.
  368. * It gets a parent area for its area by calling its parent LM.
  369. * Finally, based on the dimensions of the parent area, it initializes
  370. * its own area. This includes setting the content IPD and the maximum
  371. * BPD.
  372. *
  373. * @param childArea the child area
  374. * @return the parent area of the child
  375. */
  376. public Area getParentArea(Area childArea) {
  377. if (curBlockArea == null) {
  378. curBlockArea = new Block();
  379. // Set up dimensions
  380. // Must get dimensions from parent area
  381. /*Area parentArea =*/ parentLayoutManager.getParentArea(curBlockArea);
  382. TraitSetter.setProducerID(curBlockArea, getTable().getId());
  383. curBlockArea.setIPD(getContentAreaIPD());
  384. setCurrentArea(curBlockArea);
  385. }
  386. return curBlockArea;
  387. }
  388. /**
  389. * Add the child area to this layout manager.
  390. *
  391. * @param childArea the child area to add
  392. */
  393. public void addChildArea(Area childArea) {
  394. if (curBlockArea != null) {
  395. curBlockArea.addBlock((Block) childArea);
  396. }
  397. }
  398. /**
  399. * Adds the given area to this layout manager's area, without updating the used bpd.
  400. *
  401. * @param background an area
  402. */
  403. void addBackgroundArea(Block background) {
  404. curBlockArea.addChildArea(background);
  405. }
  406. /** {@inheritDoc} */
  407. public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
  408. // TODO Auto-generated method stub
  409. return 0;
  410. }
  411. /** {@inheritDoc} */
  412. public void discardSpace(KnuthGlue spaceGlue) {
  413. // TODO Auto-generated method stub
  414. }
  415. /** {@inheritDoc} */
  416. public KeepProperty getKeepTogetherProperty() {
  417. return getTable().getKeepTogether();
  418. }
  419. /** {@inheritDoc} */
  420. public KeepProperty getKeepWithPreviousProperty() {
  421. return getTable().getKeepWithPrevious();
  422. }
  423. /** {@inheritDoc} */
  424. public KeepProperty getKeepWithNextProperty() {
  425. return getTable().getKeepWithNext();
  426. }
  427. // --------- Property Resolution related functions --------- //
  428. /**
  429. * {@inheritDoc}
  430. */
  431. public int getBaseLength(int lengthBase, FObj fobj) {
  432. // Special handler for TableColumn width specifications
  433. if (fobj instanceof TableColumn && fobj.getParent() == getFObj()) {
  434. switch (lengthBase) {
  435. case LengthBase.CONTAINING_BLOCK_WIDTH:
  436. return getContentAreaIPD();
  437. case LengthBase.TABLE_UNITS:
  438. return (int) this.tableUnit;
  439. default:
  440. log.error("Unknown base type for LengthBase.");
  441. return 0;
  442. }
  443. } else {
  444. switch (lengthBase) {
  445. case LengthBase.TABLE_UNITS:
  446. return (int) this.tableUnit;
  447. default:
  448. return super.getBaseLength(lengthBase, fobj);
  449. }
  450. }
  451. }
  452. /** {@inheritDoc} */
  453. public void reset() {
  454. super.reset();
  455. curBlockArea = null;
  456. tableUnit = 0.0;
  457. }
  458. /**
  459. * Saves a TableCellLayoutManager for later use.
  460. *
  461. * @param tclm a TableCellLayoutManager that has a RetrieveTableMarker
  462. */
  463. protected void saveTableHeaderTableCellLayoutManagers(TableCellLayoutManager tclm) {
  464. if (savedTCLMs == null) {
  465. savedTCLMs = new ArrayList<TableCellLayoutManager>();
  466. }
  467. if (!areAllTCLMsSaved) {
  468. savedTCLMs.add(tclm);
  469. }
  470. }
  471. /**
  472. * Calls addAreas() for each of the saved TableCellLayoutManagers.
  473. */
  474. protected void repeatAddAreasForSavedTableHeaderTableCellLayoutManagers() {
  475. if (savedTCLMs == null) {
  476. return;
  477. }
  478. // if we get to this stage then we are at the footer of the table fragment; this means that no more
  479. // different TCLM need to be saved (we already have all); we flag the list as being complete then
  480. areAllTCLMsSaved = true;
  481. for (int i = 0; i < savedTCLMs.size(); i++) {
  482. TableCellLayoutManager tclm = savedTCLMs.get(i);
  483. if (this.repeatedHeader) {
  484. tclm.setHasRepeatedHeader(true);
  485. }
  486. tclm.repeatAddAreas();
  487. }
  488. }
  489. /**
  490. * Resolves a RetrieveTableMarker by finding a qualifying Marker to which it is bound to.
  491. * @param rtm the RetrieveTableMarker to be resolved
  492. * @return a bound RetrieveTableMarker instance or null if no qualifying Marker found
  493. */
  494. public RetrieveTableMarker resolveRetrieveTableMarker(RetrieveTableMarker rtm) {
  495. String name = rtm.getRetrieveClassName();
  496. int originalPosition = rtm.getPosition();
  497. boolean changedPosition = false;
  498. Marker mark = null;
  499. // try the primary retrieve scope area, which is the same as table-fragment
  500. mark = (tableFragmentMarkers == null) ? null : tableFragmentMarkers.resolve(rtm);
  501. if (mark == null && rtm.getBoundary() != Constants.EN_TABLE_FRAGMENT) {
  502. rtm.changePositionTo(Constants.EN_LAST_ENDING);
  503. changedPosition = true;
  504. // try the page scope area
  505. mark = getCurrentPV().resolveMarker(rtm);
  506. if (mark == null && rtm.getBoundary() != Constants.EN_PAGE) {
  507. // try the table scope area
  508. mark = (tableMarkers == null) ? null : tableMarkers.resolve(rtm);
  509. }
  510. }
  511. if (changedPosition) {
  512. // so that the next time it is called looks unchanged
  513. rtm.changePositionTo(originalPosition);
  514. }
  515. if (mark == null) {
  516. log.debug("found no marker with name: " + name);
  517. return null;
  518. } else {
  519. rtm.bindMarker(mark);
  520. return rtm;
  521. }
  522. }
  523. /**
  524. * Register the markers for this table.
  525. *
  526. * @param marks the map of markers to add
  527. * @param starting if the area being added is starting or ending
  528. * @param isfirst if the area being added has is-first trait
  529. * @param islast if the area being added has is-last trait
  530. */
  531. public void registerMarkers(Map<String, Marker> marks, boolean starting, boolean isfirst,
  532. boolean islast) {
  533. if (tableMarkers == null) {
  534. tableMarkers = new Markers();
  535. }
  536. tableMarkers.register(marks, starting, isfirst, islast);
  537. if (tableFragmentMarkers == null) {
  538. tableFragmentMarkers = new Markers();
  539. }
  540. tableFragmentMarkers.register(marks, starting, isfirst, islast);
  541. }
  542. /**
  543. * Clears the list of markers in the current table fragment. Should be called just before starting a new
  544. * header (that belongs to the next table fragment).
  545. */
  546. protected void clearTableFragmentMarkers() {
  547. tableFragmentMarkers = null;
  548. }
  549. public void flagAsHavingRetrieveTableMarker() {
  550. hasRetrieveTableMarker = true;
  551. }
  552. protected void possiblyRegisterMarkersForTables(Map<String, Marker> markers, boolean isStarting,
  553. boolean isFirst, boolean isLast) {
  554. // note: if we allow table-footer after a table-body this check should not be made and the markers
  555. // should be registered regardless because the retrieval may be done only in the footer
  556. if (hasRetrieveTableMarker) {
  557. registerMarkers(markers, isStarting, isFirst, isLast);
  558. }
  559. super.possiblyRegisterMarkersForTables(markers, isStarting, isFirst, isLast);
  560. }
  561. void setHeaderFootnotes(List<List<KnuthElement>> footnotes) {
  562. this.headerFootnotes = footnotes;
  563. }
  564. List<List<KnuthElement>> getHeaderFootnotes() {
  565. return headerFootnotes;
  566. }
  567. void setFooterFootnotes(List<List<KnuthElement>> footnotes) {
  568. this.footerFootnotes = footnotes;
  569. }
  570. public void setRepeateHeader(boolean repeateHeader) {
  571. this.repeatedHeader = repeateHeader;
  572. }
  573. List<List<KnuthElement>> getFooterFootnotes() {
  574. return footerFootnotes;
  575. }
  576. }