unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Pegoraro <spegoraro@tutive.com>
To: emacs-devel@gnu.org
Subject: HiDPI support for wave style underlines
Date: Sat, 29 Jul 2017 11:29:43 +0800	[thread overview]
Message-ID: <CAPzg8ESH0Sr=jH5=Uj3bV1iDoqWvWu1x1nKGLfkGSkiszgfHKw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 599 bytes --]

Hi,

I have made an attempt at implementing scaled drawing of wave style
underlines for hidpi displays, X only for now.
This is my first contribution to emacs so any feedback would be great!
I've followed the commit and patch style from CONTRIBUTE as closely as
I could but let me know if there's any issue.

It works by determining a scale factor from x_display_info's resx and
resy members then setting the wave_height and wave_length values
accordingly. Thickness was added using XSetLineAttributes and scaled
as well. Tested on displays with various scales from 1 to 3.


Cheers,
Steve Pegoraro

[-- Attachment #2: 0001-Implement-HiDPI-support-for-wave-style-underlines.patch --]
[-- Type: text/x-patch, Size: 2334 bytes --]

From bc71dbc78a455b46a91619bcd38af45e4e9831fb Mon Sep 17 00:00:00 2001
From: Stephen Pegoraro <spegoraro@tutive.com>
Date: Sat, 29 Jul 2017 11:12:03 +0800
Subject: [PATCH] Implement HiDPI support for wave style underlines

* src/xterm.c (x_draw_underwave): Compute height, length and thickness
based on scale factor.
(x_get_scale_factor): New function.
---
 src/xterm.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index a214cd8103..5476c22a0b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -23,9 +23,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef USE_CAIRO
 #include <math.h>
-#endif
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -3475,6 +3473,15 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
   s->background_filled_p = true;
 }
 
+static int x_get_scale_factor(Display *disp)
+{
+    struct x_display_info * dpyinfo = x_display_info_for_display (disp);
+    if (!dpyinfo)
+        emacs_abort ();
+
+    return floor(dpyinfo->resy / 96);
+}
+
 /*
    Draw a wavy line under S. The wave fills wave_height pixels from y0.
 
@@ -3485,11 +3492,13 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
     wave_height = 3  | *   *   *   *
 
 */
-
 static void
 x_draw_underwave (struct glyph_string *s)
 {
-  int wave_height = 3, wave_length = 2;
+    /* Adjust for scale/HiDPI */
+    int scale = x_get_scale_factor (s->display);
+    int wave_height = 3 * scale, wave_length = 2 * scale, thickness = scale;
+
 #ifdef USE_CAIRO
   x_draw_horizontal_wave (s->f, s->gc, s->x, s->ybase - wave_height + 3,
 			  s->width, wave_height, wave_length);
@@ -3501,7 +3510,7 @@ x_draw_underwave (struct glyph_string *s)
   dx = wave_length;
   dy = wave_height - 1;
   x0 = s->x;
-  y0 = s->ybase - wave_height + 3;
+  y0 = s->ybase + wave_height / 2;
   width = s->width;
   xmax = x0 + width;
 
@@ -3535,6 +3544,8 @@ x_draw_underwave (struct glyph_string *s)
 
   while (x1 <= xmax)
     {
+      XSetLineAttributes (s->display, s->gc, thickness, LineSolid, CapButt,
+                          JoinRound);
       XDrawLine (s->display, FRAME_X_DRAWABLE (s->f), s->gc, x1, y1, x2, y2);
       x1  = x2, y1 = y2;
       x2 += dx, y2 = y0 + odd*dy;
-- 
2.13.3


             reply	other threads:[~2017-07-29  3:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-29  3:29 Stephen Pegoraro [this message]
2017-07-29  7:13 ` HiDPI support for wave style underlines Eli Zaretskii
     [not found]   ` <CAPzg8ETxJYr8Gw0Pag5zpWqA7aap_kduwuGvJaxAT5yvPhNd6w@mail.gmail.com>
2017-07-29  9:12     ` Stephen Pegoraro
2017-08-18  8:17       ` Eli Zaretskii
2017-08-21 12:20         ` Yuri D'Elia
2017-08-21 12:32           ` Yuri D'Elia
2017-08-21 14:49             ` Eli Zaretskii
2017-08-27  4:26               ` Stephen Pegoraro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPzg8ESH0Sr=jH5=Uj3bV1iDoqWvWu1x1nKGLfkGSkiszgfHKw@mail.gmail.com' \
    --to=spegoraro@tutive.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).