From 006a7fac1d8f191ed8d750a341b389ea1a2a947d Mon Sep 17 00:00:00 2001 From: Shunmugaraj Date: Sun, 22 Jan 2023 10:17:27 +0300 Subject: [PATCH] Issue in height calculation for RTL text when there is headIndent and firstlineheadIndent. Signed-off-by: Shunmugaraj toshanmugaraj@gmail.com --- .../Utils/EventFormatter/MXKEventFormatter.m | 18 ++++++++++++++++++ changelog.d/7288.bugfix | 1 + 2 files changed, 19 insertions(+) create mode 100644 changelog.d/7288.bugfix diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index 422e089902..30647b6320 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -1379,6 +1379,24 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent*)event // Build the attributed string with the right font and color for the event attributedDisplayText = [self renderString:body forEvent:event]; } + + // Issue in height calculation for RTL text when there is headIndent and firstlineheadIndent. + if(attributedDisplayText != nil) { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @"(?s).*\\p{Arabic}.*"]; + if ([predicate evaluateWithObject:body]) { + NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithAttributedString:attributedDisplayText]; + + NSMutableParagraphStyle *paragraphStyle = [attributedDisplayText attribute:NSParagraphStyleAttributeName atIndex:0 effectiveRange:nil]; + if (paragraphStyle) { + paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft; + paragraphStyle.alignment = NSTextAlignmentJustified; + paragraphStyle.headIndent = 0; + paragraphStyle.firstLineHeadIndent = 0; + [attString addAttributes:@{NSParagraphStyleAttributeName : paragraphStyle} range:NSMakeRange(0, attString.length)]; + attributedDisplayText = [[NSAttributedString alloc] initWithAttributedString:attString]; + } + } + } // Build the full emote string after the body message formatting if ([msgtype isEqualToString:kMXMessageTypeEmote]) diff --git a/changelog.d/7288.bugfix b/changelog.d/7288.bugfix new file mode 100644 index 0000000000..21432ace7c --- /dev/null +++ b/changelog.d/7288.bugfix @@ -0,0 +1 @@ +RTL replies sometimes don't get rendered \ No newline at end of file