Skip to content

Commit 4fd17bb

Browse files
committed
#44 Fixed base style render for font/size on StyleGroup
1 parent 86ddcd1 commit 4fd17bb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Sources/SwiftRichString/Style/StyleGroup.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,7 @@ public class StyleGroup: StyleProtocol {
180180
let str = attrStr.string
181181

182182
// Apply default base style if specified
183-
if let baseStyle = self.baseStyle {
184-
if adding {
185-
attrStr.addAttributes(baseStyle.attributes, range: NSMakeRange(0, attrStr.length))
186-
} else {
187-
attrStr.setAttributes(baseStyle.attributes, range: NSMakeRange(0, attrStr.length))
188-
}
189-
}
183+
self.baseStyle?.set(to: attrStr, range: nil)
190184

191185
// Parse tags
192186
if let regex = try? NSRegularExpression(pattern: tagRegex, options: .dotMatchesLineSeparators) {

Sources/SwiftRichString/Style/StyleProtocol.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ public protocol StyleProtocol: class {
4141
var fontData: FontData? { get }
4242

4343
func set(to source: String, range: NSRange?) -> AttributedString
44+
4445
func add(to source: AttributedString, range: NSRange?) -> AttributedString
46+
47+
@discardableResult
4548
func set(to source: AttributedString, range: NSRange?) -> AttributedString
49+
50+
@discardableResult
4651
func remove(from source: AttributedString, range: NSRange?) -> AttributedString
4752
}
4853

@@ -61,12 +66,14 @@ public extension StyleProtocol {
6166
return source
6267
}
6368

69+
@discardableResult
6470
func set(to source: AttributedString, range: NSRange?) -> AttributedString {
6571
self.fontData?.addAttributes(to: source, range: range)
6672
source.addAttributes(self.attributes, range: (range ?? NSMakeRange(0, source.length)))
6773
return source
6874
}
6975

76+
@discardableResult
7077
func remove(from source: AttributedString, range: NSRange?) -> AttributedString {
7178
self.attributes.keys.forEach({
7279
source.removeAttribute($0, range: (range ?? NSMakeRange(0, source.length)))

0 commit comments

Comments
 (0)