Skip to content
Browse files

Reverted changes to prefixForListItemWithCounter:

  • Loading branch information...
1 parent 5b3ac68 commit 73bba398dd07cba1e546de49189cd8c90301dbf7 @odrobnik odrobnik committed May 14, 2013
Showing with 27 additions and 22 deletions.
  1. +1 −1 Core/Source/NSAttributedString+DTCoreText.h
  2. +26 −21 Core/Source/NSAttributedString+DTCoreText.m
View
2 Core/Source/NSAttributedString+DTCoreText.h
@@ -122,6 +122,6 @@
@param attributes The attribute dictionary for the text to be prefixed
@returns An attributed string with the list prefix
*/
-+ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent leftMargin:(CGFloat)leftMargin leftPadding:(CGFloat)leftPadding attributes:(NSDictionary *)attributes;
++ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent attributes:(NSDictionary *)attributes;
@end
View
47 Core/Source/NSAttributedString+DTCoreText.m
@@ -10,7 +10,6 @@
#import "NSAttributedString+DTCoreText.h"
#import "DTHTMLWriter.h"
#import "NSURL+DTComparing.h"
-#import "NSDictionary+DTCoreText.h"
@implementation NSAttributedString (DTCoreText)
@@ -265,32 +264,38 @@ - (NSString *)plainTextString
}
#pragma mark Generating Special Attributed Strings
-+ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent leftMargin:(CGFloat)leftMargin leftPadding:(CGFloat)leftPadding attributes:(NSDictionary *)attributes
++ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent attributes:(NSDictionary *)attributes
{
- DTCoreTextParagraphStyle *paragraphStyle = [attributes paragraphStyle];
- NSParameterAssert(paragraphStyle);
-
- DTCoreTextFontDescriptor *fontDescriptor = [attributes fontDescriptor];
- NSParameterAssert(fontDescriptor);
+ // get existing values from attributes
+ CTParagraphStyleRef paraStyle = (__bridge CTParagraphStyleRef)[attributes objectForKey:(id)kCTParagraphStyleAttributeName];
+ CTFontRef font = (__bridge CTFontRef)[attributes objectForKey:(id)kCTFontAttributeName];
- // modify paragraph style
- paragraphStyle.firstLineHeadIndent = listIndent; // first line has prefix and starts at list indent;
-
- // resets tabs
- paragraphStyle.tabStops = nil;
+ DTCoreTextFontDescriptor *fontDescriptor = nil;
+ DTCoreTextParagraphStyle *paragraphStyle = nil;
- // set tab stops
- if (listStyle.type != DTCSSListStyleTypeNone)
+ if (paraStyle)
{
- NSAssert(leftMargin>0, @"There needs to be a margin greater than zero in %s", __PRETTY_FUNCTION__);
+ paragraphStyle = [DTCoreTextParagraphStyle paragraphStyleWithCTParagraphStyle:paraStyle];
+
+ paragraphStyle.tabStops = nil;
- // first tab is to right-align bullet, numbering against
- CGFloat tabOffset = leftMargin - (CGFloat)5.0; // TODO: change with font size
- [paragraphStyle addTabStopAtPosition:tabOffset alignment:kCTRightTextAlignment];
+ paragraphStyle.headIndent = listIndent;
+
+ if (listStyle.type != DTCSSListStyleTypeNone)
+ {
+ // first tab is to right-align bullet, numbering against
+ CGFloat tabOffset = paragraphStyle.headIndent - (CGFloat)5.0; // TODO: change with font size
+ [paragraphStyle addTabStopAtPosition:tabOffset alignment:kCTRightTextAlignment];
+ }
+
+ // second tab is for the beginning of first line after bullet
+ [paragraphStyle addTabStopAtPosition:paragraphStyle.headIndent alignment:kCTLeftTextAlignment];
}
- // second tab is for the beginning of first line after bullet
- [paragraphStyle addTabStopAtPosition:leftMargin + leftPadding alignment:kCTLeftTextAlignment];
+ if (font)
+ {
+ fontDescriptor = [DTCoreTextFontDescriptor fontDescriptorForCTFont:font];
+ }
NSMutableDictionary *newAttributes = [NSMutableDictionary dictionary];
@@ -302,7 +307,7 @@ + (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter lis
fontDesc.boldTrait = NO;
fontDesc.italicTrait = NO;
- CTFontRef font = [fontDesc newMatchingFont];
+ font = [fontDesc newMatchingFont];
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)

0 comments on commit 73bba39

Please sign in to comment.
Something went wrong with that request. Please try again.