From b07bf73f78d723c83ac2cdb1d44abab875364548 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 15 Sep 2019 04:00:24 -0500 Subject: [PATCH 1/3] =?UTF-8?q?Revert=20"Scale=20images,=20when=20needed,?= =?UTF-8?q?=20before=20generating=20inline=20HTML=20data=20in=20ArticleRen?= =?UTF-8?q?derer=20=E2=80=94=C2=A0this=20keeps=20us=20from=20getting=20hug?= =?UTF-8?q?e=20amounts=20of=20data,=20which=20slows=20down=20rendering."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c3e26ea307248b5ed0b8638098a17b2abfd94f2e. --- .../Article Rendering/ArticleRenderer.swift | 49 ++----------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index d66aac5a2..833228120 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -159,48 +159,6 @@ private extension ArticleRenderer { return permalink != preferredLink // Make date a link if it’s a different link from the title’s link } - static let avatarDimension = 48 - static let doubledDimension = CGFloat(avatarDimension * 2) - - static func imageScaledForDisplay(image: RSImage) -> RSImage { - // Aspect fit. - #if os(macOS) - - if image.size.height <= doubledDimension && image.size.width <= doubledDimension { - return image - } - - let scaledImage = NSImage.init(size: NSSize(width: doubledDimension, height: doubledDimension)) - scaledImage.lockFocus() - - var imageRectWidth = doubledDimension - var imageRectHeight = doubledDimension - var imageRectOriginX = CGFloat(0.0) - var imageRectOriginY = CGFloat(0.0) - - if image.size.width > image.size.height { - let factor: CGFloat = doubledDimension / image.size.width - imageRectHeight = image.size.height * factor - imageRectOriginY = (doubledDimension - imageRectHeight) / 2.0 - } - else if image.size.height > image.size.width { - let factor: CGFloat = doubledDimension / image.size.height - imageRectWidth = image.size.width * factor - imageRectOriginX = (doubledDimension - imageRectWidth) / 2.0 - } - - image.draw(in: NSRect(x: imageRectOriginX, y: imageRectOriginY, width: imageRectWidth, height: imageRectHeight)) - scaledImage.unlockFocus() - return scaledImage - - #else //iOS - - // TODO: https://github.com/brentsimmons/NetNewsWire/issues/1021 - - return image - #endif - } - func faviconImgTag(forFeed feed: Feed) -> String? { if let cachedImgTag = ArticleRenderer.faviconImgTagCache[feed] { @@ -208,8 +166,7 @@ private extension ArticleRenderer { } if let favicon = appDelegate.faviconDownloader.favicon(for: feed) { - let scaledImage = ArticleRenderer.imageScaledForDisplay(image: favicon) - if let s = base64String(forImage: scaledImage) { + if let s = base64String(forImage: favicon) { var dimension = min(favicon.size.height, CGFloat(ArticleRenderer.avatarDimension)) // Assuming square images. dimension = max(dimension, 16) // Some favicons say they’re < 16. Force them larger. if dimension >= CGFloat(ArticleRenderer.avatarDimension) * 0.8 { //Close enough to scale up. @@ -238,8 +195,7 @@ private extension ArticleRenderer { } if let icon = appDelegate.feedIconDownloader.icon(for: feed) { - let scaledImage = ArticleRenderer.imageScaledForDisplay(image: icon) - if let s = base64String(forImage: scaledImage) { + if let s = base64String(forImage: icon) { #if os(macOS) let imgTag = "" #else @@ -272,6 +228,7 @@ private extension ArticleRenderer { return nil } + static let avatarDimension = 48 struct Avatar { let imageURL: String From 20dda3727ba1704ab6e757b8cd0ac8d5559de6b3 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 15 Sep 2019 04:05:11 -0500 Subject: [PATCH 2/3] Change to use the scaled avatar version of the favicon. --- Shared/Article Rendering/ArticleRenderer.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 833228120..bb7fedc7a 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -165,7 +165,7 @@ private extension ArticleRenderer { return cachedImgTag } - if let favicon = appDelegate.faviconDownloader.favicon(for: feed) { + if let favicon = appDelegate.faviconDownloader.faviconAsAvatar(for: feed) { if let s = base64String(forImage: favicon) { var dimension = min(favicon.size.height, CGFloat(ArticleRenderer.avatarDimension)) // Assuming square images. dimension = max(dimension, 16) // Some favicons say they’re < 16. Force them larger. @@ -210,6 +210,7 @@ private extension ArticleRenderer { } func base64String(forImage image: RSImage) -> String? { + print("height: \(image.size.height) width: \(image.size.width)") return image.dataRepresentation()?.base64EncodedString() } From dc67c9f03b85eeab43d7e37723f5803fb67c56fd Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 15 Sep 2019 04:06:24 -0500 Subject: [PATCH 3/3] Update to latest RSCore --- submodules/RSCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/RSCore b/submodules/RSCore index 6bbc375a6..98c050aca 160000 --- a/submodules/RSCore +++ b/submodules/RSCore @@ -1 +1 @@ -Subproject commit 6bbc375a61775b85dca181feda8a5e98331f2bb7 +Subproject commit 98c050aca6e2c4f034b22c1d3d4f938893290543