Top Fields Constructors Methods
com.openhtmltopdf.layout

public Class WhitespaceStripper

extends Object
Class Inheritance
Imports
java.util.Arrays, .Iterator, .List, java.util.regex.Pattern, com.openhtmltopdf.css.constants.CSSName, .IdentValue, com.openhtmltopdf.css.style.CalculatedStyle, com.openhtmltopdf.render.InlineBox

Author
Torbjoern Gannholm

Field Summary

Modifier and TypeField and Description
public static final String
public static final char
public static final Pattern
public static final Pattern
public static final String
public static final Pattern
public static final Pattern
public static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
private static String
collapseWhitespace(InlineBox iB, IdentValue whitespace, String text, boolean collapseLeading)

private static String
collapseWhitespaceNormalOrNoWrap(String text, boolean collapseLeading)

Collapse whitespace for normal or no-wrap modes.

public static void
stripInlineContent(List<Styleable>
the inline content to strip the whitespaces on
inlineContent
)

Strips whitespace early in inline content generation.

private static void
private static boolean

Returns:

whether the next leading space should collapse or not.
stripWhitespace
(InlineBox iB, boolean collapseLeading)

this function strips all whitespace from the text according to the CSS 2.1 spec on whitespace handling.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EOLback to summary
public static final String EOL
EOLCback to summary
public static final char EOLC
linefeed_space_collapseback to summary
public static final Pattern linefeed_space_collapse
linefeed_to_spaceback to summary
public static final Pattern linefeed_to_space
SPACEback to summary
public static final String SPACE
space_before_linefeed_collapseback to summary
public static final Pattern space_before_linefeed_collapse
space_collapseback to summary
public static final Pattern space_collapse
tab_to_spaceback to summary
public static final Pattern tab_to_space

Constructor Detail

WhitespaceStripperback to summary
public WhitespaceStripper()

Method Detail

canCollapseThroughback to summary
private static boolean canCollapseThrough(Styleable styleable)
collapseWhitespaceback to summary
private static String collapseWhitespace(InlineBox iB, IdentValue whitespace, String text, boolean collapseLeading)
collapseWhitespaceNormalOrNoWrapback to summary
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.

stripInlineContentback to summary
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:List<Styleable>

the inline content to strip the whitespaces on

stripTextContentback to summary
private static void stripTextContent(List<Styleable> stripped)
stripWhitespaceback to summary
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

Returns:boolean

whether the next leading space should collapse or not.