]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/font-interface.cc
(stop_translation_timestep):
[lilypond.git] / lily / font-interface.cc
index c5c32c2337d2f2df2b08694af97e1786226a718c..5a7d6300df5eca55d71f0b0a3b8db67a94db5d64 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
@@ -38,17 +38,22 @@ Font_interface::font_alist_chain (Grob *me)
   /*
     Ugh: why the defaults?
    */
-  SCM defaults = ly_cdr (scm_assoc (ly_symbol2scm ("font-defaults"),
-                                   me->paper_l ()->style_sheet_));
-
-  SCM ch = scm_list_n (me->mutable_property_alist_,
-                   me->immutable_property_alist_,
-                   defaults,
-                   SCM_UNDEFINED);
+  SCM defaults = me->get_paper ()->lookup_variable (ly_symbol2scm ("font-defaults"));
 
+  SCM ch = me->get_property_alist_chain (defaults);
   return ch;
 }
 
+
+MAKE_SCHEME_CALLBACK(Font_interface, get_property_alist_chain, 1);
+SCM
+Font_interface::get_property_alist_chain (SCM grob)
+{
+  Grob * g = unsmob_grob (grob);
+  SCM_ASSERT_TYPE(g, grob, SCM_ARG1, __FUNCTION__, "grob");
+  return  font_alist_chain (g);
+}
+
 /*
   todo: split up this func, reuse in text_item? 
  */
@@ -65,8 +70,9 @@ Font_interface::get_default_font (Grob*me)
 }
 
 
-SCM
-ly_font_interface_get_default_font (SCM grob)
+LY_DEFINE(ly_font_interface_get_default_font,
+         "ly:get-default-font", 1 , 0, 0,
+         (SCM grob), "Return the default font for grob @var{gr}.")
 {
   Grob * gr  = unsmob_grob (grob);
   SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "grob");
@@ -74,21 +80,29 @@ ly_font_interface_get_default_font (SCM grob)
   return Font_interface::get_default_font (gr)->self_scm ();
 }
 
-SCM
-ly_font_interface_get_font (SCM grob, SCM alist)
+LY_DEFINE(ly_font_interface_get_font,"ly:get-font", 2, 0, 0,
+         (SCM grob, SCM chain),
+         "Return a font metric satisfying the font-qualifiers in the alist chain @var{chain}.\n"
+"\n"
+"The font object represents the metric information of a font. Every font\n"
+"that is loaded into LilyPond can be accessed via Scheme. \n"
+"\n"
+"LilyPond only needs to know the dimension of glyph to be able to process\n"
+"them. This information is stored in font metric files. LilyPond can read\n"
+"two types of font-metrics: @TeX{} Font Metric files (TFM files) and\n"
+"Adobe Font Metric files (AFM files).  LilyPond will always try to load\n"
+"AFM files first since they are more versatile.\n"
+"\n"
+"An alist chain is a list of alists.\n")
 {
   Grob * gr  = unsmob_grob (grob);
   SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "grob");
 
-  Font_metric*fm=
-    Font_interface::get_font (gr, gh_cons (alist,
-                                          Font_interface::font_alist_chain (gr)));
-
+  Font_metric*fm = Font_interface::get_font (gr, chain);
   return fm->self_scm();
 }
 
 
-
 Font_metric *
 Font_interface::get_font (Grob *me, SCM chain)
 {
@@ -96,21 +110,21 @@ Font_interface::get_font (Grob *me, SCM chain)
   
   if (!gh_string_p (name))
     {
-      SCM ss = me->paper_l ()->style_sheet_;
-
-      SCM proc = ly_cdr (scm_assoc (ly_symbol2scm ("properties-to-font"),
-                                   ss));
+      Paper_def * p =  me->get_paper ();
 
-      SCM fonts = ly_cdr (scm_assoc (ly_symbol2scm ("fonts"), ss));
+      SCM proc = p->lookup_variable (ly_symbol2scm ("properties-to-font"));
+      SCM fonts = p->lookup_variable (ly_symbol2scm ("fonts"));
 
       assert (gh_procedure_p (proc));
       name = gh_call2 (proc, fonts, chain);
     }
   
-  SCM mag = me->get_grob_property ("font-magnification");
-  Real rmag = gh_number_p (mag) ? gh_scm2double (mag) : 1.0;
+  SCM mag = ly_assoc_chain (ly_symbol2scm ("font-magnification"), chain);
+  
+  Real rmag = gh_pair_p (mag) && gh_number_p (gh_cdr (mag))
+    ? gh_scm2double (gh_cdr (mag)) : 1.0;
   
-  Font_metric *fm = me->paper_l ()->find_font (name, rmag);
+  Font_metric *fm = me->get_paper ()->find_font (name, rmag);
   return fm;
 }
 
@@ -118,10 +132,8 @@ SCM
 Font_interface::add_style (Grob* me, SCM style, SCM chain)
 {
   assert (gh_symbol_p (style));
-  
-  SCM sheet = me->paper_l ()->style_sheet_;
       
-  SCM style_alist = ly_cdr (scm_assoc (ly_symbol2scm ("style-alist"), sheet));
+  SCM style_alist = me->get_paper ()->lookup_variable (ly_symbol2scm ("style-alist"));
   SCM entry = scm_assoc (style, style_alist);
   if (gh_pair_p (entry))
     {
@@ -150,7 +162,7 @@ so a 14% speedup.
 
 */
 
-static SCM shape_sym, family_sym, series_sym, rel_sz_sym, design_sz_sym, wild_sym;
+static SCM shape_sym, family_sym, series_sym, rel_str0_sym, design_str0_sym, wild_sym;
 
 
 static void
@@ -159,16 +171,12 @@ init_syms ()
   shape_sym  = scm_permanent_object (ly_symbol2scm ("font-shape"));
   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"));
-  design_sz_sym = scm_permanent_object (ly_symbol2scm ("font-design-size"));
+  rel_str0_sym = scm_permanent_object (ly_symbol2scm ("font-relative-size"));
+  design_str0_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);
-  scm_c_define_gsubr ("ly-get-font", 2, 0, 0,
-                     (Scheme_function_unknown) ly_font_interface_get_font);
 }
 
+ADD_SCM_INIT_FUNC(fi_init_syms, init_syms);
 
 bool
 Font_interface::wild_compare (SCM field_val, SCM val)
@@ -176,8 +184,6 @@ 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);
-
 
 MAKE_SCHEME_CALLBACK (Font_interface,properties_to_font_name,2);
 SCM
@@ -188,8 +194,8 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
   SCM series = SCM_BOOL_F;
 
   
-  SCM point_sz = ly_assoc_chain (design_sz_sym, alist_chain);
-  SCM rel_sz = SCM_BOOL_F;
+  SCM point_str0 = ly_assoc_chain (design_str0_sym, alist_chain);
+  SCM rel_str0 = SCM_BOOL_F;
 
   shape = ly_assoc_chain (shape_sym, alist_chain);
   family = ly_assoc_chain (family_sym, alist_chain);
@@ -203,13 +209,13 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
     series = ly_cdr (series);
 
 
-  if (gh_pair_p (point_sz))
-    point_sz = ly_cdr (point_sz);
+  if (gh_pair_p (point_str0))
+    point_str0 = ly_cdr (point_str0);
   else
     {
-      rel_sz = ly_assoc_chain (rel_sz_sym, alist_chain);
-      if (gh_pair_p (rel_sz))
-       rel_sz = ly_cdr (rel_sz);
+      rel_str0 = ly_assoc_chain (rel_str0_sym, alist_chain);
+      if (gh_pair_p (rel_str0))
+       rel_str0 = ly_cdr (rel_str0);
     }
 
   for (SCM s = fonts ; gh_pair_p (s); s = ly_cdr (s))
@@ -223,7 +229,7 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
       if (!wild_compare (scm_list_ref (qlist, gh_int2scm (3)), family))
        continue;
   
-      if (point_sz == SCM_BOOL_F && !wild_compare (ly_car (qlist), rel_sz))
+      if (point_str0 == SCM_BOOL_F && !wild_compare (ly_car (qlist), rel_str0))
        continue;
           
       SCM qname = ly_cdar (s);
@@ -231,9 +237,16 @@ Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
     }
 
   warning (_ ("couldn't find any font satisfying "));
-  scm_write (scm_list_n (point_sz, shape, series , family, rel_sz, SCM_UNDEFINED), scm_current_error_port ());
+  scm_write (scm_list_n (point_str0, shape, series , family, rel_str0,
+                        SCM_UNDEFINED), scm_current_error_port ());
   scm_flush (scm_current_error_port ());
  
-  return ly_str02scm ("cmr10");
+  return scm_makfrom0str ("cmr10");
   
 }
+
+
+
+ADD_INTERFACE (Font_interface, "font-interface",
+  "Any symbol that is typeset through fixed sets of glyphs (ie. fonts)",
+  "font-magnification font-style font font-series font-shape font-family font-name font-design-size font-relative-size");