Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
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 AsyncDisplayKit/TextKit/ASTextKitCoreTextAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
cleanAttributes[NSForegroundColorAttributeName] = [UIColor colorWithCGColor:(CGColorRef)coreTextValue];
}
// kCTParagraphStyleAttributeName -> NSParagraphStyleAttributeName
else if ([coreTextKey isEqualToString:(NSString *)kCTParagraphStyleAttributeName]) {
else if ([coreTextKey isEqualToString:(NSString *)kCTParagraphStyleAttributeName] && ![coreTextValue isKindOfClass:[NSParagraphStyle class]]) {
cleanAttributes[NSParagraphStyleAttributeName] = [NSParagraphStyle paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)coreTextValue];
}
// kCTStrokeWidthAttributeName -> NSStrokeWidthAttributeName
Expand Down
21 changes: 21 additions & 0 deletions AsyncDisplayKitTests/ASTextKitCoreTextAdditionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#import "ASTextKitCoreTextAdditions.h"

BOOL floatsCloseEnough(CGFloat float1, CGFloat float2) {
CGFloat epsilon = 0.00001;
return (fabs(float1 - float2) < epsilon);
}

@interface ASTextKitCoreTextAdditionsTests : XCTestCase

@end
Expand Down Expand Up @@ -44,5 +49,21 @@ - (void)testNoAttributeCleansing
XCTAssertTrue([testString isEqualToAttributedString:actualCleansedString], @"Expected the output string %@ to be the same as the input %@ if there are no core text attributes", actualCleansedString, testString);
}

- (void)testNSParagraphStyleNoCleansing
{
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 10.0;

//NSUnderlineStyleAttributeName flags the unsupported CT attribute check
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after // - also should go ahead and link to this issue or give slightly more description on the expected behavior, as it currently is unclear why we'd want an unsupported attribute to make it through

NSDictionary *attributes = @{NSParagraphStyleAttributeName:paragraphStyle,
NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)};

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Test" attributes:attributes];
NSAttributedString *cleansedString = ASCleanseAttributedStringOfCoreTextAttributes(attributedString);

NSParagraphStyle *cleansedParagraphStyle = [cleansedString attribute:NSParagraphStyleAttributeName atIndex:0 effectiveRange:NULL];

XCTAssertTrue(floatsCloseEnough(cleansedParagraphStyle.lineSpacing, paragraphStyle.lineSpacing), @"Expected the output line spacing: %f to be equal to the input line spacing: %f", cleansedParagraphStyle.lineSpacing, paragraphStyle.lineSpacing);
}

@end