Skip to content

Commit

Permalink
#599 Make text-indent prop work with break-word.
Browse files Browse the repository at this point in the history
text-indent was not working when the following conditions were met:

+ The element box was smaller than the text-indent.
+ word-wrap was set to break-word.

With test proof.
  • Loading branch information
danfickle committed Nov 22, 2020
1 parent 22cae14 commit 58b1fa8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf -text
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ public static LineBreakResult breakText(LayoutContext c,
}
}
case WORD_BREAKING_UNBREAKABLE: {
if (context.getWidth() >= lineWidth) {
// If the word is too long to fit on a line by itself, retry it in
// character breaking mode.
if (context.getWidth() >= lineWidth ||
context.isFirstCharInLine()) {
// If the word is too long to fit on a line by itself or
// if we are at the start of a line,
// retry in character breaking mode.
tryToBreakAnywhere = true;
context.setEnd(savedEnd);
continue LOOP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public static void layoutContent(LayoutContext c, BlockBox box, int initialY, in
do {
lbContext.reset();

lbContext.setFirstCharInLine(lbContext.getStart() == 0 && !current.line.isContainsContent());

int fit = 0;
if (lbContext.getStart() == 0) {
fit += space.pendingLeftMBP + space.pendingRightMBP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum LineBreakResult {
private int _nextWidth;
private boolean _endsOnWordBreak;
private boolean _finishedInCharBreakingMode;
private boolean _isFirstChar;

public int getLast() {
return _master.length();
Expand Down Expand Up @@ -189,4 +190,20 @@ public void setFinishedInCharBreakingMode(boolean mode) {
public boolean isFinishedInCharBreakingMode() {
return _finishedInCharBreakingMode;
}

/**
* @return true if this is the first non-trimmed character
* in a line.
*/
public boolean isFirstCharInLine() {
return _isFirstChar;
}

/**
* @param isFirstChar set to true if this is the first non-trimmable
* character in a line.
*/
public void setFirstCharInLine(boolean isFirstChar) {
_isFirstChar = isFirstChar;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ public void testIssue596CSSDataUriInImportUrl() throws IOException {
}

@Test
@Ignore // It is not throwing, but the text-indent property is ignored.
public void testIssue599TrimLeadingSpaceException() throws IOException {
assertTrue(vt.runTest("issue-599-trim-leading-space-exception"));
}
Expand Down

0 comments on commit 58b1fa8

Please sign in to comment.