From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: exposing x_get_scale_factor into elisp level Date: Wed, 24 Mar 2021 22:55:42 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="qJKiYZ8Tj+SDL1MJ" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6949"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Evgeny Zajcev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 24 23:56: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 1lPCQr-0001hV-K9 for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Mar 2021 23:56:57 +0100 Original-Received: from localhost ([::1]:59600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPCQq-0002qQ-Ie for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Mar 2021 18:56:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPCPp-0001ZO-5X for emacs-devel@gnu.org; Wed, 24 Mar 2021 18:55:53 -0400 Original-Received: from outbound.soverin.net ([2a01:4f8:fff0:2d:8::218]:32989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPCPm-0001kX-66 for emacs-devel@gnu.org; Wed, 24 Mar 2021 18:55:52 -0400 Original-Received: from smtp.soverin.net (unknown [10.10.3.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 12262600D0 for ; Wed, 24 Mar 2021 22:55:47 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.138]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1616626546; bh=uZvZcd6idOpG0m2rPfYndGE8MZcz8hQRLmDP95+PnlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=asvJA3CmL3BiKkf9C/3+1YL3+3m3hpZgRiRI+1/CrHI3jAtZzrCrxPmThrydRjD1y pAkGjVjz8Qm2lJlE7U7aagjhtu/pB7/6TI0cvfFImqj4Ehj6PH8vQfq+Pt5Npl0gu3 blR25mmiiM+LFczQFOzTlkvVy7KY2AJoKl7MdCk/gxIi+3JoZhaNU2CXFhG6+w3NC9 IEkdaEYwKkn4cvGDOQV5N5jWH92wobNZcSqgwjN0AoSrqdu1EF0smaWyXvp+HHzfFT quh6UPTaN+nyEFzkxCQZJucKK4Tya9iGLbvREMuCYZRTb4C+fOSZ+D4l8uTFHGBk65 lNULEnswgJItA== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 800E7202B1C745; Wed, 24 Mar 2021 22:55:42 +0000 (GMT) Mail-Followup-To: Alan Third , Evgeny Zajcev , emacs-devel Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=2a01:4f8:fff0:2d:8::218; envelope-from=alan@idiocy.org; helo=outbound.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:266994 Archived-At: --qJKiYZ8Tj+SDL1MJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu, Mar 25, 2021 at 12:20:09AM +0300, Evgeny Zajcev wrote: > ср, 24 мар. 2021 г. в 23:27, Alan Third : > > > On Mon, Mar 22, 2021 at 02:07:41AM +0300, Evgeny Zajcev wrote: > > > HiDPI is very common nowadays. Internally Emacs has decent support for > > > HiDPI displays. However elisp code, that generates non-svg images don't > > > have any idea that logical pixel may differ from physical one, resulting > > in > > > generating images in low resolution on HiDPI displays. > > > > > > Emacs internally has a notion about HiDPI displays, such as > > > `x_get_scale_factor`, maybe expose this function to elisp level, so > > > packages may utilize it to generate images in highres? > > > > On NS platforms (macOS and GNUstep) and, I believe, native GTK the > > scale factor is how much the TOOLKIT scales things up for display. > > > > The problem we hit on MacOS is that line height is reported in logical > pixels, and we generate PNG images using that line height value. This > results in poor PNG quality since the physical pixel is x4 times larger. > Now we use heavy heuristics to workaround this, it will be great to have > some general approach as Emacs do internally (`x_get_scale_factor') My point, which wasn't clear, is that x_get_scale_factor is not general. IMO exposing its output to lisp is likely to just cause confusion. That said, I've attached an implementation that ignores X and possibly won't work for Windows. -- Alan Third --qJKiYZ8Tj+SDL1MJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Implement-frame-scale-factor.patch" >From 96f96c5e9da6db91509afea4c1ac9b1ba04ddaae Mon Sep 17 00:00:00 2001 From: Alan Third Date: Wed, 24 Mar 2021 22:50:03 +0000 Subject: [PATCH] Implement frame-scale-factor * src/frame.c (Fframe_scale_factor): New function. (syms_of_frame): Add frame-scale-factor. * src/frame.h: Add FRAME_SCALE_FACTOR. * src/image.c: Move FRAME_SCALE_FACTOR to frame.h. --- src/frame.c | 12 ++++++++++++ src/frame.h | 7 +++++++ src/image.c | 8 -------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/frame.c b/src/frame.c index a62347c1fb..fd649ff0fa 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3744,6 +3744,17 @@ DEFUN ("set-frame-window-state-change", Fset_frame_window_state_change, return (FRAME_WINDOW_STATE_CHANGE (f) = !NILP (arg)) ? Qt : Qnil; } +DEFUN ("frame-scale-factor", Fframe_scale_factor, Sframe_scale_factor, + 0, 1, 0, + doc: /* Return FRAMEs scale factor. +The scale factor is the amount a logical pixel size must be multiplied +to find the real number of pixels. */) + (Lisp_Object frame) +{ + struct frame *f = decode_live_frame (frame); + + return (make_float (FRAME_SCALE_FACTOR (f))); +} /*********************************************************************** Frame Parameters @@ -6457,6 +6468,7 @@ focus (where a frame immediately loses focus when it's left by the mouse defsubr (&Sframe_pointer_visible_p); defsubr (&Sframe_window_state_change); defsubr (&Sset_frame_window_state_change); + defsubr (&Sframe_scale_factor); #ifdef HAVE_WINDOW_SYSTEM defsubr (&Sx_get_resource); diff --git a/src/frame.h b/src/frame.h index 9ddcb4c681..9963112036 100644 --- a/src/frame.h +++ b/src/frame.h @@ -907,6 +907,13 @@ #define FRAME_HAS_MINIBUF_P(f) \ (WINDOWP (f->minibuffer_window) \ && XFRAME (XWINDOW (f->minibuffer_window)->frame) == f) +/* Scale factor of frame F. */ +#if defined HAVE_NS +# define FRAME_SCALE_FACTOR(f) (FRAME_NS_P (f) ? ns_frame_scale_factor (f) : 1) +#else +# define FRAME_SCALE_FACTOR(f) 1; +#endif + /* Pixel width of frame F. */ #define FRAME_PIXEL_WIDTH(f) ((f)->pixel_width) diff --git a/src/image.c b/src/image.c index 3d504effa6..24089e5cb0 100644 --- a/src/image.c +++ b/src/image.c @@ -135,14 +135,6 @@ #define PIX_MASK_DRAW 1 # define COLOR_TABLE_SUPPORT 1 #endif -#ifdef HAVE_RSVG -#if defined HAVE_NS -# define FRAME_SCALE_FACTOR(f) ns_frame_scale_factor (f) -#else -# define FRAME_SCALE_FACTOR(f) 1; -#endif -#endif - static void image_disable_image (struct frame *, struct image *); static void image_edge_detection (struct frame *, struct image *, Lisp_Object, Lisp_Object); -- 2.29.2 --qJKiYZ8Tj+SDL1MJ--