diff --git a/Tusker/HTMLConverter.swift b/Tusker/HTMLConverter.swift
index e2d523966a..32f25c8a20 100644
--- a/Tusker/HTMLConverter.swift
+++ b/Tusker/HTMLConverter.swift
@@ -14,6 +14,7 @@ import WebURLFoundationExtras
struct HTMLConverter {
static let defaultFont = UIFont.systemFont(ofSize: 17)
+ static let defaultMonospaceFont = UIFont.monospacedSystemFont(ofSize: 17, weight: .regular)
static let defaultColor = UIColor.label
static let defaultParagraphStyle: NSParagraphStyle = {
let style = NSMutableParagraphStyle()
@@ -23,6 +24,7 @@ struct HTMLConverter {
}()
var font: UIFont = defaultFont
+ var monospaceFont: UIFont = defaultMonospaceFont
var color: UIColor = defaultColor
var paragraphStyle: NSParagraphStyle = defaultParagraphStyle
@@ -90,11 +92,10 @@ struct HTMLConverter {
case "del":
attributed.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: attributed.fullRange)
case "code":
- // TODO: this probably breaks with dynamic type
- attributed.addAttribute(.font, value: UIFont.monospacedSystemFont(ofSize: font.pointSize, weight: .regular), range: attributed.fullRange)
+ attributed.addAttribute(.font, value: monospaceFont, range: attributed.fullRange)
case "pre":
attributed.append(NSAttributedString(string: "\n\n"))
- attributed.addAttribute(.font, value: UIFont.monospacedSystemFont(ofSize: font.pointSize, weight: .regular), range: attributed.fullRange)
+ attributed.addAttribute(.font, value: monospaceFont, range: attributed.fullRange)
case "ol", "ul":
attributed.append(NSAttributedString(string: "\n\n"))
attributed.trimLeadingCharactersInSet(.whitespacesAndNewlines)
@@ -106,7 +107,7 @@ struct HTMLConverter {
let index = (try? node.elementSiblingIndex()) ?? 0
// we use the monospace digit font so that the periods of all the list items line up
// TODO: this probably breaks with dynamic type
- bullet = NSAttributedString(string: "\(index + 1).\t", attributes: [.font: UIFont.monospacedDigitSystemFont(ofSize: font.pointSize, weight: .regular), .foregroundColor: color])
+ bullet = NSAttributedString(string: "\(index + 1).\t", attributes: [.font: monospaceFont, .foregroundColor: color])
} else if parentTag == "ul" {
bullet = NSAttributedString(string: "\u{2022}\t", attributes: [.font: font, .foregroundColor: color])
} else {
diff --git a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift
index be065a1b83..ca3174891c 100644
--- a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift
+++ b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift
@@ -33,6 +33,7 @@ class FeaturedProfileCollectionViewCell: UICollectionViewCell {
displayNameLabel.adjustsFontForContentSizeCategory = true
noteTextView.defaultFont = .preferredFont(forTextStyle: .body)
+ noteTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 17, weight: .regular))
noteTextView.adjustsFontForContentSizeCategory = true
noteTextView.textContainer.lineBreakMode = .byTruncatingTail
noteTextView.textContainerInset = UIEdgeInsets(top: 16, left: 4, bottom: 16, right: 4)
diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift
index d58642b263..6b4883ea67 100644
--- a/Tusker/Screens/Timeline/TimelineViewController.swift
+++ b/Tusker/Screens/Timeline/TimelineViewController.swift
@@ -42,6 +42,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
}
self.filterer = Filterer(mastodonController: mastodonController, context: filterContext)
self.filterer.htmlConverter.font = TimelineStatusCollectionViewCell.contentFont
+ self.filterer.htmlConverter.monospaceFont = TimelineStatusCollectionViewCell.monospaceFont
self.filterer.htmlConverter.paragraphStyle = TimelineStatusCollectionViewCell.contentParagraphStyle
super.init(nibName: nil, bundle: nil)
diff --git a/Tusker/Views/ConfirmReblogStatusPreviewView.swift b/Tusker/Views/ConfirmReblogStatusPreviewView.swift
index 1d68ee6b68..fd195e58f0 100644
--- a/Tusker/Views/ConfirmReblogStatusPreviewView.swift
+++ b/Tusker/Views/ConfirmReblogStatusPreviewView.swift
@@ -61,6 +61,7 @@ class ConfirmReblogStatusPreviewView: UIView {
let contentView = StatusContentTextView()
contentView.defaultFont = .preferredFont(forTextStyle: .caption2)
+ contentView.monospaceFont = UIFontMetrics(forTextStyle: .caption2).scaledFont(for: .monospacedSystemFont(ofSize: 17, weight: .regular))
contentView.isUserInteractionEnabled = false
contentView.isScrollEnabled = false
contentView.backgroundColor = nil
diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift
index ff36eef932..fcd49bc835 100644
--- a/Tusker/Views/ContentTextView.swift
+++ b/Tusker/Views/ContentTextView.swift
@@ -27,6 +27,10 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
_read { yield htmlConverter.font }
_modify { yield &htmlConverter.font }
}
+ var monospaceFont: UIFont {
+ _read { yield htmlConverter.monospaceFont }
+ _modify { yield &htmlConverter.monospaceFont }
+ }
var defaultColor: UIColor {
_read { yield htmlConverter.color }
_modify { yield &htmlConverter.color }
diff --git a/Tusker/Views/Instance Cell/InstanceTableViewCell.swift b/Tusker/Views/Instance Cell/InstanceTableViewCell.swift
index 6fda7a3145..443aed3064 100644
--- a/Tusker/Views/Instance Cell/InstanceTableViewCell.swift
+++ b/Tusker/Views/Instance Cell/InstanceTableViewCell.swift
@@ -35,6 +35,7 @@ class InstanceTableViewCell: UITableViewCell {
adultLabel.layer.cornerRadius = 0.5 * adultLabel.bounds.height
descriptionTextView.defaultFont = .preferredFont(forTextStyle: .body)
+ descriptionTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 17, weight: .regular))
descriptionTextView.adjustsFontForContentSizeCategory = true
}
diff --git a/Tusker/Views/Profile Header/ProfileFieldsView.swift b/Tusker/Views/Profile Header/ProfileFieldsView.swift
index 555272e674..c678d25a5e 100644
--- a/Tusker/Views/Profile Header/ProfileFieldsView.swift
+++ b/Tusker/Views/Profile Header/ProfileFieldsView.swift
@@ -184,6 +184,7 @@ private class ProfileFieldValueView: UIView {
textView.isSelectable = false
textView.defaultFont = .preferredFont(forTextStyle: .body)
+ textView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 17, weight: .regular))
textView.adjustsFontForContentSizeCategory = true
textView.setTextFromHtml(field.value)
textView.setEmojis(account.emojis, identifier: account.id)
diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift
index b18a72d80b..4f9de6989b 100644
--- a/Tusker/Views/Profile Header/ProfileHeaderView.swift
+++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift
@@ -82,6 +82,7 @@ class ProfileHeaderView: UIView {
relationshipLabel.adjustsFontForContentSizeCategory = true
noteTextView.defaultFont = .preferredFont(forTextStyle: .body)
+ noteTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 17, weight: .regular))
noteTextView.adjustsFontForContentSizeCategory = true
pagesSegmentedControl = ScrollingSegmentedControl(frame: .zero)
diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift
index d15f9cedfa..8f812ea790 100644
--- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift
+++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift
@@ -64,7 +64,8 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell {
contentWarningLabel.font = .preferredFont(forTextStyle: .body).withTraits(.traitBold)!
contentWarningLabel.adjustsFontForContentSizeCategory = true
- contentTextView.defaultFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 18))
+ contentTextView.defaultFont = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 18))
+ contentTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 18, weight: .regular))
contentTextView.adjustsFontForContentSizeCategory = true
contentTextView.dataDetectorTypes = [.flightNumber, .address, .shipmentTrackingNumber, .phoneNumber]
if #available(iOS 16.0, *) {
diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift
index 59cd320748..e34ec77b47 100644
--- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift
+++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift
@@ -16,7 +16,8 @@ private let hashtagIcon = UIImage(systemName: "number")
class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollectionViewCell {
static let separatorInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 0)
- static let contentFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 16))
+ static let contentFont = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 16))
+ static let monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 16, weight: .regular))
static let contentParagraphStyle = HTMLConverter.defaultParagraphStyle
// MARK: Subviews
@@ -167,6 +168,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
let contentContainer = StatusContentContainer().configure {
$0.contentTextView.defaultFont = TimelineStatusCollectionViewCell.contentFont
+ $0.contentTextView.monospaceFont = TimelineStatusCollectionViewCell.monospaceFont
$0.contentTextView.paragraphStyle = TimelineStatusCollectionViewCell.contentParagraphStyle
$0.setContentHuggingPriority(.defaultLow, for: .vertical)
}
diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift
index 3e58beef2f..fcd4d81d71 100644
--- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift
+++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift
@@ -85,7 +85,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
]), size: 0)
contentWarningLabel.adjustsFontForContentSizeCategory = true
- contentTextView.defaultFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 16))
+ contentTextView.defaultFont = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 16))
+ contentTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 16, weight: .regular))
contentTextView.adjustsFontForContentSizeCategory = true
// todo: double check this on RTL layouts