From 2bdd78dd41084f303244c84d7fa5ff82cb2dfd2d Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 2 Oct 2019 16:58:56 +0100 Subject: [PATCH 01/17] Remove unused style code. --- .../AttributedStringSerializer.swift | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift index 08146561c..6329ac1c5 100644 --- a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift +++ b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift @@ -181,32 +181,6 @@ class AttributedStringSerializer { return content } - - // MARK: - Formatter Maps - - public lazy var attributeFormattersMap: [String: AttributeFormatter] = { - return [:] - }() - - public let styleToFormattersMap: [String: (AttributeFormatter, (String)->Any?)] = [ - "color": (ColorFormatter(), {(value) in return UIColor(hexString: value)}), - "text-decoration": (UnderlineFormatter(), { (value) in return value == "underline" ? NSUnderlineStyle.single.rawValue : nil}) - ] - - func parseStyle(style: String) -> [String: String] { - var stylesDictionary = [String: String]() - let styleAttributes = style.components(separatedBy: ";") - for sytleAttribute in styleAttributes { - let keyValue = sytleAttribute.components(separatedBy: ":") - guard keyValue.count == 2, - let key = keyValue.first?.trimmingCharacters(in: CharacterSet.whitespaces), - let value = keyValue.last?.trimmingCharacters(in: CharacterSet.whitespaces) else { - continue - } - stylesDictionary[key] = value - } - return stylesDictionary - } } private extension AttributedStringSerializer { From 30f661ea9915834858c88390276db8fe90b75e9f Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 2 Oct 2019 17:33:46 +0100 Subject: [PATCH 02/17] Add color converter and tests --- Aztec.xcodeproj/project.pbxproj | 8 +++++++ ...groundColorElementAttributeConverter.swift | 24 +++++++++++++++++++ .../Libxml2/DOM/Data/CSSAttributeType.swift | 1 + .../ForegroundColorCSSAttributeMatcher.swift | 12 ++++++++++ .../AttributedStringSerializer.swift | 1 + AztecTests/TextKit/TextViewTests.swift | 7 ++++++ 6 files changed, 53 insertions(+) create mode 100644 Aztec/Classes/Converters/AttributesToStringAttributes/Implementations/ForegroundColorElementAttributeConverter.swift create mode 100644 Aztec/Classes/Libxml2/DOM/Logic/CSS/ForegroundColorCSSAttributeMatcher.swift diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index 826034637..ce2398578 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -239,6 +239,8 @@ FFA61EC21DF6C1C900B71BF6 /* NSAttributedString+Archive.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFA61EC11DF6C1C900B71BF6 /* NSAttributedString+Archive.swift */; }; FFB5D29720BEB21A0038DCFB /* CiteFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB5D29620BEB21A0038DCFB /* CiteFormatter.swift */; }; FFD0FEB71DAE59A700430586 /* NSLayoutManager+Attachments.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD0FEB61DAE59A700430586 /* NSLayoutManager+Attachments.swift */; }; + FFD3C1712344DB4E00AE8DA0 /* ForegroundColorCSSAttributeMatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD3C1702344DB4E00AE8DA0 /* ForegroundColorCSSAttributeMatcher.swift */; }; + FFD3C1732344DCA900AE8DA0 /* ForegroundColorElementAttributeConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD3C1722344DCA900AE8DA0 /* ForegroundColorElementAttributeConverter.swift */; }; FFD436981E3180A500A0E26F /* FontFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFD436971E3180A500A0E26F /* FontFormatterTests.swift */; }; FFFEC7DB1EA7698900F4210F /* VideoAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFFEC7DA1EA7698900F4210F /* VideoAttachment.swift */; }; /* End PBXBuildFile section */ @@ -516,6 +518,8 @@ FFB5D29620BEB21A0038DCFB /* CiteFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CiteFormatter.swift; sourceTree = ""; }; FFC2BBF81F2A25CF00E404FB /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; }; FFD0FEB61DAE59A700430586 /* NSLayoutManager+Attachments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSLayoutManager+Attachments.swift"; sourceTree = ""; }; + FFD3C1702344DB4E00AE8DA0 /* ForegroundColorCSSAttributeMatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForegroundColorCSSAttributeMatcher.swift; sourceTree = ""; }; + FFD3C1722344DCA900AE8DA0 /* ForegroundColorElementAttributeConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForegroundColorElementAttributeConverter.swift; sourceTree = ""; }; FFD436971E3180A500A0E26F /* FontFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FontFormatterTests.swift; sourceTree = ""; }; FFFEC7DA1EA7698900F4210F /* VideoAttachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoAttachment.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -898,6 +902,7 @@ F1098740214FF55F00983B6A /* BoldElementAttributeConverter.swift */, F109874421501A2F00983B6A /* ItalicElementAttributeConverter.swift */, F109874821501C8B00983B6A /* UnderlineElementAttributeConverter.swift */, + FFD3C1722344DCA900AE8DA0 /* ForegroundColorElementAttributeConverter.swift */, ); path = Implementations; sourceTree = ""; @@ -1087,6 +1092,7 @@ F15BA610215167D200424120 /* CSSAttributeMatcher.swift */, F1F5C9DA21516E4B00F67990 /* ItalicCSSAttributeMatcher.swift */, F1F5C9DC2151702600F67990 /* UnderlineCSSAttributeMatcher.swift */, + FFD3C1702344DB4E00AE8DA0 /* ForegroundColorCSSAttributeMatcher.swift */, ); path = CSS; sourceTree = ""; @@ -1524,6 +1530,8 @@ B572AC281E817CFE008948C2 /* CommentAttachment.swift in Sources */, F1E1D5881FEC52EE0086B339 /* GenericElementConverter.swift in Sources */, F1FA0E861E6EF514009D98EE /* Node.swift in Sources */, + FFD3C1712344DB4E00AE8DA0 /* ForegroundColorCSSAttributeMatcher.swift in Sources */, + FFD3C1732344DCA900AE8DA0 /* ForegroundColorElementAttributeConverter.swift in Sources */, F1656FDE2152A6A6009C7E3A /* CiteStringAttributeConverter.swift in Sources */, 599F254B1D8BC9A1002871D6 /* String+RangeConversion.swift in Sources */, 599F25481D8BC9A1002871D6 /* Metrics.swift in Sources */, diff --git a/Aztec/Classes/Converters/AttributesToStringAttributes/Implementations/ForegroundColorElementAttributeConverter.swift b/Aztec/Classes/Converters/AttributesToStringAttributes/Implementations/ForegroundColorElementAttributeConverter.swift new file mode 100644 index 000000000..ba661389e --- /dev/null +++ b/Aztec/Classes/Converters/AttributesToStringAttributes/Implementations/ForegroundColorElementAttributeConverter.swift @@ -0,0 +1,24 @@ +import Foundation +import UIKit + +class ForegroundColorElementAttributesConverter: ElementAttributeConverter { + + let cssAttributeMatcher = ForegroundColorCSSAttributeMatcher() + + func convert( + _ attribute: Attribute, + inheriting attributes: [NSAttributedString.Key: Any]) -> [NSAttributedString.Key: Any] { + + guard let cssColor = attribute.firstCSSAttribute(ofType: .foregroundColor), + let colorValue = cssColor.value, + let color = UIColor(hexString: colorValue) else { + return attributes + } + + var attributes = attributes + + attributes[.foregroundColor] = color + + return attributes + } +} diff --git a/Aztec/Classes/Libxml2/DOM/Data/CSSAttributeType.swift b/Aztec/Classes/Libxml2/DOM/Data/CSSAttributeType.swift index 9f74c2977..6d008b5a1 100644 --- a/Aztec/Classes/Libxml2/DOM/Data/CSSAttributeType.swift +++ b/Aztec/Classes/Libxml2/DOM/Data/CSSAttributeType.swift @@ -23,6 +23,7 @@ extension CSSAttributeType { public static let fontStyle = CSSAttributeType("font-style") public static let fontWeight = CSSAttributeType("font-weight") public static let textDecoration = CSSAttributeType("text-decoration") + public static let foregroundColor = CSSAttributeType("color") } diff --git a/Aztec/Classes/Libxml2/DOM/Logic/CSS/ForegroundColorCSSAttributeMatcher.swift b/Aztec/Classes/Libxml2/DOM/Logic/CSS/ForegroundColorCSSAttributeMatcher.swift new file mode 100644 index 000000000..b5f50c94f --- /dev/null +++ b/Aztec/Classes/Libxml2/DOM/Logic/CSS/ForegroundColorCSSAttributeMatcher.swift @@ -0,0 +1,12 @@ +import Foundation + +open class ForegroundColorCSSAttributeMatcher: CSSAttributeMatcher { + + public func check(_ cssAttribute: CSSAttribute) -> Bool { + guard let value = cssAttribute.value else { + return false + } + + return cssAttribute.type == .foregroundColor && !value.isEmpty + } +} diff --git a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift index 6329ac1c5..235a8062c 100644 --- a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift +++ b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringSerializer.swift @@ -29,6 +29,7 @@ class AttributedStringSerializer { BoldElementAttributesConverter(), ItalicElementAttributesConverter(), UnderlineElementAttributesConverter(), + ForegroundColorElementAttributesConverter(), ] ) diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index 4891ba702..cbf8f69b4 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -377,6 +377,13 @@ class TextViewTests: XCTestCase { XCTAssert(!textView.formattingIdentifiersAtIndex(1).contains(.blockquote)) } + func testColorAttributeAtPosition() { + let textView = TextViewStub(withHTML: "foobarbaz") + + XCTAssert(textView.attributedText!.attributes(at: 4, effectiveRange: nil).keys.contains(.foregroundColor)) + let color = textView.attributedText!.attributes(at: 4, effectiveRange: nil)[.foregroundColor] as! UIColor + XCTAssertEqual(color, UIColor(hexString: "#FF0000")) + } // MARK: - Adding newlines From 73d74f148b00d184bbd6c03559ecf524a474e875 Mon Sep 17 00:00:00 2001 From: James Treanor Date: Fri, 4 Oct 2019 15:44:49 +0100 Subject: [PATCH 03/17] CircleCI: Publish pods when the repo is tagged --- .circleci/config.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aa058ec4b..c30b3bf15 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: # This uses the iOS Orb located at https://github.com/wordpress-mobile/circleci-orbs - ios: wordpress-mobile/ios@0.0.32 + ios: wordpress-mobile/ios@0.0.35 workflows: test_and_validate: @@ -30,3 +30,26 @@ workflows: podspec-path: WordPress-Editor-iOS.podspec # Updating specs is needed since WordPress-Editor-iOS depends on WordPress-Aztec-iOS update-specs-repo: true + + - ios/publish-podspec: + name: Publish WordPress-Aztec-iOS to Trunk + xcode-version: "11.0" + podspec-path: WordPress-Aztec-iOS.podspec + post-to-slack: true + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ + + - ios/publish-podspec: + name: Publish WordPress-Editor-iOS to Trunk + requires: [ "Publish WordPress-Aztec-iOS to Trunk" ] + xcode-version: "11.0" + podspec-path: WordPress-Editor-iOS.podspec + post-to-slack: true + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ From 1f47ac8c5c7a34c0aa745d343dd6ab9143f6a40f Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Mon, 7 Oct 2019 14:29:44 +0100 Subject: [PATCH 04/17] Allow dynamic change of default font. --- Aztec/Classes/TextKit/TextView.swift | 21 ++++++++++++++++++++- Example/Example/EditorDemoController.swift | 6 +++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index b0b7a53be..bc0e2339d 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -226,7 +226,26 @@ open class TextView: UITextView { // MARK: - Properties: UI Defaults - public let defaultFont: UIFont + public var monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12) + + public var defaultFont: UIFont { + didSet { + refreshFont(oldFont: oldValue, newFont: defaultFont) + } + } + + private func refreshFont(oldFont: UIFont, newFont: UIFont) { + let fullRange = NSRange(location: 0, length: textStorage.length) + + textStorage.beginEditing() + textStorage.enumerateAttributes(in: fullRange, options: []) { (attributes, subrange, stop) in + if let currentFont = attributes[.font] as? UIFont, currentFont == oldFont { + textStorage.addAttribute(.font, value: newFont, range: subrange) + } + } + textStorage.endEditing() + } + public let defaultParagraphStyle: ParagraphStyle var defaultMissingImage: UIImage diff --git a/Example/Example/EditorDemoController.swift b/Example/Example/EditorDemoController.swift index 5cd6472e0..a45c9f074 100644 --- a/Example/Example/EditorDemoController.swift +++ b/Example/Example/EditorDemoController.swift @@ -195,11 +195,15 @@ class EditorDemoController: UIViewController { } else { html = "" } - + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(changeFont)) editorView.setHTML(html) editorView.becomeFirstResponder() } + @objc func changeFont() { + editorView.richTextView.defaultFont = UIFont.preferredFont(forTextStyle: .callout) + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) From ae81f1c838363f4f62b4091cd8c4f77094f6053a Mon Sep 17 00:00:00 2001 From: James Treanor Date: Tue, 8 Oct 2019 14:31:17 +0100 Subject: [PATCH 05/17] CircleCI: Use --include-podspecs when validating WordPress-Editor-iOS.podspec to avoid publishing problems --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c30b3bf15..c78dde06f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: # This uses the iOS Orb located at https://github.com/wordpress-mobile/circleci-orbs - ios: wordpress-mobile/ios@0.0.35 + ios: wordpress-mobile/ios@dev:cocoapods-addtional-options workflows: test_and_validate: @@ -28,8 +28,8 @@ workflows: name: Validate WordPress-Editor-iOS.podspec xcode-version: "11.0" podspec-path: WordPress-Editor-iOS.podspec - # Updating specs is needed since WordPress-Editor-iOS depends on WordPress-Aztec-iOS - update-specs-repo: true + # Reference WordPress-Aztec-iOS.podspec locally so we don't have to get it from the specs repo + additional-parameters: --include-podspecs=WordPress-Aztec-iOS.podspec - ios/publish-podspec: name: Publish WordPress-Aztec-iOS to Trunk From efc0760d4d2c11ce60960d7921e31c93ac3d2a43 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 8 Oct 2019 21:43:27 +0100 Subject: [PATCH 06/17] Remove unused code. --- Aztec/Classes/TextKit/TextView.swift | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index bc0e2339d..330a48900 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -226,8 +226,6 @@ open class TextView: UITextView { // MARK: - Properties: UI Defaults - public var monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12) - public var defaultFont: UIFont { didSet { refreshFont(oldFont: oldValue, newFont: defaultFont) @@ -260,23 +258,6 @@ open class TextView: UITextView { return attributes } - /// This closure will be executed whenever the `TextView` needs to set the base style for - /// a caption. Override this to customize the caption styling. - /// - public lazy var captionStyler: ([NSAttributedString.Key:Any]) -> [NSAttributedString.Key:Any] = { [weak self] attributes in - guard let `self` = self else { - return attributes - } - - let font = self.defaultFont.withSize(10) - - var attributes = attributes - attributes[.font] = font - attributes[.foregroundColor] = UIColor.darkGray - - return attributes - } - // MARK: - Plugin Loading var pluginManager: PluginManager { From cdb281483f979cdca5a88a5ed9b441ea717be470 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 8 Oct 2019 21:44:50 +0100 Subject: [PATCH 07/17] Use font provider class to provide default fonts Instead of having random places where we obtain/configure fonts, this commits creates a central class where fonts can be retrieved. --- Aztec.xcodeproj/project.pbxproj | 4 +++ .../Implementations/CodeFormatter.swift | 11 ++----- .../Implementations/PreFormatter.swift | 13 ++------ Aztec/Classes/TextKit/FontProvider.swift | 33 +++++++++++++++++++ Aztec/Classes/TextKit/TextView.swift | 8 +---- 5 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 Aztec/Classes/TextKit/FontProvider.swift diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index ce2398578..cb6e07e08 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -235,6 +235,7 @@ FF61909E202481F4004BCD0A /* CodeFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF61909D202481F4004BCD0A /* CodeFormatter.swift */; }; FF7A1C511E5651EA00C4C7C8 /* LineAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7A1C501E5651EA00C4C7C8 /* LineAttachment.swift */; }; FF7C89B01E3BC52F000472A8 /* NSAttributedString+FontTraits.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7C89AF1E3BC52F000472A8 /* NSAttributedString+FontTraits.swift */; }; + FF7EAEC4234D253B007A26E0 /* FontProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7EAEC3234D253B007A26E0 /* FontProvider.swift */; }; FFA61E891DF18F3D00B71BF6 /* ParagraphStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFA61E881DF18F3D00B71BF6 /* ParagraphStyle.swift */; }; FFA61EC21DF6C1C900B71BF6 /* NSAttributedString+Archive.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFA61EC11DF6C1C900B71BF6 /* NSAttributedString+Archive.swift */; }; FFB5D29720BEB21A0038DCFB /* CiteFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB5D29620BEB21A0038DCFB /* CiteFormatter.swift */; }; @@ -513,6 +514,7 @@ FF7A1C4A1E51F05700C4C7C8 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = ""; }; FF7A1C501E5651EA00C4C7C8 /* LineAttachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineAttachment.swift; sourceTree = ""; }; FF7C89AF1E3BC52F000472A8 /* NSAttributedString+FontTraits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+FontTraits.swift"; sourceTree = ""; }; + FF7EAEC3234D253B007A26E0 /* FontProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontProvider.swift; sourceTree = ""; }; FFA61E881DF18F3D00B71BF6 /* ParagraphStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParagraphStyle.swift; sourceTree = ""; }; FFA61EC11DF6C1C900B71BF6 /* NSAttributedString+Archive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+Archive.swift"; sourceTree = ""; }; FFB5D29620BEB21A0038DCFB /* CiteFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CiteFormatter.swift; sourceTree = ""; }; @@ -804,6 +806,7 @@ FFA61E881DF18F3D00B71BF6 /* ParagraphStyle.swift */, B5A99D831EBA073D00DED081 /* HTMLStorage.swift */, F9982CF521877663001E606B /* TextViewPasteboardDelegate.swift */, + FF7EAEC3234D253B007A26E0 /* FontProvider.swift */, ); path = TextKit; sourceTree = ""; @@ -1573,6 +1576,7 @@ F165D92A20C72EF500EAA6B0 /* Array+ShortcodeAttribute.swift in Sources */, F165D92420C72C1000EAA6B0 /* ShortcodeAttributeSerializer.swift in Sources */, F177FF751FB6404D00CBBE35 /* UILayoutPriority+Swift4.swift in Sources */, + FF7EAEC4234D253B007A26E0 /* FontProvider.swift in Sources */, F1C05B9D1E37FA77007510EA /* String+CharacterName.swift in Sources */, F1FF7D9F201A1D24007B0B32 /* Figcaption.swift in Sources */, FF17B2D2227A589F0022AECE /* LIElementConverter.swift in Sources */, diff --git a/Aztec/Classes/Formatters/Implementations/CodeFormatter.swift b/Aztec/Classes/Formatters/Implementations/CodeFormatter.swift index 1583dacda..04918e19d 100644 --- a/Aztec/Classes/Formatters/Implementations/CodeFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/CodeFormatter.swift @@ -12,15 +12,8 @@ class CodeFormatter: AttributeFormatter { // MARK: - Init - init(monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12), backgroundColor: UIColor = UIColor.lightGray) { - let font: UIFont - - if #available(iOS 11.0, *) { - font = UIFontMetrics.default.scaledFont(for: monospaceFont) - } else { - font = monospaceFont - } - self.monospaceFont = font + init(monospaceFont: UIFont = FontProvider.shared.monospaceFont, backgroundColor: UIColor = UIColor.lightGray) { + self.monospaceFont = monospaceFont self.backgroundColor = backgroundColor self.htmlRepresentationKey = .codeHtmlRepresentation } diff --git a/Aztec/Classes/Formatters/Implementations/PreFormatter.swift b/Aztec/Classes/Formatters/Implementations/PreFormatter.swift index 384c7b117..cf6ecbbd4 100644 --- a/Aztec/Classes/Formatters/Implementations/PreFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/PreFormatter.swift @@ -14,19 +14,10 @@ open class PreFormatter: ParagraphAttributeFormatter { /// let placeholderAttributes: [NSAttributedString.Key: Any]? - /// Designated Initializer /// - init(monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12), placeholderAttributes: [NSAttributedString.Key : Any]? = nil) { - let font: UIFont - - if #available(iOS 11.0, *) { - font = UIFontMetrics.default.scaledFont(for: monospaceFont) - } else { - font = monospaceFont - } - - self.monospaceFont = font + init(monospaceFont: UIFont = FontProvider.shared.monospaceFont, placeholderAttributes: [NSAttributedString.Key : Any]? = nil) { + self.monospaceFont = monospaceFont self.placeholderAttributes = placeholderAttributes } diff --git a/Aztec/Classes/TextKit/FontProvider.swift b/Aztec/Classes/TextKit/FontProvider.swift new file mode 100644 index 000000000..b5f4abb7a --- /dev/null +++ b/Aztec/Classes/TextKit/FontProvider.swift @@ -0,0 +1,33 @@ +import Foundation +import UIKit + +public class FontProvider { + + private init() { + + } + + static var shared = FontProvider() + + lazy var monospaceFont: UIFont = { + let baseFont = UIFont(descriptor:UIFontDescriptor(name: "Menlo", size: 14), size:14) + let font: UIFont + if #available(iOS 11.0, *) { + font = UIFontMetrics.default.scaledFont(for: baseFont) + } else { + font = baseFont + } + return font + }() + + lazy var defaultFont: UIFont = { + let baseFont = UIFont.systemFont(ofSize: 14) + let font: UIFont + if #available(iOS 11.0, *) { + font = UIFontMetrics.default.scaledFont(for: baseFont) + } else { + font = baseFont + } + return font + }() +} diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index 330a48900..ad0ec352f 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -397,13 +397,7 @@ open class TextView: UITextView { } required public init?(coder aDecoder: NSCoder) { - let font = UIFont.systemFont(ofSize: 14) - if #available(iOS 11.0, *) { - self.defaultFont = UIFontMetrics.default.scaledFont(for: font) - } else { - self.defaultFont = font - } - + self.defaultFont = FontProvider.shared.defaultFont defaultParagraphStyle = ParagraphStyle.default defaultMissingImage = Assets.imageIcon From b155e7da0594a718d75b7c851ba6a1cbb55fab44 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 8 Oct 2019 21:53:44 +0100 Subject: [PATCH 08/17] Make font properties public --- Aztec/Classes/TextKit/FontProvider.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aztec/Classes/TextKit/FontProvider.swift b/Aztec/Classes/TextKit/FontProvider.swift index b5f4abb7a..880d7b01e 100644 --- a/Aztec/Classes/TextKit/FontProvider.swift +++ b/Aztec/Classes/TextKit/FontProvider.swift @@ -9,7 +9,7 @@ public class FontProvider { static var shared = FontProvider() - lazy var monospaceFont: UIFont = { + public lazy var monospaceFont: UIFont = { let baseFont = UIFont(descriptor:UIFontDescriptor(name: "Menlo", size: 14), size:14) let font: UIFont if #available(iOS 11.0, *) { @@ -20,7 +20,7 @@ public class FontProvider { return font }() - lazy var defaultFont: UIFont = { + public lazy var defaultFont: UIFont = { let baseFont = UIFont.systemFont(ofSize: 14) let font: UIFont if #available(iOS 11.0, *) { From 1994a24a032c5a59f245d145d7d18e6990d08d82 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 8 Oct 2019 22:13:58 +0100 Subject: [PATCH 09/17] Update code for iOS 11 --- Aztec.xcodeproj/project.pbxproj | 12 ++++-- Aztec/Classes/EditorView/EditorView.swift | 20 ++++------ Aztec/Classes/GUI/FormatBar/FormatBar.swift | 13 ++----- Aztec/Classes/TextKit/FontProvider.swift | 12 +----- .../TextKit/ParagraphProperty/Header.swift | 7 +--- Aztec/Classes/TextKit/TextView.swift | 12 ++---- .../AztecExample.xcodeproj/project.pbxproj | 8 ++-- Example/Example/EditorDemoController.swift | 39 +++++++------------ WordPress-Aztec-iOS.podspec | 4 +- WordPress-Editor-iOS.podspec | 4 +- .../WordPressEditor.xcodeproj/project.pbxproj | 9 +++-- 11 files changed, 55 insertions(+), 85 deletions(-) diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index cb6e07e08..05dd68e4f 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -1812,7 +1812,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; @@ -1873,7 +1873,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = "-lxml2"; SDKROOT = iphoneos; @@ -1905,6 +1905,7 @@ ); INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1934,6 +1935,7 @@ ); INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2075,7 +2077,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; @@ -2107,6 +2109,7 @@ ); INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2187,7 +2190,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lxml2"; @@ -2220,6 +2223,7 @@ ); INFOPLIST_FILE = Aztec/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Aztec; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Aztec/Classes/EditorView/EditorView.swift b/Aztec/Classes/EditorView/EditorView.swift index a10643e10..53d727161 100644 --- a/Aztec/Classes/EditorView/EditorView.swift +++ b/Aztec/Classes/EditorView/EditorView.swift @@ -107,12 +107,10 @@ public class EditorView: UIView { self.htmlTextView = htmlTextView self.richTextView = richTextView - - if #available(iOS 11, *) { - htmlTextView.smartInsertDeleteType = .no - htmlTextView.smartDashesType = .no - htmlTextView.smartQuotesType = .no - } + + htmlTextView.smartInsertDeleteType = .no + htmlTextView.smartDashesType = .no + htmlTextView.smartQuotesType = .no super.init(coder: aDecoder) @@ -129,12 +127,10 @@ public class EditorView: UIView { self.htmlTextView = UITextView(frame: .zero, textContainer: container) self.richTextView = TextView(defaultFont: defaultFont, defaultParagraphStyle: defaultParagraphStyle, defaultMissingImage: defaultMissingImage) - - if #available(iOS 11, *) { - htmlTextView.smartInsertDeleteType = .no - htmlTextView.smartDashesType = .no - htmlTextView.smartQuotesType = .no - } + + htmlTextView.smartInsertDeleteType = .no + htmlTextView.smartDashesType = .no + htmlTextView.smartQuotesType = .no super.init(frame: .zero) diff --git a/Aztec/Classes/GUI/FormatBar/FormatBar.swift b/Aztec/Classes/GUI/FormatBar/FormatBar.swift index 82ca1300a..0e339c48b 100644 --- a/Aztec/Classes/GUI/FormatBar/FormatBar.swift +++ b/Aztec/Classes/GUI/FormatBar/FormatBar.swift @@ -326,9 +326,7 @@ open class FormatBar: UIView { open override func didMoveToWindow() { super.didMoveToWindow() - if #available(iOS 11.0, *) { - updateForSafeAreaInsets() - } + updateForSafeAreaInsets() } open override func layoutSubviews() { @@ -683,13 +681,8 @@ private extension FormatBar { /// Sets up the Constraints /// func configureConstraints() { - var leadingAnchor = self.leadingAnchor - var trailingAnchor = self.trailingAnchor - - if #available(iOS 11.0, *) { - leadingAnchor = safeAreaLayoutGuide.leadingAnchor - trailingAnchor = safeAreaLayoutGuide.trailingAnchor - } + var leadingAnchor = safeAreaLayoutGuide.leadingAnchor + var trailingAnchor = safeAreaLayoutGuide.trailingAnchor ///Overflow toggle item diff --git a/Aztec/Classes/TextKit/FontProvider.swift b/Aztec/Classes/TextKit/FontProvider.swift index 880d7b01e..0d84c5338 100644 --- a/Aztec/Classes/TextKit/FontProvider.swift +++ b/Aztec/Classes/TextKit/FontProvider.swift @@ -12,22 +12,14 @@ public class FontProvider { public lazy var monospaceFont: UIFont = { let baseFont = UIFont(descriptor:UIFontDescriptor(name: "Menlo", size: 14), size:14) let font: UIFont - if #available(iOS 11.0, *) { - font = UIFontMetrics.default.scaledFont(for: baseFont) - } else { - font = baseFont - } + font = UIFontMetrics.default.scaledFont(for: baseFont) return font }() public lazy var defaultFont: UIFont = { let baseFont = UIFont.systemFont(ofSize: 14) let font: UIFont - if #available(iOS 11.0, *) { - font = UIFontMetrics.default.scaledFont(for: baseFont) - } else { - font = baseFont - } + font = UIFontMetrics.default.scaledFont(for: baseFont) return font }() } diff --git a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift index 46b600695..a13dafe0c 100644 --- a/Aztec/Classes/TextKit/ParagraphProperty/Header.swift +++ b/Aztec/Classes/TextKit/ParagraphProperty/Header.swift @@ -33,12 +33,7 @@ open class Header: ParagraphProperty { public var fontSize: Float { let fontSize = HeaderType.fontSizeMap[self] ?? Constants.defaultFontSize - - if #available(iOS 11.0, *) { - return Float(UIFontMetrics.default.scaledValue(for: CGFloat(fontSize))) - } else { - return fontSize - } + return Float(UIFontMetrics.default.scaledValue(for: CGFloat(fontSize))) } } diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index ad0ec352f..725d5070c 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -376,11 +376,8 @@ open class TextView: UITextView { defaultParagraphStyle: ParagraphStyle = ParagraphStyle.default, defaultMissingImage: UIImage) { - if #available(iOS 11.0, *) { - self.defaultFont = UIFontMetrics.default.scaledFont(for: defaultFont) - } else { - self.defaultFont = defaultFont - } + self.defaultFont = UIFontMetrics.default.scaledFont(for: defaultFont) + self.defaultParagraphStyle = defaultParagraphStyle self.defaultMissingImage = defaultMissingImage @@ -407,9 +404,8 @@ open class TextView: UITextView { private func commonInit() { allowsEditingTextAttributes = true - if #available(iOS 10.0, *) { - adjustsFontForContentSizeCategory = true - } + adjustsFontForContentSizeCategory = true + storage.attachmentsDelegate = self font = defaultFont linkTextAttributes = [.underlineStyle: NSNumber(value: NSUnderlineStyle.single.rawValue), .foregroundColor: tintColor as Any] diff --git a/Example/AztecExample.xcodeproj/project.pbxproj b/Example/AztecExample.xcodeproj/project.pbxproj index 88248f3c4..5e6cc212b 100644 --- a/Example/AztecExample.xcodeproj/project.pbxproj +++ b/Example/AztecExample.xcodeproj/project.pbxproj @@ -582,7 +582,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -635,7 +635,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; STRIP_INSTALLED_PRODUCT = NO; @@ -797,7 +797,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -880,7 +880,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = /usr/include/libxml2; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; diff --git a/Example/Example/EditorDemoController.swift b/Example/Example/EditorDemoController.swift index a45c9f074..a1045394b 100644 --- a/Example/Example/EditorDemoController.swift +++ b/Example/Example/EditorDemoController.swift @@ -30,12 +30,8 @@ class EditorDemoController: UIViewController { fileprivate(set) lazy var editorView: Aztec.EditorView = { let defaultHTMLFont: UIFont - - if #available(iOS 11, *) { - defaultHTMLFont = UIFontMetrics.default.scaledFont(for: Constants.defaultContentFont) - } else { - defaultHTMLFont = Constants.defaultContentFont - } + + defaultHTMLFont = UIFontMetrics.default.scaledFont(for: Constants.defaultContentFont) let editorView = Aztec.EditorView( defaultFont: Constants.defaultContentFont, @@ -63,10 +59,8 @@ class EditorDemoController: UIViewController { textView.textAttachmentDelegate = self textView.accessibilityIdentifier = "richContentView" textView.clipsToBounds = false - if #available(iOS 11, *) { - textView.smartDashesType = .no - textView.smartQuotesType = .no - } + textView.smartDashesType = .no + textView.smartQuotesType = .no } private func setupHTMLTextView(_ textView: UITextView) { @@ -79,14 +73,10 @@ class EditorDemoController: UIViewController { textView.autocorrectionType = .no textView.autocapitalizationType = .none textView.clipsToBounds = false - if #available(iOS 10, *) { - textView.adjustsFontForContentSizeCategory = true - } - - if #available(iOS 11, *) { - textView.smartDashesType = .no - textView.smartQuotesType = .no - } + textView.adjustsFontForContentSizeCategory = true + + textView.smartDashesType = .no + textView.smartQuotesType = .no } fileprivate(set) lazy var titleTextView: UITextView = { @@ -249,9 +239,8 @@ class EditorDemoController: UIViewController { func updateScrollInsets() { var scrollInsets = editorView.contentInset var rightMargin = (view.frame.maxX - editorView.frame.maxX) - if #available(iOS 11.0, *) { - rightMargin -= view.safeAreaInsets.right - } + rightMargin -= view.safeAreaInsets.right + scrollInsets.right = -rightMargin editorView.scrollIndicatorInsets = scrollInsets } @@ -499,6 +488,10 @@ extension EditorDemoController : UITextViewDelegate { return true } + func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { + return false + } + func scrollViewDidScroll(_ scrollView: UIScrollView) { updateTitlePosition() } @@ -798,9 +791,7 @@ extension EditorDemoController { textField.clearButtonMode = UITextField.ViewMode.always; textField.placeholder = NSLocalizedString("URL", comment:"URL text field placeholder"); textField.keyboardType = .URL - if #available(iOS 10, *) { - textField.textContentType = .URL - } + textField.textContentType = .URL textField.text = urlToUse?.absoluteString textField.addTarget(self, diff --git a/WordPress-Aztec-iOS.podspec b/WordPress-Aztec-iOS.podspec index 2b56b742a..0573047d7 100644 --- a/WordPress-Aztec-iOS.podspec +++ b/WordPress-Aztec-iOS.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'WordPress-Aztec-iOS' - s.version = '1.10.1' + s.version = '1.11' s.summary = 'The native HTML Editor.' # This description is used to generate tags and improve search results. @@ -27,7 +27,7 @@ Pod::Spec.new do |s| s.author = { 'Automattic' => 'mobile@automattic.com', 'Diego Rey Mendez' => 'diego.rey.mendez@automattic.com', 'Sergio Estevao' => 'sergioestevao@gmail.com', 'Jorge Leandro Perez' => 'jorge.perez@automattic.com' } s.social_media_url = "http://twitter.com/WordPressiOS" s.source = { :git => 'https://github.com/wordpress-mobile/WordPress-Aztec-iOS.git', :tag => s.version.to_s } - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '11.0' s.swift_version = '5.0' s.module_name = "Aztec" diff --git a/WordPress-Editor-iOS.podspec b/WordPress-Editor-iOS.podspec index 33cdc4e8b..025233351 100644 --- a/WordPress-Editor-iOS.podspec +++ b/WordPress-Editor-iOS.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'WordPress-Editor-iOS' - s.version = '1.10.1' + s.version = '1.11' s.summary = 'The WordPress HTML Editor.' # This description is used to generate tags and improve search results. @@ -27,7 +27,7 @@ Pod::Spec.new do |s| s.author = { 'Automattic' => 'mobile@automattic.com', 'Diego Rey Mendez' => 'diego.rey.mendez@automattic.com', 'Sergio Estevao' => 'sergioestevao@gmail.com', 'Jorge Leandro Perez' => 'jorge.perez@automattic.com' } s.social_media_url = "http://twitter.com/WordPressiOS" s.source = { :git => 'https://github.com/wordpress-mobile/WordPress-Aztec-iOS.git', :tag => s.version.to_s } - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '11.0' s.swift_version = '5.0' s.module_name = "WordPressEditor" diff --git a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj index 9dae87d91..455e8dbf9 100644 --- a/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj +++ b/WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj @@ -762,7 +762,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -787,6 +787,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -871,7 +872,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -930,7 +931,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; @@ -955,6 +956,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -980,6 +982,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = WordPressEditor/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", From 4aa260aeacd47dac48913154df4798781f9e3619 Mon Sep 17 00:00:00 2001 From: James Treanor Date: Wed, 9 Oct 2019 09:45:46 +0100 Subject: [PATCH 10/17] Use published Orb --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c78dde06f..bf7ef87f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: # This uses the iOS Orb located at https://github.com/wordpress-mobile/circleci-orbs - ios: wordpress-mobile/ios@dev:cocoapods-addtional-options + ios: wordpress-mobile/ios@0.0.36 workflows: test_and_validate: From 7f998f49949c539384ce2d81601eda8eaf396dcc Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 09:49:14 +0100 Subject: [PATCH 11/17] Improve and generalize code for replacement of fonts in attributed strings. --- Aztec.xcodeproj/project.pbxproj | 4 ++++ ...leAttributedString+ReplaceAttributes.swift | 21 +++++++++++++++++++ Aztec/Classes/TextKit/TextView.swift | 14 +------------ 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index cb6e07e08..5176420de 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -231,6 +231,7 @@ FF24AC991F0146AF003CA91D /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF24AC981F0146AF003CA91D /* Assets.swift */; }; FF437B6420D7CB2D000D9666 /* HTMLLi.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF437B6320D7CB2D000D9666 /* HTMLLi.swift */; }; FF437B6620D7CB83000D9666 /* LiFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF437B6520D7CB83000D9666 /* LiFormatter.swift */; }; + FF48CAC8234DD5D3007FFC79 /* NSMutableAttributedString+ReplaceAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF48CAC7234DD5D3007FFC79 /* NSMutableAttributedString+ReplaceAttributes.swift */; }; FF4E26601EA8DF1E005E8E42 /* ImageAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4E265F1EA8DF1E005E8E42 /* ImageAttachment.swift */; }; FF61909E202481F4004BCD0A /* CodeFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF61909D202481F4004BCD0A /* CodeFormatter.swift */; }; FF7A1C511E5651EA00C4C7C8 /* LineAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7A1C501E5651EA00C4C7C8 /* LineAttachment.swift */; }; @@ -506,6 +507,7 @@ FF24AC981F0146AF003CA91D /* Assets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = ""; }; FF437B6320D7CB2D000D9666 /* HTMLLi.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLLi.swift; sourceTree = ""; }; FF437B6520D7CB83000D9666 /* LiFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiFormatter.swift; sourceTree = ""; }; + FF48CAC7234DD5D3007FFC79 /* NSMutableAttributedString+ReplaceAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+ReplaceAttributes.swift"; sourceTree = ""; }; FF4E265F1EA8DF1E005E8E42 /* ImageAttachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageAttachment.swift; sourceTree = ""; }; FF5B98E21DC29D0C00571CA4 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; }; FF5B98E41DC355B400571CA4 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = SOURCE_ROOT; }; @@ -748,6 +750,7 @@ FFD0FEB61DAE59A700430586 /* NSLayoutManager+Attachments.swift */, F1584795203C9B4C00EE05A1 /* NSMutableAttributedString+ParagraphProperty.swift */, F10BE6171EA7ADA6002E4625 /* NSMutableAttributedString+ReplaceOcurrences.swift */, + FF48CAC7234DD5D3007FFC79 /* NSMutableAttributedString+ReplaceAttributes.swift */, F18733C41DA096EE005AEB80 /* NSRange+Helpers.swift */, FF20D6431EDC395E00294B78 /* NSTextingResult+Helpers.swift */, F1C05B9C1E37FA77007510EA /* String+CharacterName.swift */, @@ -1643,6 +1646,7 @@ 599F25381D8BC9A1002871D6 /* InAttributesConverter.swift in Sources */, B551A4A01E770B3800EE3A7F /* UIFont+Emoji.swift in Sources */, F13E8AD820B71BAA007C9F8A /* PluginManager.swift in Sources */, + FF48CAC8234DD5D3007FFC79 /* NSMutableAttributedString+ReplaceAttributes.swift in Sources */, F12F586E1EF20394008AE298 /* LinkFormatter.swift in Sources */, F1584796203C9B4C00EE05A1 /* NSMutableAttributedString+ParagraphProperty.swift in Sources */, F15BA6092151501300424120 /* BoldStringAttributeConverter.swift in Sources */, diff --git a/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift b/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift new file mode 100644 index 000000000..1a1c9ff43 --- /dev/null +++ b/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift @@ -0,0 +1,21 @@ +import Foundation +import UIKit + +public extension NSMutableAttributedString { + + func replace(font: UIFont, with newFont: UIFont) { + let fullRange = NSRange(location: 0, length: self.length) + + self.beginEditing() + self.enumerateAttributes(in: fullRange, options: []) { (attributes, subrange, stop) in + if let currentFont = attributes[.font] as? UIFont, currentFont.familyName == font.familyName { + var replacementFont = newFont + if let fontDescriptor = newFont.fontDescriptor.withSymbolicTraits(currentFont.fontDescriptor.symbolicTraits) { + replacementFont = UIFont(descriptor: fontDescriptor, size: currentFont.pointSize) + } + self.addAttribute(.font, value: replacementFont, range: subrange) + } + } + self.endEditing() + } +} diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index ad0ec352f..e1afb9a8c 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -228,22 +228,10 @@ open class TextView: UITextView { public var defaultFont: UIFont { didSet { - refreshFont(oldFont: oldValue, newFont: defaultFont) + textStorage.replace(font: oldValue, with: defaultFont) } } - private func refreshFont(oldFont: UIFont, newFont: UIFont) { - let fullRange = NSRange(location: 0, length: textStorage.length) - - textStorage.beginEditing() - textStorage.enumerateAttributes(in: fullRange, options: []) { (attributes, subrange, stop) in - if let currentFont = attributes[.font] as? UIFont, currentFont == oldFont { - textStorage.addAttribute(.font, value: newFont, range: subrange) - } - } - textStorage.endEditing() - } - public let defaultParagraphStyle: ParagraphStyle var defaultMissingImage: UIImage From 31e70a0cad75ea5445ab0b66d58abb6725a1e518 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 09:49:28 +0100 Subject: [PATCH 12/17] Make font provider shared instance public --- Aztec/Classes/TextKit/FontProvider.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/FontProvider.swift b/Aztec/Classes/TextKit/FontProvider.swift index 880d7b01e..0e8b5f40e 100644 --- a/Aztec/Classes/TextKit/FontProvider.swift +++ b/Aztec/Classes/TextKit/FontProvider.swift @@ -7,7 +7,7 @@ public class FontProvider { } - static var shared = FontProvider() + public static var shared = FontProvider() public lazy var monospaceFont: UIFont = { let baseFont = UIFont(descriptor:UIFontDescriptor(name: "Menlo", size: 14), size:14) From 3d0c2e8177f5468710f1b0a6cbb667fed93d5fe3 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 09:54:13 +0100 Subject: [PATCH 13/17] Improve replaceFont code and add some documentation. --- ...leAttributedString+ReplaceAttributes.swift | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift b/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift index 1a1c9ff43..84f2a388d 100644 --- a/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift +++ b/Aztec/Classes/Extensions/NSMutableAttributedString+ReplaceAttributes.swift @@ -3,19 +3,23 @@ import UIKit public extension NSMutableAttributedString { + /// Replace all instances of the .font attribute that belong to the same family for the new font, trying to keep the same symbolic traits + /// - Parameter font: the original font to be replaced + /// - Parameter newFont: the new font to use. func replace(font: UIFont, with newFont: UIFont) { - let fullRange = NSRange(location: 0, length: self.length) + let fullRange = NSRange(location: 0, length: length) - self.beginEditing() - self.enumerateAttributes(in: fullRange, options: []) { (attributes, subrange, stop) in - if let currentFont = attributes[.font] as? UIFont, currentFont.familyName == font.familyName { - var replacementFont = newFont - if let fontDescriptor = newFont.fontDescriptor.withSymbolicTraits(currentFont.fontDescriptor.symbolicTraits) { - replacementFont = UIFont(descriptor: fontDescriptor, size: currentFont.pointSize) - } - self.addAttribute(.font, value: replacementFont, range: subrange) + beginEditing() + enumerateAttributes(in: fullRange, options: []) { (attributes, subrange, stop) in + guard let currentFont = attributes[.font] as? UIFont, currentFont.familyName == font.familyName else { + return } + var replacementFont = newFont + if let fontDescriptor = newFont.fontDescriptor.withSymbolicTraits(currentFont.fontDescriptor.symbolicTraits) { + replacementFont = UIFont(descriptor: fontDescriptor, size: currentFont.pointSize) + } + addAttribute(.font, value: replacementFont, range: subrange) } - self.endEditing() + endEditing() } } From 7eddd3733a4e0983e3995437fc4a715db7e65b66 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 10:15:06 +0100 Subject: [PATCH 14/17] Fix possible issues were font is not available. --- Aztec/Classes/TextKit/LayoutManager.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Aztec/Classes/TextKit/LayoutManager.swift b/Aztec/Classes/TextKit/LayoutManager.swift index aaaef8fc7..dbe233234 100644 --- a/Aztec/Classes/TextKit/LayoutManager.swift +++ b/Aztec/Classes/TextKit/LayoutManager.swift @@ -317,7 +317,11 @@ private extension LayoutManager { traits.remove(.traitBold) traits.remove(.traitItalic) - let descriptor = font.fontDescriptor.withSymbolicTraits(traits) - return UIFont(descriptor: descriptor!, size: font.pointSize) + if let descriptor = font.fontDescriptor.withSymbolicTraits(traits) { + return UIFont(descriptor: descriptor, size: font.pointSize) + } else { + // Don't touch the font if we cannot remove the symbolic traits. + return font + } } } From f7561ef1fffd6360a2db87fd522ed71a71d103eb Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 12:28:19 +0100 Subject: [PATCH 15/17] Convert to let variables. --- Aztec/Classes/GUI/FormatBar/FormatBar.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aztec/Classes/GUI/FormatBar/FormatBar.swift b/Aztec/Classes/GUI/FormatBar/FormatBar.swift index 0e339c48b..c370f5be2 100644 --- a/Aztec/Classes/GUI/FormatBar/FormatBar.swift +++ b/Aztec/Classes/GUI/FormatBar/FormatBar.swift @@ -681,8 +681,8 @@ private extension FormatBar { /// Sets up the Constraints /// func configureConstraints() { - var leadingAnchor = safeAreaLayoutGuide.leadingAnchor - var trailingAnchor = safeAreaLayoutGuide.trailingAnchor + let leadingAnchor = safeAreaLayoutGuide.leadingAnchor + let trailingAnchor = safeAreaLayoutGuide.trailingAnchor ///Overflow toggle item From 46ac801299efaa9abdcc6ea7c4080bdfa8c34130 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 12:29:39 +0100 Subject: [PATCH 16/17] Add documentation. --- Aztec/Classes/TextKit/TextView.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index e1afb9a8c..589c15c41 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -226,6 +226,8 @@ open class TextView: UITextView { // MARK: - Properties: UI Defaults + /// The font to use to render any HTML that doesn't specify an explicit font. + /// If this is changed all the instances that use this font will be updated to the new one. public var defaultFont: UIFont { didSet { textStorage.replace(font: oldValue, with: defaultFont) @@ -359,6 +361,10 @@ open class TextView: UITextView { // MARK: - Init & deinit + /// Creates a Text View using the provided parameters as a base for HTML rendering. + /// - Parameter defaultFont: The font to use to render the elements if no specific font is set by the HTML. + /// - Parameter defaultParagraphStyle: The default paragraph style if no explicit attributes are defined in HTML + /// - Parameter defaultMissingImage: The image to use if the view is not able to render an image specified in the HTML. @objc public init( defaultFont: UIFont, defaultParagraphStyle: ParagraphStyle = ParagraphStyle.default, @@ -385,7 +391,7 @@ open class TextView: UITextView { } required public init?(coder aDecoder: NSCoder) { - self.defaultFont = FontProvider.shared.defaultFont + defaultFont = FontProvider.shared.defaultFont defaultParagraphStyle = ParagraphStyle.default defaultMissingImage = Assets.imageIcon From fa4c640cf08c0f933483a18d36226af87c2ad5a9 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Wed, 9 Oct 2019 12:29:46 +0100 Subject: [PATCH 17/17] Fix test --- AztecTests/TextKit/TextViewTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index cbf8f69b4..c3c878be6 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -1673,7 +1673,7 @@ class TextViewTests: XCTestCase { textView.insertText("😘") let currentTypingFont = textView.typingAttributes[.font] as! UIFont - XCTAssertEqual(currentTypingFont, font, "Font should be set to default") + XCTAssertEqual(currentTypingFont.fontDescriptor, font.fontDescriptor, "Font should be set to default") }