@@ -188,8 +188,8 @@ public virtual void EndChildMarginsHandling(Rectangle layoutBox) {
188
188
}
189
189
190
190
public virtual void StartMarginsCollapse ( Rectangle parentBBox ) {
191
- collapseInfo . GetCollapseBefore ( ) . JoinMargin ( GetModelTopMargin ( renderer ) ) ;
192
- collapseInfo . GetCollapseAfter ( ) . JoinMargin ( GetModelBottomMargin ( renderer ) ) ;
191
+ collapseInfo . GetCollapseBefore ( ) . JoinMargin ( DefineTopMarginValueForCollapse ( renderer ) ) ;
192
+ collapseInfo . GetCollapseAfter ( ) . JoinMargin ( DefineBottomMarginValueForCollapse ( renderer ) ) ;
193
193
if ( ! FirstChildMarginAdjoinedToParent ( renderer ) ) {
194
194
float topIndent = collapseInfo . GetCollapseBefore ( ) . GetCollapsedMarginsSize ( ) ;
195
195
ApplyTopMargin ( parentBBox , topIndent ) ;
@@ -231,7 +231,7 @@ public virtual void EndMarginsCollapse(Rectangle layoutBox) {
231
231
else {
232
232
ownCollapseAfter = new MarginsCollapse ( ) ;
233
233
}
234
- ownCollapseAfter . JoinMargin ( GetModelBottomMargin ( renderer ) ) ;
234
+ ownCollapseAfter . JoinMargin ( DefineBottomMarginValueForCollapse ( renderer ) ) ;
235
235
collapseInfo . SetOwnCollapseAfter ( ownCollapseAfter ) ;
236
236
if ( collapseInfo . IsSelfCollapsing ( ) ) {
237
237
if ( prevChildMarginInfo != null ) {
@@ -509,33 +509,19 @@ private static bool HasPositiveHeight(IRenderer renderer) {
509
509
}
510
510
511
511
private static bool HasTopPadding ( IRenderer renderer ) {
512
- UnitValue padding = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( Property . PADDING_TOP ) ;
513
- if ( null != padding && ! padding . IsPointValue ( ) ) {
514
- ILogger logger = ITextLogManager . GetLogger ( typeof ( iText . Layout . Margincollapse . MarginsCollapseHandler ) ) ;
515
- logger . LogError ( MessageFormatUtil . Format ( iText . IO . Logs . IoLogMessageConstant . PROPERTY_IN_PERCENTS_NOT_SUPPORTED
516
- , Property . PADDING_TOP ) ) ;
517
- }
518
- return padding != null && padding . GetValue ( ) > 0 ;
512
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . HasPadding ( renderer , Property . PADDING_TOP ) ;
519
513
}
520
514
521
515
private static bool HasBottomPadding ( IRenderer renderer ) {
522
- UnitValue padding = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( Property . PADDING_BOTTOM ) ;
523
- if ( null != padding && ! padding . IsPointValue ( ) ) {
524
- ILogger logger = ITextLogManager . GetLogger ( typeof ( iText . Layout . Margincollapse . MarginsCollapseHandler ) ) ;
525
- logger . LogError ( MessageFormatUtil . Format ( iText . IO . Logs . IoLogMessageConstant . PROPERTY_IN_PERCENTS_NOT_SUPPORTED
526
- , Property . PADDING_BOTTOM ) ) ;
527
- }
528
- return padding != null && padding . GetValue ( ) > 0 ;
516
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . HasPadding ( renderer , Property . PADDING_BOTTOM ) ;
529
517
}
530
518
531
519
private static bool HasTopBorders ( IRenderer renderer ) {
532
- IPropertyContainer modelElement = renderer . GetModelElement ( ) ;
533
- return modelElement . HasProperty ( Property . BORDER_TOP ) || modelElement . HasProperty ( Property . BORDER ) ;
520
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . HasBorders ( renderer , Property . BORDER_TOP ) ;
534
521
}
535
522
536
523
private static bool HasBottomBorders ( IRenderer renderer ) {
537
- IPropertyContainer modelElement = renderer . GetModelElement ( ) ;
538
- return modelElement . HasProperty ( Property . BORDER_BOTTOM ) || modelElement . HasProperty ( Property . BORDER ) ;
524
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . HasBorders ( renderer , Property . BORDER_BOTTOM ) ;
539
525
}
540
526
541
527
private static bool RendererIsFloated ( IRenderer renderer ) {
@@ -546,42 +532,61 @@ private static bool RendererIsFloated(IRenderer renderer) {
546
532
return floatPropertyValue != null && ! floatPropertyValue . Equals ( FloatPropertyValue . NONE ) ;
547
533
}
548
534
549
- private static float GetModelTopMargin ( IRenderer renderer ) {
550
- UnitValue marginUV = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( Property . MARGIN_TOP ) ;
551
- if ( null != marginUV && ! marginUV . IsPointValue ( ) ) {
552
- ILogger logger = ITextLogManager . GetLogger ( typeof ( iText . Layout . Margincollapse . MarginsCollapseHandler ) ) ;
553
- logger . LogError ( MessageFormatUtil . Format ( iText . IO . Logs . IoLogMessageConstant . PROPERTY_IN_PERCENTS_NOT_SUPPORTED
554
- , Property . MARGIN_TOP ) ) ;
555
- }
556
- // TODO Concerning "renderer instanceof CellRenderer" check: may be try to apply more general solution in future
557
- return marginUV != null && ! ( renderer is CellRenderer ) ? marginUV . GetValue ( ) : 0 ;
535
+ private static float DefineTopMarginValueForCollapse ( IRenderer renderer ) {
536
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . DefineMarginValueForCollapse ( renderer , Property .
537
+ MARGIN_TOP ) ;
558
538
}
559
539
560
540
private static void IgnoreModelTopMargin ( IRenderer renderer ) {
561
- renderer . SetProperty ( Property . MARGIN_TOP , UnitValue . CreatePointValue ( 0f ) ) ;
541
+ iText . Layout . Margincollapse . MarginsCollapseHandler . OverrideModelTopMargin ( renderer , 0f ) ;
562
542
}
563
543
564
544
private static void OverrideModelTopMargin ( IRenderer renderer , float collapsedMargins ) {
565
- renderer . SetProperty ( Property . MARGIN_TOP , UnitValue . CreatePointValue ( collapsedMargins ) ) ;
545
+ iText . Layout . Margincollapse . MarginsCollapseHandler . OverrideModelMargin ( renderer , Property . MARGIN_TOP , collapsedMargins
546
+ ) ;
566
547
}
567
548
568
- private static float GetModelBottomMargin ( IRenderer renderer ) {
569
- UnitValue marginUV = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( Property . MARGIN_BOTTOM ) ;
549
+ private static float DefineBottomMarginValueForCollapse ( IRenderer renderer ) {
550
+ return iText . Layout . Margincollapse . MarginsCollapseHandler . DefineMarginValueForCollapse ( renderer , Property .
551
+ MARGIN_BOTTOM ) ;
552
+ }
553
+
554
+ private static void IgnoreModelBottomMargin ( IRenderer renderer ) {
555
+ iText . Layout . Margincollapse . MarginsCollapseHandler . OverrideModelBottomMargin ( renderer , 0f ) ;
556
+ }
557
+
558
+ private static void OverrideModelBottomMargin ( IRenderer renderer , float collapsedMargins ) {
559
+ iText . Layout . Margincollapse . MarginsCollapseHandler . OverrideModelMargin ( renderer , Property . MARGIN_BOTTOM , collapsedMargins
560
+ ) ;
561
+ }
562
+
563
+ private static float DefineMarginValueForCollapse ( IRenderer renderer , int property ) {
564
+ UnitValue marginUV = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( property ) ;
570
565
if ( null != marginUV && ! marginUV . IsPointValue ( ) ) {
571
566
ILogger logger = ITextLogManager . GetLogger ( typeof ( iText . Layout . Margincollapse . MarginsCollapseHandler ) ) ;
572
567
logger . LogError ( MessageFormatUtil . Format ( iText . IO . Logs . IoLogMessageConstant . PROPERTY_IN_PERCENTS_NOT_SUPPORTED
573
- , Property . MARGIN_TOP ) ) ;
568
+ , property ) ) ;
574
569
}
575
- // TODO Concerning "renderer instanceof CellRenderer" check: may be try to apply more general solution in future
576
570
return marginUV != null && ! ( renderer is CellRenderer ) ? marginUV . GetValue ( ) : 0 ;
577
571
}
578
572
579
- private static void IgnoreModelBottomMargin ( IRenderer renderer ) {
580
- renderer . SetProperty ( Property . MARGIN_BOTTOM , UnitValue . CreatePointValue ( 0f ) ) ;
573
+ private static void OverrideModelMargin ( IRenderer renderer , int property , float collapsedMargins ) {
574
+ renderer . SetProperty ( property , UnitValue . CreatePointValue ( collapsedMargins ) ) ;
581
575
}
582
576
583
- private static void OverrideModelBottomMargin ( IRenderer renderer , float collapsedMargins ) {
584
- renderer . SetProperty ( Property . MARGIN_BOTTOM , UnitValue . CreatePointValue ( collapsedMargins ) ) ;
577
+ private static bool HasPadding ( IRenderer renderer , int property ) {
578
+ UnitValue padding = renderer . GetModelElement ( ) . GetProperty < UnitValue > ( property ) ;
579
+ if ( null != padding && ! padding . IsPointValue ( ) ) {
580
+ ILogger logger = ITextLogManager . GetLogger ( typeof ( iText . Layout . Margincollapse . MarginsCollapseHandler ) ) ;
581
+ logger . LogError ( MessageFormatUtil . Format ( iText . IO . Logs . IoLogMessageConstant . PROPERTY_IN_PERCENTS_NOT_SUPPORTED
582
+ , property ) ) ;
583
+ }
584
+ return padding != null && padding . GetValue ( ) > 0 ;
585
+ }
586
+
587
+ private static bool HasBorders ( IRenderer renderer , int property ) {
588
+ IPropertyContainer modelElement = renderer . GetModelElement ( ) ;
589
+ return modelElement . HasProperty ( property ) || modelElement . HasProperty ( Property . BORDER ) ;
585
590
}
586
591
}
587
592
}
0 commit comments