mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improve code blocks
(cherry picked from commit 94de15f0b68a565ae8c58e66e879036a1f2ca28e)
This commit is contained in:
parent
0dca4a544c
commit
3d44192e2f
@ -10,6 +10,10 @@ private let quoteIcon: UIImage = {
|
||||
return UIImage(bundleImageName: "Chat/Message/ReplyQuoteIcon")!.precomposed()
|
||||
}()
|
||||
|
||||
private let codeIcon: UIImage = {
|
||||
return UIImage(bundleImageName: "Chat/Message/TextCodeIcon")!.precomposed()
|
||||
}()
|
||||
|
||||
private final class TextNodeStrikethrough {
|
||||
let range: NSRange
|
||||
let frame: CGRect
|
||||
@ -1363,7 +1367,9 @@ open class TextNode: ASDisplayNode {
|
||||
case .quote:
|
||||
additionalSegmentRightInset = blockQuoteIconInset
|
||||
case .code:
|
||||
break
|
||||
if segment.title != nil {
|
||||
additionalSegmentRightInset = blockQuoteIconInset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2245,7 +2251,17 @@ open class TextNode: ASDisplayNode {
|
||||
context.restoreGState()
|
||||
context.resetClip()
|
||||
case .code:
|
||||
break
|
||||
if blockQuote.data.title != nil {
|
||||
let quoteRect = CGRect(origin: CGPoint(x: blockFrame.maxX - 4.0 - codeIcon.size.width, y: blockFrame.minY + 4.0), size: codeIcon.size)
|
||||
context.saveGState()
|
||||
context.translateBy(x: quoteRect.midX, y: quoteRect.midY)
|
||||
context.scaleBy(x: 1.0, y: -1.0)
|
||||
context.translateBy(x: -quoteRect.midX, y: -quoteRect.midY)
|
||||
context.clip(to: quoteRect, mask: codeIcon.cgImage!)
|
||||
context.fill(quoteRect)
|
||||
context.restoreGState()
|
||||
context.resetClip()
|
||||
}
|
||||
}
|
||||
|
||||
let lineFrame = CGRect(origin: CGPoint(x: blockFrame.minX, y: blockFrame.minY), size: CGSize(width: lineWidth, height: blockFrame.height))
|
||||
|
12
submodules/TelegramUI/Images.xcassets/Chat/Message/TextCodeIcon.imageset/Contents.json
vendored
Normal file
12
submodules/TelegramUI/Images.xcassets/Chat/Message/TextCodeIcon.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "codemini.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
147
submodules/TelegramUI/Images.xcassets/Chat/Message/TextCodeIcon.imageset/codemini.pdf
vendored
Normal file
147
submodules/TelegramUI/Images.xcassets/Chat/Message/TextCodeIcon.imageset/codemini.pdf
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
%PDF-1.7
|
||||
|
||||
1 0 obj
|
||||
<< >>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<< /Length 3 0 R >>
|
||||
stream
|
||||
/DeviceRGB CS
|
||||
/DeviceRGB cs
|
||||
q
|
||||
1.000000 0.000000 -0.000000 1.000000 1.000000 0.677734 cm
|
||||
0.000000 0.000000 0.000000 scn
|
||||
3.086899 6.235367 m
|
||||
3.411034 6.559502 3.411034 7.085029 3.086899 7.409164 c
|
||||
2.762764 7.733299 2.237236 7.733299 1.913101 7.409164 c
|
||||
3.086899 6.235367 l
|
||||
h
|
||||
0.000000 4.322266 m
|
||||
-0.586899 4.909164 l
|
||||
-0.911034 4.585029 -0.911034 4.059502 -0.586899 3.735367 c
|
||||
0.000000 4.322266 l
|
||||
h
|
||||
1.913101 1.235367 m
|
||||
2.237236 0.911232 2.762764 0.911232 3.086899 1.235367 c
|
||||
3.411034 1.559502 3.411034 2.085029 3.086899 2.409164 c
|
||||
1.913101 1.235367 l
|
||||
h
|
||||
1.913101 7.409164 m
|
||||
-0.586899 4.909164 l
|
||||
0.586899 3.735367 l
|
||||
3.086899 6.235367 l
|
||||
1.913101 7.409164 l
|
||||
h
|
||||
-0.586899 3.735367 m
|
||||
1.913101 1.235367 l
|
||||
3.086899 2.409164 l
|
||||
0.586899 4.909164 l
|
||||
-0.586899 3.735367 l
|
||||
h
|
||||
f
|
||||
n
|
||||
Q
|
||||
q
|
||||
-1.000000 0.000000 -0.000000 -1.000000 13.000000 9.322266 cm
|
||||
0.000000 0.000000 0.000000 scn
|
||||
3.086899 6.235367 m
|
||||
3.411034 6.559502 3.411034 7.085029 3.086899 7.409164 c
|
||||
2.762764 7.733299 2.237236 7.733299 1.913101 7.409164 c
|
||||
3.086899 6.235367 l
|
||||
h
|
||||
0.000000 4.322266 m
|
||||
-0.586899 4.909164 l
|
||||
-0.911034 4.585029 -0.911034 4.059502 -0.586899 3.735367 c
|
||||
0.000000 4.322266 l
|
||||
h
|
||||
1.913101 1.235367 m
|
||||
2.237236 0.911232 2.762764 0.911232 3.086899 1.235367 c
|
||||
3.411034 1.559502 3.411034 2.085029 3.086899 2.409164 c
|
||||
1.913101 1.235367 l
|
||||
h
|
||||
1.913101 7.409164 m
|
||||
-0.586899 4.909164 l
|
||||
0.586899 3.735367 l
|
||||
3.086899 6.235367 l
|
||||
1.913101 7.409164 l
|
||||
h
|
||||
-0.586899 3.735367 m
|
||||
1.913101 1.235367 l
|
||||
3.086899 2.409164 l
|
||||
0.586899 4.909164 l
|
||||
-0.586899 3.735367 l
|
||||
h
|
||||
f
|
||||
n
|
||||
Q
|
||||
q
|
||||
1.000000 0.000000 -0.000000 1.000000 6.000000 -0.833008 cm
|
||||
0.000000 0.000000 0.000000 scn
|
||||
2.805218 9.631703 m
|
||||
2.916396 10.076413 2.646014 10.527049 2.201305 10.638227 c
|
||||
1.756595 10.749404 1.305959 10.479022 1.194782 10.034312 c
|
||||
2.805218 9.631703 l
|
||||
h
|
||||
-0.805218 2.034312 m
|
||||
-0.916396 1.589602 -0.646014 1.138967 -0.201305 1.027789 c
|
||||
0.243405 0.916612 0.694041 1.186994 0.805218 1.631703 c
|
||||
-0.805218 2.034312 l
|
||||
h
|
||||
1.194782 10.034312 m
|
||||
-0.805218 2.034312 l
|
||||
0.805218 1.631703 l
|
||||
2.805218 9.631703 l
|
||||
1.194782 10.034312 l
|
||||
h
|
||||
f
|
||||
n
|
||||
Q
|
||||
|
||||
endstream
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
2021
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<< /Annots []
|
||||
/Type /Page
|
||||
/MediaBox [ 0.000000 0.000000 14.000000 10.000000 ]
|
||||
/Resources 1 0 R
|
||||
/Contents 2 0 R
|
||||
/Parent 5 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
5 0 obj
|
||||
<< /Kids [ 4 0 R ]
|
||||
/Count 1
|
||||
/Type /Pages
|
||||
>>
|
||||
endobj
|
||||
|
||||
6 0 obj
|
||||
<< /Pages 5 0 R
|
||||
/Type /Catalog
|
||||
>>
|
||||
endobj
|
||||
|
||||
xref
|
||||
0 7
|
||||
0000000000 65535 f
|
||||
0000000010 00000 n
|
||||
0000000034 00000 n
|
||||
0000002111 00000 n
|
||||
0000002134 00000 n
|
||||
0000002307 00000 n
|
||||
0000002381 00000 n
|
||||
trailer
|
||||
<< /ID [ (some) (id) ]
|
||||
/Root 6 0 R
|
||||
/Size 7
|
||||
>>
|
||||
startxref
|
||||
2440
|
||||
%%EOF
|
@ -215,9 +215,11 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
||||
nsString = text as NSString
|
||||
}
|
||||
if let codeBlockTitleColor, let codeBlockAccentColor, let codeBlockBackgroundColor {
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .code(language: language), title: language.flatMap {
|
||||
NSAttributedString(string: $0.capitalized, font: boldFont.withSize(round(boldFont.pointSize * 0.8235294117647058)), textColor: codeBlockTitleColor)
|
||||
}, color: codeBlockAccentColor, secondaryColor: nil, tertiaryColor: nil, backgroundColor: codeBlockBackgroundColor), range: range)
|
||||
var title: NSAttributedString?
|
||||
if let language, !language.isEmpty {
|
||||
title = NSAttributedString(string: language.capitalized, font: boldFont.withSize(round(boldFont.pointSize * 0.8235294117647058)), textColor: codeBlockTitleColor)
|
||||
}
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .code(language: language), title: title, color: codeBlockAccentColor, secondaryColor: nil, tertiaryColor: nil, backgroundColor: codeBlockBackgroundColor), range: range)
|
||||
}
|
||||
case .BlockQuote:
|
||||
addFontAttributes(range, .blockQuote)
|
||||
|
Loading…
x
Reference in New Issue
Block a user