mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various improvements
This commit is contained in:
parent
4790c3c5b9
commit
f957979db9
@ -70,10 +70,12 @@ public struct TextRangeRectEdge: Equatable {
|
||||
public final class TextNodeBlockQuoteData: NSObject {
|
||||
public let title: NSAttributedString?
|
||||
public let color: UIColor
|
||||
public let secondaryColor: UIColor?
|
||||
|
||||
public init(title: NSAttributedString?, color: UIColor) {
|
||||
public init(title: NSAttributedString?, color: UIColor, secondaryColor: UIColor?) {
|
||||
self.title = title
|
||||
self.color = color
|
||||
self.secondaryColor = secondaryColor
|
||||
|
||||
super.init()
|
||||
}
|
||||
@ -93,6 +95,13 @@ public final class TextNodeBlockQuoteData: NSObject {
|
||||
if !self.color.isEqual(other.color) {
|
||||
return false
|
||||
}
|
||||
if let lhsSecondaryColor = self.secondaryColor, let rhsSecondaryColor = other.secondaryColor {
|
||||
if !lhsSecondaryColor.isEqual(rhsSecondaryColor) {
|
||||
return false
|
||||
}
|
||||
} else if (self.secondaryColor == nil) != (other.secondaryColor == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@ -131,10 +140,12 @@ private final class TextNodeLine {
|
||||
private final class TextNodeBlockQuote {
|
||||
let frame: CGRect
|
||||
let tintColor: UIColor
|
||||
let secondaryTintColor: UIColor?
|
||||
|
||||
init(frame: CGRect, tintColor: UIColor) {
|
||||
init(frame: CGRect, tintColor: UIColor, secondaryTintColor: UIColor?) {
|
||||
self.frame = frame
|
||||
self.tintColor = tintColor
|
||||
self.secondaryTintColor = secondaryTintColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -1200,6 +1211,7 @@ open class TextNode: ASDisplayNode {
|
||||
let firstCharacterOffset: Int
|
||||
let isBlockQuote: Bool
|
||||
let tintColor: UIColor?
|
||||
let secondaryTintColor: UIColor?
|
||||
}
|
||||
var stringSegments: [StringSegment] = []
|
||||
|
||||
@ -1222,7 +1234,8 @@ open class TextNode: ASDisplayNode {
|
||||
)),
|
||||
firstCharacterOffset: segmentCharacterOffset,
|
||||
isBlockQuote: false,
|
||||
tintColor: nil
|
||||
tintColor: nil,
|
||||
secondaryTintColor: nil
|
||||
))
|
||||
}
|
||||
|
||||
@ -1233,7 +1246,8 @@ open class TextNode: ASDisplayNode {
|
||||
substring: attributedString.attributedSubstring(from: effectiveRange),
|
||||
firstCharacterOffset: effectiveRange.location,
|
||||
isBlockQuote: true,
|
||||
tintColor: value.color
|
||||
tintColor: value.color,
|
||||
secondaryTintColor: value.secondaryColor
|
||||
))
|
||||
}
|
||||
segmentCharacterOffset = effectiveRange.location + effectiveRange.length
|
||||
@ -1246,7 +1260,8 @@ open class TextNode: ASDisplayNode {
|
||||
substring: attributedString.attributedSubstring(from: effectiveRange),
|
||||
firstCharacterOffset: effectiveRange.location,
|
||||
isBlockQuote: false,
|
||||
tintColor: nil
|
||||
tintColor: nil,
|
||||
secondaryTintColor: nil
|
||||
))
|
||||
segmentCharacterOffset = effectiveRange.location + effectiveRange.length
|
||||
}
|
||||
@ -1261,7 +1276,8 @@ open class TextNode: ASDisplayNode {
|
||||
)),
|
||||
firstCharacterOffset: segmentCharacterOffset,
|
||||
isBlockQuote: false,
|
||||
tintColor: nil
|
||||
tintColor: nil,
|
||||
secondaryTintColor: nil
|
||||
))
|
||||
}
|
||||
|
||||
@ -1273,6 +1289,7 @@ open class TextNode: ASDisplayNode {
|
||||
var titleLine: TextNodeLine?
|
||||
var lines: [TextNodeLine] = []
|
||||
var tintColor: UIColor?
|
||||
var secondaryTintColor: UIColor?
|
||||
var isBlockQuote: Bool = false
|
||||
var additionalWidth: CGFloat = 0.0
|
||||
}
|
||||
@ -1283,6 +1300,7 @@ open class TextNode: ASDisplayNode {
|
||||
var calculatedSegment = CalculatedSegment()
|
||||
calculatedSegment.isBlockQuote = segment.isBlockQuote
|
||||
calculatedSegment.tintColor = segment.tintColor
|
||||
calculatedSegment.secondaryTintColor = segment.secondaryTintColor
|
||||
|
||||
let rawSubstring = segment.substring.string as NSString
|
||||
let substringLength = rawSubstring.length
|
||||
@ -1484,7 +1502,7 @@ open class TextNode: ASDisplayNode {
|
||||
}
|
||||
|
||||
if segment.isBlockQuote, let tintColor = segment.tintColor {
|
||||
blockQuotes.append(TextNodeBlockQuote(frame: CGRect(origin: CGPoint(x: 0.0, y: blockMinY - 2.0), size: CGSize(width: blockWidth, height: blockMaxY - (blockMinY - 2.0) + 4.0)), tintColor: tintColor))
|
||||
blockQuotes.append(TextNodeBlockQuote(frame: CGRect(origin: CGPoint(x: 0.0, y: blockMinY - 2.0), size: CGSize(width: blockWidth, height: blockMaxY - (blockMinY - 2.0) + 4.0)), tintColor: tintColor, secondaryTintColor: segment.secondaryTintColor))
|
||||
}
|
||||
}
|
||||
|
||||
@ -2178,7 +2196,46 @@ open class TextNode: ASDisplayNode {
|
||||
context.addArc(tangent1End: CGPoint(x: lineFrame.minX, y: lineFrame.maxY), tangent2End: CGPoint(x: lineFrame.minX, y: lineFrame.maxY - radius), radius: radius)
|
||||
context.closePath()
|
||||
context.clip()
|
||||
context.fill(lineFrame)
|
||||
|
||||
if let secondaryTintColor = blockQuote.secondaryTintColor {
|
||||
let isMonochrome = secondaryTintColor.alpha == 0.0
|
||||
|
||||
do {
|
||||
context.saveGState()
|
||||
|
||||
if isMonochrome {
|
||||
context.setFillColor(blockQuote.tintColor.withMultipliedAlpha(0.2).cgColor)
|
||||
context.fill(lineFrame)
|
||||
context.setFillColor(blockQuote.tintColor.cgColor)
|
||||
} else {
|
||||
context.setFillColor(blockQuote.tintColor.cgColor)
|
||||
context.fill(lineFrame)
|
||||
context.setFillColor(secondaryTintColor.cgColor)
|
||||
}
|
||||
|
||||
let dashOffset: CGFloat = isMonochrome ? -4.0 : 5.0
|
||||
context.translateBy(x: blockFrame.minX, y: blockFrame.minY + dashOffset)
|
||||
|
||||
var offset = 0.0
|
||||
while offset < blockFrame.height {
|
||||
context.move(to: CGPoint(x: 0.0, y: 3.0))
|
||||
context.addLine(to: CGPoint(x: lineWidth, y: 0.0))
|
||||
context.addLine(to: CGPoint(x: lineWidth, y: 9.0))
|
||||
context.addLine(to: CGPoint(x: 0.0, y: 9.0 + 3.0))
|
||||
context.closePath()
|
||||
context.fillPath()
|
||||
|
||||
context.translateBy(x: 0.0, y: 18.0)
|
||||
offset += 18.0
|
||||
}
|
||||
|
||||
context.restoreGState()
|
||||
}
|
||||
} else {
|
||||
context.setFillColor(blockQuote.tintColor.cgColor)
|
||||
context.fill(lineFrame)
|
||||
}
|
||||
|
||||
context.resetClip()
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,27 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
underlineLinks = false
|
||||
}
|
||||
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: messageTheme.primaryTextColor, linkColor: messageTheme.linkTextColor, baseQuoteTintColor: messageTheme.accentTextColor, baseFont: textFont, linkFont: textFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, boldItalicFont: item.presentationData.messageBoldItalicFont, fixedFont: item.presentationData.messageFixedFont, blockQuoteFont: item.presentationData.messageBlockQuoteFont, underlineLinks: underlineLinks, message: item.message, adjustQuoteFontSize: true)
|
||||
let author = item.message.author
|
||||
let mainColor: UIColor
|
||||
var secondaryColor: UIColor?
|
||||
if !incoming {
|
||||
mainColor = messageTheme.accentTextColor
|
||||
if let _ = author?.nameColor?.dashColors.1 {
|
||||
secondaryColor = .clear
|
||||
}
|
||||
} else {
|
||||
var authorNameColor: UIColor?
|
||||
authorNameColor = author?.nameColor?.color
|
||||
secondaryColor = author?.nameColor?.dashColors.1
|
||||
|
||||
if let authorNameColor {
|
||||
mainColor = authorNameColor
|
||||
} else {
|
||||
mainColor = messageTheme.accentTextColor
|
||||
}
|
||||
}
|
||||
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: messageTheme.primaryTextColor, linkColor: messageTheme.linkTextColor, baseQuoteTintColor: mainColor, baseQuoteSecondaryTintColor: secondaryColor, baseFont: textFont, linkFont: textFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, boldItalicFont: item.presentationData.messageBoldItalicFont, fixedFont: item.presentationData.messageFixedFont, blockQuoteFont: item.presentationData.messageBlockQuoteFont, underlineLinks: underlineLinks, message: item.message, adjustQuoteFontSize: true)
|
||||
} else if !rawText.isEmpty {
|
||||
attributedText = NSAttributedString(string: rawText, font: textFont, textColor: messageTheme.primaryTextColor)
|
||||
} else {
|
||||
|
@ -55,7 +55,7 @@ public func chatInputStateStringWithAppliedEntities(_ text: String, entities: [M
|
||||
return string
|
||||
}
|
||||
|
||||
public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], baseColor: UIColor, linkColor: UIColor, baseQuoteTintColor: UIColor? = nil, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, boldItalicFont: UIFont, fixedFont: UIFont, blockQuoteFont: UIFont, underlineLinks: Bool = true, external: Bool = false, message: Message?, entityFiles: [MediaId: TelegramMediaFile] = [:], adjustQuoteFontSize: Bool = false) -> NSAttributedString {
|
||||
public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], baseColor: UIColor, linkColor: UIColor, baseQuoteTintColor: UIColor? = nil, baseQuoteSecondaryTintColor: UIColor? = nil, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, boldItalicFont: UIFont, fixedFont: UIFont, blockQuoteFont: UIFont, underlineLinks: Bool = true, external: Bool = false, message: Message?, entityFiles: [MediaId: TelegramMediaFile] = [:], adjustQuoteFontSize: Bool = false) -> NSAttributedString {
|
||||
let baseQuoteTintColor = baseQuoteTintColor ?? baseColor
|
||||
|
||||
var nsString: NSString?
|
||||
@ -214,7 +214,7 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
||||
case .BlockQuote:
|
||||
addFontAttributes(range, .blockQuote)
|
||||
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(title: nil, color: baseQuoteTintColor), range: range)
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(title: nil, color: baseQuoteTintColor, secondaryColor: baseQuoteSecondaryTintColor), range: range)
|
||||
case .BankCard:
|
||||
string.addAttribute(NSAttributedString.Key.foregroundColor, value: linkColor, range: range)
|
||||
if underlineLinks && underlineAllLinks {
|
||||
|
Loading…
x
Reference in New Issue
Block a user