unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Anand Tamariya <atamariya@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Pixel padding with variable pitch font
Date: Mon, 07 Jun 2021 16:35:07 +0300	[thread overview]
Message-ID: <831r9dhk6s.fsf@gnu.org> (raw)
In-Reply-To: <CADm7Y4=xFu4oZJanRxphrbtrfi-zte80s8x+xL6a3C6mXkgNWg@mail.gmail.com> (message from Anand Tamariya on Mon, 7 Jun 2021 18:49:01 +0530)

> From: Anand Tamariya <atamariya@gmail.com>
> Date: Mon, 7 Jun 2021 18:49:01 +0530
> 
> If you need to pad space with variable pitch font, and you are unable to use ':align-to display' option for any
> reason, you can use the following code. This uses unicode spacing characters to insert required amount of
> space.
> 
> Screenshot: https://lifeofpenguin.blogspot.com/2021/06/gnu-emacs.html
> 
> (defun company--insert-space (width w)
>   "Insert unicode space characters to fit the WIDTH."
>   (let ((num 0))
>     (dolist (spc '((#x2001 .  1) (#x2000 . 0.5) (#x2004 . 0.33) (#x2005 . 0.25) (#x2006 . 0.16) (#x200A . 0.125)))
>       (setq num (floor (/ width w (cdr spc))))
>       (if (memq (car spc) '(#x2001 #x2000 #x2004 #x2005))
>           ;; Allow finer spaces towards the end for better accuracy
>           (setq num (1- num)))
>       (when (> num 0)
>         (dotimes (i num)
>           (insert (car spc)))
>         (setq width (- width (* num w (cdr spc))))
>         ))))

This assumes that, e.g., #x2001 takes the same horizontal space as the
SPC character (or the same as a column)?  That's only so in
fixed-pitch fonts; in variable-pitch fonts the SPC could be much more
narrow, and columns are all but meaningless.  Caveat emptor!



  reply	other threads:[~2021-06-07 13:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 13:19 Pixel padding with variable pitch font Anand Tamariya
2021-06-07 13:35 ` Eli Zaretskii [this message]
2021-06-08  2:59   ` Ihor Radchenko
2021-06-08  5:04     ` Anand Tamariya

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=831r9dhk6s.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=atamariya@gmail.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).