Class WhitespaceStripper

java.lang.Object
com.openhtmltopdf.layout.WhitespaceStripper

public class WhitespaceStripper extends Object
  • Field Details

    • SPACE

      public static final String SPACE
      See Also:
    • EOL

      public static final String EOL
      See Also:
    • EOLC

      public static final char EOLC
      See Also:
    • linefeed_space_collapse

      public static final Pattern linefeed_space_collapse
    • linefeed_to_space

      public static final Pattern linefeed_to_space
    • tab_to_space

      public static final Pattern tab_to_space
    • space_collapse

      public static final Pattern space_collapse
    • space_before_linefeed_collapse

      public static final Pattern space_before_linefeed_collapse
  • Constructor Details

    • WhitespaceStripper

      public WhitespaceStripper()
  • Method Details

    • stripInlineContent

      public static void stripInlineContent(List<Styleable> inlineContent)
      Strips whitespace early in inline content generation. This can be done because "whitespage" does not ally to :first-line and :first-letter. For dynamic pseudo-classes we are allowed to choose which properties apply. NOTE: The inlineContent parameter may be modified
      Parameters:
      inlineContent - the inline content to strip the whitespaces on
    • canCollapseThrough

      private static boolean canCollapseThrough(Styleable styleable)
    • stripTextContent

      private static void stripTextContent(List<Styleable> stripped)
    • stripWhitespace

      private static boolean stripWhitespace(InlineBox iB, boolean collapseLeading)
      this function strips all whitespace from the text according to the CSS 2.1 spec on whitespace handling. It accounts for the different whitespace settings like normal, nowrap, pre, etc
      Parameters:
      collapseLeading -
      style -
      tc - the TextContent to strip. The text in it is modified.
      Returns:
      whether the next leading space should collapse or not.
    • collapseWhitespaceNormalOrNoWrap

      private static String collapseWhitespaceNormalOrNoWrap(String text, boolean collapseLeading)
      Collapse whitespace for normal or no-wrap modes. Much faster (15x in simple testing) than using multiple regular expressions. NOTE: Slightly different behavior to using regular expressions as definition of space characters differ, but I believe this is the correct definition according to CSS specifications.
      Parameters:
      text -
      collapseLeading -
      Returns:
    • collapseWhitespace

      private static String collapseWhitespace(InlineBox iB, IdentValue whitespace, String text, boolean collapseLeading)