GNU bug report logs - #39264
26.3; (frame-char-width) is different from real char width of monospace font 'Noto Sans Mono'

Previous Next

Package: emacs;

Reported by: ynyaaa <at> gmail.com

Date: Fri, 24 Jan 2020 14:56:02 UTC

Severity: normal

Tags: notabug

Found in version 26.3

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 39264 in the body.
You can then email your comments to 39264 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#39264; Package emacs. (Fri, 24 Jan 2020 14:56:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to ynyaaa <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 24 Jan 2020 14:56:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: ynyaaa <at> gmail.com
To: bug-gnu-emacs <at> gnu.org
Subject: 26.3;
 (frame-char-width) is different from real char width of monospace
 font 'Noto Sans Mono'
Date: Fri, 24 Jan 2020 23:55:42 +0900
I installed Noto fonts.
With setting frame font to "Noto Sans Mono", which is a monospace font,
(frame-char-width) and the real char width may differ.

For example, using "Noto Sans Mono-13", (frame-char-width) is one pixel larger.
  (progn
    (set-frame-font "Noto Sans Mono-13")
    (list (frame-char-width) (car (window-text-pixel-size nil 1 2))))
  => (11 10)
Then the TAB pixel width is 8 pixels wider than 8 SPCs.
And the frame with 80-character width is wider than a real 80-character line.

Here is a list of problematic combinations of font names and font sizes.
The sizes are selected from between 10 and 20.

;;; NOTE: THIS FORM USE #'set-frame-font MANY TIMES
(let (last cell ret)
  (save-window-excursion
    (with-temp-buffer
      (switch-to-buffer (current-buffer))
      (insert ?\s)
      (dolist (family (sort (font-family-list) #'string<))
        (when (and (not (equal family last))
                   (string-match "Noto.*Mono" family))
          (setq cell (list family)
                ret (cons cell ret))
          (dolist (size (number-sequence 10 20))
            (set-frame-font (format "%s-%d" family size))
            (unless (= (car (window-text-pixel-size nil 1 2))
                       (frame-char-width))
              (setq cell (nconc cell (list size))))))
        (setq last family))))
  (nreverse ret))
=>
(("Noto Mono")
 ("Noto Sans Mono" 13 14 15 17 18 19 20)
 ("Noto Sans Mono Blk" 13 14 15 17 18 19 20)
 ("Noto Sans Mono CJK JP Bold" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK JP Regular" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK KR Bold" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK KR Regular" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK SC Bold" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK SC Regular" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK TC Bold" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono CJK TC Regular" 10 11 12 13 14 15 16 17 18 19 20)
 ("Noto Sans Mono Cond" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond Blk" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond ExtBd" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond ExtLt" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond Light" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond Med" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond SemBd" 12 14 16 17 19 20)
 ("Noto Sans Mono Cond Thin" 12 14 16 17 19 20)
 ("Noto Sans Mono ExtBd" 13 14 15 17 18 19 20)
 ("Noto Sans Mono ExtCond" 15 18)
 ("Noto Sans Mono ExtCond Blk" 15 18)
 ("Noto Sans Mono ExtCond ExtBd" 15 18)
 ("Noto Sans Mono ExtCond ExtLt" 15 18)
 ("Noto Sans Mono ExtCond Light" 15 18)
 ("Noto Sans Mono ExtCond Med" 15 18)
 ("Noto Sans Mono ExtCond SemBd" 15 18)
 ("Noto Sans Mono ExtCond Thin" 15 18)
 ("Noto Sans Mono ExtLt" 13 14 15 17 18 19 20)
 ("Noto Sans Mono Light" 13 14 15 17 18 19 20)
 ("Noto Sans Mono Med" 13 14 15 17 18 19 20)
 ("Noto Sans Mono SemBd" 13 14 15 17 18 19 20)
 ("Noto Sans Mono SemCond" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond Blk" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond ExtBd" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond ExtLt" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond Light" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond Med" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond SemBd" 10 11 15 17 19 20)
 ("Noto Sans Mono SemCond Thin" 10 11 15 17 19 20)
 ("Noto Sans Mono Thin" 13 14 15 17 18 19 20))



In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
 of 2019-08-29 built on CIRROCUMULUS
Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd
Windowing system distributor 'Microsoft Corp.', version 10.0.18363
Recent messages:

Configured using:
 'configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS THREADS LCMS2

Important settings:
  value of $LANG: JPN
  locale-coding-system: cp932

Major mode: Emacs-Lisp

Minor modes in effect:
  diff-auto-refine-mode: t
  display-time-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(term/bobcat descr-text mailclient browse-url cus-edit cus-start
cus-load wid-edit info crm eieio-opt speedbar sb-image ezimage dframe
shadow emacsbug network-stream nsm starttls tls gnutls mailalias
smtpmail auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
sendmail sort mail-extr message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse
rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev
mail-utils gmm-utils mailheader compare-w diff-mode easy-mmode find-func
cl-extra pp ibuf-ext ibuffer ibuffer-loaddefs seq thingatpt help-fns
radix-tree misearch multi-isearch help-mode easymenu cl-print byte-opt
gv bytecomp byte-compile cl-loaddefs cl-lib cconv debug time elec-pair
time-date mule-util japan-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads w32notify w32 lcms2 multi-tty make-network-process
emacs)

Memory information:
((conses 16 238951 47126)
 (symbols 48 50848 0)
 (miscs 40 140 601)
 (strings 32 120075 1414)
 (string-bytes 1 2925132)
 (vectors 16 31299)
 (vector-slots 8 1261645 35200)
 (floats 8 74 499)
 (intervals 56 17535 168)
 (buffers 992 22))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39264; Package emacs. (Fri, 24 Jan 2020 15:35:01 GMT) Full text and rfc822 format available.

Message #8 received at 39264 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: ynyaaa <at> gmail.com
Cc: 39264 <at> debbugs.gnu.org
Subject: Re: bug#39264: 26.3;
 (frame-char-width) is different from real char width of monospace
 font 'Noto Sans Mono'
Date: Fri, 24 Jan 2020 17:34:04 +0200
tags 39264 notabug
thanks

> From: ynyaaa <at> gmail.com
> Date: Fri, 24 Jan 2020 23:55:42 +0900
> 
> I installed Noto fonts.
> With setting frame font to "Noto Sans Mono", which is a monospace font,
> (frame-char-width) and the real char width may differ.
> 
> For example, using "Noto Sans Mono-13", (frame-char-width) is one pixel larger.
>   (progn
>     (set-frame-font "Noto Sans Mono-13")
>     (list (frame-char-width) (car (window-text-pixel-size nil 1 2))))
>   => (11 10)

This is not a bug.  frame-char-width returns the value of the font's
"average width" attribute, whereas window-text-pixel-size actually
performs the layout of the specified text, simulating its display, and
measures the result.  Thus, the values can differ, although for
monospaced fonts they cannot (or should not) differ by too much.

The upshot of this is that you cannot really perform accurate layout
calculations from Lisp, at least not easily.  There's no way around
this basic difficulty.




Added tag(s) notabug. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Fri, 24 Jan 2020 15:35:02 GMT) Full text and rfc822 format available.

Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Mon, 10 Feb 2020 15:37:02 GMT) Full text and rfc822 format available.

Notification sent to ynyaaa <at> gmail.com:
bug acknowledged by developer. (Mon, 10 Feb 2020 15:37:03 GMT) Full text and rfc822 format available.

Message #15 received at 39264-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: ynyaaa <at> gmail.com, 39264-done <at> debbugs.gnu.org
Subject: Re: bug#39264: 26.3; (frame-char-width) is different from real char
 width of monospace font 'Noto Sans Mono'
Date: Mon, 10 Feb 2020 16:36:26 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> tags 39264 notabug
> thanks
>
>> From: ynyaaa <at> gmail.com
>> Date: Fri, 24 Jan 2020 23:55:42 +0900
>> 
>> I installed Noto fonts.
>> With setting frame font to "Noto Sans Mono", which is a monospace font,
>> (frame-char-width) and the real char width may differ.
>> 
>> For example, using "Noto Sans Mono-13", (frame-char-width) is one pixel larger.
>>   (progn
>>     (set-frame-font "Noto Sans Mono-13")
>>     (list (frame-char-width) (car (window-text-pixel-size nil 1 2))))
>>   => (11 10)
>
> This is not a bug.  frame-char-width returns the value of the font's
> "average width" attribute, whereas window-text-pixel-size actually
> performs the layout of the specified text, simulating its display, and
> measures the result.  Thus, the values can differ, although for
> monospaced fonts they cannot (or should not) differ by too much.
>
> The upshot of this is that you cannot really perform accurate layout
> calculations from Lisp, at least not easily.  There's no way around
> this basic difficulty.

I'm consequently also closing this bug report.

Best regards,
Stefan Kangas




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 10 Mar 2020 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 48 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.