changeset 105156:25063db12150

* nsfont.m (Vns_reg_to_script): New lisp variable. (syms_of_nsfont): Declare it. (ns_registry_to_script): New function. (ns_get_req_script): Call it. (ns_findfonts): Don't give up on non-unicode registry.
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Wed, 23 Sep 2009 02:36:57 +0000
parents 00973a055b5e
children 33cdbbd76097
files src/nsfont.m
diffstat 1 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/nsfont.m	Wed Sep 23 02:35:54 2009 +0000
+++ b/src/nsfont.m	Wed Sep 23 02:36:57 2009 +0000
@@ -46,6 +46,7 @@
 
 extern Lisp_Object Qns;
 extern Lisp_Object Qnormal, Qbold, Qitalic, Qcondensed, Qexpanded;
+static Lisp_Object Vns_reg_to_script;
 static Lisp_Object Qapple, Qroman, Qmedium;
 extern Lisp_Object Qappend;
 extern int ns_antialias_text;
@@ -301,17 +302,35 @@
 }
 
 
-/* Searches the :script, :lang, and :otf extra-bundle properties of the spec
-   for something that can be mapped to a unicode script.  Empty string returned
-   if no script spec found.
-   TODO: Eventually registry / encoding should be checked and mapped, but for
-   now the font backend will try script/lang/otf if registry fails, so it is
-   not needed. */
+/* Convert a font registry, such as  */
+static NSString
+*ns_registry_to_script (char *reg)
+{
+    Lisp_Object script, r, rts = Vns_reg_to_script;
+    while CONSP (rts)
+      {
+        r = XCAR (XCAR (rts));
+        if (!strncmp(SDATA(r), reg, strlen(SDATA(r))))
+          {
+            script = XCDR (XCAR (rts));
+            return [NSString stringWithUTF8String: SDATA (SYMBOL_NAME (script))];
+          }
+        rts = XCDR (rts);
+      }
+    return  @"";
+}
+
+
+/* Searches the :script, :lang, and :otf extra-bundle properties of the spec,
+   plus registry regular property, for something that can be mapped to a
+   unicode script.  Empty string returned if no script spec found. */
 static NSString
 *ns_get_req_script (Lisp_Object font_spec)
 {
+    Lisp_Object reg = AREF (font_spec, FONT_REGISTRY_INDEX);
     Lisp_Object extra = AREF (font_spec, FONT_EXTRA_INDEX);
 
+    /* The extra-bundle properties have priority. */
     for ( ; CONSP (extra); extra = XCDR (extra))
       {
 	Lisp_Object tmp = XCAR (extra);
@@ -327,6 +346,20 @@
 		return ns_otf_to_script (val);
 	  }
       }
+
+    /* If we get here, check the charset portion of the registry. */
+    if (! NILP (reg))
+      {
+        /* XXX: iso10646 is passed in for non-ascii latin-1 characters
+           (which causes box rendering if we don't treat it like iso8858-1)
+           but also for ascii (which causes unnecessary font substitution). */
+#if 0
+        if (EQ (reg, Qiso10646_1))
+          reg = Qiso8859_1;
+#endif
+        return ns_registry_to_script (SDATA (SYMBOL_NAME (reg)));
+      }
+
     return @"";
 }
 
@@ -466,11 +499,6 @@
 	debug_print (font_spec);
       }
 
-    /* If has non-unicode registry, give up. */
-    tem = AREF (font_spec, FONT_REGISTRY_INDEX);
-    if (! NILP (tem) && !EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
-	return isMatch ? ns_fallback_entity () : Qnil;
-
     cFamilies = ns_get_covering_families (ns_get_req_script (font_spec), 0.90);
 
     fdesc = ns_spec_to_descriptor (font_spec);
@@ -1490,6 +1518,8 @@
   DEFSYM (Qapple, "apple");
   DEFSYM (Qroman, "roman");
   DEFSYM (Qmedium, "medium");
+  DEFVAR_LISP ("ns-reg-to-script", &Vns_reg_to_script,
+               doc: /* Internal use: maps font registry to unicode script. */);
 }
 
 // arch-tag: d6c3c6f0-62de-4978-8b1e-b7966fe02cae