Skip to content

Commit

Permalink
NSTextContainer handle exclusion zones extending outside of area (#1792)
Browse files Browse the repository at this point in the history
Fixes #1779
  • Loading branch information
aballway authored Jan 24, 2017
1 parent 4c153c4 commit 601e300
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Frameworks/UIKit/NSTextContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static CGRect __FirstPossibleRectForProposed(CGRect proposed,
}
}
if (path.origin.x + path.size.width > proposed.origin.x) {
proposed.origin.x = (path.origin.x + path.size.width) + padding;
proposed.origin.x = std::min((path.origin.x + path.size.width) + padding, maxWidth);
proposed.size.width = maxWidth - proposed.origin.x;
}
}
Expand Down
16 changes: 14 additions & 2 deletions tests/unittests/UIKit/NSTextContainerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

TEST(NSTextContainer, LineFragmentRectForProposedRect) {
NSTextContainer* textContainer = [[[NSTextContainer alloc] initWithSize:CGSizeMake(1000, FLT_MAX)] autorelease];

// Exclusion paths not in horizontal order to make sure non-ordered are sorted properly
textContainer.exclusionPaths = @[
[UIBezierPath bezierPathWithRect:CGRectMake(100, 0, 100, 100)],
[UIBezierPath bezierPathWithRect:CGRectMake(700, 0, 150, 300)],
[UIBezierPath bezierPathWithRect:CGRectMake(300, 0, 200, 150)],
[UIBezierPath bezierPathWithRect:CGRectMake(700, 0, 150, 300)]
[UIBezierPath bezierPathWithRect:CGRectMake(950, 0, 1000, 300)]
];

// First rect starts at beginning of area, ends before first exclusion
Expand Down Expand Up @@ -53,7 +56,7 @@
writingDirection:NSWritingDirectionNatural
remainingRect:&remaining];
EXPECT_EQ(CGRectMake(550, 0, 145, 10), fragmentRect);
EXPECT_EQ(CGRectMake(855, 0, 145, 10), remaining);
EXPECT_EQ(CGRectMake(855, 0, 90, 10), remaining);

// First rect starts at beginning of text container, passes under first exclusion and ends before second
// Remaining rect starts after second exclusion, ends before third
Expand All @@ -72,4 +75,13 @@
remainingRect:&remaining];
EXPECT_EQ(CGRectMake(0, 400, 1000, 10), fragmentRect);
EXPECT_EQ(CGRectZero, remaining);

// First rect starts at end of text container, has width of 0
// There is no remaining rect
fragmentRect = [textContainer lineFragmentRectForProposedRect:CGRectMake(975, 0, 1000, 10)
atIndex:0
writingDirection:NSWritingDirectionNatural
remainingRect:&remaining];
EXPECT_EQ(CGRectMake(1000, 0, 0, 10), fragmentRect);
EXPECT_EQ(CGRectZero, remaining);
}

0 comments on commit 601e300

Please sign in to comment.