Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSTextContainer handle exclusion zones extending outside of area #1792

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposed.size.width [](start = 12, length = 20)

proposed.size.width of 0 is valid? if the min ends up being maxWidth?

}
}
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);
}