mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 03:21:29 +00:00
Drawing improvements
This commit is contained in:
parent
c42220b618
commit
6ece02e998
@ -338,15 +338,17 @@ final class DrawingSettings: Codable, Equatable {
|
||||
|
||||
private final class ReferenceContentSource: ContextReferenceContentSource {
|
||||
private let sourceView: UIView
|
||||
private let contentArea: CGRect
|
||||
private let customPosition: CGPoint
|
||||
|
||||
init(sourceView: UIView, customPosition: CGPoint) {
|
||||
init(sourceView: UIView, contentArea: CGRect, customPosition: CGPoint) {
|
||||
self.sourceView = sourceView
|
||||
self.contentArea = contentArea
|
||||
self.customPosition = customPosition
|
||||
}
|
||||
|
||||
func transitionInfo() -> ContextControllerReferenceViewInfo? {
|
||||
return ContextControllerReferenceViewInfo(referenceView: self.sourceView, contentAreaInScreenSpace: UIScreen.main.bounds, customPosition: customPosition)
|
||||
return ContextControllerReferenceViewInfo(referenceView: self.sourceView, contentAreaInScreenSpace: self.contentArea, customPosition: customPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@ -849,7 +851,7 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
)
|
||||
]
|
||||
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }.withUpdated(theme: defaultDarkPresentationTheme)
|
||||
let contextController = ContextController(account: self.context.account, presentationData: presentationData, source: .reference(ReferenceContentSource(sourceView: sourceView, customPosition: CGPoint(x: 7.0, y: 3.0))), items: .single(ContextController.Items(content: .list(items))))
|
||||
let contextController = ContextController(account: self.context.account, presentationData: presentationData, source: .reference(ReferenceContentSource(sourceView: sourceView, contentArea: UIScreen.main.bounds, customPosition: CGPoint(x: 7.0, y: 3.0))), items: .single(ContextController.Items(content: .list(items))))
|
||||
self.present(contextController)
|
||||
}
|
||||
|
||||
@ -2294,18 +2296,18 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
|
||||
|
||||
private weak var currentFontPicker: ContextController?
|
||||
func presentFontPicker(sourceView: UIView) {
|
||||
guard !self.dismissFontPicker() else {
|
||||
guard !self.dismissFontPicker(), let validLayout = self.validLayout?.0 else {
|
||||
return
|
||||
}
|
||||
let fonts: [DrawingTextFont] = [
|
||||
.sanFrancisco,
|
||||
.newYork,
|
||||
.other("MarkerFelt-Wide", "Marker Felt"),
|
||||
.other("Chalkduster", "Chalkduster"),
|
||||
.other("Menlo-Bold", "Menlo"),
|
||||
.other("Copperplate-Bold", "Copperplate"),
|
||||
.other("GillSans-SemiBold", "Gill Sans"),
|
||||
.other("Papyrus", "Papyrus")
|
||||
.other("AmericanTypewriter", "American Typewriter"),
|
||||
.other("AvenirNext-DemiBoldItalic", "Avenir Next"),
|
||||
.other("CourierNewPS-BoldMT", "Courier New"),
|
||||
.other("Noteworthy-Bold", "Noteworthy"),
|
||||
.other("Georgia-Bold", "Georgia"),
|
||||
.other("Papyrus", "Papyrus"),
|
||||
.other("SnellRoundhand-Bold", "Snell Roundhand")
|
||||
]
|
||||
|
||||
var items: [ContextMenuItem] = []
|
||||
@ -2325,7 +2327,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
|
||||
}
|
||||
|
||||
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }.withUpdated(theme: defaultDarkPresentationTheme)
|
||||
let contextController = ContextController(account: self.context.account, presentationData: presentationData, source: .reference(ReferenceContentSource(sourceView: sourceView, customPosition: CGPoint(x: 7.0, y: 0.0))), items: .single(ContextController.Items(content: .list(items))))
|
||||
let contextController = ContextController(account: self.context.account, presentationData: presentationData, source: .reference(ReferenceContentSource(sourceView: sourceView, contentArea: CGRect(origin: .zero, size: CGSize(width: validLayout.size.width, height: validLayout.size.height - (validLayout.inputHeight ?? 0.0))), customPosition: CGPoint(x: 0.0, y: 1.0))), items: .single(ContextController.Items(content: .list(items))))
|
||||
self.controller?.present(contextController, in: .window(.root))
|
||||
self.currentFontPicker = contextController
|
||||
}
|
||||
|
||||
@ -78,7 +78,6 @@ public final class DrawingTextEntity: DrawingEntity, Codable {
|
||||
|
||||
enum Font: Codable {
|
||||
case sanFrancisco
|
||||
case newYork
|
||||
case other(String, String)
|
||||
}
|
||||
|
||||
@ -551,11 +550,9 @@ final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate {
|
||||
var font: UIFont
|
||||
switch self.textEntity.font {
|
||||
case .sanFrancisco:
|
||||
font = Font.with(size: fontSize, design: .regular, weight: .semibold)
|
||||
case .newYork:
|
||||
font = Font.with(size: fontSize, design: .serif, weight: .semibold)
|
||||
font = Font.with(size: fontSize, design: .round, weight: .semibold)
|
||||
case let .other(fontName, _):
|
||||
font = UIFont(name: fontName, size: fontSize) ?? Font.with(size: fontSize, design: .regular, weight: .semibold)
|
||||
font = UIFont(name: fontName, size: fontSize) ?? Font.with(size: fontSize, design: .round, weight: .semibold)
|
||||
}
|
||||
|
||||
text.addAttribute(.font, value: font, range: range)
|
||||
@ -1286,6 +1283,7 @@ private var availableFonts: [String: (String, String)] = {
|
||||
|
||||
var preferredFont: String?
|
||||
for name in names {
|
||||
print(name)
|
||||
let originalName = name
|
||||
let name = name.lowercased()
|
||||
if (!name.contains("-") || name.contains("regular")) && preferredFont == nil {
|
||||
@ -1301,6 +1299,6 @@ private var availableFonts: [String: (String, String)] = {
|
||||
result[shortname] = (preferredFont, family)
|
||||
}
|
||||
}
|
||||
print(result)
|
||||
//print(result)
|
||||
return result
|
||||
}()
|
||||
|
||||
@ -46,15 +46,12 @@ enum DrawingTextAlignment: Equatable {
|
||||
|
||||
enum DrawingTextFont: Equatable, Hashable {
|
||||
case sanFrancisco
|
||||
case newYork
|
||||
case other(String, String)
|
||||
|
||||
init(font: DrawingTextEntity.Font) {
|
||||
switch font {
|
||||
case .sanFrancisco:
|
||||
self = .sanFrancisco
|
||||
case .newYork:
|
||||
self = .newYork
|
||||
case let .other(font, name):
|
||||
self = .other(font, name)
|
||||
}
|
||||
@ -64,8 +61,6 @@ enum DrawingTextFont: Equatable, Hashable {
|
||||
switch self {
|
||||
case .sanFrancisco:
|
||||
return .sanFrancisco
|
||||
case .newYork:
|
||||
return .newYork
|
||||
case let .other(font, name):
|
||||
return .other(font, name)
|
||||
}
|
||||
@ -75,8 +70,6 @@ enum DrawingTextFont: Equatable, Hashable {
|
||||
switch self {
|
||||
case .sanFrancisco:
|
||||
return "San Francisco"
|
||||
case .newYork:
|
||||
return "New York"
|
||||
case let .other(_, name):
|
||||
return name
|
||||
}
|
||||
@ -85,9 +78,7 @@ enum DrawingTextFont: Equatable, Hashable {
|
||||
func uiFont(size: CGFloat) -> UIFont {
|
||||
switch self {
|
||||
case .sanFrancisco:
|
||||
return Font.semibold(size)
|
||||
case .newYork:
|
||||
return Font.with(size: size, design: .serif, weight: .semibold)
|
||||
return Font.with(size: size, design: .round, weight: .semibold)
|
||||
case let .other(font, _):
|
||||
return UIFont(name: font, size: size) ?? Font.semibold(size)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user