Drawing improvements

This commit is contained in:
Ilya Laktyushin 2022-12-24 15:45:17 +04:00
parent c42220b618
commit 6ece02e998
3 changed files with 19 additions and 28 deletions

View File

@ -338,15 +338,17 @@ final class DrawingSettings: Codable, Equatable {
private final class ReferenceContentSource: ContextReferenceContentSource { private final class ReferenceContentSource: ContextReferenceContentSource {
private let sourceView: UIView private let sourceView: UIView
private let contentArea: CGRect
private let customPosition: CGPoint private let customPosition: CGPoint
init(sourceView: UIView, customPosition: CGPoint) { init(sourceView: UIView, contentArea: CGRect, customPosition: CGPoint) {
self.sourceView = sourceView self.sourceView = sourceView
self.contentArea = contentArea
self.customPosition = customPosition self.customPosition = customPosition
} }
func transitionInfo() -> ContextControllerReferenceViewInfo? { 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 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) self.present(contextController)
} }
@ -2294,18 +2296,18 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
private weak var currentFontPicker: ContextController? private weak var currentFontPicker: ContextController?
func presentFontPicker(sourceView: UIView) { func presentFontPicker(sourceView: UIView) {
guard !self.dismissFontPicker() else { guard !self.dismissFontPicker(), let validLayout = self.validLayout?.0 else {
return return
} }
let fonts: [DrawingTextFont] = [ let fonts: [DrawingTextFont] = [
.sanFrancisco, .sanFrancisco,
.newYork, .other("AmericanTypewriter", "American Typewriter"),
.other("MarkerFelt-Wide", "Marker Felt"), .other("AvenirNext-DemiBoldItalic", "Avenir Next"),
.other("Chalkduster", "Chalkduster"), .other("CourierNewPS-BoldMT", "Courier New"),
.other("Menlo-Bold", "Menlo"), .other("Noteworthy-Bold", "Noteworthy"),
.other("Copperplate-Bold", "Copperplate"), .other("Georgia-Bold", "Georgia"),
.other("GillSans-SemiBold", "Gill Sans"), .other("Papyrus", "Papyrus"),
.other("Papyrus", "Papyrus") .other("SnellRoundhand-Bold", "Snell Roundhand")
] ]
var items: [ContextMenuItem] = [] var items: [ContextMenuItem] = []
@ -2325,7 +2327,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
} }
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }.withUpdated(theme: defaultDarkPresentationTheme) 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.controller?.present(contextController, in: .window(.root))
self.currentFontPicker = contextController self.currentFontPicker = contextController
} }

View File

@ -78,7 +78,6 @@ public final class DrawingTextEntity: DrawingEntity, Codable {
enum Font: Codable { enum Font: Codable {
case sanFrancisco case sanFrancisco
case newYork
case other(String, String) case other(String, String)
} }
@ -551,11 +550,9 @@ final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate {
var font: UIFont var font: UIFont
switch self.textEntity.font { switch self.textEntity.font {
case .sanFrancisco: case .sanFrancisco:
font = Font.with(size: fontSize, design: .regular, weight: .semibold) font = Font.with(size: fontSize, design: .round, weight: .semibold)
case .newYork:
font = Font.with(size: fontSize, design: .serif, weight: .semibold)
case let .other(fontName, _): 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) text.addAttribute(.font, value: font, range: range)
@ -1286,6 +1283,7 @@ private var availableFonts: [String: (String, String)] = {
var preferredFont: String? var preferredFont: String?
for name in names { for name in names {
print(name)
let originalName = name let originalName = name
let name = name.lowercased() let name = name.lowercased()
if (!name.contains("-") || name.contains("regular")) && preferredFont == nil { if (!name.contains("-") || name.contains("regular")) && preferredFont == nil {
@ -1301,6 +1299,6 @@ private var availableFonts: [String: (String, String)] = {
result[shortname] = (preferredFont, family) result[shortname] = (preferredFont, family)
} }
} }
print(result) //print(result)
return result return result
}() }()

View File

@ -46,15 +46,12 @@ enum DrawingTextAlignment: Equatable {
enum DrawingTextFont: Equatable, Hashable { enum DrawingTextFont: Equatable, Hashable {
case sanFrancisco case sanFrancisco
case newYork
case other(String, String) case other(String, String)
init(font: DrawingTextEntity.Font) { init(font: DrawingTextEntity.Font) {
switch font { switch font {
case .sanFrancisco: case .sanFrancisco:
self = .sanFrancisco self = .sanFrancisco
case .newYork:
self = .newYork
case let .other(font, name): case let .other(font, name):
self = .other(font, name) self = .other(font, name)
} }
@ -64,8 +61,6 @@ enum DrawingTextFont: Equatable, Hashable {
switch self { switch self {
case .sanFrancisco: case .sanFrancisco:
return .sanFrancisco return .sanFrancisco
case .newYork:
return .newYork
case let .other(font, name): case let .other(font, name):
return .other(font, name) return .other(font, name)
} }
@ -75,8 +70,6 @@ enum DrawingTextFont: Equatable, Hashable {
switch self { switch self {
case .sanFrancisco: case .sanFrancisco:
return "San Francisco" return "San Francisco"
case .newYork:
return "New York"
case let .other(_, name): case let .other(_, name):
return name return name
} }
@ -85,9 +78,7 @@ enum DrawingTextFont: Equatable, Hashable {
func uiFont(size: CGFloat) -> UIFont { func uiFont(size: CGFloat) -> UIFont {
switch self { switch self {
case .sanFrancisco: case .sanFrancisco:
return Font.semibold(size) return Font.with(size: size, design: .round, weight: .semibold)
case .newYork:
return Font.with(size: size, design: .serif, weight: .semibold)
case let .other(font, _): case let .other(font, _):
return UIFont(name: font, size: size) ?? Font.semibold(size) return UIFont(name: font, size: size) ?? Font.semibold(size)
} }