mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix intersecting font attributes display
This commit is contained in:
parent
3f8df7776f
commit
b01d67574c
@ -251,20 +251,56 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var addedAttributes: [(NSRange, ChatTextFontAttributes)] = []
|
||||||
|
func addFont(ranges: [NSRange], fontAttributes: ChatTextFontAttributes) {
|
||||||
|
for range in ranges {
|
||||||
|
var font: UIFont?
|
||||||
|
if fontAttributes == [.bold, .italic] {
|
||||||
|
font = boldItalicFont
|
||||||
|
} else if fontAttributes == [.bold] {
|
||||||
|
font = boldFont
|
||||||
|
addedAttributes.append((range, fontAttributes))
|
||||||
|
} else if fontAttributes == [.italic] {
|
||||||
|
font = italicFont
|
||||||
|
addedAttributes.append((range, fontAttributes))
|
||||||
|
}
|
||||||
|
if let font = font {
|
||||||
|
string.addAttribute(NSAttributedString.Key.font, value: font, range: range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (range, fontAttributes) in fontAttributes {
|
for (range, fontAttributes) in fontAttributes {
|
||||||
var font: UIFont?
|
var ranges = [range]
|
||||||
if fontAttributes.contains(.blockQuote) {
|
var fontAttributes = fontAttributes
|
||||||
font = blockQuoteFont
|
if fontAttributes != [.bold, .italic] {
|
||||||
} else if fontAttributes == [.bold, .italic] {
|
for (existingRange, existingAttributes) in addedAttributes {
|
||||||
font = boldItalicFont
|
if let intersection = existingRange.intersection(range) {
|
||||||
} else if fontAttributes == [.bold] {
|
if intersection.length == range.length {
|
||||||
font = boldFont
|
if existingAttributes == .bold || existingAttributes == .italic {
|
||||||
} else if fontAttributes == [.italic] {
|
fontAttributes.insert(existingAttributes)
|
||||||
font = italicFont
|
}
|
||||||
}
|
} else {
|
||||||
if let font = font {
|
var fontAttributes = fontAttributes
|
||||||
string.addAttribute(NSAttributedString.Key.font, value: font, range: range)
|
if existingAttributes == .bold || existingAttributes == .italic {
|
||||||
|
fontAttributes.insert(existingAttributes)
|
||||||
|
}
|
||||||
|
addFont(ranges: [intersection], fontAttributes: fontAttributes)
|
||||||
|
|
||||||
|
ranges = []
|
||||||
|
if range.upperBound > existingRange.lowerBound {
|
||||||
|
ranges.append(NSRange(location: range.lowerBound, length: existingRange.lowerBound - range.lowerBound))
|
||||||
|
}
|
||||||
|
if range.upperBound > existingRange.upperBound {
|
||||||
|
ranges.append(NSRange(location: existingRange.upperBound, length: range.upperBound - existingRange.upperBound))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addFont(ranges: ranges, fontAttributes: fontAttributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string
|
return string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user