From 827b0ba8f39fcb0cbcb0d1c655dc1dd0405d2387 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 16 Apr 2026 13:03:56 +0300 Subject: [PATCH] Remove more DTCoreText/Foundation references as they are no longer directly imported or used --- .../HTMLParsing/AttributedStringBuilder.swift | 4 - .../UIFont+AttributedStringBuilder.h | 19 ----- .../UIFont+AttributedStringBuilder.m | 75 ------------------- .../Media/MediaUploadingPreprocessor.swift | 3 +- 4 files changed, 2 insertions(+), 99 deletions(-) delete mode 100644 ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.h delete mode 100644 ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.m diff --git a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift index b76b89aca..30870e139 100644 --- a/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift +++ b/ElementX/Sources/Other/HTMLParsing/AttributedStringBuilder.swift @@ -76,10 +76,6 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol { /// Do not use the default HTML renderer of NSAttributedString because this method /// runs on the UI thread which we want to avoid because renderHTMLString is called /// most of the time from a background thread. - /// Use DTCoreText HTML renderer instead. - /// Using DTCoreText, which renders static string, helps to avoid code injection attacks - /// that could happen with the default HTML renderer of NSAttributedString which is a - /// webview. func fromHTML(_ htmlString: String?) -> AttributedString? { guard let originalHTMLString = htmlString else { return nil diff --git a/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.h b/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.h deleted file mode 100644 index a82219345..000000000 --- a/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright 2025 Element Creations Ltd. -// Copyright 2022-2025 New Vector Ltd. -// -// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. -// Please see LICENSE files in the repository root for full details. -// - -@import UIKit; - -NS_ASSUME_NONNULL_BEGIN - -@interface UIFont(DTCoreTextFix) - -// Fix DTCoreText iOS 13 issue (https://github.com/Cocoanetics/DTCoreText/issues/1168) - -@end - -NS_ASSUME_NONNULL_END diff --git a/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.m b/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.m deleted file mode 100644 index 93316168a..000000000 --- a/ElementX/Sources/Other/HTMLParsing/UIFont+AttributedStringBuilder.m +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2025 Element Creations Ltd. -// Copyright 2022-2025 New Vector Ltd. -// -// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. -// Please see LICENSE files in the repository root for full details. -// - -#import "UIFont+AttributedStringBuilder.h" - -@import UIKit; -@import CoreText; -@import ObjectiveC; - -#pragma mark - UIFont DTCoreText fix - -@interface UIFont (vc_DTCoreTextFix) - -+ (UIFont *)vc_fixedFontWithCTFont:(CTFontRef)ctFont; - -@end - -@implementation UIFont (vc_DTCoreTextFix) - -+ (UIFont *)vc_fixedFontWithCTFont:(CTFontRef)ctFont { - NSString *fontName = (__bridge_transfer NSString *)CTFontCopyName(ctFont, kCTFontPostScriptNameKey); - - CGFloat fontSize = CTFontGetSize(ctFont); - UIFont *font = [UIFont fontWithName:fontName size:fontSize]; - - // On iOS 13+ "TimesNewRomanPSMT" will be used instead of "SFUI" - // In case of "Times New Roman" fallback, use system font and reuse UIFontDescriptorSymbolicTraits. - if ([font.familyName.lowercaseString containsString:@"times"]) { - UIFontDescriptorSymbolicTraits symbolicTraits = (UIFontDescriptorSymbolicTraits)CTFontGetSymbolicTraits(ctFont); - - // Start with the body text style and update it to keep consistent line spacing with plain text messages. - UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; - fontDescriptor = [fontDescriptor fontDescriptorWithSize:fontSize]; - fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits]; - - font = [UIFont fontWithDescriptor:fontDescriptor size:fontSize]; - } - - - return font; -} - -@end - -#pragma mark - Implementation - -@implementation UIFont(DTCoreTextFix) - -// DTCoreText iOS 13 fix. See issue and comment here: https://github.com/Cocoanetics/DTCoreText/issues/1168#issuecomment-583541514 -// Also see https://github.com/Cocoanetics/DTCoreText/pull/1245 for a possible future solution -+ (void)load -{ - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - Class originalClass = object_getClass([UIFont class]); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundeclared-selector" - SEL originalSelector = @selector(fontWithCTFont:); // DTCoreText method we're overriding - SEL ourSelector = @selector(vc_fixedFontWithCTFont:); // Use custom implementation -#pragma clang diagnostic pop - - Method originalMethod = class_getClassMethod(originalClass, originalSelector); - Method swizzledMethod = class_getClassMethod(originalClass, ourSelector); - - method_exchangeImplementations(originalMethod, swizzledMethod); - }); -} - -@end diff --git a/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift b/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift index 2d4a4fca5..3f67cdd37 100644 --- a/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift +++ b/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift @@ -350,9 +350,10 @@ struct MediaUploadingPreprocessor { throw .failedGeneratingImageThumbnail(error) } - guard let thumbnail = try? UIImage(contentsOf: thumbnailURL, cachePolicy: .useProtocolCachePolicy) else { + guard let thumbnail = UIImage(contentsOfFile: thumbnailURL.path(percentEncoded: false)) else { throw .failedGeneratingImageThumbnail(nil) } + let blurhash = thumbnail.blurHash(numberOfComponents: (3, 3)) return .init(url: thumbnailURL, height: thumbnail.size.height, width: thumbnail.size.width, mimeType: "image/jpeg", blurhash: blurhash)