Skip to content

Commit

Permalink
Merge pull request #691 from Akylas/border-radius_and_more
Browse files Browse the repository at this point in the history
new style properties
  • Loading branch information
odrobnik committed Dec 18, 2013
2 parents 40254fe + 451b9d7 commit 92b55c1
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Core/Source/DTCoreTextConstants.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ extern NSString * const DTTextBlocksAttribute;
extern NSString * const DTFieldAttribute; extern NSString * const DTFieldAttribute;
extern NSString * const DTCustomAttributesAttribute; extern NSString * const DTCustomAttributesAttribute;
extern NSString * const DTAscentMultiplierAttribute; extern NSString * const DTAscentMultiplierAttribute;
extern NSString * const DTBackgroundStrokeColorAttribute;
extern NSString * const DTBackgroundStrokeWidthAttribute;
extern NSString * const DTBackgroundCornerRadiusAttribute;


// field constants // field constants


Expand Down
3 changes: 3 additions & 0 deletions Core/Source/DTCoreTextConstants.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
NSString * const DTFieldAttribute = @"DTField"; NSString * const DTFieldAttribute = @"DTField";
NSString * const DTCustomAttributesAttribute = @"DTCustomAttributes"; NSString * const DTCustomAttributesAttribute = @"DTCustomAttributes";
NSString * const DTAscentMultiplierAttribute = @"DTAscentMultiplierAttribute"; NSString * const DTAscentMultiplierAttribute = @"DTAscentMultiplierAttribute";
NSString * const DTBackgroundStrokeColorAttribute = @"DTBackgroundStrokeColor";
NSString * const DTBackgroundStrokeWidthAttribute = @"DTBackgroundStrokeWidth";
NSString * const DTBackgroundCornerRadiusAttribute = @"DTBackgroundCornerRadius";


// field constants // field constants
NSString * const DTListPrefixField = @"{listprefix}"; NSString * const DTListPrefixField = @"{listprefix}";
Expand Down
19 changes: 19 additions & 0 deletions Core/Source/DTHTMLElement.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
DTColor *_textColor; DTColor *_textColor;
DTColor *_backgroundColor; DTColor *_backgroundColor;


DTColor *_backgroundStrokeColor;
CGFloat _backgroundStrokeWidth;
CGFloat _backgroundCornerRadius;

CTUnderlineStyle _underlineStyle; CTUnderlineStyle _underlineStyle;


NSString *_beforeContent; NSString *_beforeContent;
Expand Down Expand Up @@ -152,6 +156,21 @@
*/ */
@property (nonatomic, strong) DTColor *backgroundColor; @property (nonatomic, strong) DTColor *backgroundColor;


/**
Background stroke color in the receiver
*/
@property (nonatomic, strong) DTColor *backgroundStrokeColor;

/**
Background stroke width in the receiver
*/
@property (nonatomic, assign) CGFloat backgroundStrokeWidth;

/**
Background stroke width in the receiver
*/
@property (nonatomic, assign) CGFloat backgroundCornerRadius;

/** /**
The custom letter spacing of the receiver, default is 0px The custom letter spacing of the receiver, default is 0px
*/ */
Expand Down
44 changes: 43 additions & 1 deletion Core/Source/DTHTMLElement.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -296,6 +296,21 @@ - (NSDictionary *)attributesForAttributedStringRepresentation
{ {
[tmpDict setObject:_paragraphStyle.textBlocks forKey:DTTextBlocksAttribute]; [tmpDict setObject:_paragraphStyle.textBlocks forKey:DTTextBlocksAttribute];
} }

if (_backgroundStrokeColor)
{
[tmpDict setObject:(id)[_backgroundStrokeColor CGColor] forKey:DTBackgroundStrokeColorAttribute];
}

if (_backgroundStrokeWidth)
{
[tmpDict setObject:DTNSNumberFromCGFloat(_backgroundStrokeWidth) forKey:DTBackgroundStrokeWidthAttribute];
}

if (_backgroundCornerRadius)
{
[tmpDict setObject:DTNSNumberFromCGFloat(_backgroundCornerRadius) forKey:DTBackgroundCornerRadiusAttribute];
}


return tmpDict; return tmpDict;
} }
Expand Down Expand Up @@ -1166,7 +1181,29 @@ - (void)applyStyleDictionary:(NSDictionary *)styles
} }
} }


BOOL needsTextBlock = (_backgroundColor!=nil); NSString *borderColor = [styles objectForKey:@"border-color"];
if (borderColor)
{
self.backgroundStrokeColor = DTColorCreateWithHTMLName(borderColor);
}
NSString *borderWidth = [[styles objectForKey:@"border-width"] lowercaseString];
if (borderWidth)
{
_backgroundStrokeWidth = [borderWidth floatValue];
}
else {
_backgroundStrokeWidth = 0.0f;
}
NSString *cornerRadius = [[styles objectForKey:@"border-radius"] lowercaseString];
if (cornerRadius)
{
_backgroundCornerRadius = [cornerRadius floatValue];
}
else {
_backgroundCornerRadius = 0.0f;
}

BOOL needsTextBlock = (_backgroundColor!=nil || _backgroundStrokeColor!=nil || _backgroundCornerRadius > 0 || _backgroundStrokeWidth > 0);


BOOL hasMargins = NO; BOOL hasMargins = NO;


Expand Down Expand Up @@ -1355,6 +1392,11 @@ - (void)inheritAttributesFromElement:(DTHTMLElement *)element
_currentTextSize = element.currentTextSize; _currentTextSize = element.currentTextSize;
_textScale = element.textScale; _textScale = element.textScale;


_backgroundColor = element.backgroundColor;
_backgroundStrokeColor = element.backgroundStrokeColor;
_backgroundStrokeWidth = element.backgroundStrokeWidth;
_backgroundCornerRadius = element.backgroundCornerRadius;

// only inherit background-color from inline elements // only inherit background-color from inline elements
if (element.displayStyle == DTHTMLElementDisplayStyleInline || element.displayStyle == DTHTMLElementDisplayStyleListItem) if (element.displayStyle == DTHTMLElementDisplayStyleInline || element.displayStyle == DTHTMLElementDisplayStyleListItem)
{ {
Expand Down
35 changes: 35 additions & 0 deletions Core/Source/NSDictionary+DTCoreText.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -221,4 +221,39 @@ - (CGFloat)kerning
return [kerningNum floatValue]; return [kerningNum floatValue];
} }


- (DTColor *)backgroundStrokeColor
{
CGColorRef cgColor = (__bridge CGColorRef)[self objectForKey:DTBackgroundStrokeColorAttribute];

if (cgColor)
{
return [DTColor colorWithCGColor:cgColor];
}
return nil;
}

- (CGFloat)backgroundStrokeWidth
{
NSNumber *num = [self objectForKey:DTBackgroundStrokeWidthAttribute];

if (num)
{
return [num floatValue];
}

return 0.0f;
}

- (CGFloat)backgroundCornerRadius
{
NSNumber *num = [self objectForKey:DTBackgroundCornerRadiusAttribute];

if (num)
{
return [num floatValue];
}

return 0.0f;
}

@end @end

0 comments on commit 92b55c1

Please sign in to comment.