From 9f96a01f875f902c6451e05f448d30a37d453346 Mon Sep 17 00:00:00 2001 From: tettoffensive Date: Fri, 25 Mar 2016 12:11:59 -0700 Subject: [PATCH 1/3] add support for line break mode --- Example/Tests/BONTextAlignmentTestCase.m | 3 +++ Pod/Classes/BONChain.h | 2 ++ Pod/Classes/BONChain.m | 11 +++++++++++ Pod/Classes/BONText.h | 1 + Pod/Classes/BONText.m | 8 ++++++++ README.md | 1 + 6 files changed, 26 insertions(+) diff --git a/Example/Tests/BONTextAlignmentTestCase.m b/Example/Tests/BONTextAlignmentTestCase.m index 462c64ad..408147da 100644 --- a/Example/Tests/BONTextAlignmentTestCase.m +++ b/Example/Tests/BONTextAlignmentTestCase.m @@ -75,6 +75,7 @@ - (void)testParagraphStyle .headIndent(2.34) .tailIndent(3.45) .lineHeightMultiple(3.14) + .lineBreakMode(NSLineBreakByTruncatingTail) .maximumLineHeight(5.67) .minimumLineHeight(4.56) .lineSpacing(2.72) @@ -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; @@ -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); } diff --git a/Pod/Classes/BONChain.h b/Pod/Classes/BONChain.h index 6ce44027..621e498a 100644 --- a/Pod/Classes/BONChain.h +++ b/Pod/Classes/BONChain.h @@ -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); @@ -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; diff --git a/Pod/Classes/BONChain.m b/Pod/Classes/BONChain.m index 31eda898..d3502285 100644 --- a/Pod/Classes/BONChain.m +++ b/Pod/Classes/BONChain.m @@ -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) { diff --git a/Pod/Classes/BONText.h b/Pod/Classes/BONText.h index c2f5a1c4..3288d15c 100644 --- a/Pod/Classes/BONText.h +++ b/Pod/Classes/BONText.h @@ -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; diff --git a/Pod/Classes/BONText.m b/Pod/Classes/BONText.m index 892dcb73..95cbfc90 100644 --- a/Pod/Classes/BONText.m +++ b/Pod/Classes/BONText.m @@ -311,6 +311,13 @@ - (BONStringDict *)attributes populateParagraphStyleIfNecessary(); paragraphStyle.lineSpacing = self.lineSpacing; } + + // Line Break Mode + + if (self.lineBreakMode != NSLineBreakByWordWrapping) { + populateParagraphStyleIfNecessary(); + paragraphStyle.lineBreakMode = self.lineBreakMode; + } // Paragraph Spacing @@ -382,6 +389,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; diff --git a/README.md b/README.md index 4dec5827..7c93a44b 100644 --- a/README.md +++ b/README.md @@ -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 From aab376012cfb55ffecac0952dcec49060060bb85 Mon Sep 17 00:00:00 2001 From: tettoffensive Date: Fri, 25 Mar 2016 13:25:54 -0700 Subject: [PATCH 2/3] add lineBreakMode to initialization --- Pod/Classes/BONText.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Pod/Classes/BONText.m b/Pod/Classes/BONText.m index 95cbfc90..c4e0b1b1 100644 --- a/Pod/Classes/BONText.m +++ b/Pod/Classes/BONText.m @@ -37,6 +37,7 @@ - (instancetype)init self.alignment = NSTextAlignmentNatural; self.underlineStyle = NSUnderlineStyleNone; self.strikethroughStyle = NSUnderlineStyleNone; + self.lineBreakMode = NSLineBreakByWordWrapping; } return self; From ef8d3439a62d2d5ae5f6bc2be2817139eadfcdcf Mon Sep 17 00:00:00 2001 From: Stuart Tett Date: Sat, 26 Mar 2016 15:26:32 -0700 Subject: [PATCH 3/3] moved linebreakmode after linespacing --- Example/Tests/BONTextAlignmentTestCase.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Tests/BONTextAlignmentTestCase.m b/Example/Tests/BONTextAlignmentTestCase.m index 408147da..0534d4cc 100644 --- a/Example/Tests/BONTextAlignmentTestCase.m +++ b/Example/Tests/BONTextAlignmentTestCase.m @@ -75,10 +75,10 @@ - (void)testParagraphStyle .headIndent(2.34) .tailIndent(3.45) .lineHeightMultiple(3.14) - .lineBreakMode(NSLineBreakByTruncatingTail) .maximumLineHeight(5.67) .minimumLineHeight(4.56) .lineSpacing(2.72) + .lineBreakMode(NSLineBreakByTruncatingTail) .paragraphSpacingAfter(6.78) .paragraphSpacingBefore(7.89); NSAttributedString *string = chain.attributedString;