Permalink
Browse files

Moved setting of the display size to after styles have been applied

This fixes a bug where the max display size would not be heeded since version 1.3.
Also fixes #338
  • Loading branch information...
1 parent 4748dd9 commit 99da4df18008f8104fc894e388e2d4a151409e48 @odrobnik odrobnik committed Mar 13, 2013
Showing with 25 additions and 10 deletions.
  1. +0 −10 Core/Source/DTHTMLElement.m
  2. +25 −0 Core/Source/DTHTMLElementAttachment.m
@@ -941,22 +941,12 @@ - (void)applyStyleDictionary:(NSDictionary *)styles
if (widthString && ![widthString isEqualToString:@"auto"])
{
_size.width = [widthString pixelSizeOfCSSMeasureRelativeToCurrentTextSize:self.fontDescriptor.pointSize textScale:_textScale];
-
- // if this has an attachment set its size too
- CGSize displaySize = _textAttachment.displaySize;
- displaySize.width = _size.width;
- _textAttachment.displaySize = displaySize;
}
NSString *heightString = [styles objectForKey:@"height"];
if (heightString && ![heightString isEqualToString:@"auto"])
{
_size.height = [heightString pixelSizeOfCSSMeasureRelativeToCurrentTextSize:self.fontDescriptor.pointSize textScale:_textScale];
-
- // if this has an attachment set its size too
- CGSize displaySize = _textAttachment.displaySize;
- displaySize.height = _size.height;
- _textAttachment.displaySize = displaySize;
}
NSString *whitespaceString = [styles objectForKey:@"white-space"];
@@ -14,6 +14,9 @@
#import "NSMutableAttributedString+HTML.h"
@implementation DTHTMLElementAttachment
+{
+ CGSize _maxDisplaySize;
+}
- (id)initWithName:(NSString *)name attributes:(NSDictionary *)attributes options:(NSDictionary *)options
{
@@ -33,6 +36,19 @@ - (id)initWithName:(NSString *)name attributes:(NSDictionary *)attributes option
// specifiying line height interfers with correct positioning
_paragraphStyle.minimumLineHeight = 0;
_paragraphStyle.maximumLineHeight = 0;
+
+ // remember the maximum display size
+ _maxDisplaySize = CGSizeZero;
+
+ NSValue *maxImageSizeValue =[options objectForKey:DTMaxImageSize];
+ if (maxImageSizeValue)
+ {
+#if TARGET_OS_IPHONE
+ _maxDisplaySize = [maxImageSizeValue CGSizeValue];
+#else
+ _maxDisplaySize = [maxImageSizeValue sizeValue];
+#endif
+ }
}
return self;
@@ -68,4 +84,13 @@ - (DTHTMLElementDisplayStyle)displayStyle
return DTHTMLElementDisplayStyleBlock;
}
+- (void)applyStyleDictionary:(NSDictionary *)styles
+{
+ // element size is determined in super (tag attribute and style)
+ [super applyStyleDictionary:styles];
+
+ // update the display size
+ [_textAttachment setDisplaySize:_size withMaxDisplaySize:_maxDisplaySize];
+}
+
@end

0 comments on commit 99da4df

Please sign in to comment.