From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: handa Newsgroups: gmane.emacs.bugs Subject: bug#28339: 25.2; Emacs shows ZWNJ character (Zero Width non-Joiner) as Space Date: Wed, 13 Sep 2017 23:02:56 +0900 Message-ID: <87fubqsnlb.fsf@gnu.org> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1505311457 9981 195.159.176.226 (13 Sep 2017 14:04:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 13 Sep 2017 14:04:17 +0000 (UTC) Cc: 28339@debbugs.gnu.org To: Nima Aryan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 13 16:04:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ds8Gx-0002SX-Du for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Sep 2017 16:04:11 +0200 Original-Received: from localhost ([::1]:42693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds8H4-0000wW-BR for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Sep 2017 10:04:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds8Gs-0000tu-Bv for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2017 10:04:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds8Go-0000tE-D1 for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2017 10:04:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ds8Go-0000tA-9q for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2017 10:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ds8Go-0006Qr-26 for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2017 10:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: handa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Sep 2017 14:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28339 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28339-submit@debbugs.gnu.org id=B28339.150531140424682 (code B ref 28339); Wed, 13 Sep 2017 14:04:02 +0000 Original-Received: (at 28339) by debbugs.gnu.org; 13 Sep 2017 14:03:24 +0000 Original-Received: from localhost ([127.0.0.1]:38414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ds8GC-0006Q2-HV for submit@debbugs.gnu.org; Wed, 13 Sep 2017 10:03:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36006) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ds8GB-0006Pp-3t for 28339@debbugs.gnu.org; Wed, 13 Sep 2017 10:03:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds8Fz-000081-W2 for 28339@debbugs.gnu.org; Wed, 13 Sep 2017 10:03:17 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds8Fr-0008UZ-OQ; Wed, 13 Sep 2017 10:03:03 -0400 Original-Received: from fl1-119-240-89-46.iba.mesh.ad.jp ([119.240.89.46]:53172 helo=shatin) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ds8Fr-00075O-6d; Wed, 13 Sep 2017 10:03:03 -0400 Original-Received: from handa by shatin with local (Exim 4.86_2) (envelope-from ) id 1ds8Fk-0001my-Rl; Wed, 13 Sep 2017 23:02:56 +0900 In-Reply-To: (message from Nima Aryan on Tue, 12 Sep 2017 07:59:27 +0000) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:136879 Archived-At: --=-=-= Content-Type: text/plain In article , Nima Aryan writes: > I can confirm that this code solves the problem for many fonts I tested > including: > DejaVu Sans, Vazir Code, Inconsolata-g, Office Code Pro, Ubunto, Meslo, > ... Thank you for testing my code. > The fonts I still see some problems are 'Droid Sans Regular' which shows > hallow boxes and Noto Sans which shows a narrow width bar. That's perhaps because they define those glyphs for ZWNJ. To avoid that problem, there are two ways: (1) display ZWNJ with a glyph for space (if the font has a glyph for space) (2) do not generate a glypgh for ZWNJ Please try the attached new version. It tries (1). If you change the value of arabic-font-shape-gstring to `arabic-font-shape-gstring-ZWNJ-absorb, it tries (2). As an editor, I think (1) is better, but an Arabic/Persian user may have different opinion. --- K. Handa handa@gnu.org --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=arabic-shape.el Content-Transfer-Encoding: quoted-printable (defun arabic-font-shape-gstring-ZWNJ-thin-width (gstring) (setq gstring (font-shape-gstring gstring)) (dotimes (i (lgstring-glyph-len gstring)) (let ((glyph (lgstring-glyph gstring i))) (if (eq (lglyph-char glyph) #x200c) (let ((lbearing (lglyph-lbearing glyph)) (rbearing (lglyph-rbearing glyph)) (xoff nil)) (if (> (/ (+ rbearing lbearing) 2) 1) (setq xoff (- (/ (+ rbearing lbearing) 2)))) (lglyph-set-adjustment glyph xoff nil 1))))) (lgstring-set-id gstring nil) gstring) ;; Remove glyph at IDX from GSTRING. This must go to composite.el. (defun gstring-remove-glyph (gstring idx) (setq gstring (copy-sequence gstring)) (lgstring-set-id gstring nil) (let ((len (length gstring))) (setq idx (+ idx 3)) (while (< idx len) (aset gstring (1- idx) (aref gstring idx)) (setq idx (1+ idx))) (aset gstring (1- len) nil)) gstring) (defun arabic-font-shape-gstring-ZWNJ-absorb (gstring) (setq gstring (font-shape-gstring gstring)) (let ((i 1) (len (lgstring-glyph-len gstring))) (while (< i len) (let ((glyph (lgstring-glyph gstring i))) (if (eq (lglyph-char glyph) #x200c) (let ((prev (lgstring-glyph gstring (1- i)))) (lglyph-set-from-to prev (lglyph-from prev) (lglyph-to glyph)) (setq gstring (gstring-remove-glyph gstring i)) (setq len (1- len))) (setq i (1+ i)))))) (lgstring-set-id gstring nil) gstring) (defun arabic-font-shape-gstring-ZWNJ-as-space (gstring) (setq gstring (font-shape-gstring gstring)) (let ((font (lgstring-font gstring)) (i 1) (len (lgstring-glyph-len gstring))) (while (< i len) (let ((glyph (lgstring-glyph gstring i))) (when (eq (lglyph-char glyph) #x200c) (if (> (+ (lglyph-lbearing glyph) (lglyph-rbearing glyph)) 0) (let ((space-glyph (aref (font-get-glyphs font 0 1 " ") 0))) (when space-glyph (lglyph-set-code glyph (aref space-glyph 3)) (lglyph-set-width glyph (aref space-glyph 4))))) (lglyph-set-adjustment glyph 0 0 1)) (setq i (1+ i))))) (lgstring-set-id gstring nil) gstring) ;;(defvar arabic-font-shape-gstring 'arabic-font-shape-gstring-ZWNJ-thin-wi= dth) ;;(defvar arabic-font-shape-gstring 'arabic-font-shape-gstring-ZWNJ-absorb) (defvar arabic-font-shape-gstring 'arabic-font-shape-gstring-ZWNJ-as-space) (set-char-table-range composition-function-table '(#x600 . #x74F) (list (vector "[\u0600-\u074F\u200C\u200D]+" 0 arabic-font-shape-gstring) (vector "[\u200C\u200D][\u0600-\u074F\u200C\u200D]+" 1 arabic-font-shape-gstring))) --=-=-=--