Skip to content

Commit 5295943

Browse files
committed
Merge branch 'release-1.5.1'
2 parents 3fa41cc + 938a7f1 commit 5295943

12 files changed

+91
-52
lines changed

Core/Source/DTAttributedTextContentView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ - (void)drawRect:(CGRect)rect
448448

449449
- (void)relayoutText
450450
{
451+
if (![NSThread isMainThread])
452+
{
453+
[self performSelectorOnMainThread:@selector(relayoutText) withObject:nil waitUntilDone:YES];
454+
return;
455+
}
456+
451457
// Make sure we actually have a superview and a previous layout before attempting to relayout the text.
452458
if (_layoutFrame && self.superview)
453459
{

Core/Source/DTAttributedTextView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ - (void)scrollRangeToVisible:(NSRange)range animated:(BOOL)animated
125125

126126
- (void)relayoutText
127127
{
128+
if (![NSThread isMainThread])
129+
{
130+
[self performSelectorOnMainThread:@selector(relayoutText) withObject:nil waitUntilDone:YES];
131+
return;
132+
}
133+
128134
// need to reset the layouter because otherwise we get the old framesetter or cached layout frames
129135
_attributedTextContentView.layouter=nil;
130136

Core/Source/DTCSSStylesheet.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ - (void)_uncompressShorthands:(NSMutableDictionary *)styles
160160
{
161161
NSString *fontStyle = @"normal";
162162
NSArray *validFontStyles = [NSArray arrayWithObjects:@"italic", @"oblique", nil];
163-
BOOL fontStyleSet = NO;
164163

165164
NSString *fontVariant = @"normal";
166165
NSArray *validFontVariants = [NSArray arrayWithObjects:@"small-caps", nil];
@@ -177,7 +176,6 @@ - (void)_uncompressShorthands:(NSMutableDictionary *)styles
177176
NSArray *suffixesToIgnore = [NSArray arrayWithObjects:@"caption", @"icon", @"menu", @"message-box", @"small-caption", @"status-bar", @"inherit", nil];
178177

179178
NSString *lineHeight = @"normal";
180-
BOOL lineHeightSet = NO;
181179

182180
NSMutableString *fontFamily = [NSMutableString string];
183181

@@ -204,7 +202,6 @@ - (void)_uncompressShorthands:(NSMutableDictionary *)styles
204202
fontSizeSet = YES;
205203

206204
lineHeight = [oneComponent substringFromIndex:slashIndex+1];
207-
lineHeightSet = YES;
208205

209206
continue;
210207
}
@@ -240,7 +237,6 @@ - (void)_uncompressShorthands:(NSMutableDictionary *)styles
240237
if (!fontWeightSet && [validFontStyles containsObject:oneComponent])
241238
{
242239
fontStyle = oneComponent;
243-
fontStyleSet = YES;
244240
}
245241
else if (!fontVariantSet && [validFontVariants containsObject:oneComponent])
246242
{

Core/Source/DTHTMLElement.m

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,8 @@ - (NSAttributedString *)attributedString
406406
{
407407
if (![[tmpString string] hasSuffix:@"\n"])
408408
{
409-
if ([tmpString length])
410-
{
411-
// extend same paragraph and font style
412-
[tmpString appendString:@"\n"];
413-
}
414-
else
415-
{
416-
// tmpString has no attributes to extend, so we make a new string with attributes
417-
418-
// need all attributes to e.g. extend list to include this character
419-
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"\n" attributes:[self attributesDictionary]];
420-
[tmpString appendAttributedString:attributedString];
421-
}
409+
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"\n" attributes:[self attributesDictionary]];
410+
[tmpString appendAttributedString:attributedString];
422411
}
423412
}
424413
}

Core/Source/DTLazyImageView.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,15 @@ - (void)completeDownloadWithData:(NSData *)data
211211

212212
if (_url)
213213
{
214-
// cache image
215-
[_imageCache setObject:image forKey:_url];
214+
if (image)
215+
{
216+
// cache image
217+
[_imageCache setObject:image forKey:_url];
218+
}
219+
else
220+
{
221+
NSLog(@"Warning, %@ did not get an image for %@", NSStringFromClass([self class]), [_url absoluteString]);
222+
}
216223
}
217224

218225
}

Core/Source/NSDictionary+DTCoreText.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
Convenience methods for editors dealing with Core Text attribute dictionaries.
1616
*/
17-
@interface NSDictionary (DTRichText)
17+
@interface NSDictionary (DTCoreText)
1818

1919
/**
2020
@name Getting State information
@@ -50,6 +50,12 @@
5050
*/
5151
- (BOOL)hasAttachment;
5252

53+
/**
54+
The header level of the receiver
55+
@returns The header level (1-6) or 0 if no header level is set
56+
*/
57+
- (NSUInteger)headerLevel;
58+
5359
/**
5460
@name Getting Style Information
5561
*/

Core/Source/NSDictionary+DTCoreText.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#import "DTCoreTextFunctions.h"
1616
#import "DTCoreTextParagraphStyle.h"
1717

18-
@implementation NSDictionary (DTRichText)
18+
@implementation NSDictionary (DTCoreText)
1919

2020
- (BOOL)isBold
2121
{
@@ -87,6 +87,13 @@ - (BOOL)isStrikethrough
8787
return NO;
8888
}
8989

90+
- (NSUInteger)headerLevel
91+
{
92+
NSNumber *headerLevelNum = [self objectForKey:DTHeaderLevelAttribute];
93+
94+
return [headerLevelNum integerValue];
95+
}
96+
9097
- (BOOL)hasAttachment
9198
{
9299
return [self objectForKey:NSAttachmentAttributeName]!=nil;

Core/Test/Source/DTHTMLAttributedStringBuilderTest.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ - (void)testFontSizeInterpretation
240240
__block CGFloat paragraphFontSize = 0; // initialized from first font in paragraph
241241

242242
[output enumerateAttribute:(id)kCTFontAttributeName inRange:paragraphRange options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
243+
244+
NSString *subString = [[output string] substringWithRange:range];
245+
246+
// the NL are exempt from the test
247+
if ([subString isEqualToString:@"\n"])
248+
{
249+
return;
250+
}
251+
243252
DTCoreTextFontDescriptor *fontDescriptor = [DTCoreTextFontDescriptor fontDescriptorForCTFont:(__bridge CTFontRef)(value)];
244253

245254
if (paragraphFontSize==0)
@@ -300,7 +309,7 @@ - (void)testOrderedListStartingNumber
300309
// testing if Helvetica font family returns the correct font
301310
- (void)testHelveticaVariants
302311
{
303-
NSAttributedString *attributedString = [self _attributedStringFromHTMLString:@"<p style=\"font-family:Helvetica\">Regular</p><p style=\"font-family:Helvetica\"><b>Bold</b></p><p style=\"font-family:Helvetica\"><i>Italic</i></p><p style=\"font-family:Helvetica\"><b><i>Bold+Italic</i></b></p>"];
312+
NSAttributedString *attributedString = [self _attributedStringFromHTMLString:@"<p style=\"font-family:Helvetica\">Regular</p><p style=\"font-family:Helvetica;font-weight:bold;\">Bold</p><p style=\"font-family:Helvetica;font-style:italic;}\">Italic</p><p style=\"font-family:Helvetica;font-style:italic;font-weight:bold;}\">Bold+Italic</p>"];
304313

305314
NSString *string = [attributedString string];
306315
NSRange entireStringRange = NSMakeRange(0, [string length]);
@@ -363,6 +372,23 @@ - (void)testHeaderLevelTransfer
363372
STAssertEquals(level, (NSInteger)3, @"Level should be 3");
364373
}
365374

375+
// Issue 437, strikethrough bleeding into NL
376+
- (void)testBleedingOutAttributes
377+
{
378+
NSAttributedString *attributedString = [self _attributedStringFromHTMLString:@"<p><del>abc<br/></del></p>"];
379+
380+
STAssertTrue([attributedString length] == 5, @"Attributed String should be 5 characters long");
381+
382+
NSRange effectiveRange;
383+
NSNumber *strikethroughStyle = [attributedString attribute:DTStrikeOutAttribute atIndex:0 effectiveRange:&effectiveRange];
384+
385+
STAssertNotNil(strikethroughStyle, @"There should be a strikethrough style");
386+
387+
NSRange expectedRange = NSMakeRange(0, 4);
388+
389+
STAssertEquals(effectiveRange, expectedRange, @"Strikethrough style should only contain abc, not the NL");
390+
}
391+
366392
#pragma mark - Nested Lists
367393

368394
- (void)testNestedListWithStyleNone

DTCoreText.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'DTCoreText'
3-
spec.version = '1.5.0'
3+
spec.version = '1.5.1'
44
spec.platform = :ios, '4.3'
55
spec.license = 'BSD'
66
spec.source = { :git => 'https://github.com/Cocoanetics/DTCoreText.git', :tag => spec.version.to_s }

Demo/Resources/CurrentTest.html

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
<head>
2-
<style type="text/css">
3-
hr {
4-
padding: 30px;
5-
color: red;
6-
-webkit-margin-before: 0.0px;
7-
-webkit-margin-after: 0.5em;
8-
-webkit-margin-start: auto;
9-
-webkit-margin-end: auto;
10-
}
11-
</style>
12-
</head>
13-
<body>
14-
15-
<object class="Bla" style="width:150px; height:150px" src="Oliver.jpg" />
16-
17-
<object class="Bla" width=200 height=200 src="Oliver.jpg" />
18-
19-
<object height="38" width="32" />
20-
21-
22-
23-
24-
<object style="height:38px;width:32px" />
25-
26-
</body>
1+
<!DOCTYPE html>
2+
<html lang='en'>
3+
<head>
4+
<style> p{ line-height : 1.5em; } </style>
5+
</head>
6+
<body>
7+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <img src='Oliver.jpg' alt='image' /> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)