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

add support for line break mode #128

Merged
merged 3 commits into from
Mar 28, 2016
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
3 changes: 3 additions & 0 deletions Example/Tests/BONTextAlignmentTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ - (void)testParagraphStyle
.maximumLineHeight(5.67)
.minimumLineHeight(4.56)
.lineSpacing(2.72)
.lineBreakMode(NSLineBreakByTruncatingTail)
.paragraphSpacingAfter(6.78)
.paragraphSpacingBefore(7.89);
NSAttributedString *string = chain.attributedString;
Expand All @@ -91,6 +92,7 @@ - (void)testParagraphStyle
controlParagraphStyle.maximumLineHeight = 5.67;
controlParagraphStyle.minimumLineHeight = 4.56;
controlParagraphStyle.lineSpacing = 2.72;
controlParagraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
controlParagraphStyle.paragraphSpacing = 6.78;
controlParagraphStyle.paragraphSpacingBefore = 7.89;

Expand All @@ -113,6 +115,7 @@ - (void)testParagraphStyle
XCTAssertEqualWithAccuracy(testParagraphStyle.maximumLineHeight, 5.67, kBONDoubleEpsilon);
XCTAssertEqualWithAccuracy(testParagraphStyle.minimumLineHeight, 4.56, kBONDoubleEpsilon);
XCTAssertEqualWithAccuracy(testParagraphStyle.lineSpacing, 2.72, kBONDoubleEpsilon);
XCTAssertEqual(testParagraphStyle.lineBreakMode, NSLineBreakByTruncatingTail);
XCTAssertEqualWithAccuracy(testParagraphStyle.paragraphSpacing, 6.78, kBONDoubleEpsilon);
XCTAssertEqualWithAccuracy(testParagraphStyle.paragraphSpacingBefore, 7.89, kBONDoubleEpsilon);
}
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/BONChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef BONChain *BONCNonnull (^BONChainLineHeight)(CGFloat lineHeightMultiple);
typedef BONChain *BONCNonnull (^BONChainMaximumLineHeight)(CGFloat maximumLineHeight);
typedef BONChain *BONCNonnull (^BONChainMinimumLineHeight)(CGFloat minimumLineHeight);
typedef BONChain *BONCNonnull (^BONChainLineSpacing)(CGFloat lineSpacing);
typedef BONChain *BONCNonnull (^BONChainLineBreakMode)(NSLineBreakMode lineBreakMode);
typedef BONChain *BONCNonnull (^BONChainParagraphSpacingAfter)(CGFloat paragraphSpacing);
typedef BONChain *BONCNonnull (^BONChainParagraphSpacingBefore)(CGFloat paragraphSpacingBefore);
typedef BONChain *BONCNonnull (^BONChainBaselineOffset)(CGFloat baselineOffset);
Expand Down Expand Up @@ -67,6 +68,7 @@ typedef BONChain *BONCNonnull (^BONChainStrikethroughColor)(UIColor *BONCNullabl
@property (copy, nonatomic, readonly) BONChainMaximumLineHeight maximumLineHeight;
@property (copy, nonatomic, readonly) BONChainMinimumLineHeight minimumLineHeight;
@property (copy, nonatomic, readonly) BONChainLineSpacing lineSpacing;
@property (copy, nonatomic, readonly) BONChainLineBreakMode lineBreakMode;
@property (copy, nonatomic, readonly) BONChainParagraphSpacingAfter paragraphSpacingAfter;
@property (copy, nonatomic, readonly) BONChainParagraphSpacingBefore paragraphSpacingBefore;

Expand Down
11 changes: 11 additions & 0 deletions Pod/Classes/BONChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ - (BONChainLineSpacing)lineSpacing
return [lineSpacingBlock copy];
}

- (BONChainLineBreakMode)lineBreakMode
{
BONChainLineBreakMode lineBreakModeBlock = ^(NSLineBreakMode lineBreakMode) {
__typeof(self) newChain = self.copyWithoutNextText;
newChain.text.lineBreakMode = lineBreakMode;
return newChain;
};

return [lineBreakModeBlock copy];
}

- (BONChainParagraphSpacingAfter)paragraphSpacingAfter
{
BONChainParagraphSpacingAfter paragraphSpacingAfterBlock = ^(CGFloat paragraphSpacingAfter) {
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/BONText.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef NS_ENUM(NSUInteger, BONFigureSpacing) {
@property (nonatomic) CGFloat maximumLineHeight;
@property (nonatomic) CGFloat minimumLineHeight;
@property (nonatomic) CGFloat lineSpacing;
@property (nonatomic) NSLineBreakMode lineBreakMode;
@property (nonatomic) CGFloat paragraphSpacingAfter;
@property (nonatomic) CGFloat paragraphSpacingBefore;

Expand Down
9 changes: 9 additions & 0 deletions Pod/Classes/BONText.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (instancetype)init
self.alignment = NSTextAlignmentNatural;
self.underlineStyle = NSUnderlineStyleNone;
self.strikethroughStyle = NSUnderlineStyleNone;
self.lineBreakMode = NSLineBreakByWordWrapping;
}

return self;
Expand Down Expand Up @@ -311,6 +312,13 @@ - (BONStringDict *)attributes
populateParagraphStyleIfNecessary();
paragraphStyle.lineSpacing = self.lineSpacing;
}

// Line Break Mode

if (self.lineBreakMode != NSLineBreakByWordWrapping) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer not to rely on the implementation detail that this property is initialized to 0, which happens to equal NSLineBreakByWordWrapping. Please add explicit initialization to -init of BONText.m.

populateParagraphStyleIfNecessary();
paragraphStyle.lineBreakMode = self.lineBreakMode;
}

// Paragraph Spacing

Expand Down Expand Up @@ -382,6 +390,7 @@ - (id)copyWithZone:(NSZone *)zone
text.maximumLineHeight = self.maximumLineHeight;
text.minimumLineHeight = self.minimumLineHeight;
text.lineSpacing = self.lineSpacing;
text.lineBreakMode = self.lineBreakMode;
text.paragraphSpacingAfter = self.paragraphSpacingAfter;
text.paragraphSpacingBefore = self.paragraphSpacingBefore;
text.baselineOffset = self.baselineOffset;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BonMot uses attributed strings to give you control over the following typographi
- Maximum line height
- Minimum line height
- Line spacing
- Line break mode
- Paragraph spacing before
- Paragraph spacing after
- Baseline offset
Expand Down