mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-02 12:48:45 +00:00
Fixed overlapping entities display
This commit is contained in:
parent
5d6f009ee8
commit
48d460af36
@ -277,7 +277,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
|
||||
}
|
||||
var dismissImpl: (() -> Void)?
|
||||
let alertTheme = AlertControllerTheme(presentationTheme: strongSelf.theme)
|
||||
let attributedText = stringWithAppliedEntities(termsOfService.text, entities: termsOfService.entities, baseColor: alertTheme.primaryColor, linkColor: alertTheme.accentColor, baseFont: Font.regular(13.0), linkFont: Font.regular(13.0), boldFont: Font.semibold(13.0), italicFont: Font.italic(13.0), fixedFont: Font.regular(13.0))
|
||||
let attributedText = stringWithAppliedEntities(termsOfService.text, entities: termsOfService.entities, baseColor: alertTheme.primaryColor, linkColor: alertTheme.accentColor, baseFont: Font.regular(13.0), linkFont: Font.regular(13.0), boldFont: Font.semibold(13.0), italicFont: Font.italic(13.0), boldItalicFont: Font.semiboldItalic(13.0), fixedFont: Font.regular(13.0))
|
||||
let contentNode = TextAlertContentNode(theme: alertTheme, title: NSAttributedString(string: strongSelf.strings.Login_TermsOfServiceHeader, font: Font.medium(17.0), textColor: alertTheme.primaryColor, paragraphAlignment: .center), text: attributedText, actions: [
|
||||
TextAlertAction(type: .defaultAction, title: strongSelf.strings.Login_TermsOfServiceAgree, action: {
|
||||
dismissImpl?()
|
||||
|
||||
@ -6,10 +6,11 @@ import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
|
||||
private let messageFont: UIFont = UIFont.systemFont(ofSize: 17.0)
|
||||
private let messageBoldFont: UIFont = UIFont.boldSystemFont(ofSize: 17.0)
|
||||
private let messageItalicFont: UIFont = UIFont.italicSystemFont(ofSize: 17.0)
|
||||
private let messageFixedFont: UIFont = UIFont(name: "Menlo-Regular", size: 16.0) ?? UIFont.systemFont(ofSize: 17.0)
|
||||
private let messageFont = Font.regular(17.0)
|
||||
private let messageBoldFont = Font.semibold(17.0)
|
||||
private let messageItalicFont = Font.italic(17.0)
|
||||
private let messageBoldItalicFont = Font.semiboldItalic(17.0)
|
||||
private let messageFixedFont = UIFont(name: "Menlo-Regular", size: 16.0) ?? UIFont.systemFont(ofSize: 17.0)
|
||||
|
||||
final class ChatBotInfoItem: ListViewItem {
|
||||
fileprivate let text: String
|
||||
@ -151,7 +152,7 @@ final class ChatBotInfoItemNode: ListViewItemNode {
|
||||
updatedTextAndEntities = (item.text, generateTextEntities(item.text, enabledTypes: .all))
|
||||
}
|
||||
|
||||
let attributedText = stringWithAppliedEntities(updatedTextAndEntities.0, entities: updatedTextAndEntities.1, baseColor: item.presentationData.theme.theme.chat.bubble.infoPrimaryTextColor, linkColor: item.presentationData.theme.theme.chat.bubble.infoLinkTextColor, baseFont: messageFont, linkFont: messageFont, boldFont: messageBoldFont, italicFont: messageItalicFont, fixedFont: messageFixedFont)
|
||||
let attributedText = stringWithAppliedEntities(updatedTextAndEntities.0, entities: updatedTextAndEntities.1, baseColor: item.presentationData.theme.theme.chat.bubble.infoPrimaryTextColor, linkColor: item.presentationData.theme.theme.chat.bubble.infoLinkTextColor, baseFont: messageFont, linkFont: messageFont, boldFont: messageBoldFont, italicFont: messageItalicFont, boldItalicFont: messageBoldItalicFont, fixedFont: messageFixedFont)
|
||||
|
||||
let horizontalEdgeInset: CGFloat = 10.0 + params.leftInset
|
||||
let horizontalContentInset: CGFloat = 12.0
|
||||
|
||||
@ -412,14 +412,6 @@ func contextMenuForChatPresentationIntefaceState(chatPresentationInterfaceState:
|
||||
}
|
||||
}
|
||||
storeMessageTextInPasteboard(message.text, entities: messageEntities)
|
||||
// if let messageEntities = messageEntities {
|
||||
//
|
||||
// let attributedString = chatInputStateStringWithAppliedEntities(message.text, entities: messageEntities)
|
||||
// //stringWithAppliedEntities(message.text, entities: messageEntities, baseColor: .black, linkColor: .black, baseFont: Font.regular(14.0), linkFont: Font.regular(14.0), boldFont: Font.bold(14.0), italicFont: Font.italic(14.0), fixedFont: Font.monospace(14.0))
|
||||
// UIPasteboard.general.set(attributedString: attributedString)
|
||||
// } else {
|
||||
// UIPasteboard.general.string = message.text
|
||||
// }
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
@ -385,7 +385,7 @@ private func universalServiceMessageString(theme: ChatPresentationThemeData?, st
|
||||
}
|
||||
attributedString = NSAttributedString(string: titleString, font: titleFont, textColor: primaryTextColor)
|
||||
case let .customText(text, entities):
|
||||
attributedString = stringWithAppliedEntities(text, entities: entities, baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, fixedFont: titleFont, underlineLinks: false)
|
||||
attributedString = stringWithAppliedEntities(text, entities: entities, baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, boldItalicFont: titleBoldFont, fixedFont: titleFont, underlineLinks: false)
|
||||
case let .botDomainAccessGranted(domain):
|
||||
attributedString = NSAttributedString(string: strings.AuthSessions_Message(domain).0, font: titleFont, textColor: primaryTextColor)
|
||||
case let .botSentSecureValues(types):
|
||||
|
||||
@ -9,12 +9,13 @@ import Postbox
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
|
||||
private let titleFont: UIFont = Font.semibold(15.0)
|
||||
private let textFont: UIFont = Font.regular(15.0)
|
||||
private let textBoldFont: UIFont = Font.semibold(15.0)
|
||||
private let textItalicFont: UIFont = Font.italic(15.0)
|
||||
private let textFixedFont: UIFont = Font.regular(15.0)
|
||||
private let buttonFont: UIFont = Font.semibold(13.0)
|
||||
private let titleFont = Font.semibold(15.0)
|
||||
private let textFont = Font.regular(15.0)
|
||||
private let textBoldFont = Font.semibold(15.0)
|
||||
private let textItalicFont = Font.italic(15.0)
|
||||
private let textBoldItalicFont = Font.semiboldItalic(15.0)
|
||||
private let textFixedFont = Font.regular(15.0)
|
||||
private let buttonFont = Font.semibold(13.0)
|
||||
|
||||
enum ChatMessageAttachedContentActionIcon {
|
||||
case instant
|
||||
@ -370,7 +371,7 @@ final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
string.append(NSAttributedString(string: "\n", font: textFont, textColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor))
|
||||
}
|
||||
if let entities = entities {
|
||||
string.append(stringWithAppliedEntities(text, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, fixedFont: textFixedFont))
|
||||
string.append(stringWithAppliedEntities(text, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, boldItalicFont: textBoldItalicFont, fixedFont: textFixedFont))
|
||||
} else {
|
||||
string.append(NSAttributedString(string: text + "\n", font: textFont, textColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor))
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
let forceStatusNewline = false
|
||||
|
||||
if let entities = entities {
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: textFont, linkFont: textFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, fixedFont: item.presentationData.messageFixedFont)
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: textFont, linkFont: textFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, boldItalicFont: item.presentationData.messageBoldItalicFont, fixedFont: item.presentationData.messageFixedFont)
|
||||
} else {
|
||||
attributedText = NSAttributedString(string: rawText, font: textFont, textColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor)
|
||||
}
|
||||
|
||||
@ -12,8 +12,11 @@ struct ChatTextInputAttributes {
|
||||
static let italic = NSAttributedStringKey(rawValue: "Attribute__Italic")
|
||||
static let monospace = NSAttributedStringKey(rawValue: "Attribute__Monospace")
|
||||
static let strikethrough = NSAttributedStringKey(rawValue: "Attribute__Strikethrough")
|
||||
static let underline = NSAttributedStringKey(rawValue: "Attribute__Underline")
|
||||
static let textMention = NSAttributedStringKey(rawValue: "Attribute__TextMention")
|
||||
static let textUrl = NSAttributedStringKey(rawValue: "Attribute__TextUrl")
|
||||
|
||||
static let allAttributes = [ChatTextInputAttributes.bold, ChatTextInputAttributes.italic, ChatTextInputAttributes.monospace, ChatTextInputAttributes.strikethrough, ChatTextInputAttributes.underline, ChatTextInputAttributes.textMention, ChatTextInputAttributes.textUrl]
|
||||
}
|
||||
|
||||
func stateAttributedStringForText(_ text: NSAttributedString) -> NSAttributedString {
|
||||
@ -22,9 +25,7 @@ func stateAttributedStringForText(_ text: NSAttributedString) -> NSAttributedStr
|
||||
|
||||
text.enumerateAttributes(in: fullRange, options: [], using: { attributes, range, _ in
|
||||
for (key, value) in attributes {
|
||||
if key == ChatTextInputAttributes.textMention || key == ChatTextInputAttributes.textUrl {
|
||||
result.addAttribute(key, value: value, range: range)
|
||||
} else if key == ChatTextInputAttributes.bold || key == ChatTextInputAttributes.italic || key == ChatTextInputAttributes.monospace || key == ChatTextInputAttributes.strikethrough {
|
||||
if ChatTextInputAttributes.allAttributes.contains(key) {
|
||||
result.addAttribute(key, value: value, range: range)
|
||||
}
|
||||
}
|
||||
@ -32,12 +33,12 @@ func stateAttributedStringForText(_ text: NSAttributedString) -> NSAttributedStr
|
||||
return result
|
||||
}
|
||||
|
||||
private struct FontAttributes: OptionSet {
|
||||
struct ChatTextFontAttributes: OptionSet {
|
||||
var rawValue: Int32 = 0
|
||||
|
||||
static let bold = FontAttributes(rawValue: 1 << 0)
|
||||
static let italic = FontAttributes(rawValue: 1 << 1)
|
||||
static let monospace = FontAttributes(rawValue: 1 << 2)
|
||||
static let bold = ChatTextFontAttributes(rawValue: 1 << 0)
|
||||
static let italic = ChatTextFontAttributes(rawValue: 1 << 1)
|
||||
static let monospace = ChatTextFontAttributes(rawValue: 1 << 2)
|
||||
}
|
||||
|
||||
func textAttributedStringForStateText(_ stateText: NSAttributedString, fontSize: CGFloat, textColor: UIColor, accentTextColor: UIColor) -> NSAttributedString {
|
||||
@ -48,7 +49,7 @@ func textAttributedStringForStateText(_ stateText: NSAttributedString, fontSize:
|
||||
result.addAttribute(NSAttributedStringKey.foregroundColor, value: textColor, range: fullRange)
|
||||
|
||||
stateText.enumerateAttributes(in: fullRange, options: [], using: { attributes, range, _ in
|
||||
var fontAttributes: FontAttributes = []
|
||||
var fontAttributes: ChatTextFontAttributes = []
|
||||
|
||||
for (key, value) in attributes {
|
||||
if key == ChatTextInputAttributes.textMention || key == ChatTextInputAttributes.textUrl {
|
||||
@ -69,6 +70,9 @@ func textAttributedStringForStateText(_ stateText: NSAttributedString, fontSize:
|
||||
} else if key == ChatTextInputAttributes.strikethrough {
|
||||
result.addAttribute(key, value: value, range: range)
|
||||
result.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
} else if key == ChatTextInputAttributes.underline {
|
||||
result.addAttribute(key, value: value, range: range)
|
||||
result.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,7 +425,7 @@ func refreshChatTextInputAttributes(_ textNode: ASEditableTextNode, theme: Prese
|
||||
textNode.textView.textStorage.addAttribute(NSAttributedStringKey.foregroundColor, value: theme.chat.inputPanel.primaryTextColor, range: fullRange)
|
||||
|
||||
attributedText.enumerateAttributes(in: fullRange, options: [], using: { attributes, range, _ in
|
||||
var fontAttributes: FontAttributes = []
|
||||
var fontAttributes: ChatTextFontAttributes = []
|
||||
|
||||
for (key, value) in attributes {
|
||||
if key == ChatTextInputAttributes.textMention || key == ChatTextInputAttributes.textUrl {
|
||||
@ -443,6 +447,9 @@ func refreshChatTextInputAttributes(_ textNode: ASEditableTextNode, theme: Prese
|
||||
} else if key == ChatTextInputAttributes.strikethrough {
|
||||
textNode.textView.textStorage.addAttribute(key, value: value, range: range)
|
||||
textNode.textView.textStorage.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
} else if key == ChatTextInputAttributes.underline {
|
||||
textNode.textView.textStorage.addAttribute(key, value: value, range: range)
|
||||
textNode.textView.textStorage.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -118,10 +118,11 @@ func internalDocumentItemSupportsMimeType(_ type: String, fileName: String?) ->
|
||||
private let textFont = Font.regular(16.0)
|
||||
private let boldFont = Font.bold(16.0)
|
||||
private let italicFont = Font.italic(16.0)
|
||||
private let boldItalicFont = Font.semiboldItalic(16.0)
|
||||
private let fixedFont = UIFont(name: "Menlo-Regular", size: 15.0) ?? textFont
|
||||
|
||||
func galleryCaptionStringWithAppliedEntities(_ text: String, entities: [MessageTextEntity]) -> NSAttributedString {
|
||||
return stringWithAppliedEntities(text, entities: entities, baseColor: .white, linkColor: UIColor(rgb: 0x5ac8fa), baseFont: textFont, linkFont: textFont, boldFont: boldFont, italicFont: italicFont, fixedFont: fixedFont, underlineLinks: false)
|
||||
return stringWithAppliedEntities(text, entities: entities, baseColor: .white, linkColor: UIColor(rgb: 0x5ac8fa), baseFont: textFont, linkFont: textFont, boldFont: boldFont, italicFont: italicFont, boldItalicFont: boldItalicFont, fixedFont: fixedFont, underlineLinks: false)
|
||||
}
|
||||
|
||||
private func galleryMessageCaptionText(_ message: Message) -> String {
|
||||
|
||||
@ -134,6 +134,8 @@ func generateChatInputTextEntities(_ text: NSAttributedString) -> [MessageTextEn
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .Code))
|
||||
} else if key == ChatTextInputAttributes.strikethrough {
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .Strikethrough))
|
||||
} else if key == ChatTextInputAttributes.underline {
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .Underline))
|
||||
} else if key == ChatTextInputAttributes.textMention, let value = value as? ChatTextInputTextMentionAttribute {
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .TextMention(peerId: value.peerId)))
|
||||
} else if key == ChatTextInputAttributes.textUrl, let value = value as? ChatTextInputTextUrlAttribute {
|
||||
|
||||
@ -80,6 +80,7 @@ private let labelFont = Font.regular(14.0)
|
||||
private let textFont = Font.regular(17.0)
|
||||
private let textBoldFont = Font.medium(17.0)
|
||||
private let textItalicFont = Font.italic(17.0)
|
||||
private let textBoldItalicFont = Font.semiboldItalic(17.0)
|
||||
private let textFixedFont = Font.regular(17.0)
|
||||
|
||||
class ItemListAddressItemNode: ListViewItemNode {
|
||||
@ -181,7 +182,7 @@ class ItemListAddressItemNode: ListViewItemNode {
|
||||
let (labelLayout, labelApply) = makeLabelLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.label, font: labelFont, textColor: labelColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftOffset - leftInset - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
|
||||
let baseColor = item.theme.list.itemPrimaryTextColor
|
||||
let string = stringWithAppliedEntities(item.text, entities: [], baseColor: baseColor, linkColor: item.theme.list.itemAccentColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, fixedFont: textFixedFont)
|
||||
let string = stringWithAppliedEntities(item.text, entities: [], baseColor: baseColor, linkColor: item.theme.list.itemAccentColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, boldItalicFont: textBoldItalicFont, fixedFont: textFixedFont)
|
||||
|
||||
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: string, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width - leftOffset - leftInset - rightInset - 98.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
let padding: CGFloat = !item.label.isEmpty ? 39.0 : 20.0
|
||||
|
||||
@ -86,6 +86,7 @@ class ItemListMultilineTextItem: ListViewItem, ItemListItem {
|
||||
private let titleFont = Font.regular(17.0)
|
||||
private let titleBoldFont = Font.medium(17.0)
|
||||
private let titleItalicFont = Font.italic(17.0)
|
||||
private let titleBoldItalicFont = Font.semiboldItalic(17.0)
|
||||
private let titleFixedFont = Font.regular(17.0)
|
||||
|
||||
class ItemListMultilineTextItemNode: ListViewItemNode {
|
||||
@ -184,7 +185,7 @@ class ItemListMultilineTextItemNode: ListViewItemNode {
|
||||
}
|
||||
|
||||
let entities = generateTextEntities(item.text, enabledTypes: item.enabledEntitiyTypes)
|
||||
let string = stringWithAppliedEntities(item.text, entities: entities, baseColor: textColor, linkColor: item.theme.list.itemAccentColor, baseFont: titleFont, linkFont: titleFont, boldFont: titleBoldFont, italicFont: titleItalicFont, fixedFont: titleFixedFont)
|
||||
let string = stringWithAppliedEntities(item.text, entities: entities, baseColor: textColor, linkColor: item.theme.list.itemAccentColor, baseFont: titleFont, linkFont: titleFont, boldFont: titleBoldFont, italicFont: titleItalicFont, boldItalicFont: titleBoldItalicFont, fixedFont: titleFixedFont)
|
||||
|
||||
let (titleLayout, titleApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: string, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width - params.leftInset - params.rightInset - 20.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ private let labelFont = Font.regular(14.0)
|
||||
private let textFont = Font.regular(17.0)
|
||||
private let textBoldFont = Font.medium(17.0)
|
||||
private let textItalicFont = Font.italic(17.0)
|
||||
private let textBoldItalicFont = Font.semiboldItalic(17.0)
|
||||
private let textFixedFont = Font.regular(17.0)
|
||||
|
||||
class ItemListTextWithLabelItemNode: ListViewItemNode {
|
||||
@ -208,7 +209,7 @@ class ItemListTextWithLabelItemNode: ListViewItemNode {
|
||||
case .highlighted:
|
||||
baseColor = item.theme.list.itemHighlightedColor
|
||||
}
|
||||
let string = stringWithAppliedEntities(item.text, entities: entities, baseColor: baseColor, linkColor: item.theme.list.itemAccentColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, fixedFont: textFixedFont)
|
||||
let string = stringWithAppliedEntities(item.text, entities: entities, baseColor: baseColor, linkColor: item.theme.list.itemAccentColor, baseFont: textFont, linkFont: textFont, boldFont: textBoldFont, italicFont: textItalicFont, boldItalicFont: textBoldItalicFont, fixedFont: textFixedFont)
|
||||
|
||||
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: string, backgroundColor: nil, maximumNumberOfLines: item.multiline ? 0 : 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftOffset - leftInset - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
let contentSize = CGSize(width: params.width, height: textLayout.size.height + 39.0)
|
||||
|
||||
@ -374,7 +374,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol
|
||||
|
||||
if self.currentItems.isEmpty && !updatedItems.isEmpty {
|
||||
let entities = generateTextEntities(info.title, enabledTypes: [.mention])
|
||||
self.contentTitleNode.attributedText = stringWithAppliedEntities(info.title, entities: entities, baseColor: self.presentationData.theme.actionSheet.primaryTextColor, linkColor: self.presentationData.theme.actionSheet.controlAccentColor, baseFont: Font.medium(20.0), linkFont: Font.medium(20.0), boldFont: Font.medium(20.0), italicFont: Font.medium(20.0), fixedFont: Font.medium(20.0))
|
||||
self.contentTitleNode.attributedText = stringWithAppliedEntities(info.title, entities: entities, baseColor: self.presentationData.theme.actionSheet.primaryTextColor, linkColor: self.presentationData.theme.actionSheet.controlAccentColor, baseFont: Font.medium(20.0), linkFont: Font.medium(20.0), boldFont: Font.medium(20.0), italicFont: Font.medium(20.0), boldItalicFont: Font.medium(20.0), fixedFont: Font.medium(20.0))
|
||||
animateIn = true
|
||||
}
|
||||
transaction = StickerPackPreviewGridTransaction(previousList: self.currentItems, list: updatedItems, account: self.context.account, interaction: self.interaction)
|
||||
|
||||
@ -36,6 +36,8 @@ func chatInputStateStringWithAppliedEntities(_ text: String, entities: [MessageT
|
||||
string.addAttribute(ChatTextInputAttributes.monospace, value: true as NSNumber, range: range)
|
||||
case .Strikethrough:
|
||||
string.addAttribute(ChatTextInputAttributes.strikethrough, value: true as NSNumber, range: range)
|
||||
case .Underline:
|
||||
string.addAttribute(ChatTextInputAttributes.underline, value: true as NSNumber, range: range)
|
||||
default:
|
||||
break
|
||||
}
|
||||
@ -43,7 +45,7 @@ func chatInputStateStringWithAppliedEntities(_ text: String, entities: [MessageT
|
||||
return string
|
||||
}
|
||||
|
||||
func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], baseColor: UIColor, linkColor: UIColor, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, fixedFont: UIFont, underlineLinks: Bool = true, external: Bool = false) -> NSAttributedString {
|
||||
func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], baseColor: UIColor, linkColor: UIColor, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, boldItalicFont: UIFont, fixedFont: UIFont, underlineLinks: Bool = true, external: Bool = false) -> NSAttributedString {
|
||||
var nsString: NSString?
|
||||
let string = NSMutableAttributedString(string: text, attributes: [NSAttributedStringKey.font: baseFont, NSAttributedStringKey.foregroundColor: baseColor])
|
||||
var skipEntity = false
|
||||
@ -52,6 +54,8 @@ func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], ba
|
||||
if linkColor.isEqual(baseColor) {
|
||||
underlineAllLinks = true
|
||||
}
|
||||
var fontAttributes: [NSRange: ChatTextFontAttributes] = [:]
|
||||
|
||||
for i in 0 ..< entities.count {
|
||||
if skipEntity {
|
||||
skipEntity = false
|
||||
@ -108,9 +112,17 @@ func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], ba
|
||||
string.addAttribute(NSAttributedStringKey(rawValue: TelegramTextAttributes.URL), value: url, range: range)
|
||||
}
|
||||
case .Bold:
|
||||
string.addAttribute(NSAttributedStringKey.font, value: boldFont, range: range)
|
||||
if let fontAttribute = fontAttributes[range] {
|
||||
fontAttributes[range] = fontAttribute.union(.bold)
|
||||
} else {
|
||||
fontAttributes[range] = .bold
|
||||
}
|
||||
case .Italic:
|
||||
string.addAttribute(NSAttributedStringKey.font, value: italicFont, range: range)
|
||||
if let fontAttribute = fontAttributes[range] {
|
||||
fontAttributes[range] = fontAttribute.union(.italic)
|
||||
} else {
|
||||
fontAttributes[range] = .italic
|
||||
}
|
||||
case .Mention:
|
||||
string.addAttribute(NSAttributedStringKey.foregroundColor, value: linkColor, range: range)
|
||||
if underlineLinks && underlineAllLinks {
|
||||
@ -125,6 +137,8 @@ func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], ba
|
||||
string.addAttribute(NSAttributedStringKey(rawValue: TelegramTextAttributes.PeerTextMention), value: nsString!.substring(with: range), range: range)
|
||||
case .Strikethrough:
|
||||
string.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
case .Underline:
|
||||
string.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue as NSNumber, range: range)
|
||||
case let .TextMention(peerId):
|
||||
string.addAttribute(NSAttributedStringKey.foregroundColor, value: linkColor, range: range)
|
||||
if underlineLinks && underlineAllLinks {
|
||||
@ -191,6 +205,20 @@ func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], ba
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
for (range, fontAttributes) in fontAttributes {
|
||||
var font: UIFont?
|
||||
if fontAttributes == [.bold, .italic] {
|
||||
font = boldItalicFont
|
||||
} else if fontAttributes == [.bold] {
|
||||
font = boldFont
|
||||
} else if fontAttributes == [.italic] {
|
||||
font = italicFont
|
||||
}
|
||||
if let font = font {
|
||||
string.addAttribute(NSAttributedStringKey.font, value: font, range: range)
|
||||
}
|
||||
}
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ final class TermsOfServiceControllerNode: ViewControllerTracingNode {
|
||||
self.contentTextNode = ImmediateTextNode()
|
||||
self.contentTextNode.displaysAsynchronously = false
|
||||
self.contentTextNode.maximumNumberOfLines = 0
|
||||
self.contentTextNode.attributedText = stringWithAppliedEntities(text, entities: entities, baseColor: theme.primary, linkColor: theme.accent, baseFont: Font.regular(15.0), linkFont: Font.regular(15.0), boldFont: Font.semibold(15.0), italicFont: Font.italic(15.0), fixedFont: Font.monospace(15.0))
|
||||
self.contentTextNode.attributedText = stringWithAppliedEntities(text, entities: entities, baseColor: theme.primary, linkColor: theme.accent, baseFont: Font.regular(15.0), linkFont: Font.regular(15.0), boldFont: Font.semibold(15.0), italicFont: Font.italic(15.0), boldItalicFont: Font.semiboldItalic(15.0), fixedFont: Font.monospace(15.0))
|
||||
|
||||
self.toolbarNode = ASDisplayNode()
|
||||
self.toolbarSeparatorNode = ASDisplayNode()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user