From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Anand Tamariya Newsgroups: gmane.emacs.devel Subject: Pixel padding with variable pitch font Date: Mon, 7 Jun 2021 18:49:01 +0530 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000028171405c42ce304" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33760"; 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 Mon Jun 07 15:20:13 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 1lqFAq-0008X8-HW for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Jun 2021 15:20:12 +0200 Original-Received: from localhost ([::1]:41282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqFAp-0005JG-HR for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Jun 2021 09:20:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqF9z-0004cz-3q for emacs-devel@gnu.org; Mon, 07 Jun 2021 09:19:19 -0400 Original-Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:37546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqF9x-0004OI-3l for emacs-devel@gnu.org; Mon, 07 Jun 2021 09:19:18 -0400 Original-Received: by mail-io1-xd31.google.com with SMTP id q7so18258302iob.4 for ; Mon, 07 Jun 2021 06:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=25F7Ax90ttHB6vqlFFhB2InT726P56OqvZmBLK+WpBs=; b=vFWE2fSkKlzWxIaBeOQf8ReCZjEWHsey2B5GIbuPRx7WXbZIEEhVLNa1c0IunJg548 VnlSxW4Gb0LUMa8idmYJwML4zmQZYqu1BheOhEEJ7+KynDoBOOtFS+o37Si0qpWkeTSP xZHHeGQ/Mv3wmsX/zo3oxEOL9nPMCi9Ycdzt11DWPfFXSdMiCX+r1eTYg1H0tPHUYX0v c+3O3kBCajZfrJkO3PYSCTgw4FcEu9OYumkmMLXg5McRXMdbet+ef1Gex4fTWSDyPKSi FzPLZ5A9z79jAnE33Qkt4AjCqm8iPNj5tswpqz1+ogpREOSk/pH5njB/vGEmm/66y7YB ey3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=25F7Ax90ttHB6vqlFFhB2InT726P56OqvZmBLK+WpBs=; b=P4efqInEVJiCJF4/y1FRJg2KkyOahcnbVj4QDarazbe5B+57DuTlQ5j4GEWvQO778D lmfdLTJdGH9RDDjRctmmqXiDI86giFPdi68JsqeYRaxEvDm6ZT7EueoJ+/6QxrqTnWOu MZJ8iHo2V9Ag4YJTlbeoIcty+pMubybk+V5BY0dWLqCizrtzafGH2Sc77nDFScMetxED DFltCx9jHaxc03yR7F7gHkczMSMyx/m0ReUPS9NiL52iBovfnedlqp5chMe+wB6yL9w5 dkpC8zy9DuognwEHnvyYhqOVpLvTf4VrMowYX9NcSwL+cgbuVGOpLXgMmJhT8UtrwBKu 5NPg== X-Gm-Message-State: AOAM530KMnhA6KdhVcyyQ+jGncyIJzif7+MWsdVtm+280KLYHg4uD3Eo eRq5kNwEuXNeHbIHpxvMwjXPeWDghl5FPqTdo4lF6/JApEQ= X-Google-Smtp-Source: ABdhPJwW234ryjTxTzuJxWigh4y+X5F1m8EoVJ3VIenK35Pmm9/Qe2zabRzHxhjmLZpgOhJBiWxMVcrR120pOfpeTFs= X-Received: by 2002:a02:900b:: with SMTP id w11mr16174473jaf.5.1623071952212; Mon, 07 Jun 2021 06:19:12 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::d31; envelope-from=atamariya@gmail.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_40=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=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-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:270526 Archived-At: --00000000000028171405c42ce304 Content-Type: text/plain; charset="UTF-8" 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)))) )))) --00000000000028171405c42ce304 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

If you need to pad space with variable pitch font, and you are unable to=20 use ':align-to display' option for any reason, you can use the foll= owing 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))))
        ))))
--00000000000028171405c42ce304--