TraitSetter (Apache FOP Core 2.11 API)
Date: 2025-04-24

org.apache.fop.layoutmgr

## Class TraitSetter

- java.lang.Object
- - org.apache.fop.layoutmgr.TraitSetter

-     public final class TraitSetter
      extends Object

  This is a helper class used for setting common traits on areas.

- - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addBackground(Area area, CommonBorderPaddingBackground backProps, PercentBaseContext context)` Add background to an area.
    `static void` | `addBackground(Area area, CommonBorderPaddingBackground backProps, PercentBaseContext context, int ipdShift, int bpdShift, int referenceIPD, int referenceBPD)` Add background to an area.
    `static void` | `addBorders(Area area, CommonBorderPaddingBackground borderProps, boolean discardBefore, boolean discardAfter, boolean discardStart, boolean discardEnd, PercentBaseContext context)` Add borders to an area.
    `static void` | `addBorders(Area area, CommonBorderPaddingBackground borderProps, PercentBaseContext context)` Deprecated. Call the other addBorders() method and addPadding separately.
    `static void` | `addBreaks(Area area, int breakBefore, int breakAfter)` Sets the traits for breaks on an area.
    `static void` | `addCollapsingBorders(Area area, CommonBorderPaddingBackground.BorderInfo borderBefore, CommonBorderPaddingBackground.BorderInfo borderAfter, CommonBorderPaddingBackground.BorderInfo borderStart, CommonBorderPaddingBackground.BorderInfo borderEnd, boolean[] outer)` Add borders to an area for the collapsing border model in tables.
    `static void` | `addFontTraits(Area area, Font font)` Adds font traits to an area
    `static void` | `addMargins(Area area, CommonBorderPaddingBackground bpProps, CommonMarginBlock marginProps, PercentBaseContext context)` Add space to a block area.
    `static void` | `addMargins(Area area, CommonBorderPaddingBackground bpProps, int startIndent, int endIndent, PercentBaseContext context)` Add space to a block area.
    `static void` | `addPadding(Area area, CommonBorderPaddingBackground bordProps, boolean discardBefore, boolean discardAfter, boolean discardStart, boolean discardEnd, PercentBaseContext context)` Add padding to an area.
    `static void` | `addSpaceBeforeAfter(Area area, double adjust, MinOptMax spaceBefore, MinOptMax spaceAfter)` Adds traits for space-before and space-after to an area.
    `static void` | `addStructureTreeElement(Area area, StructureTreeElement structureTreeElement)` Sets the structure tree element associated to the given area.
    `static void` | `addTextDecoration(Area area, CommonTextDecoration deco)` Adds the text-decoration traits to the area.
    `static int` | `getEffectiveSpace(double adjust, MinOptMax space)` Returns the effective space length of a resolved space specifier based on the adjustment value.
    `static void` | `setBorderPaddingTraits(Area area, CommonBorderPaddingBackground bpProps, boolean isNotFirst, boolean isNotLast, PercentBaseContext context)` Sets border and padding traits on areas.
    `static void` | `setLayer(Area area, String layer)` Sets the optional content group layer as a trait on the area.
    `static void` | `setProducerID(Area area, String id)` Sets the producer's ID as a trait on the area.
    `static void` | `setVisibility(Area area, int visibility)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### setBorderPaddingTraits

          public static void setBorderPaddingTraits(Area area,
                                                    CommonBorderPaddingBackground bpProps,
                                                    boolean isNotFirst,
                                                    boolean isNotLast,
                                                    PercentBaseContext context)

      Sets border and padding traits on areas.
      Parameters:
        `area` - area to set the traits on
        `bpProps` - border and padding properties
        `isNotFirst` - True if the area is not the first area
        `isNotLast` - True if the area is not the last area
        `context` - Property evaluation context

    - #### addBorders

          public static void addBorders(Area area,
                                        CommonBorderPaddingBackground borderProps,
                                        PercentBaseContext context)

      Deprecated. Call the other addBorders() method and addPadding separately.
      Add borders to an area. Note: this method also adds unconditional padding. Don't use! Layout managers that create areas with borders can use this to add the borders to the area.
      Parameters:
        `area` - the area to set the traits on.
        `borderProps` - border properties
        `context` - Property evaluation context

    - #### addBorders

          public static void addBorders(Area area,
                                        CommonBorderPaddingBackground borderProps,
                                        boolean discardBefore,
                                        boolean discardAfter,
                                        boolean discardStart,
                                        boolean discardEnd,
                                        PercentBaseContext context)

      Add borders to an area. Layout managers that create areas with borders can use this to add the borders to the area.
      Parameters:
        `area` - the area to set the traits on.
        `borderProps` - border properties
        `discardBefore` - true if the before border should be discarded
        `discardAfter` - true if the after border should be discarded
        `discardStart` - true if the start border should be discarded
        `discardEnd` - true if the end border should be discarded
        `context` - Property evaluation context

    - #### addCollapsingBorders

          public static void addCollapsingBorders(Area area,
                                                  CommonBorderPaddingBackground.BorderInfo borderBefore,
                                                  CommonBorderPaddingBackground.BorderInfo borderAfter,
                                                  CommonBorderPaddingBackground.BorderInfo borderStart,
                                                  CommonBorderPaddingBackground.BorderInfo borderEnd,
                                                  boolean[] outer)

      Add borders to an area for the collapsing border model in tables. Layout managers that create areas with borders can use this to add the borders to the area.
      Parameters:
        `area` - the area to set the traits on.
        `borderBefore` - the resolved before border
        `borderAfter` - the resolved after border
        `borderStart` - the resolved start border
        `borderEnd` - the resolved end border
        `outer` - 4 boolean values indicating if the side represents the table's outer border. Order: before, after, start, end

    - #### addPadding

          public static void addPadding(Area area,
                                        CommonBorderPaddingBackground bordProps,
                                        boolean discardBefore,
                                        boolean discardAfter,
                                        boolean discardStart,
                                        boolean discardEnd,
                                        PercentBaseContext context)

      Add padding to an area. Layout managers that create areas with padding can use this to add the borders to the area.
      Parameters:
        `area` - the area to set the traits on.
        `bordProps` - border and padding properties
        `discardBefore` - true if the before padding should be discarded
        `discardAfter` - true if the after padding should be discarded
        `discardStart` - true if the start padding should be discarded
        `discardEnd` - true if the end padding should be discarded
        `context` - Property evaluation context

    - #### addBackground

          public static void addBackground(Area area,
                                           CommonBorderPaddingBackground backProps,
                                           PercentBaseContext context,
                                           int ipdShift,
                                           int bpdShift,
                                           int referenceIPD,
                                           int referenceBPD)

      Add background to an area. This method is mainly used by table-related layout managers to add background for column, body or row. Since the area corresponding to border-separation must be filled with the table's background, for every cell an additional area with the same dimensions is created to hold the background for the corresponding column/body/row. An additional shift must then be added to background-position-horizontal/vertical to ensure the background images are correctly placed. Indeed the placement of images must be made WRT the column/body/row and not the cell.

      Note: The area's IPD and BPD must be set before calling this method.

      TODO the regular `addBackground(Area, CommonBorderPaddingBackground, PercentBaseContext)` method should be used instead, and a means to retrieve the original area's dimensions must be found.

      TODO the placement of images in the x- or y-direction will be incorrect if background-repeat is set for that direction.

      Parameters:
        `area` - the area to set the traits on
        `backProps` - the background properties
        `context` - Property evaluation context
        `ipdShift` - horizontal shift to affect to the background, in addition to the value of the background-position-horizontal property
        `bpdShift` - vertical shift to affect to the background, in addition to the value of the background-position-vertical property
        `referenceIPD` - value to use as a reference for percentage calculation
        `referenceBPD` - value to use as a reference for percentage calculation

    - #### addBackground

          public static void addBackground(Area area,
                                           CommonBorderPaddingBackground backProps,
                                           PercentBaseContext context)

      Add background to an area. Layout managers that create areas with a background can use this to add the background to the area. Note: The area's IPD and BPD must be set before calling this method.
      Parameters:
        `area` - the area to set the traits on
        `backProps` - the background properties
        `context` - Property evaluation context

    - #### addMargins

          public static void addMargins(Area area,
                                        CommonBorderPaddingBackground bpProps,
                                        int startIndent,
                                        int endIndent,
                                        PercentBaseContext context)

      Add space to a block area. Layout managers that create block areas can use this to add space outside of the border rectangle to the area.
      Parameters:
        `area` - the area to set the traits on.
        `bpProps` - the border, padding and background properties
        `startIndent` - the effective start-indent value
        `endIndent` - the effective end-indent value
        `context` - the context for evaluation of percentages

    - #### addMargins

          public static void addMargins(Area area,
                                        CommonBorderPaddingBackground bpProps,
                                        CommonMarginBlock marginProps,
                                        PercentBaseContext context)

      Add space to a block area. Layout managers that create block areas can use this to add space outside of the border rectangle to the area.
      Parameters:
        `area` - the area to set the traits on.
        `bpProps` - the border, padding and background properties
        `marginProps` - the margin properties.
        `context` - the context for evaluation of percentages

    - #### getEffectiveSpace

          public static int getEffectiveSpace(double adjust,
                                              MinOptMax space)

      Returns the effective space length of a resolved space specifier based on the adjustment value.
      Parameters:
        `adjust` - the adjustment value
        `space` - the space specifier
      Returns:
        the effective space length

    - #### addSpaceBeforeAfter

          public static void addSpaceBeforeAfter(Area area,
                                                 double adjust,
                                                 MinOptMax spaceBefore,
                                                 MinOptMax spaceAfter)

      Adds traits for space-before and space-after to an area.
      Parameters:
        `area` - the target area
        `adjust` - the adjustment value
        `spaceBefore` - the space-before space specifier
        `spaceAfter` - the space-after space specifier

    - #### addBreaks

          public static void addBreaks(Area area,
                                       int breakBefore,
                                       int breakAfter)

      Sets the traits for breaks on an area.
      Parameters:
        `area` - the area to set the traits on.
        `breakBefore` - the value for break-before
        `breakAfter` - the value for break-after

    - #### addFontTraits

          public static void addFontTraits(Area area,
                                           Font font)

      Adds font traits to an area
      Parameters:
        `area` - the target are
        `font` - the font to use

    - #### addTextDecoration

          public static void addTextDecoration(Area area,
                                               CommonTextDecoration deco)

      Adds the text-decoration traits to the area.
      Parameters:
        `area` - the area to set the traits on
        `deco` - the text decorations

    - #### setVisibility

          public static void setVisibility(Area area,
                                           int visibility)

    - #### addStructureTreeElement

          public static void addStructureTreeElement(Area area,
                                                     StructureTreeElement structureTreeElement)

      Sets the structure tree element associated to the given area.
      Parameters:
        `area` - the area to set the traits on
        `structureTreeElement` - the element the area is associated to in the document structure

    - #### setProducerID

          public static void setProducerID(Area area,
                                           String id)

      Sets the producer's ID as a trait on the area. This can be used to track back the generating FO node.
      Parameters:
        `area` - the area to set the traits on
        `id` - the ID to set

    - #### setLayer

          public static void setLayer(Area area,
                                      String layer)

      Sets the optional content group layer as a trait on the area.
      Parameters:
        `area` - the area to set the traits on
        `layer` - the layer ID to set

Copyright © 2025 Apache Software Foundation. All rights reserved.