|
8 | 8 | import UIKit |
9 | 9 |
|
10 | 10 | final class NitroTextImpl { |
11 | | - private weak var nitroTextView : NitroTextView? |
12 | | - private var currentTextAlignment: NSTextAlignment = .natural |
13 | | - private var currentTransform: TextTransform = .none |
14 | | - private var currentEllipsize: NSLineBreakMode = .byTruncatingTail |
| 11 | + weak var nitroTextView : NitroTextView? |
| 12 | + var currentTextAlignment: NSTextAlignment = .natural |
| 13 | + var currentTransform: TextTransform = .none |
| 14 | + var currentEllipsize: NSLineBreakMode = .byTruncatingTail |
15 | 15 |
|
16 | 16 | init(_ nitroTextView: NitroTextView) { |
17 | 17 | self.nitroTextView = nitroTextView |
@@ -40,7 +40,7 @@ final class NitroTextImpl { |
40 | 40 | nitroTextView?.textContainer.lineBreakMode = effectiveLineBreakMode(forLines: n) |
41 | 41 | } |
42 | 42 |
|
43 | | - private func effectiveLineBreakMode(forLines n: Int) -> NSLineBreakMode { |
| 43 | + func effectiveLineBreakMode(forLines n: Int) -> NSLineBreakMode { |
44 | 44 | guard n > 0 else { return .byWordWrapping } |
45 | 45 | if n == 1 { return currentEllipsize } |
46 | 46 | // Multi-line behavior: allow wrapping, then apply final-line behavior. |
@@ -113,81 +113,7 @@ final class NitroTextImpl { |
113 | 113 | setText(result) |
114 | 114 | } |
115 | 115 |
|
116 | | - // MARK: - Attribute helpers |
117 | | - |
118 | | - private func makeAttributes( |
119 | | - for fragment: Fragment, |
120 | | - defaultColor: UIColor |
121 | | - ) -> [NSAttributedString.Key: Any] { |
122 | | - var attrs: [NSAttributedString.Key: Any] = [:] |
123 | | - |
124 | | - let font = makeFont(for: fragment, defaultPointSize: nitroTextView?.font?.pointSize) |
125 | | - attrs[.font] = font.value |
126 | | - if font.isItalic { attrs[.obliqueness] = 0.2 } |
127 | | - |
128 | | - let para = makeParagraphStyle(for: fragment) |
129 | | - attrs[.paragraphStyle] = para |
130 | | - |
131 | | - let color = resolveColor(for: fragment, defaultColor: defaultColor) |
132 | | - attrs[.foregroundColor] = color |
133 | | - |
134 | | - return attrs |
135 | | - } |
136 | | - |
137 | | - // makeFont moved to NitroTextImpl+Font.swift |
138 | | - |
139 | | - private func makeParagraphStyle(for fragment: Fragment) -> NSMutableParagraphStyle { |
140 | | - let para = NSMutableParagraphStyle() |
141 | | - |
142 | | - if let lineHeight = fragment.lineHeight, lineHeight > 0 { |
143 | | - para.minimumLineHeight = lineHeight |
144 | | - para.maximumLineHeight = lineHeight |
145 | | - } |
146 | | - |
147 | | - if let align = fragment.textAlign { |
148 | | - switch align { |
149 | | - case .center: para.alignment = .center |
150 | | - case .right: para.alignment = .right |
151 | | - case .justify: para.alignment = .justified |
152 | | - case .left: para.alignment = .left |
153 | | - case .auto: para.alignment = .natural |
154 | | - } |
155 | | - } else { |
156 | | - para.alignment = currentTextAlignment |
157 | | - } |
158 | | - |
159 | | - guard let n = nitroTextView?.textContainer.maximumNumberOfLines else { return para } |
160 | | - para.lineBreakMode = effectiveLineBreakMode(forLines: n) |
161 | | - return para |
162 | | - } |
163 | | - |
164 | | - private func resolveColor(for fragment: Fragment, defaultColor: UIColor) -> UIColor { |
165 | | - if let value = fragment.fontColor, let parsed = ColorParser.parse(value) { |
166 | | - return parsed |
167 | | - } |
168 | | - return defaultColor |
169 | | - } |
170 | | - |
171 | | - private func transform(_ text: String, with fragment: Fragment) -> String { |
172 | | - let effective: TextTransform = { |
173 | | - if let ft = fragment.textTransform { |
174 | | - switch ft { |
175 | | - case .uppercase: return .uppercase |
176 | | - case .lowercase: return .lowercase |
177 | | - case .capitalize: return .capitalize |
178 | | - case .none: return .none |
179 | | - } |
180 | | - } |
181 | | - return currentTransform |
182 | | - }() |
183 | | - |
184 | | - switch effective { |
185 | | - case .uppercase: return text.uppercased() |
186 | | - case .lowercase: return text.lowercased() |
187 | | - case .capitalize: return text.capitalized |
188 | | - case .none: return text |
189 | | - } |
190 | | - } |
| 116 | + // Attribute helpers moved to NitroTextImpl+Attributes.swift |
191 | 117 | } |
192 | 118 |
|
193 | 119 |
|
|
0 commit comments