From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "James N. V. Cash" Newsgroups: gmane.emacs.devel Subject: [PATCH] avoid hard-coded assumptions in image scaling Date: Sun, 02 May 2021 16:18:30 -0400 Message-ID: <87eeeoopnt.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36369"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 02 22:42:58 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldIvZ-0009M3-Rd for ged-emacs-devel@m.gmane-mx.org; Sun, 02 May 2021 22:42:57 +0200 Original-Received: from localhost ([::1]:58174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldIvY-0008FM-Ua for ged-emacs-devel@m.gmane-mx.org; Sun, 02 May 2021 16:42:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldIXz-0000tR-6w for emacs-devel@gnu.org; Sun, 02 May 2021 16:18:35 -0400 Original-Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]:37389) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldIXx-0008Gm-CW for emacs-devel@gnu.org; Sun, 02 May 2021 16:18:34 -0400 Original-Received: by mail-qk1-x736.google.com with SMTP id i67so173501qkc.4 for ; Sun, 02 May 2021 13:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version; bh=fNyzKSwgIIn5RLzysU8i8Dy8jOTigkOz4HTf6J6w2qc=; b=KxA+4epnyeVx4yVaxxeQn7LQMRtz/8sON+ZKSqvwFUegE+zh46S0HjVgV1hEAWyXlw M8kyIa+HatVmqP3nWsZ2E/PTRKCxubeVv8GxEAcB/TbDFJzeyXkGkBspkLC9ZXwYYxto m+eHuDsr5f6uQpFHhTUz98b6SnQw8Is1mmzbKYXzK0aZ5VSgEpAtHO+6AWvwS8jWMj4E afpW+ow8JMlYhXg/r71Mhh+bdmpL614ZG1moUd2GFx3kvmyultHDLCwR25oDfO3I3o9u 78YkEN+qWzR0HCEgmGSNGYRHqMA4UuGf0AAkRzbOXz0ZFGf6nuPH8HYjLh7nfhDlw1cC KRdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=fNyzKSwgIIn5RLzysU8i8Dy8jOTigkOz4HTf6J6w2qc=; b=VKjYc3WwvrVfpG6k8j1zws+4/jH/d8Mz0zEi66jTdS6ZAnKqisNKcBzsONaRGkpOn+ N1oNwQXYjD0FQAUqV23+6d+MVKmSfT+taMvBHRHUBw4IahQg30J16lcWy6AYzhkLeSEh US++fMHTtnFBELPxO5eTJpK6hDUfyr0lobG5DziMWE4kAUtQcK+SjkebbfOgpoFZRwHC vW2qGnR1lc3lCE2ArR19mjT3Yr/GKqIQHzoRMyeLKPALz4dhM+aWh5JehpL7RbMy986D 2TwLHuOV8g+Ct4dviMQNZxhm9W9ab3hqUbVfZP3kzExbaC0+YTXIhFlLpikUuFqxn5Np 8QLQ== X-Gm-Message-State: AOAM530LYPmlWqri58tWQ+ISnXrFaeJSZXogjEAJtuLLA07R2XuX7s4/ oLjqFrZDD3M2+jisbxxe7S05fGAcPmpcEg== X-Google-Smtp-Source: ABdhPJxQAn0nbvD3Js4iBfEY5VUaw9et5K/UM7gFVOnfrHKGzN52hABBNMB0JyMhfT0gKVx5371kOQ== X-Received: by 2002:a37:8246:: with SMTP id e67mr16069365qkd.410.1619986711663; Sun, 02 May 2021 13:18:31 -0700 (PDT) Original-Received: from gonk ([2607:fea8:10e2:9e00:4c3d:41a2:416f:1808]) by smtp.gmail.com with ESMTPSA id z18sm1705062qki.55.2021.05.02.13.18.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 13:18:31 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::736; envelope-from=james.nvc@gmail.com; helo=mail-qk1-x736.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 02 May 2021 16:42:09 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268781 Archived-At: In image-compute-scaling-factor in images.el, it currently hard-codes the assumption that the average character width is 10 pixels. Since `frame-char-width` gives this information though, it seems like it's less error-prone to use that function instead of assuming. --- lisp/image.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lisp/image.el b/lisp/image.el index 610d020aab..8a9cfec841 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -561,12 +561,11 @@ image-compute-scaling-factor ((numberp scaling) scaling) ((eq scaling 'auto) (let ((width (/ (float (window-width nil t)) (window-width)))) - ;; If we assume that a typical character is 10 pixels in width, - ;; then we should scale all images according to how wide they - ;; are. But don't scale images down. - (if (< width 10) + ;; We should scale all images according to how wide they are. + ;; But don't scale images down. + (if (< width (frame-char-width)) 1 - (/ (float width) 10)))) + (/ (float width) (frame-char-width))))) (t (error "Invalid scaling factor %s" scaling)))) -- 2.25.1