@@ -168,35 +168,16 @@ public void addChild(IRenderer renderer) {
168
168
}
169
169
} else {
170
170
if (currentArea .isEmptyArea () && result .getAreaBreak () == null ) {
171
- if (Boolean .TRUE .equals (result .getOverflowRenderer ().getModelElement ().<Boolean >getProperty (Property .KEEP_TOGETHER ))) {
172
- result .getOverflowRenderer ().getModelElement ().setProperty (Property .KEEP_TOGETHER , false );
173
- Logger logger = LoggerFactory .getLogger (RootRenderer .class );
174
- logger .warn (MessageFormatUtil .format (LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , "KeepTogether property will be ignored." ));
175
- if (!rendererIsFloat ) {
176
- rootRendererStateHandler .attemptGoBackToStoredPreviousStateAndStoreNextState (this );
177
- }
178
- } else if (null != result .getCauseOfNothing () && Boolean .TRUE .equals (result .getCauseOfNothing ().<Boolean >getProperty (Property .KEEP_TOGETHER ))) {
179
- // set KEEP_TOGETHER false on the deepest parent (maybe the element itself) to have KEEP_TOGETHER == true
180
- IRenderer theDeepestKeptTogether = result .getCauseOfNothing ();
181
- IRenderer parent ;
182
- while (null == theDeepestKeptTogether .getModelElement () || null == theDeepestKeptTogether .getModelElement ().<Boolean >getOwnProperty (Property .KEEP_TOGETHER )) {
183
- parent = ((AbstractRenderer ) theDeepestKeptTogether ).parent ;
184
- if (parent == null ) {
185
- break ;
186
- }
187
- theDeepestKeptTogether = parent ;
188
- }
189
- theDeepestKeptTogether .getModelElement ().setProperty (Property .KEEP_TOGETHER , false );
190
- Logger logger = LoggerFactory .getLogger (RootRenderer .class );
191
- logger .warn (MessageFormatUtil .format (LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , "KeepTogether property of inner element will be ignored." ));
192
- if (!rendererIsFloat ) {
193
- rootRendererStateHandler .attemptGoBackToStoredPreviousStateAndStoreNextState (this );
194
- }
195
- } else if (!Boolean .TRUE .equals (renderer .<Boolean >getProperty (Property .FORCED_PLACEMENT ))) {
196
- result .getOverflowRenderer ().setProperty (Property .FORCED_PLACEMENT , true );
197
- Logger logger = LoggerFactory .getLogger (RootRenderer .class );
198
- logger .warn (MessageFormatUtil .format (LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , "" ));
199
- } else {
171
+ boolean keepTogetherChanged = tryDisableKeepTogether (result ,
172
+ rendererIsFloat , rootRendererStateHandler );
173
+
174
+ boolean areKeepTogetherAndForcedPlacementBothNotChanged = !keepTogetherChanged ;
175
+ if (areKeepTogetherAndForcedPlacementBothNotChanged ) {
176
+ areKeepTogetherAndForcedPlacementBothNotChanged =
177
+ ! updateForcedPlacement (renderer , result .getOverflowRenderer ());
178
+ }
179
+
180
+ if (areKeepTogetherAndForcedPlacementBothNotChanged ) {
200
181
// FORCED_PLACEMENT was already set to the renderer and
201
182
// LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA message was logged.
202
183
// This else-clause should never be hit, otherwise there is a bug in FORCED_PLACEMENT implementation.
@@ -490,4 +471,51 @@ private void addWaitingNextPageRenderers() {
490
471
addChild (renderer );
491
472
}
492
473
}
474
+
475
+ private boolean updateForcedPlacement (IRenderer currentRenderer , IRenderer overflowRenderer ) {
476
+ if (Boolean .TRUE .equals (currentRenderer .<Boolean >getProperty (Property .FORCED_PLACEMENT ))) {
477
+ return false ;
478
+ } else {
479
+ overflowRenderer .setProperty (Property .FORCED_PLACEMENT , true );
480
+ Logger logger = LoggerFactory .getLogger (RootRenderer .class );
481
+ if (logger .isWarnEnabled ()) {
482
+ logger .warn (MessageFormatUtil .format (LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , "" ));
483
+ }
484
+ return true ;
485
+ }
486
+ }
487
+
488
+ private boolean tryDisableKeepTogether (LayoutResult result ,
489
+ boolean rendererIsFloat , RootRendererAreaStateHandler rootRendererStateHandler ) {
490
+ IRenderer toDisableKeepTogether = null ;
491
+
492
+ // looking for the most outer keep together element
493
+ IRenderer current = result .getCauseOfNothing ();
494
+ while (current != null ) {
495
+ if (Boolean .TRUE .equals (current .<Boolean >getProperty (Property .KEEP_TOGETHER ))) {
496
+ toDisableKeepTogether = current ;
497
+ }
498
+ current = current .getParent ();
499
+ }
500
+
501
+ if (toDisableKeepTogether == null ) {
502
+ return false ;
503
+ }
504
+
505
+ // Ideally the disabling of keep together property should be done on the renderers layer,
506
+ // but due to the problem with renderers tree (parent links from causeOfNothing
507
+ // may not lead to overflowRenderer) such approach does not work now. So we
508
+ // disabling keep together on the models layer.
509
+ toDisableKeepTogether .getModelElement ().setProperty (Property .KEEP_TOGETHER , false );
510
+ Logger logger = LoggerFactory .getLogger (RootRenderer .class );
511
+ if (logger .isWarnEnabled ()) {
512
+ logger .warn (MessageFormatUtil .format (
513
+ LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA ,
514
+ "KeepTogether property will be ignored." ));
515
+ }
516
+ if (!rendererIsFloat ) {
517
+ rootRendererStateHandler .attemptGoBackToStoredPreviousStateAndStoreNextState (this );
518
+ }
519
+ return true ;
520
+ }
493
521
}
0 commit comments