Skip to content

Commit

Permalink
Add support for word-break:break-all CSS property.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdastephens committed Nov 5, 2024
1 parent ce267a5 commit 171ffa9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,18 @@ public final class CSSName implements Comparable<CSSName> {
new PrimitivePropertyBuilders.WhiteSpace()
);

/**
* Unique CSSName instance for CSS3 property.
*/
public static final CSSName WORD_BREAK =
addProperty(
"word-break",
PRIMITIVE,
"normal",
INHERITS,
new PrimitivePropertyBuilders.WordBreak()
);

/**
* Unique CSSName instance for CSS3 property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class IdentValue implements FSDerivedValue {
public static final IdentValue BORDER_BOX = addValue("border-box");
public static final IdentValue BOTH = addValue("both");
public static final IdentValue BOTTOM = addValue("bottom");
public static final IdentValue BREAK_ALL = addValue("break-all");
public static final IdentValue CAPITALIZE = addValue("capitalize");
public static final IdentValue CENTER = addValue("center");
public static final IdentValue CIRCLE = addValue("circle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,18 @@ protected BitSet getAllowed() {
}
}

public static class WordBreak extends SingleIdent {
// normal | break-all
private static final BitSet ALLOWED = setFor(
new IdentValue[] {
IdentValue.NORMAL, IdentValue.BREAK_ALL});

@Override
protected BitSet getAllowed() {
return ALLOWED;
}
}

public static class WordWrap extends SingleIdent {
// normal | break-word
private static final BitSet ALLOWED = setFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ public IdentValue getWordWrap() {
return getIdent(CSSName.WORD_WRAP);
}

public IdentValue getWordBreak() {
return getIdent(CSSName.WORD_BREAK);
}

public IdentValue getHyphens() {
return getIdent(CSSName.HYPHENS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ public static void breakText(LayoutContext c,
}

context.setEndsOnNL(false);
doBreakText(c, context, avail, style, false);

boolean tryToBreakAnywhere = style.getWordBreak() == IdentValue.BREAK_ALL;

doBreakText(c, context, avail, style, tryToBreakAnywhere);
}

private static int getWidth(LayoutContext c, FSFont f, String text) {
Expand Down

0 comments on commit 171ffa9

Please sign in to comment.