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

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