From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#64420: string-width of =?UTF-8?Q?=E2=80=A6?= is 2 in CJK environments Date: Tue, 11 Jul 2023 05:13:57 +0300 Message-ID: <7b8ab44d-f383-4a58-95fa-536db7dd7931@gutov.dev> References: <961e5083-ccf3-9d39-175d-5c5957130d50@gutov.dev> <83cz1ao3x0.fsf@gnu.org> <83a5weo2dz.fsf@gnu.org> <39c8c0b0-070d-88c0-f074-a878a74ef780@gutov.dev> <838rbsgrpd.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22820"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cc: 64420@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 11 04:15:27 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qJ2uT-0005be-Aa for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 11 Jul 2023 04:15:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJ2u9-0003M0-MC; Mon, 10 Jul 2023 22:15:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJ2u7-0003Lp-2u for bug-gnu-emacs@gnu.org; Mon, 10 Jul 2023 22:15:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJ2u6-00016D-Og for bug-gnu-emacs@gnu.org; Mon, 10 Jul 2023 22:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJ2u6-0002cI-6A for bug-gnu-emacs@gnu.org; Mon, 10 Jul 2023 22:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Jul 2023 02:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64420 X-GNU-PR-Package: emacs Original-Received: via spool by 64420-submit@debbugs.gnu.org id=B64420.16890416499971 (code B ref 64420); Tue, 11 Jul 2023 02:15:02 +0000 Original-Received: (at 64420) by debbugs.gnu.org; 11 Jul 2023 02:14:09 +0000 Original-Received: from localhost ([127.0.0.1]:49442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJ2tE-0002ai-TM for submit@debbugs.gnu.org; Mon, 10 Jul 2023 22:14:09 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:43175) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJ2tC-0002a5-G0 for 64420@debbugs.gnu.org; Mon, 10 Jul 2023 22:14:07 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 88DC7320095C; Mon, 10 Jul 2023 22:14:00 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 10 Jul 2023 22:14:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1689041640; x=1689128040; bh=7v9M46rzhQ3raaBglJQqO5RIl1V3fatIEWJ G/2CUHFU=; b=ZB7loZge6n7m7q3v2bJtg8VlaNjfs1N56xPY+loQrJ096YWYERS BGN8DtFudmyYpjR/4XwGU1ui99ilYdjLYIYXe8XrU16EE6Ug9AqzEtJsTkw48VxE KBSwOIJhSY7AfnMWLxAYxCUe5X9AJ8pkabfuybJ+Iz/EC9dfngK3BytKJ1a2ZLAg 75Ijy5F9rgRRTfIqnvZQFiRw3YfR3wXCYdA9rkE1qInPXBJExpujUse6G0S54ysL sNseNw0Tbo05wIOo1TUDcRD4j54Zv9AIyMQv7QGGc7qG9d8rAOIF8E+xBSZJRrDf QV4gH1tSt6gm+uRwdvb+YT7lQRfS8+ivOkw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1689041640; x=1689128040; bh=7v9M46rzhQ3raaBglJQqO5RIl1V3fatIEWJ G/2CUHFU=; b=FLQaPhQOMfbcR59ekCqetZpdBevQtoAcJbPFBjSKryyY1bT8DUk JSeXTmR7FlAHkbPgZHCLm5uM9n1mPKnZ3h6pc59o6MjgQQmp8V6QaJ2af65t327A euEOu4JdxbpvydESDYAvvcWZOMQJmhnDF821xkbMevSYQJO5hnocdyp8BWoWFhNr WaMlBWd45tzxomtUB07u3qNs+gGDtgyM2cO7hkLrhve4kBIo8N74Mp7AUgcxHKMB 2RZM1RirgdkFDmiWtV8XKiv5eF5Eoh3WWDB9KLiDlLqGYiEzlg+4sX7BLShinSLg SGlcv8ZRwX75IsExJpzBuwldga1ppMYXzPg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrvdelgdehjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthekredttdefjeenucfhrhhomhepffhmihht rhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrghtth gvrhhnpefhffehleejffegffeugefhkeektdffgfehjedvgeejtedtudehueffgffgfeej heenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumh hithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 10 Jul 2023 22:13:59 -0400 (EDT) Content-Language: en-US In-Reply-To: <838rbsgrpd.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264913 Archived-At: On 07/07/2023 09:29, Eli Zaretskii wrote: >> Date: Fri, 7 Jul 2023 05:13:50 +0300 >> Cc: 64420@debbugs.gnu.org >> From: Dmitry Gutov >> >> On 02/07/2023 16:43, Eli Zaretskii wrote: >>>> Is there some inherent reason why string-width differs from the result >>>> of the above expression >>> Because string-width doesn't consult the actual metrics of the font. >>> It uses a char-table that we set "by hand". >> >> Would it be appropriate to fix the entry for … in that table either way? > > "Fix" in what way? In most language-environments we get > > (char-width ?…) => 1 > > What's wrong with that? It returns 2 in Chinese-BIG5. While the actual metrics of the char don't change. >> Or does that not match the principle with which those entries are done? > > Sorry, I don't understand the question: what principle are you talking > about? The principles by which we fill in the said char-table which we fill "by hand". E.g. which characters to include, and which to leave with "automatic" metrics. >>>> and especially only does that on CJK? >>> In CJK locales, most characters are double-width because those locales >>> use fonts where the glyphs are wider. Or at least this is the theory. >>> string-pixel-width is free from these assumptions because it actually >>> measures the font glyphs. >> >> I'm guessing it's somewhat slower because of that too > > It isn't. The entries in char-width-table are set up when you switch > to the language-environment which requires that; see, for example, > lisp/language/chinese.el where we call set-language-info-alist for any > Chinese-* language-environment. What I meant is, string-lixel-width must be slower than string-width because it uses a temp buffer and actual measurements, whereas the latter function only does a table lookup, more or less (N times). >>>> (defun company--string-width (str) >>>> (if (display-graphic-p) >>>> (ceiling (/ (string-pixel-width str) >>>> (float (default-font-width)))) >>>> (string-width str))) >>> Yes, definitely. (Actually, display-multi-font-p is better than >>> display-graphic-p, but in practice they will return the same value.) >> >> Could you suggest a similar alternative to move-to-column? > > Try this: > > (vertical-motion (cons (/ (float PIXELS) (default-font-width)) 0)) Thank you. I just uses the column values I was already working with. I'm trying whole-pixelwise addressing in the next version, but the better precision seems to necessitate a whole new approach, using string-pixel-width and the space :width display spec. Seems to be working okay too, in my brief testing.