Skip to content

Commit

Permalink
Deprecate font name and size and adjust documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Jan 17, 2024
1 parent 7e3d4a6 commit 232794a
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 85 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ let package = Package(
resources: [.process("Resources")],
swiftSettings: [
.define("macOS", .when(platforms: [.macOS])),
.define("iOS", .when(platforms: [.iOS, .macCatalyst])),
.define("iOS", .when(platforms: [.iOS, .macCatalyst]))
]
),
.testTarget(
name: "RichTextKitTests",
dependencies: ["RichTextKit", "MockingKit"],
swiftSettings: [
.define("macOS", .when(platforms: [.macOS])),
.define("iOS", .when(platforms: [.iOS, .macCatalyst])),
.define("iOS", .when(platforms: [.iOS, .macCatalyst]))
]
),
)
]
)
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ This release starts moving types and views that relate to other types into the t
* `RichTextActionButtonGroup` has been renamed to `RichTextAction.ButtonGroup`.
* `RichTextActionButtonStack` has been renamed to `RichTextAction.ButtonStack`.
* `RichTextAlignmentPicker` has been renamed to `RichTextAlignment.Picker`.
* `RichTextArgumentReader` deprecates the font name and size functions.
* `RichTextArgumentWriter` deprecates the font name and size functions.
* `RichTextComponent` deprecates the font name and size functions.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension RichTextAttributeReader {

/// Get the text alignment at a certain range.
/// Get the rich text alignment at a certain range.
func richTextAlignment(
at range: NSRange
) -> RichTextAlignment? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ import Foundation

public extension RichTextAttributeReader {

/// Get the font at a certain range.
/// Get the rich text font at a certain range.
func richTextFont(
at range: NSRange
) -> FontRepresentable? {
richTextAttribute(.font, at: range)
}

/// Get the font size (in points) at a certain range.
func richTextFontSize(
at range: NSRange
) -> CGFloat? {
richTextFont(at: range)?.pointSize
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension RichTextAttributeReader {

/// Get the text indent in points at a certain range.
/// Get the rich text indent at a certain range.
func richTextIndent(
at range: NSRange
) -> CGFloat? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AppKit

public extension RichTextAttributeReader {

/// Get the paragraph style at a certain range.
/// Get the rich text paragraph style at a certain range.
func richTextParagraphStyle(
at range: NSRange
) -> NSMutableParagraphStyle? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension RichTextAttributeReader {

/// Get the text styles at a certain range.
/// Get all rich text styles at a certain range.
func richTextStyles(
at range: NSRange
) -> [RichTextStyle] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension NSAttributedString: RichTextAttributeReader {}

public extension RichTextAttributeReader {

/// Get a rich text attribute at a certain range.
/// Get a certain rich text attribute at a certain range.
func richTextAttribute<Value>(
_ attribute: RichTextAttribute,
at range: NSRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import AppKit
public extension RichTextAttributeWriter {

/// Set the rich text alignment at a certain range.
///
/// Unlike some other attributes, this attribute applies
/// to the entire paragraph, not just the selected range.
func setRichTextAlignment(
_ alignment: RichTextAlignment,
at range: NSRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Foundation

public extension RichTextAttributeWriter {

/// Set the font at a certain range.
/// Set the rich text font at a certain range.
func setRichTextFont(
_ font: FontRepresentable,
at range: NSRange
) {
setRichTextAttribute(.font, to: font, at: range)
}

/// Set the font name at a certain range.
/// Set the rich text font name at a certain range.
///
/// This may seem complicated, but so far it is the only
/// way that seems to work correctly.
Expand Down Expand Up @@ -52,7 +52,7 @@ public extension RichTextAttributeWriter {
text.endEditing()
}

/// Set the font size at a certain range.
/// Set the rich text font size at a certain range.
func setRichTextFontSize(
_ size: CGFloat,
at range: NSRange
Expand All @@ -70,12 +70,12 @@ public extension RichTextAttributeWriter {
text.endEditing()
}

/// Step the font size at a certain range.
/// Step the rich text font size at a certain range.
func stepRichTextFontSize(
points: Int,
at range: NSRange
) {
guard let size = richTextFontSize(at: range) else { return }
guard let size = richTextFont(at: range)?.pointSize else { return }
let newSize = size + CGFloat(points)
setRichTextFontSize(newSize, at: range)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public extension RichTextAttributeWriter {
return stepRichTextIndent(points: points, atIndex: index)
}

/// Step the text indent at a certain index.
/// Step the rich text indent at a certain index.
func stepRichTextIndent(
points: CGFloat,
atIndex index: Int
Expand All @@ -75,7 +75,7 @@ public extension RichTextAttributeWriter {
return attributes
}

/// Step the text indent at a certain index.
/// Step the rich text text indent at a certain index.
func stepRichTextIndent(
points: CGFloat,
atIndex index: UInt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// RichTextAttributeWriter+Style.swift
// RichTextAttributeWriter+Styles.swift
// RichTextKit
//
// Created by Daniel Saidi on 2022-05-28.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation

public extension RichTextAttributeWriter {

/// Set the superscript level at a certain range.
/// Set the rich text superscript at a certain range.
func setRichTextSuperscriptLevel(
_ level: Int,
at range: NSRange
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Colors/RichTextColorPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private extension RichTextColorPicker {
} label: {
color
}
.buttonStyle(ColorButtonStyle( ))
.buttonStyle(ColorButtonStyle())
}

var quickPickerDivider: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ import AppKit

public extension RichTextViewComponent {

/// Get the current rich text alignment.
/// Get the rich text alignment at current range.
var richTextAlignment: RichTextAlignment? {
let attribute: NSMutableParagraphStyle? = richTextAttribute(.paragraphStyle)
guard let style = attribute else { return nil }
guard let style = richTextParagraphStyle else { return nil }
return RichTextAlignment(style.alignment)
}

/// Set the current text alignment.
/// Set the rich text alignment at current range.
func setRichTextAlignment(
_ alignment: RichTextAlignment
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension RichTextViewComponent {

/// Get all current rich text attributes.
/// Get all rich text attributes at current range.
var richTextAttributes: RichTextAttributes {
if hasSelectedRange {
return richTextAttributes(at: selectedRange)
Expand All @@ -25,14 +25,14 @@ public extension RichTextViewComponent {
#endif
}

/// Get a current rich text attribute.
/// Get a certain rich text attribute at current range.
func richTextAttribute<Value>(
_ attribute: RichTextAttribute
) -> Value? {
richTextAttributes[attribute] as? Value
}

/// Set a current rich text attribute.
/// Set a certain rich text attribute at current range.
func setRichTextAttribute(
_ attribute: RichTextAttribute,
to value: Any
Expand All @@ -49,7 +49,7 @@ public extension RichTextViewComponent {
#endif
}

/// Set some current rich text attributes.
/// Set certain attributes at current range.
func setRichTextAttributes(_ attributes: RichTextAttributes) {
attributes.forEach { attribute, value in
setRichTextAttribute(attribute, to: value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Foundation

public extension RichTextViewComponent {

/// Get a current rich text color value.
/// Get a certain rich text color at current range.
func richTextColor(
_ color: RichTextColor
) -> ColorRepresentable? {
guard let attribute = color.attribute else { return nil }
return richTextAttribute(attribute)
}

/// Set a current rich text color value.
/// Set a certain rich text color at current range.
func setRichTextColor(
_ color: RichTextColor,
to val: ColorRepresentable
Expand Down
26 changes: 8 additions & 18 deletions Sources/RichTextKit/Component/RichTextViewComponent+Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,29 @@ import Foundation

public extension RichTextViewComponent {

/// Get the current rich text font.
/// Get the rich text font at current range.
var richTextFont: FontRepresentable? {
richTextAttributes[.font] as? FontRepresentable ?? typingAttributes[.font] as? FontRepresentable
}

/// Get the current rich text font size.
var richTextFontSize: CGFloat? {
richTextFont?.pointSize
}

/// Get the current rich text font name.
var richTextFontName: String? {
richTextFont?.fontName
}

/// Set the current rich text font.
/// Set the rich text font at current range.
func setRichTextFont(_ font: FontRepresentable) {
setRichTextAttribute(.font, to: font)
}

/// Set the current rich text font name.
/// Set the rich text font name at current range.
func setRichTextFontName(_ name: String) {
if richTextFontName == name { return }
if richTextFont?.fontName == name { return }
if hasSelectedRange {
setRichTextFontName(name, at: selectedRange)
} else {
setFontNameAtCurrentPosition(to: name)
}
}

/// Set the current rich text font size.
/// Set the rich text font size at current range.
func setRichTextFontSize(_ size: CGFloat) {
if size == richTextFontSize { return }
if size == richTextFont?.pointSize { return }
#if macOS
setRichTextFontSize(size, at: selectedRange)
setFontSizeAtCurrentPosition(size)
Expand All @@ -56,9 +46,9 @@ public extension RichTextViewComponent {
#endif
}

/// Step the current rich text font size up or down.
/// Step the rich text font size at current range.
func stepRichTextFontSize(points: Int) {
let currentSize = richTextFontSize ?? .standardRichTextFontSize
let currentSize = richTextFont?.pointSize ?? .standardRichTextFontSize
let newSize = currentSize + CGFloat(points)
setRichTextFontSize(newSize)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public extension RichTextViewComponent {
imageConfiguration.pasteConfiguration
}


/// Validate that image drop will be performed.
func validateImageInsertion(
for config: RichTextImageInsertConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import AppKit

public extension RichTextViewComponent {

/// Get the current rich text indent.
/// Get the rich text indent at current range.
var richTextIndent: CGFloat? {
let attribute: NSMutableParagraphStyle? = richTextAttribute(.paragraphStyle)
guard let style = attribute else { return nil }
return style.headIndent
richTextParagraphStyle?.headIndent
}

/// Step the current rich text indent.
/// Set the rich text indent at current range.
func stepRichTextIndent(
points: CGFloat
) {
Expand All @@ -39,7 +37,6 @@ public extension RichTextViewComponent {

private extension RichTextViewComponent {

/// Step the text indent at the current position.
func step(points: CGFloat) {
guard let style = typingAttributes[.paragraphStyle] as? NSParagraphStyle else { return }
guard let mutableStyle = style.mutableCopy() as? NSMutableParagraphStyle else { return }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// RichTextViewComponent+Paragraph.swift
// RichTextKit
//
// Created by Daniel Saidi on 2024-01-17.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation

#if canImport(UIKit)
import UIKit
#endif

#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

public extension RichTextViewComponent {

/// Get the rich text paragraph style at current range.
var richTextParagraphStyle: NSMutableParagraphStyle? {
richTextAttribute(.paragraphStyle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension RichTextViewComponent {

/// Get the current rich text styles.
/// Get all rich text styles at current range.
var richTextStyles: [RichTextStyle] {
let attributes = richTextAttributes
let traits = richTextFont?.fontDescriptor.symbolicTraits
Expand All @@ -20,7 +20,7 @@ public extension RichTextViewComponent {
return styles
}

/// Set the current value of a certain rich text style.
/// Set a certain rich text style at current range.
func setRichTextStyle(
_ style: RichTextStyle,
to newValue: Bool
Expand Down
Loading

0 comments on commit 232794a

Please sign in to comment.