From 38c26ea90e1fdce791c87f00b1458311c4ee6ff7 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Mon, 20 Nov 2023 19:25:46 +0100 Subject: [PATCH] When respecting Preferred Font size, only touch font size and keep other font attributes --- .../MatrixKit/Views/MXKMessageTextView.m | 25 +++++++++++++++++-- changelog.d/927.bugfix | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelog.d/927.bugfix diff --git a/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m b/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m index e5d1b6153..6cf574da0 100644 --- a/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m +++ b/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m @@ -94,6 +94,10 @@ - (void)setAttributedText:(NSAttributedString *)attributedText if (@available(iOS 15.0, *)) { [self flushPills]; } + + // Tchap: set text type to prefered font to rerspect user text size + attributedText = [self respectPreferredFontForAttributedString:attributedText]; + [super setAttributedText:attributedText]; if (@available(iOS 15.0, *)) { @@ -101,9 +105,26 @@ - (void)setAttributedText:(NSAttributedString *)attributedText // forcing the layoutManager to redraw the glyphs at all NSAttachment positions. [self vc_invalidateTextAttachmentsDisplay]; } +} + +// Tchap: Update font size using preferred font settings but keeping other attributes +- (NSAttributedString *)respectPreferredFontForAttributedString:(NSAttributedString *)sourceString +{ + UIFont *preferredFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - // Tchap: set text type to prefered font to rerspect user text size - self.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; + NSMutableAttributedString *workString = [sourceString mutableCopy]; + + [workString beginEditing]; + [workString enumerateAttribute:NSFontAttributeName + inRange:NSMakeRange(0, workString.length) + options:0 + usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { + [workString removeAttribute:NSFontAttributeName range:range]; + [workString addAttribute:NSFontAttributeName value:[(UIFont *)value fontWithSize:preferredFont.pointSize] range:range]; + }]; + [workString endEditing]; + + return workString; } - (void)registerPillView:(UIView *)pillView diff --git a/changelog.d/927.bugfix b/changelog.d/927.bugfix new file mode 100644 index 000000000..7fa1a3e57 --- /dev/null +++ b/changelog.d/927.bugfix @@ -0,0 +1 @@ +Conserver les enrichissements de texte quand on respecte le réglage de la taille de texte de l'utilisateur \ No newline at end of file