Permalink
Browse files

Make sure that empty paragraphs also carry font and paragraph style. C…

…loses #136
  • Loading branch information...
1 parent 275829a commit e133daf6cfa85056d454364ed91d8f62486c8c12 @odrobnik odrobnik committed Feb 29, 2012
@@ -772,12 +772,19 @@ - (void)_registerTagEndHandlers
void (^pBlock)(void) = ^
{
- // we need to output something for <p></p>
if (currentTagIsEmpty)
{
+ // empty paragraph
+
+ // end of P we always add a newline
+ [tmpString appendString:@"\n" withParagraphStyle:currentTag.paragraphStyle fontDescriptor:currentTag.fontDescriptor];
+ }
+ else
+ {
+ // extend previous tag contents
[tmpString appendString:@"\n"];
- outputHasNewline = NO; // NO: otherwise a following needed NL is cancelled
}
+ outputHasNewline = YES;
};
[_tagEndHandlers setObject:[pBlock copy] forKey:@"p"];
@@ -8,15 +8,15 @@
-@class DTCoreTextParagraphStyle;
+@class DTCoreTextParagraphStyle, DTCoreTextFontDescriptor;
@interface NSMutableAttributedString (HTML)
// appends a string with the same attributes as the suffix
- (void)appendString:(NSString *)string;
-// appends a string with a different paragraph style
-- (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphStyle *)paragraphStyle;
+// appends a string with a given paragraph style and font
+- (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphStyle *)paragraphStyle fontDescriptor:(DTCoreTextFontDescriptor *)fontDescriptor;
// appends a string without any attributes
- (void)appendNakedString:(NSString *)string;
@@ -41,16 +41,20 @@ - (void)appendString:(NSString *)string
[self appendAttributedString:tmpString];
}
-- (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphStyle *)paragraphStyle
+- (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphStyle *)paragraphStyle fontDescriptor:(DTCoreTextFontDescriptor *)fontDescriptor
{
- NSMutableDictionary *attributes = nil;
-
+ NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
+
if (paragraphStyle)
{
- attributes = [NSMutableDictionary dictionary];
CTParagraphStyleRef newParagraphStyle = [paragraphStyle createCTParagraphStyle];
[attributes setObject:CFBridgingRelease(newParagraphStyle) forKey:(id)kCTParagraphStyleAttributeName];
- //CFRelease(newParagraphStyle);
+ }
+
+ if (fontDescriptor)
+ {
+ CTFontRef newFont = [fontDescriptor newMatchingFont];
+ [attributes setObject:CFBridgingRelease(newFont) forKey:(id)kCTFontAttributeName];
}
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string attributes:attributes];
@@ -60,7 +64,7 @@ - (void)appendString:(NSString *)string withParagraphStyle:(DTCoreTextParagraphS
// appends a string without any attributes
- (void)appendNakedString:(NSString *)string
{
- [self appendString:string withParagraphStyle:nil];
+ [self appendString:string withParagraphStyle:nil fontDescriptor:nil];
}
@end

0 comments on commit e133daf

Please sign in to comment.