]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/font-interface.cc
patch::: 1.5.9.jcn1
[lilypond.git] / lily / font-interface.cc
index 51b98eef5c8c93d807e5b449b01b368cc27d28f3..0ea3bf7675d25375b7fff9a8e0c4b39ba7fef038 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>
   
  */
 
 #include "warn.hh"
 
 
+/*
+  TODO revise font handling.
+
+
+* relative sizes should relate to staff-space, eg.  font-staff-space
+= 1.2 ^ relative-size
+
+* If a relative size is given, lily should magnify the closest
+design size font to match that. (ie. fonts should have variable
+scaling)
+
+(this requires that fonts are stored as (filename , designsize))
+
+
+  
+ */
+
 SCM
 Font_interface::font_alist_chain (Grob *me)
 {
   SCM defaults = gh_cdr (scm_assoc (ly_symbol2scm ("font-defaults"),
-                                   me->paper_l ()->style_sheet_ ));
+                                   me->paper_l ()->style_sheet_));
 
   SCM ch = gh_list (me->mutable_property_alist_,
                    me->immutable_property_alist_,
@@ -44,6 +61,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 +91,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 +130,7 @@ so a 14% speedup.
 
 */
 
-static SCM name_sym, shape_sym, family_sym, series_sym, rel_sz_sym, pt_sz_sym, wild_sym;
+static SCM name_sym, shape_sym, family_sym, series_sym, rel_sz_sym, design_sz_sym, wild_sym;
 
 
 static void
@@ -110,20 +141,24 @@ init_syms ()
   family_sym = scm_permanent_object (ly_symbol2scm ("font-family"));
   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"));
+  design_sz_sym = scm_permanent_object (ly_symbol2scm ("font-design-size"));
   wild_sym = scm_permanent_object (ly_symbol2scm ("*"));
+
+  scm_c_define_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)
+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);
+ADD_SCM_INIT_FUNC (Font_interface_syms,init_syms);
 
 
-MAKE_SCHEME_CALLBACK(Font_interface,properties_to_font_name,2);
+MAKE_SCHEME_CALLBACK (Font_interface,properties_to_font_name,2);
 SCM
 Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
 {
@@ -134,7 +169,7 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
   SCM series = SCM_BOOL_F;
 
   
-  SCM point_sz = ly_assoc_chain (pt_sz_sym, alist_chain);
+  SCM point_sz = ly_assoc_chain (design_sz_sym, alist_chain);
   SCM rel_sz = SCM_BOOL_F;
 
   if (!gh_pair_p (name))
@@ -169,16 +204,16 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
 
       if (name != SCM_BOOL_F)
        {
-         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (4)), name))
+         if (!wild_compare (scm_list_ref (qlist, gh_int2scm (4)), name))
            continue;
        }
       else
        {
-         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (1)), series))
+         if (!wild_compare (scm_list_ref (qlist, gh_int2scm (1)), series))
            continue;
-         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (2)), shape))
+         if (!wild_compare (scm_list_ref (qlist, gh_int2scm (2)), shape))
            continue;
-         if (!wild_compare(scm_list_ref (qlist, gh_int2scm (3)), family))
+         if (!wild_compare (scm_list_ref (qlist, gh_int2scm (3)), family))
            continue;
        }
   
@@ -186,12 +221,12 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
        {
          // 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))
+         if (!wild_compare (scm_list_ref (qlist, gh_int2scm (4)), name))
            continue;
        }
       else
        {
-         if (!wild_compare(gh_car (qlist), rel_sz))
+         if (!wild_compare (gh_car (qlist), rel_sz))
            continue;
        }
 
@@ -200,10 +235,10 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
       return qname;
     }
 
-  warning (_("couldn't find any font satisfying ") );
+  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 ());
-
+  scm_flush (scm_current_error_port ());
   return ly_str02scm ("cmr10");
   
 }