From 6ece02e998ee2812e81c9166cae8f17d71ee643d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 24 Dec 2022 15:45:17 +0400 Subject: [PATCH] Drawing improvements --- .../DrawingUI/Sources/DrawingScreen.swift | 26 ++++++++++--------- .../DrawingUI/Sources/DrawingTextEntity.swift | 10 +++---- .../Sources/TextSettingsComponent.swift | 11 +------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/submodules/DrawingUI/Sources/DrawingScreen.swift b/submodules/DrawingUI/Sources/DrawingScreen.swift index e536939a50..99a1ac87fc 100644 --- a/submodules/DrawingUI/Sources/DrawingScreen.swift +++ b/submodules/DrawingUI/Sources/DrawingScreen.swift @@ -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 } diff --git a/submodules/DrawingUI/Sources/DrawingTextEntity.swift b/submodules/DrawingUI/Sources/DrawingTextEntity.swift index 689e065690..746ec0a2b5 100644 --- a/submodules/DrawingUI/Sources/DrawingTextEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingTextEntity.swift @@ -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 }() diff --git a/submodules/DrawingUI/Sources/TextSettingsComponent.swift b/submodules/DrawingUI/Sources/TextSettingsComponent.swift index 05ca72c6d5..59ffd9bf2e 100644 --- a/submodules/DrawingUI/Sources/TextSettingsComponent.swift +++ b/submodules/DrawingUI/Sources/TextSettingsComponent.swift @@ -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) }