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

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