]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/font-select.cc
* lily/font-interface.cc (text_font_alist_chain): rename function,
[lilypond.git] / lily / font-select.cc
index 61ae2fa4fc3ed62a0483a4dd327d6f12838c3920..d4773c853c22b45b267a8626652a6655ede67512 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2003 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
  */
 
 #include "font-interface.hh"
 #include "warn.hh"
 
-LY_DEFINE(ly_paper_get_font,"ly:paper-get-font", 2, 0, 0,
-         (SCM paper, 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, containing grob properties.\n")
+LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
+          (SCM paper, SCM chain),
+
+          "Return a font metric satisfying the font-qualifiers "
+          "in the alist chain @var{chain}.\n"
+          "(An alist chain is a list of alists, containing grob properties).\n")
 {
   Paper_def *pap = unsmob_paper (paper);
-  SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
+  SCM_ASSERT_TYPE (pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
   
-  Font_metric*fm = select_font (pap, chain);
-  return fm->self_scm();
+  Font_metric *fm = select_font (pap, chain);
+  return fm->self_scm ();
 }
 
+LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
+          (SCM paper, SCM name),
+          "Return the paper variable @var{name}.")
+{
+  Paper_def *pap = unsmob_paper (paper);
+  SCM_ASSERT_TYPE (pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
+  return gh_double2scm (pap->get_realvar (name));
+}
 
 bool
 wild_compare (SCM field_val, SCM val)
 {
   return (val == SCM_BOOL_F || field_val == ly_symbol2scm ("*") || field_val == val);
 }
+
 Font_metric*
 get_font_by_design_size (Paper_def* paper, Real requested,
                         SCM font_vector)
@@ -87,51 +88,14 @@ get_font_by_mag_step (Paper_def* paper, Real requested_step,
 
 
 
-/*
-  We can probably get more efficiency points if we preprocess FONTS
-  to make lookup easier.
- */
 SCM
 properties_to_font_size_family (SCM fonts, SCM alist_chain)
 {
-  SCM shape = SCM_BOOL_F;
-  SCM family = SCM_BOOL_F;
-  SCM series = SCM_BOOL_F;
-  
-  shape = ly_assoc_chain (ly_symbol2scm ("font-shape"), alist_chain);
-  family = ly_assoc_chain (ly_symbol2scm ("font-family"), alist_chain);
-  series = ly_assoc_chain (ly_symbol2scm ("font-series"), alist_chain);
+  static SCM proc;
+  if (!proc )
+    proc = scm_c_eval_string ("lookup-font");
 
-  if (gh_pair_p (shape))
-    shape = ly_cdr (shape);
-  if (gh_pair_p (family))
-    family = ly_cdr (family);
-  if (gh_pair_p (series))
-    series = ly_cdr (series);
-
-
-  for (SCM s = fonts ; gh_pair_p (s); s = ly_cdr (s))
-    {
-      SCM qlist = ly_caar (s);
-
-      if (!wild_compare (SCM_VECTOR_REF (qlist, 0), series))
-       continue;
-      if (!wild_compare (SCM_VECTOR_REF (qlist, 1), shape))
-       continue;
-      if (!wild_compare (SCM_VECTOR_REF (qlist, 2), family))
-       continue;
-  
-      SCM qname = ly_cdar (s);
-      return qname;
-    }
-
-  warning (_ ("couldn't find any font size family satisfying "));
-  
-  scm_write (scm_list_n (shape, series , family, 
-                        SCM_UNDEFINED), scm_current_error_port ());
-  scm_flush (scm_current_error_port ());
-  return scm_makfrom0str ("cmr10");
+  return scm_call_2 (proc, fonts, alist_chain);
 }