From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Kenichi Handa <handa.kenichi@aist.go.jp>
Newsgroups: gmane.emacs.devel
Subject: Re: A patch for enforcing double-width CJK character display
Date: Wed, 18 Apr 2012 15:54:22 +0900
Message-ID: <tl7liltmswx.fsf@m17n.org>
References: <buohawk9rg3.fsf@dhlpc061.dev.necel.com>
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-2022-jp
X-Trace: dough.gmane.org 1334754651 30640 80.91.229.3 (18 Apr 2012 13:10:51 GMT)
X-Complaints-To: usenet@dough.gmane.org
NNTP-Posting-Date: Wed, 18 Apr 2012 13:10:51 +0000 (UTC)
Cc: jianzhong.huang@i-soft.com.cn, william.xwl@gmail.com, emacs-devel@gnu.org
To: Miles Bader <miles@gnu.org>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 18 15:10:45 2012
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1SKUef-0005hx-Lr
	for ged-emacs-devel@m.gmane.org; Wed, 18 Apr 2012 15:10:41 +0200
Original-Received: from localhost ([::1]:55696 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1SKUee-0002AI-SN
	for ged-emacs-devel@m.gmane.org; Wed, 18 Apr 2012 09:10:40 -0400
Original-Received: from eggs.gnu.org ([208.118.235.92]:59584)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <handa.kenichi@aist.go.jp>) id 1SKOmh-0008IV-80
	for emacs-devel@gnu.org; Wed, 18 Apr 2012 02:54:39 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <handa.kenichi@aist.go.jp>) id 1SKOmc-000519-AD
	for emacs-devel@gnu.org; Wed, 18 Apr 2012 02:54:34 -0400
Original-Received: from na3sys010aog110.obsmtp.com ([74.125.245.88]:37119)
	by eggs.gnu.org with smtp (Exim 4.71)
	(envelope-from <handa.kenichi@aist.go.jp>) id 1SKOmb-00050e-VX
	for emacs-devel@gnu.org; Wed, 18 Apr 2012 02:54:30 -0400
Original-Received: from mail-pz0-f53.google.com ([209.85.210.53]) (using TLSv1) by
	na3sys010aob110.postini.com ([74.125.244.12]) with SMTP
	ID DSNKT45lIuUDs9YIPu7GWS39dULdXGv/GLf3@postini.com;
	Tue, 17 Apr 2012 23:54:29 PDT
Original-Received: by dajr28 with SMTP id r28so9898737daj.40
	for <emacs-devel@gnu.org>; Tue, 17 Apr 2012 23:54:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aist.go.jp; s=google;
	h=from:to:cc:subject:in-reply-to:date:message-id:mime-version
	:content-type; bh=So0apz+ffEt+W+xZi1ZlVyehN6p4XFoXxk61gsBYFt8=;
	b=TEYw81BwBgev39lsBcB/N1xg6S7KHNKbmnQh7qVCChKCFjRbh+9EPd2iBw7wQk4Qwl
	j1zRGEZjjXKia15nYj6S5g26YGCS4SKphsRoRgcHSgL616hhbr826ZBtBPd4MY+LAQLT
	Qc1VKgQ4gU8b4iz28t9FO2uHb8YDIDV7+LUqs=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=google.com; s=20120113;
	h=from:to:cc:subject:in-reply-to:date:message-id:mime-version
	:content-type:x-gm-message-state;
	bh=So0apz+ffEt+W+xZi1ZlVyehN6p4XFoXxk61gsBYFt8=;
	b=hIrV4yUpeKGSkeQrGnJ/lN1+dmP2hMtqJzD9m9Eg6s+YkoLbVlRr8EHOxDBr1tJvbK
	XrawCizk8BX2KoBNCiOV6ijnJjtesv4ZkE/ELVQWXa/z72/qkgbUrp2rksf7UxpOcgie
	kliwOdIfbzFjffZB7f3nFfxiWtHc1QzDKzhygfCG46nVsIJ6zJF3Svr9IQTt6r/PjvV1
	enLvUWQV6Xb6kUsacPM5CLj5urKBX+0X/HbXT8niU04WYNVuDQ3f/CQNr2ZiEjiDg53F
	BzL2hfltBtYjd6Do5Q9F1n7CzAX8oN2K2x5D/vhOoiXpSEej8NVDp9RYqd7MlY6EJM4B
	7ujw==
Original-Received: by 10.68.220.2 with SMTP id ps2mr3941138pbc.109.1334732066171;
	Tue, 17 Apr 2012 23:54:26 -0700 (PDT)
Original-Received: from etlken ([150.29.148.131])
	by mx.google.com with ESMTPS id d4sm22892224pbr.32.2012.04.17.23.54.24
	(version=TLSv1/SSLv3 cipher=OTHER);
	Tue, 17 Apr 2012 23:54:25 -0700 (PDT)
In-Reply-To: <buohawk9rg3.fsf@dhlpc061.dev.necel.com> (message from Miles
	Bader on Mon, 16 Apr 2012 14:27:40 +0900)
X-Gm-Message-State: ALoCoQlDWbc9eVKN3DZeW9PnD1KDK1Zzbgkp41tP2YrqmSZdwUEdjLk80nVZXLeeKprO/5Vj4chU
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older,
	4)
X-Received-From: 74.125.245.88
X-Mailman-Approved-At: Wed, 18 Apr 2012 09:10:38 -0400
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.devel:149755
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/149755>

In article <buohawk9rg3.fsf@dhlpc061.dev.necel.com>, Miles Bader <miles@gnu.org> writes:

> I set the font to "Droid Sans Mono", and the Japanese font Emacs
> automatically chose was "きろ字".  I don't know _why_ Emacs chose that
> font,

That's because I couldn't use FcFontSetSort because it had a
serious bug when I wrote the relevant code long ago.  Could
you please try this patch?

---
Kenichi Handa
handa@m17n.org

=== modified file 'src/ftfont.c'
--- src/ftfont.c	2012-03-19 04:08:07 +0000
+++ src/ftfont.c	2012-04-18 06:44:59 +0000
@@ -123,6 +123,7 @@
     { "big5-0", { 0xF6B1 }, "zh-tw" },
     { "jisx0208.1983-0", { 0x4E55 }, "ja"},
     { "ksc5601.1985-0", { 0xAC00 }, "ko"},
+    { "ksc5601.1987-0", { 0xAC00 }, "ko"},
     { "cns11643.1992-1", { 0xFE32 }, "zh-tw"},
     { "cns11643.1992-2", { 0x4E33, 0x7934 }},
     { "cns11643.1992-3", { 0x201A9 }},
@@ -890,9 +891,10 @@
   Lisp_Object val = Qnil, family, adstyle;
   int i;
   FcPattern *pattern;
-  FcFontSet *fontset = NULL;
+  FcFontSet *fontset = NULL, *sorted = NULL;
   FcObjectSet *objset = NULL;
   FcCharSet *charset;
+  FcResult result;
   Lisp_Object chars = Qnil;
   char otlayout[15];		/* For "otlayout:XXXX" */
   struct OpenTypeSpec *otspec = NULL;
@@ -983,7 +985,12 @@
 	}
     }
 #endif
-  for (i = 0; i < fontset->nfont; i++)
+  if (FcConfigSubstitute (NULL, pattern, FcMatchPattern) != FcTrue)
+    goto err;
+  FcDefaultSubstitute (pattern);
+  sorted = FcFontSetSort (NULL, &fontset, 1, pattern, FcFalse, NULL, &result);
+
+  for (i = 0; i < sorted->nfont; i++)
     {
       Lisp_Object entity;
 
@@ -991,7 +998,7 @@
 	{
 	  int this;
 
-	  if ((FcPatternGetInteger (fontset->fonts[i], FC_SPACING, 0, &this)
+	  if ((FcPatternGetInteger (sorted->fonts[i], FC_SPACING, 0, &this)
 	       == FcResultMatch)
 	      && spacing != this)
 	    continue;
@@ -1002,7 +1009,7 @@
 	{
 	  FcChar8 *this;
 
-	  if (FcPatternGetString (fontset->fonts[i], FC_CAPABILITY, 0, &this)
+	  if (FcPatternGetString (sorted->fonts[i], FC_CAPABILITY, 0, &this)
 	      != FcResultMatch
 	      || ! strstr ((char *) this, otlayout))
 	    continue;
@@ -1014,7 +1021,7 @@
 	  FcChar8 *file;
 	  OTF *otf;
 
-	  if (FcPatternGetString (fontset->fonts[i], FC_FILE, 0, &file)
+	  if (FcPatternGetString (sorted->fonts[i], FC_FILE, 0, &file)
 	      != FcResultMatch)
 	    continue;
 	  otf = OTF_open ((char *) file);
@@ -1035,7 +1042,7 @@
 	{
 	  int j;
 
-	  if (FcPatternGetCharSet (fontset->fonts[i], FC_CHARSET, 0, &charset)
+	  if (FcPatternGetCharSet (sorted->fonts[i], FC_CHARSET, 0, &charset)
 	      != FcResultMatch)
 	    continue;
 	  for (j = 0; j < ASIZE (chars); j++)
@@ -1047,7 +1054,7 @@
 	}
       if (! NILP (adstyle) || langname)
 	{
-	  Lisp_Object this_adstyle = get_adstyle_property (fontset->fonts[i]);
+	  Lisp_Object this_adstyle = get_adstyle_property (sorted->fonts[i]);
 
 	  if (! NILP (adstyle)
 	      && (NILP (this_adstyle)
@@ -1059,7 +1066,7 @@
 	      && xstrcasecmp (langname, SSDATA (SYMBOL_NAME (this_adstyle))))
 	    continue;
 	}
-      entity = ftfont_pattern_entity (fontset->fonts[i],
+      entity = ftfont_pattern_entity (sorted->fonts[i],
 				      AREF (spec, FONT_EXTRA_INDEX));
       if (! NILP (entity))
 	val = Fcons (entity, val);
@@ -1076,6 +1083,7 @@
   FONT_ADD_LOG ("ftfont-list", spec, val);
   if (objset) FcObjectSetDestroy (objset);
   if (fontset) FcFontSetDestroy (fontset);
+  if (sorted) FcFontSetDestroy (sorted);
   if (pattern) FcPatternDestroy (pattern);
   return val;
 }