From 7aea9819f645dae6620016c80b73b289dabb5414 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Fri, 18 Sep 2020 16:12:31 +0300 Subject: [PATCH] [iOS] Fixed image width in bookmarks description in PP https://jira.mail.ru/browse/MAPSME-14873 --- iphone/Maps/Categories/NSAttributedString+HTML.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iphone/Maps/Categories/NSAttributedString+HTML.swift b/iphone/Maps/Categories/NSAttributedString+HTML.swift index 55ec9d1d67..2ec6bd00bf 100644 --- a/iphone/Maps/Categories/NSAttributedString+HTML.swift +++ b/iphone/Maps/Categories/NSAttributedString+HTML.swift @@ -73,10 +73,14 @@ extension NSMutableAttributedString { enumerateAttribute(.attachment, in: NSMakeRange(0, length), options: []) { (value, range, _) in if let attachement = value as? NSTextAttachment, let image = attachement.image(forBounds: attachement.bounds, textContainer: NSTextContainer(), characterIndex: range.location) { - if image.size.width > estimatedWidth { - let newImage = resizeImage(image: image, scale: estimatedWidth/image.size.width) ?? image + if image.size.width > estimatedWidth || attachement.bounds.width > estimatedWidth { let resizedAttachment = NSTextAttachment() - resizedAttachment.image = newImage + if image.size.width > estimatedWidth { + let newImage = resizeImage(image: image, scale: estimatedWidth/image.size.width) ?? image + resizedAttachment.image = newImage + } else { + resizedAttachment.image = image + } addAttribute(.attachment, value: resizedAttachment, range: range) } }