]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/font-interface.cc
release: 1.3.131
[lilypond.git] / lily / font-interface.cc
index d5a15ab2d9a5ed42a908648ab50aa444f8ab6946..0f946a74804384ae896dee25597b83bcc3102325 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
@@ -44,6 +44,21 @@ Font_interface::get_default_font (Grob*me)
   return fm;
 }
 
+
+SCM
+ly_font_interface_get_default_font (SCM grob)
+{
+  Grob * gr  = unsmob_grob (grob);
+
+  if (!gr)
+    {
+      warning ("ly_font_interface_get_default_font (): invalid argument");
+      return SCM_UNDEFINED;
+    }
+
+  return Font_interface::get_default_font (gr)->self_scm ();
+}
+
 Font_metric *
 Font_interface::get_font (Grob *me, SCM chain)
 {
@@ -59,7 +74,6 @@ Font_interface::get_font (Grob *me, SCM chain)
   SCM font_name = gh_call2 (proc, fonts, chain);
 
   Font_metric *fm = me->paper_l ()->find_font (font_name, 1.0);
-
   return fm;
 }
 
@@ -99,7 +113,7 @@ so a 14% speedup.
 
 */
 
-static SCM name_sym, shape_sym, family_sym, series_sym, rel_sz_sym, pt_sz_sym;
+static SCM name_sym, shape_sym, family_sym, series_sym, rel_sz_sym, pt_sz_sym, wild_sym;
 
 
 static void
@@ -111,9 +125,18 @@ init_syms ()
   series_sym = scm_permanent_object (ly_symbol2scm ("font-series"));
   rel_sz_sym = scm_permanent_object (ly_symbol2scm ("font-relative-size"));
   pt_sz_sym = scm_permanent_object (ly_symbol2scm ("font-point-size"));
+  wild_sym = scm_permanent_object (ly_symbol2scm ("*"));
+
+  scm_make_gsubr ("ly-get-default-font", 1 , 0, 0, (Scheme_function_unknown) ly_font_interface_get_default_font);
 }
 
 
+bool
+Font_interface::wild_compare(SCM field_val, SCM val)
+{
+  return (val == SCM_BOOL_F || field_val == wild_sym || field_val == val);
+}
+
 ADD_SCM_INIT_FUNC(Font_interface_syms,init_syms);
 
 
@@ -163,31 +186,29 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
 
       if (name != SCM_BOOL_F)
        {
-         if (scm_list_ref (qlist, gh_int2scm (4)) != name)
+         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (4)), name))
            continue;
        }
       else
        {
-         if (series != SCM_BOOL_F
-             && scm_list_ref (qlist, gh_int2scm (1)) != series)
+         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (1)), series))
            continue;
-         if (shape != SCM_BOOL_F
-             && scm_list_ref (qlist, gh_int2scm (2)) != shape)
+         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (2)), shape))
            continue;
-         if (family != SCM_BOOL_F
-             && scm_list_ref (qlist, gh_int2scm (3)) != family)
+         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (3)), family))
            continue;
        }
   
       if (point_sz != SCM_BOOL_F)
        {
-         if (scm_list_ref (qlist, gh_int2scm (4)) != name)
+         // This if statement will always be true since name must 
+         // be SCM_BOOL_F here, right?  /MB
+         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (4)), name))
            continue;
        }
       else
        {
-         if (rel_sz != SCM_BOOL_F
-             && gh_car (qlist) != rel_sz)
+         if (!wild_compare(gh_car (qlist), rel_sz))
            continue;
        }
 
@@ -198,7 +219,8 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
 
   warning (_("couldn't find any font satisfying ") );
   scm_write (gh_list (name, point_sz, shape, series , family, rel_sz, SCM_UNDEFINED), scm_current_error_port ());
-
+  scm_flush(scm_current_error_port ());
   return ly_str02scm ("cmr10");
   
 }