Skip to content

Commit 9416b99

Browse files
committed
Merge branch 'release/3.5.0'
2 parents a24bdce + c58c0c5 commit 9416b99

File tree

12 files changed

+90
-49
lines changed

12 files changed

+90
-49
lines changed

ExampleiOS/Assets.xcassets/rocket.imageset/Contents.json renamed to ExampleiOS/Assets.xcassets/therocket.imageset/Contents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"images" : [
33
{
44
"idiom" : "universal",
5+
"filename" : "816c77975b4ccce940d41933081b19d7.png",
56
"scale" : "1x"
67
},
78
{
89
"idiom" : "universal",
9-
"filename" : "816c77975b4ccce940d41933081b19d7.png",
1010
"scale" : "2x"
1111
},
1212
{

ExampleiOS/file.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<strong>Parler du don d'organe n'est plus tabou. Je me renseigne, j'en discute avec mes proches,... <rainbow>et je décide!</rainbow></strong>
22

3-
<img named="rocket" rect="0,-50,30,30"/>
3+
<img named="therocket" rect="0,-50,30,30"/>
44

55
<img url="https://www.macitynet.it/wp-content/uploads/2018/05/video_ApplePark_magg18.jpg"/>
66

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ The following properties are available:
706706
## Requirements
707707

708708
* Swift 5.1+
709-
* iOS 8.0+
710-
* macOS 10.10+
709+
* iOS 9.0+
710+
* macOS 11.0+
711711
* watchOS 2.0+
712712
* tvOS 11.0+
713713

Sources/SwiftRichString/Attributes/TextTransform.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,34 @@ public enum TextTransform {
4545
var transformer: TransformFunction {
4646
switch self {
4747
case .lowercase:
48-
return { string in string.localizedLowercase }
48+
return { string in
49+
string.localizedLowercase
50+
}
4951

5052
case .uppercase:
51-
return { string in string.localizedUppercase }
53+
return { string in
54+
string.localizedUppercase
55+
}
5256

5357
case .capitalized:
54-
return { string in string.localizedCapitalized }
58+
return { string in
59+
string.localizedCapitalized
60+
}
5561

5662
case .lowercaseWithLocale(let locale):
57-
return { string in string.lowercased(with: locale) }
63+
return { string in
64+
string.lowercased(with: locale)
65+
}
5866

5967
case .uppercaseWithLocale(let locale):
60-
return { string in string.uppercased(with: locale) }
68+
return { string in
69+
string.uppercased(with: locale)
70+
}
6171

6272
case .capitalizedWithLocale(let locale):
63-
return { string in string.capitalized(with: locale) }
73+
return { string in
74+
string.capitalized(with: locale)
75+
}
6476

6577
case .custom(let transform):
6678
return transform

Sources/SwiftRichString/Extensions/AttributedString+Attachments.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import AppKit
3636
import UIKit
3737
#endif
3838

39-
#if os(OSX) || os(iOS)
40-
4139
public extension AttributedString {
4240

41+
#if os(iOS)
42+
4343
/// Initialize a new text attachment with a remote image resource.
4444
/// Image will be loaded asynchronously after the text appear inside the control.
4545
///
@@ -61,6 +61,10 @@ public extension AttributedString {
6161
self.init(attachment: attachment)
6262
}
6363

64+
#endif
65+
66+
#if os(iOS) || os(OSX)
67+
6468
/// Initialize a new text attachment with local image contained into the assets.
6569
///
6670
/// - Parameters:
@@ -71,8 +75,9 @@ public extension AttributedString {
7175
return nil
7276
}
7377

78+
let image = Image(named: imageNamed)
7479
let boundsRect = CGRect(string: bounds)
75-
self.init(image: Image(named: imageNamed), bounds: boundsRect)
80+
self.init(image: image, bounds: boundsRect)
7681
}
7782

7883
/// Initialize a new attributed string from an image.
@@ -85,20 +90,24 @@ public extension AttributedString {
8590
return nil
8691
}
8792

93+
#if os(OSX)
94+
let attachment = NSTextAttachment(data: image.pngData()!, ofType: "png")
95+
#else
8896
var attachment: NSTextAttachment!
8997
if #available(iOS 13.0, *) {
9098
attachment = NSTextAttachment(image: image)
9199
} else {
92100
attachment = NSTextAttachment(data: image.pngData()!, ofType: "png")
93101
}
102+
#endif
94103

95104
if let bounds = bounds {
96105
attachment.bounds = bounds
97106
}
98107

99108
self.init(attachment: attachment)
100109
}
110+
111+
#endif
101112

102113
}
103-
104-
#endif

Sources/SwiftRichString/Support/AsyncTextAttachment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import UIKit
3535
import MobileCoreServices
3636
#endif
3737

38-
#if os(iOS) || os(OSX)
38+
#if os(iOS)
3939

4040
@objc public protocol AsyncTextAttachmentDelegate
4141
{

Sources/SwiftRichString/Support/Extensions.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,20 @@ extension CGRect {
113113
}
114114

115115
}
116+
117+
#if os(OSX)
118+
119+
public extension NSImage {
120+
121+
/// PNG data of the image.
122+
func pngData() -> Data? {
123+
self.lockFocus()
124+
let bitmap = NSBitmapImageRep(focusedViewRect: NSRect(x: 0, y: 0, width: size.width, height: size.height))
125+
let pngData = bitmap!.representation(using: .png, properties: [:])
126+
self.unlockFocus()
127+
return pngData
128+
}
129+
130+
}
131+
132+
#endif

Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,24 @@ open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver {
8686
case "a": // href support
8787
finalStyleToApply.linkURL = URL(string: attributes?["href"])
8888

89-
#if os(OSX) || os(iOS)
9089
case "img":
90+
#if os(iOS)
91+
// Remote Image URL support
9192
if let url = attributes?["url"] {
9293
if let image = AttributedString(imageURL: url, bounds: attributes?["rect"]) {
9394
attributedString.append(image)
9495
}
95-
} else {
96-
if let image = AttributedString(imageNamed: attributes?["named"], bounds: attributes?["rect"]) {
96+
}
97+
#endif
98+
99+
#if os(iOS) || os(OSX)
100+
// Local Image support
101+
if let imageName = attributes?["named"] {
102+
if let image = AttributedString(imageNamed: imageName, bounds: attributes?["rect"]) {
97103
attributedString.append(image)
98104
}
99105
}
100-
#endif
106+
#endif
101107

102108
default:
103109
break

SwiftRichString.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Pod::Spec.new do |s|
99
s.license = { :type => "MIT", :file => "LICENSE" }
1010
s.author = { "Daniele Margutti" => "[email protected]" }
1111
s.social_media_url = "https://twitter.com/danielemargutti"
12-
s.ios.deployment_target = "8.0"
13-
s.osx.deployment_target = "10.10"
12+
s.ios.deployment_target = "9.0"
13+
s.osx.deployment_target = "11.0"
1414
s.watchos.deployment_target = "2.0"
1515
s.tvos.deployment_target = "9.2"
1616
s.source = { :git => "https://github.com/malcommac/SwiftRichString.git", :tag => s.version.to_s }

0 commit comments

Comments
 (0)