@matiks/rn-stroke-text 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/StrokeTextView.swift +43 -22
- package/package.json +1 -1
package/ios/StrokeTextView.swift
CHANGED
|
@@ -111,8 +111,8 @@ class StrokeTextView: UIView {
|
|
|
111
111
|
private func updateFont() {
|
|
112
112
|
let size = CGFloat(truncating: fontSize)
|
|
113
113
|
|
|
114
|
-
let (family, weight) = parseFontFamily(fontFamily)
|
|
115
|
-
let resolvedName = resolveFontName(family: family, weight: weight)
|
|
114
|
+
let (family, weight, italic) = parseFontFamily(fontFamily)
|
|
115
|
+
let resolvedName = resolveFontName(family: family, weight: weight, italic: italic)
|
|
116
116
|
|
|
117
117
|
let cacheKey = "\(resolvedName)-\(size)"
|
|
118
118
|
if let cached = fontCache[cacheKey] {
|
|
@@ -131,33 +131,54 @@ class StrokeTextView: UIView {
|
|
|
131
131
|
|
|
132
132
|
/// Extracts trailing numeric weight
|
|
133
133
|
/// "Montserrat-900" → ("Montserrat", 900)
|
|
134
|
-
private func parseFontFamily(_ raw: String) -> (String, Int) {
|
|
135
|
-
let parts = raw.split(separator: "-")
|
|
134
|
+
private func parseFontFamily(_ raw: String) -> (family: String, weight: Int, italic: Bool) {
|
|
135
|
+
let parts = raw.lowercased().split(separator: "-")
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
var family = parts.first.map(String.init) ?? raw
|
|
138
|
+
var weight = 400
|
|
139
|
+
var italic = false
|
|
140
|
+
|
|
141
|
+
for part in parts.dropFirst() {
|
|
142
|
+
if part == "italic" {
|
|
143
|
+
italic = true
|
|
144
|
+
} else if let w = Int(part) {
|
|
145
|
+
weight = w
|
|
146
|
+
}
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
return (
|
|
149
|
+
return (family, weight, italic)
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
|
|
147
153
|
/// Maps numeric weight → iOS PostScript name
|
|
148
|
-
private func resolveFontName(family: String, weight: Int) -> String {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
case 700: return "\(family)-Bold"
|
|
157
|
-
case 800: return "\(family)-ExtraBold"
|
|
158
|
-
case 900: return "\(family)-Black"
|
|
159
|
-
default: return "\(family)-Regular"
|
|
154
|
+
private func resolveFontName(family: String, weight: Int, italic: Bool) -> String {
|
|
155
|
+
let singleFaceFonts: Set<String> = [
|
|
156
|
+
"bebasneue",
|
|
157
|
+
"bebas neue"
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
if singleFaceFonts.contains(family.lowercased()) {
|
|
161
|
+
return "\(family)-Regular"
|
|
160
162
|
}
|
|
163
|
+
let base: String
|
|
164
|
+
switch weight {
|
|
165
|
+
case 100: base = "Thin"
|
|
166
|
+
case 200: base = "ExtraLight"
|
|
167
|
+
case 300: base = "Light"
|
|
168
|
+
case 400: base = "Regular"
|
|
169
|
+
case 500: base = "Medium"
|
|
170
|
+
case 600: base = "SemiBold"
|
|
171
|
+
case 700: base = "Bold"
|
|
172
|
+
case 800: base = "ExtraBold"
|
|
173
|
+
case 900: base = "Black"
|
|
174
|
+
default: base = "Regular"
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if italic {
|
|
178
|
+
return "\(family)-Italic"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return "\(family)-\(base)Italic"
|
|
161
182
|
}
|
|
162
183
|
|
|
163
184
|
// MARK: - Color Helper
|