Permalink
Browse files

Merge pull request #691 from Akylas/border-radius_and_more

new style properties
  • Loading branch information...
2 parents 40254fe + 451b9d7 commit 92b55c1a5381c75d890496a7c3ca944430406496 @odrobnik odrobnik committed Dec 18, 2013
@@ -73,6 +73,9 @@ extern NSString * const DTTextBlocksAttribute;
extern NSString * const DTFieldAttribute;
extern NSString * const DTCustomAttributesAttribute;
extern NSString * const DTAscentMultiplierAttribute;
+extern NSString * const DTBackgroundStrokeColorAttribute;
+extern NSString * const DTBackgroundStrokeWidthAttribute;
+extern NSString * const DTBackgroundCornerRadiusAttribute;
// field constants
@@ -45,6 +45,9 @@
NSString * const DTFieldAttribute = @"DTField";
NSString * const DTCustomAttributesAttribute = @"DTCustomAttributes";
NSString * const DTAscentMultiplierAttribute = @"DTAscentMultiplierAttribute";
+NSString * const DTBackgroundStrokeColorAttribute = @"DTBackgroundStrokeColor";
+NSString * const DTBackgroundStrokeWidthAttribute = @"DTBackgroundStrokeWidth";
+NSString * const DTBackgroundCornerRadiusAttribute = @"DTBackgroundCornerRadius";
// field constants
NSString * const DTListPrefixField = @"{listprefix}";
@@ -33,6 +33,10 @@
DTColor *_textColor;
DTColor *_backgroundColor;
+ DTColor *_backgroundStrokeColor;
+ CGFloat _backgroundStrokeWidth;
+ CGFloat _backgroundCornerRadius;
+
CTUnderlineStyle _underlineStyle;
NSString *_beforeContent;
@@ -152,6 +156,21 @@
*/
@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
*/
@@ -296,6 +296,21 @@ - (NSDictionary *)attributesForAttributedStringRepresentation
{
[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;
}
@@ -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;
@@ -1355,6 +1392,11 @@ - (void)inheritAttributesFromElement:(DTHTMLElement *)element
_currentTextSize = element.currentTextSize;
_textScale = element.textScale;
+ _backgroundColor = element.backgroundColor;
+ _backgroundStrokeColor = element.backgroundStrokeColor;
+ _backgroundStrokeWidth = element.backgroundStrokeWidth;
+ _backgroundCornerRadius = element.backgroundCornerRadius;
+
// only inherit background-color from inline elements
if (element.displayStyle == DTHTMLElementDisplayStyleInline || element.displayStyle == DTHTMLElementDisplayStyleListItem)
{
@@ -221,4 +221,39 @@ - (CGFloat)kerning
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

0 comments on commit 92b55c1

Please sign in to comment.