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.

LineLayoutManager.java 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  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.inline;
  19. import java.util.ArrayList;
  20. import java.util.LinkedList;
  21. import java.util.List;
  22. import java.util.ListIterator;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.apache.fop.area.Area;
  26. import org.apache.fop.area.LineArea;
  27. import org.apache.fop.area.Trait;
  28. import org.apache.fop.area.inline.InlineArea;
  29. import org.apache.fop.datatypes.Length;
  30. import org.apache.fop.datatypes.Numeric;
  31. import org.apache.fop.fo.Constants;
  32. import org.apache.fop.fo.flow.Block;
  33. import org.apache.fop.fo.properties.CommonHyphenation;
  34. import org.apache.fop.fo.properties.KeepProperty;
  35. import org.apache.fop.fonts.Font;
  36. import org.apache.fop.fonts.FontInfo;
  37. import org.apache.fop.fonts.FontTriplet;
  38. import org.apache.fop.hyphenation.Hyphenation;
  39. import org.apache.fop.hyphenation.Hyphenator;
  40. import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
  41. import org.apache.fop.layoutmgr.BreakElement;
  42. import org.apache.fop.layoutmgr.BreakingAlgorithm;
  43. import org.apache.fop.layoutmgr.ElementListObserver;
  44. import org.apache.fop.layoutmgr.InlineKnuthSequence;
  45. import org.apache.fop.layoutmgr.Keep;
  46. import org.apache.fop.layoutmgr.KnuthBlockBox;
  47. import org.apache.fop.layoutmgr.KnuthBox;
  48. import org.apache.fop.layoutmgr.KnuthElement;
  49. import org.apache.fop.layoutmgr.KnuthGlue;
  50. import org.apache.fop.layoutmgr.KnuthPenalty;
  51. import org.apache.fop.layoutmgr.KnuthPossPosIter;
  52. import org.apache.fop.layoutmgr.KnuthSequence;
  53. import org.apache.fop.layoutmgr.LayoutContext;
  54. import org.apache.fop.layoutmgr.LayoutManager;
  55. import org.apache.fop.layoutmgr.LeafPosition;
  56. import org.apache.fop.layoutmgr.ListElement;
  57. import org.apache.fop.layoutmgr.NonLeafPosition;
  58. import org.apache.fop.layoutmgr.Position;
  59. import org.apache.fop.layoutmgr.PositionIterator;
  60. import org.apache.fop.layoutmgr.SpaceSpecifier;
  61. import org.apache.fop.traits.MinOptMax;
  62. /**
  63. * LayoutManager for lines. It builds one or more lines containing
  64. * inline areas generated by its sub layout managers.
  65. * A break is found for each line which may contain one of more
  66. * breaks from the child layout managers.
  67. * Once a break is found then it is return for the parent layout
  68. * manager to handle.
  69. * When the areas are being added to the page this manager
  70. * creates a line area to contain the inline areas added by the
  71. * child layout managers.
  72. */
  73. public class LineLayoutManager extends InlineStackingLayoutManager
  74. implements BlockLevelLayoutManager {
  75. /**
  76. * logging instance
  77. */
  78. private static Log log = LogFactory.getLog(LineLayoutManager.class);
  79. private Block fobj;
  80. private boolean isFirstInBlock;
  81. /** {@inheritDoc} */
  82. public void initialize() {
  83. textAlignment = fobj.getTextAlign();
  84. textAlignmentLast = fobj.getTextAlignLast();
  85. textIndent = fobj.getTextIndent();
  86. lastLineEndIndent = fobj.getLastLineEndIndent();
  87. hyphenationProperties = fobj.getCommonHyphenation();
  88. hyphenationLadderCount = fobj.getHyphenationLadderCount();
  89. wrapOption = fobj.getWrapOption();
  90. whiteSpaceTreament = fobj.getWhitespaceTreatment();
  91. //
  92. effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
  93. isFirstInBlock = (this == getParent().getChildLMs().get(0));
  94. }
  95. private int getEffectiveAlignment(int alignment, int alignmentLast) {
  96. if (textAlignment != EN_JUSTIFY && textAlignmentLast == EN_JUSTIFY) {
  97. return 0;
  98. } else {
  99. return textAlignment;
  100. }
  101. }
  102. /**
  103. * Private class to store information about inline breaks.
  104. * Each value holds the start and end indexes into a List of
  105. * inline break positions.
  106. */
  107. private static class LineBreakPosition extends LeafPosition {
  108. private int parIndex; // index of the Paragraph this Position refers to
  109. private int startIndex; //index of the first element this Position refers to
  110. private int availableShrink;
  111. private int availableStretch;
  112. private int difference;
  113. private double dAdjust; // Percentage to adjust (stretch or shrink)
  114. private double ipdAdjust; // Percentage to adjust (stretch or shrink)
  115. private int startIndent;
  116. private int lineHeight;
  117. private int lineWidth;
  118. private int spaceBefore;
  119. private int spaceAfter;
  120. private int baseline;
  121. LineBreakPosition(LayoutManager lm, int index, int startIndex, int breakIndex,
  122. int shrink, int stretch, int diff,
  123. double ipdA, double adjust, int ind,
  124. int lh, int lw, int sb, int sa, int bl) {
  125. super(lm, breakIndex);
  126. availableShrink = shrink;
  127. availableStretch = stretch;
  128. difference = diff;
  129. parIndex = index;
  130. this.startIndex = startIndex;
  131. ipdAdjust = ipdA;
  132. dAdjust = adjust;
  133. startIndent = ind;
  134. lineHeight = lh;
  135. lineWidth = lw;
  136. spaceBefore = sb;
  137. spaceAfter = sa;
  138. baseline = bl;
  139. }
  140. }
  141. private int textAlignment = EN_JUSTIFY;
  142. private int textAlignmentLast;
  143. private int effectiveAlignment;
  144. private Length textIndent;
  145. private Length lastLineEndIndent;
  146. private CommonHyphenation hyphenationProperties;
  147. private Numeric hyphenationLadderCount;
  148. private int wrapOption = EN_WRAP;
  149. private int whiteSpaceTreament;
  150. //private LayoutProps layoutProps;
  151. private Length lineHeight;
  152. private int lead;
  153. private int follow;
  154. private AlignmentContext alignmentContext;
  155. private List knuthParagraphs;
  156. private LineLayoutPossibilities lineLayouts;
  157. private List lineLayoutsList;
  158. private int ipd = 0;
  159. /**
  160. * this constant is used to create elements when text-align is center:
  161. * every TextLM descendant of LineLM must use the same value,
  162. * otherwise the line breaking algorithm does not find the right
  163. * break point
  164. */
  165. public static final int DEFAULT_SPACE_WIDTH = 3336;
  166. /**
  167. * This class is used to remember
  168. * which was the first element in the paragraph
  169. * returned by each LM.
  170. */
  171. private class Update {
  172. private InlineLevelLayoutManager inlineLM;
  173. private int iFirstIndex;
  174. public Update(InlineLevelLayoutManager lm, int index) {
  175. inlineLM = lm;
  176. iFirstIndex = index;
  177. }
  178. }
  179. // this class represents a paragraph
  180. private class Paragraph extends InlineKnuthSequence {
  181. /** Number of elements to ignore at the beginning of the list. */
  182. private int ignoreAtStart = 0;
  183. /** Number of elements to ignore at the end of the list. */
  184. private int ignoreAtEnd = 0;
  185. // space at the end of the last line (in millipoints)
  186. private MinOptMax lineFiller;
  187. private int textAlignment;
  188. private int textAlignmentLast;
  189. private int textIndent;
  190. private int lastLineEndIndent;
  191. // the LM which created the paragraph
  192. private LineLayoutManager layoutManager;
  193. Paragraph(LineLayoutManager llm, int alignment, int alignmentLast,
  194. int indent, int endIndent) {
  195. super();
  196. layoutManager = llm;
  197. textAlignment = alignment;
  198. textAlignmentLast = alignmentLast;
  199. textIndent = indent;
  200. lastLineEndIndent = endIndent;
  201. }
  202. public void startSequence() {
  203. // set the minimum amount of empty space at the end of the
  204. // last line
  205. if (textAlignment == EN_CENTER) {
  206. lineFiller = new MinOptMax(lastLineEndIndent);
  207. } else {
  208. lineFiller = new MinOptMax(lastLineEndIndent,
  209. lastLineEndIndent,
  210. layoutManager.ipd);
  211. }
  212. // add auxiliary elements at the beginning of the paragraph
  213. if (textAlignment == EN_CENTER && textAlignmentLast != EN_JUSTIFY) {
  214. this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
  215. null, false));
  216. ignoreAtStart++;
  217. }
  218. // add the element representing text indentation
  219. // at the beginning of the first paragraph
  220. if (isFirstInBlock && knuthParagraphs.size() == 0
  221. && textIndent != 0) {
  222. this.add(new KnuthInlineBox(textIndent, null,
  223. null, false));
  224. ignoreAtStart++;
  225. }
  226. }
  227. public void endParagraph() {
  228. KnuthSequence finishedPar = this.endSequence();
  229. if (finishedPar != null) {
  230. knuthParagraphs.add(finishedPar);
  231. }
  232. }
  233. public KnuthSequence endSequence() {
  234. if (this.size() > ignoreAtStart) {
  235. if (textAlignment == EN_CENTER
  236. && textAlignmentLast != EN_JUSTIFY) {
  237. this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
  238. null, false));
  239. this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
  240. false, null, false));
  241. ignoreAtEnd = 2;
  242. } else if (textAlignmentLast != EN_JUSTIFY) {
  243. // add the elements representing the space
  244. // at the end of the last line
  245. // and the forced break
  246. this.add(new KnuthPenalty(0, KnuthElement.INFINITE,
  247. false, null, false));
  248. this.add(new KnuthGlue(0,
  249. lineFiller.max - lineFiller.opt,
  250. lineFiller.opt - lineFiller.min, null, false));
  251. this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
  252. false, null, false));
  253. ignoreAtEnd = 3;
  254. } else {
  255. // add only the element representing the forced break
  256. this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
  257. false, null, false));
  258. ignoreAtEnd = 1;
  259. }
  260. return this;
  261. } else {
  262. this.clear();
  263. return null;
  264. }
  265. }
  266. /**
  267. * @return true if the sequence contains a box
  268. */
  269. public boolean containsBox() {
  270. for (int i = 0; i < this.size(); i++) {
  271. KnuthElement el = (KnuthElement)this.get(i);
  272. if (el.isBox()) {
  273. return true;
  274. }
  275. }
  276. return false;
  277. }
  278. }
  279. private class LineBreakingAlgorithm extends BreakingAlgorithm {
  280. private LineLayoutManager thisLLM;
  281. private int pageAlignment;
  282. private int activePossibility;
  283. private int addedPositions;
  284. private int textIndent;
  285. private int lineHeight;
  286. private int lead;
  287. private int follow;
  288. private static final double MAX_DEMERITS = 10e6;
  289. public LineBreakingAlgorithm (int pageAlign,
  290. int textAlign, int textAlignLast,
  291. int indent, int fillerWidth,
  292. int lh, int ld, int fl, boolean first,
  293. int maxFlagCount, LineLayoutManager llm) {
  294. super(textAlign, textAlignLast, first, false, maxFlagCount);
  295. pageAlignment = pageAlign;
  296. textIndent = indent;
  297. lineHeight = lh;
  298. lead = ld;
  299. follow = fl;
  300. thisLLM = llm;
  301. activePossibility = -1;
  302. }
  303. public void updateData1(int lineCount, double demerits) {
  304. lineLayouts.addPossibility(lineCount, demerits);
  305. if (log.isTraceEnabled()) {
  306. log.trace("Layout possibility in " + lineCount + " lines; break at position:");
  307. }
  308. }
  309. public void updateData2(KnuthNode bestActiveNode,
  310. KnuthSequence par,
  311. int total) {
  312. // compute indent and adjustment ratio, according to
  313. // the value of text-align and text-align-last
  314. int indent = 0;
  315. int difference = bestActiveNode.difference;
  316. int textAlign = (bestActiveNode.line < total) ? alignment : alignmentLast;
  317. indent += (textAlign == Constants.EN_CENTER)
  318. ? difference / 2 : (textAlign == Constants.EN_END) ? difference : 0;
  319. indent += (bestActiveNode.line == 1 && indentFirstPart && isFirstInBlock) ? textIndent : 0;
  320. double ratio = (textAlign == Constants.EN_JUSTIFY
  321. || difference < 0 && -difference <= bestActiveNode.availableShrink)
  322. ? bestActiveNode.adjustRatio : 0;
  323. // add nodes at the beginning of the list, as they are found
  324. // backwards, from the last one to the first one
  325. // the first time this method is called, initialize activePossibility
  326. if (activePossibility == -1) {
  327. activePossibility = 0;
  328. addedPositions = 0;
  329. }
  330. if (addedPositions == lineLayouts.getLineCount(activePossibility)) {
  331. activePossibility++;
  332. addedPositions = 0;
  333. }
  334. if (log.isWarnEnabled()) {
  335. int lack = difference + bestActiveNode.availableShrink;
  336. if (lack < 0) {
  337. InlineLevelEventProducer eventProducer
  338. = InlineLevelEventProducer.Provider.get(
  339. getFObj().getUserAgent().getEventBroadcaster());
  340. eventProducer.lineOverflows(this, bestActiveNode.line,
  341. -lack, getFObj().getLocator());
  342. }
  343. }
  344. //log.debug("LLM> (" + (lineLayouts.getLineNumber(activePossibility) - addedPositions)
  345. // + ") difference = " + difference + " ratio = " + ratio);
  346. lineLayouts.addBreakPosition(makeLineBreakPosition(par,
  347. (bestActiveNode.line > 1 ? bestActiveNode.previous.position + 1 : 0),
  348. bestActiveNode.position,
  349. bestActiveNode.availableShrink - (addedPositions > 0
  350. ? 0 : ((Paragraph)par).lineFiller.opt - ((Paragraph)par).lineFiller.min),
  351. bestActiveNode.availableStretch,
  352. difference, ratio, indent), activePossibility);
  353. addedPositions++;
  354. }
  355. /* reset activePossibility, as if breakpoints have not yet been computed
  356. */
  357. public void resetAlgorithm() {
  358. activePossibility = -1;
  359. }
  360. private LineBreakPosition makeLineBreakPosition(KnuthSequence par,
  361. int firstElementIndex,
  362. int lastElementIndex,
  363. int availableShrink,
  364. int availableStretch,
  365. int difference,
  366. double ratio,
  367. int indent) {
  368. // line height calculation - spaceBefore may differ from spaceAfter
  369. // by 1mpt due to rounding
  370. int spaceBefore = (lineHeight - lead - follow) / 2;
  371. int spaceAfter = lineHeight - lead - follow - spaceBefore;
  372. // height before the main baseline
  373. int lineLead = lead;
  374. // maximum follow
  375. int lineFollow = follow;
  376. // true if this line contains only zero-height, auxiliary boxes
  377. // and the actual line width is 0; in this case, the line "collapses"
  378. // i.e. the line area will have bpd = 0
  379. boolean bZeroHeightLine = (difference == ipd);
  380. // if line-stacking-strategy is "font-height", the line height
  381. // is not affected by its content
  382. if (fobj.getLineStackingStrategy() != EN_FONT_HEIGHT) {
  383. ListIterator inlineIterator
  384. = par.listIterator(firstElementIndex);
  385. AlignmentContext lastAC = null;
  386. int maxIgnoredHeight = 0; // See spec 7.13
  387. for (int j = firstElementIndex;
  388. j <= lastElementIndex;
  389. j++) {
  390. KnuthElement element = (KnuthElement) inlineIterator.next();
  391. if (element instanceof KnuthInlineBox ) {
  392. AlignmentContext ac = ((KnuthInlineBox) element).getAlignmentContext();
  393. if (ac != null && lastAC != ac) {
  394. if (!ac.usesInitialBaselineTable()
  395. || ac.getAlignmentBaselineIdentifier() != EN_BEFORE_EDGE
  396. && ac.getAlignmentBaselineIdentifier() != EN_AFTER_EDGE) {
  397. if (fobj.getLineHeightShiftAdjustment() == EN_CONSIDER_SHIFTS
  398. || ac.getBaselineShiftValue() == 0) {
  399. int alignmentOffset = ac.getTotalAlignmentBaselineOffset();
  400. if (alignmentOffset + ac.getAltitude() > lineLead) {
  401. lineLead = alignmentOffset + ac.getAltitude();
  402. }
  403. if (ac.getDepth() - alignmentOffset > lineFollow) {
  404. lineFollow = ac.getDepth() - alignmentOffset;
  405. }
  406. }
  407. } else {
  408. if (ac.getHeight() > maxIgnoredHeight) {
  409. maxIgnoredHeight = ac.getHeight();
  410. }
  411. }
  412. lastAC = ac;
  413. }
  414. if (bZeroHeightLine
  415. && (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) {
  416. bZeroHeightLine = false;
  417. }
  418. }
  419. }
  420. if (lineFollow < maxIgnoredHeight - lineLead) {
  421. lineFollow = maxIgnoredHeight - lineLead;
  422. }
  423. }
  424. constantLineHeight = lineLead + lineFollow;
  425. if (bZeroHeightLine) {
  426. return new LineBreakPosition(thisLLM,
  427. knuthParagraphs.indexOf(par),
  428. firstElementIndex, lastElementIndex,
  429. availableShrink, availableStretch,
  430. difference, ratio, 0, indent,
  431. 0, ipd, 0, 0, 0);
  432. } else {
  433. return new LineBreakPosition(thisLLM,
  434. knuthParagraphs.indexOf(par),
  435. firstElementIndex, lastElementIndex,
  436. availableShrink, availableStretch,
  437. difference, ratio, 0, indent,
  438. lineLead + lineFollow,
  439. ipd, spaceBefore, spaceAfter,
  440. lineLead);
  441. }
  442. }
  443. public int findBreakingPoints(Paragraph par, /*int lineWidth,*/
  444. double threshold, boolean force,
  445. int allowedBreaks) {
  446. return super.findBreakingPoints(par, /*lineWidth,*/
  447. threshold, force, allowedBreaks);
  448. }
  449. protected int filterActiveNodes() {
  450. KnuthNode bestActiveNode = null;
  451. if (pageAlignment == EN_JUSTIFY) {
  452. // leave all active nodes and find the optimum line number
  453. //log.debug("LBA.filterActiveNodes> " + activeNodeCount + " layouts");
  454. for (int i = startLine; i < endLine; i++) {
  455. for (KnuthNode node = getNode(i); node != null; node = node.next) {
  456. //log.debug(" + lines = " + node.line + " demerits = " + node.totalDemerits);
  457. bestActiveNode = compareNodes(bestActiveNode, node);
  458. }
  459. }
  460. // scan the node set once again and remove some nodes
  461. //log.debug("LBA.filterActiveList> layout selection");
  462. for (int i = startLine; i < endLine; i++) {
  463. for (KnuthNode node = getNode(i); node != null; node = node.next) {
  464. //if (Math.abs(node.line - bestActiveNode.line) > maxDiff) {
  465. //if (false) {
  466. if (node.line != bestActiveNode.line
  467. && node.totalDemerits > MAX_DEMERITS) {
  468. //log.debug(" XXX lines = " + node.line + " demerits = " + node.totalDemerits);
  469. removeNode(i, node);
  470. } else {
  471. //log.debug(" ok lines = " + node.line + " demerits = " + node.totalDemerits);
  472. }
  473. }
  474. }
  475. } else {
  476. // leave only the active node with fewest total demerits
  477. for (int i = startLine; i < endLine; i++) {
  478. for (KnuthNode node = getNode(i); node != null; node = node.next) {
  479. bestActiveNode = compareNodes(bestActiveNode, node);
  480. if (node != bestActiveNode) {
  481. removeNode(i, node);
  482. }
  483. }
  484. }
  485. }
  486. return bestActiveNode.line;
  487. }
  488. }
  489. private int constantLineHeight = 12000;
  490. /**
  491. * Create a new Line Layout Manager.
  492. * This is used by the block layout manager to create
  493. * line managers for handling inline areas flowing into line areas.
  494. * @param block the block formatting object
  495. * @param lh the default line height
  496. * @param l the default lead, from top to baseline
  497. * @param f the default follow, from baseline to bottom
  498. */
  499. public LineLayoutManager(Block block, Length lh, int l, int f) {
  500. super(block);
  501. fobj = block;
  502. // the child FObj are owned by the parent BlockLM
  503. // this LM has all its childLMs preloaded
  504. fobjIter = null;
  505. lineHeight = lh;
  506. lead = l;
  507. follow = f;
  508. }
  509. /** {@inheritDoc} */
  510. public List getNextKnuthElements(LayoutContext context, int alignment) {
  511. FontInfo fi = fobj.getFOEventHandler().getFontInfo();
  512. FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
  513. Font fs = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
  514. alignmentContext = new AlignmentContext(fs, lineHeight.getValue(this),
  515. context.getWritingMode());
  516. context.setAlignmentContext(alignmentContext);
  517. // Get a break from currently active child LM
  518. // Set up constraints for inline level managers
  519. //PHASE 1: Create Knuth elements
  520. if (knuthParagraphs == null) {
  521. // it's the first time this method is called
  522. knuthParagraphs = new ArrayList();
  523. // here starts Knuth's algorithm
  524. collectInlineKnuthElements(context);
  525. } else {
  526. // this method has been called before
  527. // all line breaks are already calculated
  528. }
  529. // return finished when there's no content
  530. if (knuthParagraphs.size() == 0) {
  531. setFinished(true);
  532. return null;
  533. }
  534. //PHASE 2: Create line breaks
  535. return createLineBreaks(context.getBPAlignment(), context);
  536. }
  537. /**
  538. * Phase 1 of Knuth algorithm: Collect all inline Knuth elements before determining line breaks.
  539. * @param context the LayoutContext
  540. */
  541. private void collectInlineKnuthElements(LayoutContext context) {
  542. LayoutContext inlineLC = new LayoutContext(context);
  543. ipd = context.getRefIPD();
  544. // convert all the text in a sequence of paragraphs made
  545. // of KnuthBox, KnuthGlue and KnuthPenalty objects
  546. boolean previousIsBox = false;
  547. StringBuffer trace = new StringBuffer("LineLM:");
  548. Paragraph lastPar = null;
  549. InlineLevelLayoutManager curLM;
  550. while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) {
  551. List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
  552. if (inlineElements == null || inlineElements.size() == 0) {
  553. /* curLM.getNextKnuthElements() returned null or an empty list;
  554. * this can happen if there is nothing more to layout,
  555. * so just iterate once more to see if there are other children */
  556. continue;
  557. }
  558. if (lastPar != null) {
  559. KnuthSequence firstSeq = (KnuthSequence) inlineElements.get(0);
  560. // finish last paragraph before a new block sequence
  561. if (!firstSeq.isInlineSequence()) {
  562. lastPar.endParagraph();
  563. ElementListObserver.observe(lastPar, "line", null);
  564. lastPar = null;
  565. if (log.isTraceEnabled()) {
  566. trace.append(" ]");
  567. }
  568. previousIsBox = false;
  569. }
  570. // does the first element of the first paragraph add to an existing word?
  571. if (lastPar != null) {
  572. KnuthElement thisElement;
  573. thisElement = (KnuthElement) firstSeq.get(0);
  574. if (thisElement.isBox() && !thisElement.isAuxiliary()
  575. && previousIsBox) {
  576. lastPar.addALetterSpace();
  577. }
  578. }
  579. }
  580. // loop over the KnuthSequences (and single KnuthElements) in returnedList
  581. ListIterator iter = inlineElements.listIterator();
  582. while (iter.hasNext()) {
  583. KnuthSequence sequence = (KnuthSequence) iter.next();
  584. // the sequence contains inline Knuth elements
  585. if (sequence.isInlineSequence()) {
  586. // look at the last element
  587. ListElement lastElement = sequence.getLast();
  588. assert lastElement != null;
  589. previousIsBox = lastElement.isBox()
  590. && !((KnuthElement) lastElement).isAuxiliary()
  591. && ((KnuthElement) lastElement).getW() != 0;
  592. // if last paragraph is open, add the new elements to the paragraph
  593. // else this is the last paragraph
  594. if (lastPar == null) {
  595. lastPar = new Paragraph(this,
  596. textAlignment, textAlignmentLast,
  597. textIndent.getValue(this),
  598. lastLineEndIndent.getValue(this));
  599. lastPar.startSequence();
  600. if (log.isTraceEnabled()) {
  601. trace.append(" [");
  602. }
  603. } else {
  604. if (log.isTraceEnabled()) {
  605. trace.append(" +");
  606. }
  607. }
  608. lastPar.addAll(sequence);
  609. if (log.isTraceEnabled()) {
  610. trace.append(" I");
  611. }
  612. // finish last paragraph if it was closed with a linefeed
  613. if (lastElement.isPenalty()
  614. && ((KnuthPenalty) lastElement).getP() == -KnuthPenalty.INFINITE) {
  615. // a penalty item whose value is -inf
  616. // represents a preserved linefeed,
  617. // which forces a line break
  618. lastPar.removeLast();
  619. if (!lastPar.containsBox()) {
  620. //only a forced linefeed on this line
  621. //-> compensate with an auxiliary glue
  622. lastPar.add(new KnuthGlue(ipd, 0, ipd, null, true));
  623. }
  624. lastPar.endParagraph();
  625. ElementListObserver.observe(lastPar, "line", null);
  626. lastPar = null;
  627. if (log.isTraceEnabled()) {
  628. trace.append(" ]");
  629. }
  630. previousIsBox = false;
  631. }
  632. } else { // the sequence is a block sequence
  633. // the positions will be wrapped with this LM in postProcessLineBreaks
  634. knuthParagraphs.add(sequence);
  635. if (log.isTraceEnabled()) {
  636. trace.append(" B");
  637. }
  638. }
  639. } // end of loop over returnedList
  640. }
  641. if (lastPar != null) {
  642. lastPar.endParagraph();
  643. ElementListObserver.observe(lastPar, "line", fobj.getId());
  644. if (log.isTraceEnabled()) {
  645. trace.append(" ]");
  646. }
  647. }
  648. log.trace(trace);
  649. }
  650. /**
  651. * Phase 2 of Knuth algorithm: find optimal break points.
  652. * @param alignment alignment in BP direction of the paragraph
  653. * @param context the layout context
  654. * @return a list of Knuth elements representing broken lines
  655. */
  656. private List createLineBreaks(int alignment, LayoutContext context) {
  657. // find the optimal line breaking points for each paragraph
  658. ListIterator paragraphsIterator = knuthParagraphs.listIterator(knuthParagraphs.size());
  659. lineLayoutsList = new ArrayList(knuthParagraphs.size());
  660. LineLayoutPossibilities llPoss;
  661. while (paragraphsIterator.hasPrevious()) {
  662. KnuthSequence seq = (KnuthSequence) paragraphsIterator.previous();
  663. if (!seq.isInlineSequence()) {
  664. // This set of line layout possibilities does not matter;
  665. // we only need an entry in lineLayoutsList.
  666. llPoss = new LineLayoutPossibilities();
  667. } else {
  668. llPoss = findOptimalBreakingPoints(alignment, (Paragraph) seq);
  669. }
  670. lineLayoutsList.add(0, llPoss);
  671. }
  672. setFinished(true);
  673. //Post-process the line breaks found
  674. return postProcessLineBreaks(alignment, context);
  675. }
  676. /**
  677. * Fint the optimal linebreaks for a paragraph
  678. * @param alignment alignment of the paragraph
  679. * @param currPar the Paragraph for which the linebreaks are found
  680. * @return the line layout possibilities for the paragraph
  681. */
  682. private LineLayoutPossibilities findOptimalBreakingPoints(int alignment, Paragraph currPar) {
  683. // use the member lineLayouts, which is read by LineBreakingAlgorithm.updateData1 and 2
  684. lineLayouts = new LineLayoutPossibilities();
  685. double maxAdjustment = 1;
  686. int iBPcount = 0;
  687. LineBreakingAlgorithm alg = new LineBreakingAlgorithm(alignment,
  688. textAlignment, textAlignmentLast,
  689. textIndent.getValue(this), currPar.lineFiller.opt,
  690. lineHeight.getValue(this), lead, follow,
  691. (knuthParagraphs.indexOf(currPar) == 0),
  692. hyphenationLadderCount.getEnum() == EN_NO_LIMIT
  693. ? 0 : hyphenationLadderCount.getValue(),
  694. this);
  695. if (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
  696. && fobj.getWrapOption() != EN_NO_WRAP) {
  697. findHyphenationPoints(currPar);
  698. }
  699. // first try
  700. int allowedBreaks;
  701. if (wrapOption == EN_NO_WRAP) {
  702. allowedBreaks = BreakingAlgorithm.ONLY_FORCED_BREAKS;
  703. } else {
  704. allowedBreaks = BreakingAlgorithm.NO_FLAGGED_PENALTIES;
  705. }
  706. alg.setConstantLineWidth(ipd);
  707. iBPcount = alg.findBreakingPoints(currPar,
  708. maxAdjustment, false, allowedBreaks);
  709. if (iBPcount == 0 || alignment == EN_JUSTIFY) {
  710. // if the first try found a set of breaking points, save them
  711. if (iBPcount > 0) {
  712. alg.resetAlgorithm();
  713. lineLayouts.savePossibilities(false);
  714. } else {
  715. // the first try failed
  716. log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment);
  717. }
  718. // now try something different
  719. log.debug("Hyphenation possible? " + (hyphenationProperties.hyphenate.getEnum() == EN_TRUE));
  720. if (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
  721. && !(allowedBreaks == BreakingAlgorithm.ONLY_FORCED_BREAKS)) {
  722. // consider every hyphenation point as a legal break
  723. allowedBreaks = BreakingAlgorithm.ALL_BREAKS;
  724. } else {
  725. // try with a higher threshold
  726. maxAdjustment = 5;
  727. }
  728. if ((iBPcount
  729. = alg.findBreakingPoints(currPar,
  730. maxAdjustment, false, allowedBreaks)) == 0) {
  731. // the second try failed too, try with a huge threshold
  732. // and force the algorithm to find
  733. // a set of breaking points
  734. if (log.isDebugEnabled()) {
  735. log.debug("No set of breaking points found with maxAdjustment = "
  736. + maxAdjustment
  737. + (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
  738. ? " and hyphenation" : ""));
  739. }
  740. maxAdjustment = 20;
  741. iBPcount
  742. = alg.findBreakingPoints(currPar,
  743. maxAdjustment, true, allowedBreaks);
  744. }
  745. // use non-hyphenated breaks, when possible
  746. lineLayouts.restorePossibilities();
  747. /* extension (not in the XSL FO recommendation): if vertical alignment
  748. is justify and the paragraph has only one layout, try using
  749. shorter or longer lines */
  750. //TODO This code snippet is disabled. Reenable?
  751. if (false && alignment == EN_JUSTIFY && textAlignment == EN_JUSTIFY) {
  752. //log.debug("LLM.getNextKnuthElements> layouts with more lines? " + lineLayouts.canUseMoreLines());
  753. //log.debug(" layouts with fewer lines? " + lineLayouts.canUseLessLines());
  754. if (!lineLayouts.canUseMoreLines()) {
  755. alg.resetAlgorithm();
  756. lineLayouts.savePossibilities(true);
  757. // try with shorter lines
  758. int savedLineWidth = ipd;
  759. ipd = (int) (ipd * 0.95);
  760. iBPcount = alg.findBreakingPoints(currPar,
  761. maxAdjustment, true, allowedBreaks);
  762. // use normal lines, when possible
  763. lineLayouts.restorePossibilities();
  764. ipd = savedLineWidth;
  765. }
  766. if (!lineLayouts.canUseLessLines()) {
  767. alg.resetAlgorithm();
  768. lineLayouts.savePossibilities(true);
  769. // try with longer lines
  770. int savedLineWidth = ipd;
  771. ipd = (int) (ipd * 1.05);
  772. alg.setConstantLineWidth(ipd);
  773. iBPcount = alg.findBreakingPoints(currPar,
  774. maxAdjustment, true, allowedBreaks);
  775. // use normal lines, when possible
  776. lineLayouts.restorePossibilities();
  777. ipd = savedLineWidth;
  778. }
  779. //log.debug("LLM.getNextKnuthElements> now, layouts with more lines? " + lineLayouts.canUseMoreLines());
  780. //log.debug(" now, layouts with fewer lines? " + lineLayouts.canUseLessLines());
  781. }
  782. }
  783. return lineLayouts;
  784. }
  785. /**
  786. * Creates the element list in BP direction for the broken lines.
  787. * @param alignment the currently applicable vertical alignment
  788. * @param context the layout context
  789. * @return the newly built element list
  790. */
  791. private List postProcessLineBreaks(int alignment, LayoutContext context) {
  792. List returnList = new LinkedList();
  793. for (int p = 0; p < knuthParagraphs.size(); p++) {
  794. // penalty between paragraphs
  795. if (p > 0) {
  796. Keep keep = getKeepTogether();
  797. returnList.add(new BreakElement(
  798. new Position(this),
  799. keep.getPenalty(),
  800. keep.getContext(),
  801. context));
  802. }
  803. LineLayoutPossibilities llPoss;
  804. llPoss = (LineLayoutPossibilities) lineLayoutsList.get(p);
  805. KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(p);
  806. if (!seq.isInlineSequence()) {
  807. List targetList = new LinkedList();
  808. ListIterator listIter = seq.listIterator();
  809. while (listIter.hasNext()) {
  810. ListElement tempElement;
  811. tempElement = (ListElement) listIter.next();
  812. if (tempElement.getLayoutManager() != this) {
  813. tempElement.setPosition(notifyPos(new NonLeafPosition(this,
  814. tempElement.getPosition())));
  815. }
  816. targetList.add(tempElement);
  817. }
  818. returnList.addAll(targetList);
  819. } else if (seq.isInlineSequence() && alignment == EN_JUSTIFY) {
  820. /* justified vertical alignment (not in the XSL FO recommendation):
  821. create a multi-layout sequence whose elements will contain
  822. a conventional Position */
  823. Position returnPosition = new LeafPosition(this, p);
  824. createElements(returnList, llPoss, returnPosition);
  825. } else {
  826. /* "normal" vertical alignment: create a sequence whose boxes
  827. represent effective lines, and contain LineBreakPositions */
  828. Position returnPosition = new LeafPosition(this, p);
  829. int startIndex = 0;
  830. for (int i = 0;
  831. i < llPoss.getChosenLineCount();
  832. i++) {
  833. if (returnList.size() > 0
  834. && i > 0 //if i==0 break generated above already
  835. && i >= fobj.getOrphans()
  836. && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
  837. // penalty allowing a page break between lines
  838. Keep keep = getKeepTogether();
  839. returnList.add(new BreakElement(
  840. new Position(this),
  841. keep.getPenalty(),
  842. keep.getContext(),
  843. context));
  844. }
  845. int endIndex
  846. = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
  847. // create a list of the FootnoteBodyLM handling footnotes
  848. // whose citations are in this line
  849. List footnoteList = new LinkedList();
  850. ListIterator elementIterator = seq.listIterator(startIndex);
  851. while (elementIterator.nextIndex() <= endIndex) {
  852. KnuthElement element = (KnuthElement) elementIterator.next();
  853. if (element instanceof KnuthInlineBox
  854. && ((KnuthInlineBox) element).isAnchor()) {
  855. footnoteList.add(((KnuthInlineBox) element).getFootnoteBodyLM());
  856. } else if (element instanceof KnuthBlockBox) {
  857. footnoteList.addAll(((KnuthBlockBox) element).getFootnoteBodyLMs());
  858. }
  859. }
  860. startIndex = endIndex + 1;
  861. LineBreakPosition lbp = (LineBreakPosition) llPoss.getChosenPosition(i);
  862. returnList.add(new KnuthBlockBox
  863. (lbp.lineHeight + lbp.spaceBefore + lbp.spaceAfter,
  864. footnoteList, lbp, false));
  865. /* // add stretch and shrink to the returnlist
  866. if (!seq.isInlineSequence()
  867. && lbp.availableStretch != 0 || lbp.availableShrink != 0) {
  868. returnList.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
  869. false, new Position(this), false));
  870. returnList.add(new KnuthGlue(0, lbp.availableStretch, lbp.availableShrink,
  871. new Position(this), false));
  872. }
  873. */
  874. }
  875. }
  876. }
  877. return returnList;
  878. }
  879. private void createElements(List list, LineLayoutPossibilities llPoss,
  880. Position elementPosition) {
  881. /* number of normal, inner lines */
  882. int nInnerLines = 0;
  883. /* number of lines that can be used in order to fill more space */
  884. int nOptionalLines = 0;
  885. /* number of lines that can be used in order to fill more space
  886. only if the paragraph is not parted */
  887. int nConditionalOptionalLines = 0;
  888. /* number of lines that can be omitted in order to fill less space */
  889. int nEliminableLines = 0;
  890. /* number of lines that can be omitted in order to fill less space
  891. only if the paragraph is not parted */
  892. int nConditionalEliminableLines = 0;
  893. /* number of the first unbreakable lines */
  894. int nFirstLines = fobj.getOrphans();
  895. /* number of the last unbreakable lines */
  896. int nLastLines = fobj.getWidows();
  897. /* sub-sequence used to separate the elements representing different lines */
  898. List breaker = new LinkedList();
  899. /* comment out the next lines in order to test particular situations */
  900. if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getMinLineCount()) {
  901. nInnerLines = llPoss.getMinLineCount()
  902. - (fobj.getOrphans() + fobj.getWidows());
  903. nOptionalLines = llPoss.getMaxLineCount()
  904. - llPoss.getOptLineCount();
  905. nEliminableLines = llPoss.getOptLineCount()
  906. - llPoss.getMinLineCount();
  907. } else if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getOptLineCount()) {
  908. nOptionalLines = llPoss.getMaxLineCount()
  909. - llPoss.getOptLineCount();
  910. nEliminableLines = llPoss.getOptLineCount()
  911. - (fobj.getOrphans() + fobj.getWidows());
  912. nConditionalEliminableLines = (fobj.getOrphans() + fobj.getWidows())
  913. - llPoss.getMinLineCount();
  914. } else if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getMaxLineCount()) {
  915. nOptionalLines = llPoss.getMaxLineCount()
  916. - (fobj.getOrphans() + fobj.getWidows());
  917. nConditionalOptionalLines = (fobj.getOrphans() + fobj.getWidows())
  918. - llPoss.getOptLineCount();
  919. nConditionalEliminableLines = llPoss.getOptLineCount()
  920. - llPoss.getMinLineCount();
  921. nFirstLines -= nConditionalOptionalLines;
  922. } else {
  923. nConditionalOptionalLines = llPoss.getMaxLineCount()
  924. - llPoss.getOptLineCount();
  925. nConditionalEliminableLines = llPoss.getOptLineCount()
  926. - llPoss.getMinLineCount();
  927. nFirstLines = llPoss.getOptLineCount();
  928. nLastLines = 0;
  929. }
  930. /* comment out the previous lines in order to test particular situations */
  931. /* use these lines to test particular situations
  932. nInnerLines = 0;
  933. nOptionalLines = 1;
  934. nConditionalOptionalLines = 2;
  935. nEliminableLines = 0;
  936. nConditionalEliminableLines = 0;
  937. nFirstLines = 1;
  938. nLastLines = 3;
  939. */
  940. if (nLastLines != 0
  941. && (nConditionalOptionalLines > 0 || nConditionalEliminableLines > 0)) {
  942. breaker.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, elementPosition, false));
  943. breaker.add(new KnuthGlue(0, -nConditionalOptionalLines * constantLineHeight,
  944. -nConditionalEliminableLines * constantLineHeight,
  945. LINE_NUMBER_ADJUSTMENT, elementPosition, false));
  946. breaker.add(new KnuthPenalty(nConditionalOptionalLines * constantLineHeight,
  947. 0, false, elementPosition, false));
  948. breaker.add(new KnuthGlue(0, nConditionalOptionalLines * constantLineHeight,
  949. nConditionalEliminableLines * constantLineHeight,
  950. LINE_NUMBER_ADJUSTMENT, elementPosition, false));
  951. } else if (nLastLines != 0) {
  952. breaker.add(new KnuthPenalty(0, 0, false, elementPosition, false));
  953. }
  954. //log.debug("first=" + nFirstLines + " inner=" + nInnerLines
  955. // + " optional=" + nOptionalLines + " eliminable=" + nEliminableLines
  956. // + " last=" + nLastLines
  957. // + " (condOpt=" + nConditionalOptionalLines + " condEl=" + nConditionalEliminableLines + ")");
  958. // creation of the elements:
  959. // first group of lines
  960. list.add(new KnuthBox(nFirstLines * constantLineHeight, elementPosition,
  961. (nLastLines == 0
  962. && nConditionalOptionalLines == 0
  963. && nConditionalEliminableLines == 0 ? true : false)));
  964. if (nConditionalOptionalLines > 0
  965. || nConditionalEliminableLines > 0) {
  966. list.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, elementPosition, false));
  967. list.add(new KnuthGlue(0, nConditionalOptionalLines * constantLineHeight,
  968. nConditionalEliminableLines * constantLineHeight,
  969. LINE_NUMBER_ADJUSTMENT, elementPosition, false));
  970. list.add(new KnuthBox(0, elementPosition,
  971. (nLastLines == 0 ? true : false)));
  972. }
  973. // optional lines
  974. for (int i = 0; i < nOptionalLines; i++) {
  975. list.addAll(breaker);
  976. list.add(new KnuthBox(0, elementPosition, false));
  977. list.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, elementPosition, false));
  978. list.add(new KnuthGlue(0, 1 * constantLineHeight, 0,
  979. LINE_NUMBER_ADJUSTMENT, elementPosition, false));
  980. list.add(new KnuthBox(0, elementPosition, false));
  981. }
  982. // eliminable lines
  983. for (int i = 0; i < nEliminableLines; i++) {
  984. list.addAll(breaker);
  985. list.add(new KnuthBox(1 * constantLineHeight, elementPosition, false));
  986. list.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, elementPosition, false));
  987. list.add(new KnuthGlue(0, 0, 1 * constantLineHeight,
  988. LINE_NUMBER_ADJUSTMENT, elementPosition, false));
  989. list.add(new KnuthBox(0, elementPosition, false));
  990. }
  991. // inner lines
  992. for (int i = 0; i < nInnerLines; i++) {
  993. list.addAll(breaker);
  994. list.add(new KnuthBox(1 * constantLineHeight, elementPosition, false));
  995. }
  996. // last group of lines
  997. if (nLastLines > 0) {
  998. list.addAll(breaker);
  999. list.add(new KnuthBox(nLastLines * constantLineHeight,
  1000. elementPosition, true));
  1001. }
  1002. }
  1003. /** {@inheritDoc} */
  1004. public boolean mustKeepTogether() {
  1005. return ((BlockLevelLayoutManager) getParent()).mustKeepTogether();
  1006. }
  1007. /** {@inheritDoc} */
  1008. public KeepProperty getKeepTogetherProperty() {
  1009. return ((BlockLevelLayoutManager) getParent()).getKeepTogetherProperty();
  1010. }
  1011. /** {@inheritDoc} */
  1012. public KeepProperty getKeepWithPreviousProperty() {
  1013. return ((BlockLevelLayoutManager) getParent()).getKeepWithPreviousProperty();
  1014. }
  1015. /** {@inheritDoc} */
  1016. public KeepProperty getKeepWithNextProperty() {
  1017. return ((BlockLevelLayoutManager) getParent()).getKeepWithNextProperty();
  1018. }
  1019. /** {@inheritDoc} */
  1020. public Keep getKeepTogether() {
  1021. return ((BlockLevelLayoutManager) getParent()).getKeepTogether();
  1022. }
  1023. /** {@inheritDoc} */
  1024. public boolean mustKeepWithPrevious() {
  1025. return !getKeepWithPrevious().isAuto();
  1026. }
  1027. /** {@inheritDoc} */
  1028. public boolean mustKeepWithNext() {
  1029. return !getKeepWithNext().isAuto();
  1030. }
  1031. /** {@inheritDoc} */
  1032. public Keep getKeepWithNext() {
  1033. return Keep.KEEP_AUTO;
  1034. }
  1035. /** {@inheritDoc} */
  1036. public Keep getKeepWithPrevious() {
  1037. return Keep.KEEP_AUTO;
  1038. }
  1039. /** {@inheritDoc} */
  1040. public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
  1041. LeafPosition pos = (LeafPosition)lastElement.getPosition();
  1042. int totalAdj = adj;
  1043. //if (lastElement.isPenalty()) {
  1044. // totalAdj += lastElement.getW();
  1045. //}
  1046. //int lineNumberDifference = (int)((double) totalAdj / constantLineHeight);
  1047. int lineNumberDifference = (int) Math.round((double) totalAdj / constantLineHeight
  1048. + (adj > 0 ? - 0.4 : 0.4));
  1049. //log.debug(" LLM> variazione calcolata = " + ((double) totalAdj / constantLineHeight) + " variazione applicata = " + lineNumberDifference);
  1050. LineLayoutPossibilities llPoss;
  1051. llPoss = (LineLayoutPossibilities) lineLayoutsList.get(pos.getLeafPos());
  1052. lineNumberDifference = llPoss.applyLineCountAdjustment(lineNumberDifference);
  1053. return lineNumberDifference * constantLineHeight;
  1054. }
  1055. /**
  1056. * {@inheritDoc}
  1057. */
  1058. public void discardSpace(KnuthGlue spaceGlue) {
  1059. }
  1060. /**
  1061. * {@inheritDoc}
  1062. */
  1063. public List getChangedKnuthElements(List oldList, int alignment) {
  1064. List returnList = new LinkedList();
  1065. for (int p = 0; p < knuthParagraphs.size(); p++) {
  1066. LineLayoutPossibilities llPoss;
  1067. llPoss = (LineLayoutPossibilities)lineLayoutsList.get(p);
  1068. //log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits());
  1069. for (int i = 0; i < llPoss.getChosenLineCount(); i++) {
  1070. if (!((BlockLevelLayoutManager) parentLM).mustKeepTogether()
  1071. && i >= fobj.getOrphans()
  1072. && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
  1073. // null penalty allowing a page break between lines
  1074. returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
  1075. }
  1076. LineBreakPosition lbp = (LineBreakPosition) llPoss.getChosenPosition(i);
  1077. //log.debug("LLM.getChangedKnuthElements> lineWidth= " + lbp.lineWidth + " difference= " + lbp.difference);
  1078. //log.debug(" shrink= " + lbp.availableShrink + " stretch= " + lbp.availableStretch);
  1079. //log.debug("linewidth= " + lbp.lineWidth + " difference= " + lbp.difference + " indent= " + lbp.startIndent);
  1080. MinOptMax contentIPD;
  1081. if (alignment == EN_JUSTIFY) {
  1082. contentIPD = new MinOptMax(
  1083. lbp.lineWidth - lbp.difference - lbp.availableShrink,
  1084. lbp.lineWidth - lbp.difference,
  1085. lbp.lineWidth - lbp.difference + lbp.availableStretch);
  1086. } else if (alignment == EN_CENTER) {
  1087. contentIPD = new MinOptMax(lbp.lineWidth - 2 * lbp.startIndent);
  1088. } else if (alignment == EN_END) {
  1089. contentIPD = new MinOptMax(lbp.lineWidth - lbp.startIndent);
  1090. } else {
  1091. contentIPD = new MinOptMax(lbp.lineWidth - lbp.difference + lbp.startIndent);
  1092. }
  1093. returnList.add(new KnuthBlockBox(lbp.lineHeight,
  1094. contentIPD,
  1095. (lbp.ipdAdjust != 0
  1096. ? lbp.lineWidth - lbp.difference : 0),
  1097. lbp, false));
  1098. }
  1099. }
  1100. return returnList;
  1101. }
  1102. /**
  1103. * find hyphenation points for every word int the current paragraph
  1104. * @ param currPar the paragraph whose words will be hyphenated
  1105. */
  1106. private void findHyphenationPoints(Paragraph currPar) {
  1107. // hyphenate every word
  1108. ListIterator currParIterator
  1109. = currPar.listIterator(currPar.ignoreAtStart);
  1110. // list of TLM involved in hyphenation
  1111. List updateList = new LinkedList();
  1112. KnuthElement firstElement = null;
  1113. KnuthElement nextElement = null;
  1114. // current InlineLevelLayoutManager
  1115. InlineLevelLayoutManager currLM = null;
  1116. // number of KnuthBox elements containing word fragments
  1117. int boxCount;
  1118. // number of auxiliary KnuthElements between KnuthBoxes
  1119. int auxCount;
  1120. StringBuffer sbChars = null;
  1121. // find all hyphenation points
  1122. while (currParIterator.hasNext()) {
  1123. firstElement = (KnuthElement) currParIterator.next();
  1124. //
  1125. if (firstElement.getLayoutManager() != currLM) {
  1126. currLM = (InlineLevelLayoutManager) firstElement.getLayoutManager();
  1127. if (currLM != null) {
  1128. updateList.add(new Update(currLM, currParIterator.previousIndex()));
  1129. } else {
  1130. break;
  1131. }
  1132. } else if (currLM == null) {
  1133. break;
  1134. }
  1135. //TODO Something's not right here. See block_hyphenation_linefeed_preserve.xml
  1136. //for more info: see also https://issues.apache.org/bugzilla/show_bug.cgi?id=38264
  1137. // collect word fragments, ignoring auxiliary elements;
  1138. // each word fragment was created by a different TextLM
  1139. if (firstElement.isBox() && !firstElement.isAuxiliary()) {
  1140. boxCount = 1;
  1141. auxCount = 0;
  1142. sbChars = new StringBuffer();
  1143. currLM.getWordChars(sbChars, firstElement.getPosition());
  1144. // look if next elements are boxes too
  1145. while (currParIterator.hasNext()) {
  1146. nextElement = (KnuthElement) currParIterator.next();
  1147. if (nextElement.isBox() && !nextElement.isAuxiliary()) {
  1148. // a non-auxiliary KnuthBox: append word chars
  1149. if (currLM != nextElement.getLayoutManager()) {
  1150. currLM = (InlineLevelLayoutManager) nextElement.getLayoutManager();
  1151. updateList.add(new Update(currLM, currParIterator.previousIndex()));
  1152. }
  1153. // append text to recreate the whole word
  1154. boxCount++;
  1155. currLM.getWordChars(sbChars, nextElement.getPosition());
  1156. } else if (!nextElement.isAuxiliary()) {
  1157. // a non-auxiliary non-box KnuthElement: stop
  1158. // go back to the last box or auxiliary element
  1159. currParIterator.previous();
  1160. break;
  1161. } else {
  1162. if (currLM != nextElement.getLayoutManager()) {
  1163. currLM = (InlineLevelLayoutManager) nextElement.getLayoutManager();
  1164. updateList.add(new Update(currLM, currParIterator.previousIndex()));
  1165. }
  1166. // an auxiliary KnuthElement: simply ignore it
  1167. auxCount++;
  1168. }
  1169. }
  1170. if (log.isTraceEnabled()) {
  1171. log.trace(" Word to hyphenate: " + sbChars.toString());
  1172. }
  1173. // find hyphenation points
  1174. HyphContext hc = getHyphenContext(sbChars);
  1175. // ask each LM to hyphenate its word fragment
  1176. if (hc != null) {
  1177. KnuthElement element = null;
  1178. for (int i = 0; i < (boxCount + auxCount); i++) {
  1179. currParIterator.previous();
  1180. }
  1181. for (int i = 0; i < (boxCount + auxCount); i++) {
  1182. element = (KnuthElement) currParIterator.next();
  1183. if (element.isBox() && !element.isAuxiliary()) {
  1184. ((InlineLevelLayoutManager)
  1185. element.getLayoutManager()).hyphenate(element.getPosition(), hc);
  1186. } else {
  1187. // nothing to do, element is an auxiliary KnuthElement
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. // create iterator for the updateList
  1194. ListIterator updateListIterator = updateList.listIterator();
  1195. Update currUpdate = null;
  1196. //int iPreservedElements = 0;
  1197. int iAddedElements = 0;
  1198. //int iRemovedElements = 0;
  1199. while (updateListIterator.hasNext()) {
  1200. // ask the LMs to apply the changes and return
  1201. // the new KnuthElements to replace the old ones
  1202. currUpdate = (Update) updateListIterator.next();
  1203. int fromIndex = currUpdate.iFirstIndex;
  1204. int toIndex;
  1205. if (updateListIterator.hasNext()) {
  1206. Update nextUpdate = (Update) updateListIterator.next();
  1207. toIndex = nextUpdate.iFirstIndex;
  1208. updateListIterator.previous();
  1209. } else {
  1210. // maybe this is not always correct!
  1211. toIndex = currPar.size() - currPar.ignoreAtEnd
  1212. - iAddedElements;
  1213. }
  1214. // applyChanges() returns true if the LM modifies its data,
  1215. // so it must return new KnuthElements to replace the old ones
  1216. if (((InlineLevelLayoutManager) currUpdate.inlineLM)
  1217. .applyChanges(currPar.subList(fromIndex + iAddedElements,
  1218. toIndex + iAddedElements))) {
  1219. // insert the new KnuthElements
  1220. List newElements = null;
  1221. newElements
  1222. = currUpdate.inlineLM.getChangedKnuthElements
  1223. (currPar.subList(fromIndex + iAddedElements,
  1224. toIndex + iAddedElements),
  1225. /*flaggedPenalty,*/ effectiveAlignment);
  1226. // remove the old elements
  1227. currPar.subList(fromIndex + iAddedElements,
  1228. toIndex + iAddedElements).clear();
  1229. // insert the new elements
  1230. currPar.addAll(fromIndex + iAddedElements, newElements);
  1231. iAddedElements += newElements.size() - (toIndex - fromIndex);
  1232. }
  1233. }
  1234. updateListIterator = null;
  1235. updateList.clear();
  1236. }
  1237. /**
  1238. * Line area is always considered to act as a fence.
  1239. * @param isNotFirst ignored
  1240. * @return always true
  1241. */
  1242. protected boolean hasLeadingFence(boolean isNotFirst) {
  1243. return true;
  1244. }
  1245. /**
  1246. * Line area is always considered to act as a fence.
  1247. * @param isNotLast ignored
  1248. * @return always true
  1249. */
  1250. protected boolean hasTrailingFence(boolean isNotLast) {
  1251. return true;
  1252. }
  1253. private HyphContext getHyphenContext(StringBuffer sbChars) {
  1254. // Find all hyphenation points in this word
  1255. // (get in an array of offsets)
  1256. // hyphenationProperties are from the block level?.
  1257. // Note that according to the spec,
  1258. // they also "apply to" fo:character.
  1259. // I don't know what that means, since
  1260. // if we change language in the middle of a "word",
  1261. // the effect would seem quite strange!
  1262. // Or perhaps in that case, we say that it's several words.
  1263. // We probably should bring the hyphenation props up from the actual
  1264. // TextLM which generate the hyphenation buffer,
  1265. // since these properties inherit and could be specified
  1266. // on an inline or wrapper below the block level.
  1267. Hyphenation hyph
  1268. = Hyphenator.hyphenate(hyphenationProperties.language.getString(),
  1269. hyphenationProperties.country.getString(),
  1270. getFObj().getUserAgent().getFactory().getHyphenationTreeResolver(),
  1271. sbChars.toString(),
  1272. hyphenationProperties.hyphenationRemainCharacterCount.getValue(),
  1273. hyphenationProperties.hyphenationPushCharacterCount.getValue());
  1274. // They hyph structure contains the information we need
  1275. // Now start from prev: reset to that position, ask that LM to get
  1276. // a Position for the first hyphenation offset. If the offset isn't in
  1277. // its characters, it returns null,
  1278. // but must tell how many chars it had.
  1279. // Keep looking at currentBP using next hyphenation point until the
  1280. // returned size is greater than the available size
  1281. // or no more hyphenation points remain. Choose the best break.
  1282. if (hyph != null) {
  1283. return new HyphContext(hyph.getHyphenationPoints());
  1284. } else {
  1285. return null;
  1286. }
  1287. }
  1288. /**
  1289. * Add the areas with the break points.
  1290. *
  1291. * @param parentIter the iterator of break positions
  1292. * @param context the context for adding areas
  1293. */
  1294. public void addAreas(PositionIterator parentIter,
  1295. LayoutContext context) {
  1296. while (parentIter.hasNext()) {
  1297. Position pos = (Position) parentIter.next();
  1298. boolean isLastPosition = !parentIter.hasNext();
  1299. if (pos instanceof LineBreakPosition) {
  1300. addInlineArea(context, (LineBreakPosition) pos, isLastPosition);
  1301. } else if ((pos instanceof NonLeafPosition) && pos.generatesAreas()) {
  1302. addBlockArea(context, pos, isLastPosition);
  1303. } else {
  1304. /*
  1305. * pos was the Position inside a penalty item, nothing to do;
  1306. * or Pos does not generate an area,
  1307. * i.e. it stand for spaces, borders and padding.
  1308. */
  1309. }
  1310. }
  1311. setCurrentArea(null); // ?? necessary
  1312. }
  1313. /**
  1314. * Add a line with inline content
  1315. * @param context the context for adding areas
  1316. * @param pos the position for which the line is generated
  1317. * @param isLastPosition true if this is the last position of this LM
  1318. */
  1319. private void addInlineArea(LayoutContext context, LineBreakPosition lbp,
  1320. boolean isLastPosition) {
  1321. // the TLM which created the last KnuthElement in this line
  1322. LayoutManager lastLM = null;
  1323. KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(lbp.parIndex);
  1324. int startElementIndex = lbp.startIndex;
  1325. int endElementIndex = lbp.getLeafPos();
  1326. LineArea lineArea = new LineArea(
  1327. (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
  1328. lbp.difference, lbp.availableStretch, lbp.availableShrink);
  1329. if (lbp.startIndent != 0) {
  1330. lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
  1331. }
  1332. lineArea.setBPD(lbp.lineHeight);
  1333. lineArea.setIPD(lbp.lineWidth);
  1334. lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
  1335. lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
  1336. alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
  1337. if (seq instanceof Paragraph) {
  1338. Paragraph currPar = (Paragraph) seq;
  1339. // ignore the first elements added by the LineLayoutManager
  1340. startElementIndex += (startElementIndex == 0) ? currPar.ignoreAtStart : 0;
  1341. // if this is the last line area that for this paragraph,
  1342. // ignore the last elements added by the LineLayoutManager and
  1343. // subtract the last-line-end-indent from the area ipd
  1344. if (endElementIndex == (currPar.size() - 1)) {
  1345. endElementIndex -= currPar.ignoreAtEnd;
  1346. lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
  1347. }
  1348. }
  1349. // Remove trailing spaces if allowed so
  1350. if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
  1351. || whiteSpaceTreament == EN_IGNORE
  1352. || whiteSpaceTreament == EN_IGNORE_IF_BEFORE_LINEFEED) {
  1353. // ignore the last element in the line if it is a KnuthGlue object
  1354. ListIterator seqIterator = seq.listIterator(endElementIndex);
  1355. KnuthElement lastElement = (KnuthElement) seqIterator.next();
  1356. lastLM = lastElement.getLayoutManager();
  1357. if (lastElement.isGlue()) {
  1358. endElementIndex--;
  1359. // this returns the same KnuthElement
  1360. seqIterator.previous();
  1361. if (seqIterator.hasPrevious()) {
  1362. lastLM = ((KnuthElement) seqIterator.previous()).getLayoutManager();
  1363. }
  1364. }
  1365. }
  1366. // Remove leading spaces if allowed so
  1367. if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
  1368. || whiteSpaceTreament == EN_IGNORE
  1369. || whiteSpaceTreament == EN_IGNORE_IF_AFTER_LINEFEED) {
  1370. // ignore KnuthGlue and KnuthPenalty objects
  1371. // at the beginning of the line
  1372. ListIterator seqIterator = seq.listIterator(startElementIndex);
  1373. while (seqIterator.hasNext() && !((KnuthElement) seqIterator.next()).isBox()) {
  1374. startElementIndex++;
  1375. }
  1376. }
  1377. // Add the inline areas to lineArea
  1378. PositionIterator inlinePosIter = new KnuthPossPosIter(seq, startElementIndex,
  1379. endElementIndex + 1);
  1380. LayoutContext lc = new LayoutContext(0);
  1381. lc.setAlignmentContext(alignmentContext);
  1382. lc.setSpaceAdjust(lbp.dAdjust);
  1383. lc.setIPDAdjust(lbp.ipdAdjust);
  1384. lc.setLeadingSpace(new SpaceSpecifier(true));
  1385. lc.setTrailingSpace(new SpaceSpecifier(false));
  1386. lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
  1387. /*
  1388. * extension (not in the XSL FO recommendation): if the left and right margins
  1389. * have been optimized, recompute indents and / or adjust ratio, according
  1390. * to the paragraph horizontal alignment
  1391. */
  1392. if (false && textAlignment == EN_JUSTIFY) {
  1393. // re-compute space adjust ratio
  1394. int updatedDifference = context.getRefIPD()
  1395. - lbp.lineWidth + lbp.difference;
  1396. double updatedRatio = 0.0;
  1397. if (updatedDifference > 0) {
  1398. updatedRatio = (float) updatedDifference / lbp.availableStretch;
  1399. } else if (updatedDifference < 0) {
  1400. updatedRatio = (float) updatedDifference / lbp.availableShrink;
  1401. }
  1402. lc.setIPDAdjust(updatedRatio);
  1403. //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
  1404. //log.debug(" old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
  1405. } else if (false && textAlignment == EN_CENTER) {
  1406. // re-compute indent
  1407. int updatedIndent = lbp.startIndent
  1408. + (context.getRefIPD() - lbp.lineWidth) / 2;
  1409. lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
  1410. } else if (false && textAlignment == EN_END) {
  1411. // re-compute indent
  1412. int updatedIndent = lbp.startIndent
  1413. + (context.getRefIPD() - lbp.lineWidth);
  1414. lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
  1415. }
  1416. setCurrentArea(lineArea);
  1417. setChildContext(lc);
  1418. LayoutManager childLM;
  1419. while ((childLM = inlinePosIter.getNextChildLM()) != null) {
  1420. lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
  1421. childLM.addAreas(inlinePosIter, lc);
  1422. lc.setLeadingSpace(lc.getTrailingSpace());
  1423. lc.setTrailingSpace(new SpaceSpecifier(false));
  1424. }
  1425. // if display-align is distribute, add space after
  1426. if (context.getSpaceAfter() > 0
  1427. && (!context.isLastArea() || !isLastPosition)) {
  1428. lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
  1429. }
  1430. lineArea.finalise();
  1431. parentLM.addChildArea(lineArea);
  1432. }
  1433. /**
  1434. * Add a line with block content
  1435. * @param context the context for adding areas
  1436. * @param pos the position for which the line is generated
  1437. * @param isLastPosition true if this is the last position of this LM
  1438. */
  1439. private void addBlockArea(LayoutContext context, Position pos, boolean isLastPosition) {
  1440. /* Nested block-level content;
  1441. * go down the LM stack again;
  1442. * "unwrap" the positions and put the child positions in a new list.
  1443. * The positionList must contain one area-generating position,
  1444. * which creates one line area.
  1445. */
  1446. List positionList = new ArrayList(1);
  1447. Position innerPosition;
  1448. innerPosition = ((NonLeafPosition) pos).getPosition();
  1449. positionList.add(innerPosition);
  1450. // do we have the last LM?
  1451. LayoutManager lastLM = null;
  1452. if (isLastPosition) {
  1453. lastLM = innerPosition.getLM();
  1454. }
  1455. LineArea lineArea = new LineArea();
  1456. setCurrentArea(lineArea);
  1457. LayoutContext lc = new LayoutContext(0);
  1458. lc.setAlignmentContext(alignmentContext);
  1459. setChildContext(lc);
  1460. PositionIterator childPosIter = new StackingIter(positionList.listIterator());
  1461. LayoutContext blocklc = new LayoutContext(0);
  1462. blocklc.setLeadingSpace(new SpaceSpecifier(true));
  1463. blocklc.setTrailingSpace(new SpaceSpecifier(false));
  1464. blocklc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
  1465. LayoutManager childLM;
  1466. while ((childLM = childPosIter.getNextChildLM()) != null) {
  1467. // set last area flag
  1468. blocklc.setFlags(LayoutContext.LAST_AREA,
  1469. (context.isLastArea() && childLM == lastLM));
  1470. blocklc.setStackLimitBP(context.getStackLimitBP());
  1471. // Add the line areas to Area
  1472. childLM.addAreas(childPosIter, blocklc);
  1473. blocklc.setLeadingSpace(blocklc.getTrailingSpace());
  1474. blocklc.setTrailingSpace(new SpaceSpecifier(false));
  1475. }
  1476. lineArea.updateExtentsFromChildren();
  1477. parentLM.addChildArea(lineArea);
  1478. }
  1479. /**
  1480. * {@inheritDoc}
  1481. */
  1482. public void addChildArea(Area childArea) {
  1483. // Make sure childArea is inline area
  1484. if (childArea instanceof InlineArea) {
  1485. Area parent = getCurrentArea();
  1486. if (getContext().resolveLeadingSpace()) {
  1487. addSpace(parent,
  1488. getContext().getLeadingSpace().resolve(false),
  1489. getContext().getSpaceAdjust());
  1490. }
  1491. parent.addChildArea(childArea);
  1492. }
  1493. }
  1494. // --------- Property Resolution related functions --------- //
  1495. /**
  1496. * {@inheritDoc}
  1497. */
  1498. public boolean getGeneratesBlockArea() {
  1499. return true;
  1500. }
  1501. /**
  1502. * {@inheritDoc}
  1503. */
  1504. public boolean getGeneratesLineArea() {
  1505. return true;
  1506. }
  1507. }