]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/general-scheme.cc: new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 7 Jan 2005 13:05:14 +0000 (13:05 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 7 Jan 2005 13:05:14 +0000 (13:05 +0000)
* lily/font-select.cc (get_font_by_design_size): retrieve
PangoFont for (designsize . "pango-descr") entries.

ChangeLog
lily/font-select.cc
lily/general-scheme.cc [new file with mode: 0644]
lily/lily-guile.cc
lily/ly-module.cc

index 290da25e7178ce7e8c612414095914849ac22dcc..fe1fd35e8e922d9b2abb7ed41a6720047e180f66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-01-07  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/general-scheme.cc: new file. 
+
+       * lily/font-select.cc (get_font_by_design_size): retrieve
+       PangoFont for (designsize . "pango-descr") entries.
+
        * lily/lily-parser-scheme.cc: new file.
 
        * lily/output-def-scheme.cc: new file.
index f3c84cb110317209c2baba69c0dee4f8e6a561bf..68cdc5e49793c078779aeecf2ed9a5e29615a89c 100644 (file)
@@ -13,6 +13,7 @@
 #include "output-def.hh"
 #include "font-interface.hh"
 #include "warn.hh"
+#include "pango-font.hh"
 
 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
           (SCM paper_smob, SCM chain),
@@ -57,12 +58,27 @@ get_font_by_design_size (Output_def *layout, Real requested,
   Real last_size = -1e6;
   int i = 0;
 
+  String pango_description_string;
   for (; i < n; i++)
     {
       SCM entry = SCM_VECTOR_REF (font_vector, i);
-      Font_metric *fm = unsmob_metrics (scm_force (entry));
-      size = fm->design_size ();
-
+      
+      if (scm_promise_p (entry) == SCM_BOOL_T)
+       {
+         Font_metric *fm = unsmob_metrics (scm_force (entry));
+         size = fm->design_size ();
+       }
+#if HAVE_PANGO_FT2
+      else if (scm_is_pair (entry)
+              && scm_is_number (scm_car (entry))
+              && scm_is_string (scm_cdr (entry)))
+       {
+         size = scm_to_double (scm_car (entry));
+         pango_description_string
+           = ly_scm2string (scm_cdr (entry));
+       }
+#endif
+      
       if (size > requested)
        break;
       last_size = size;
@@ -78,9 +94,23 @@ get_font_by_design_size (Output_def *layout, Real requested,
          size = last_size;
        }
     }
+  
+  Font_metric *fm = 0;
+  if (pango_description_string != "")
+    {
+#if HAVE_PANGO_FT2
+      PangoFontDescription *description
+       = pango_font_description_from_string (pango_description_string.to_str0 ());
+      fm = all_fonts_global->find_pango_font (description);
+#else
+      error ("Trying to retrieve pango font without HAVE_PANGO_FT2."); 
+#endif
+    }
+  else
+    {
+      fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i)));
+    }
 
-  Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector,
-                                                              i)));
   return find_scaled_font (layout, fm, requested / size);
 }
 
diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc
new file mode 100644 (file)
index 0000000..895bf04
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+  lily-guile.cc -- implement assorted Guile bindings
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include <math.h>   /* isinf */
+
+#include "lily-guile.hh"
+#include "string.hh"
+#include "misc.hh"
+#include "warn.hh"
+#include "version.hh"
+#include "dimensions.hh"
+#include "main.hh"
+
+/* MacOS S fix:
+   source-file.hh includes cmath which undefines isinf and isnan
+*/
+#ifdef __APPLE__
+inline int my_isinf (Real r) { return isinf (r); }
+inline int my_isnan (Real r) { return isnan (r); }
+#endif
+
+
+LY_DEFINE (ly_gulp_file, "ly:gulp-file",
+          1, 0, 0, (SCM name),
+          "Read the file @var{name}, and return its contents in a string.  "
+          "The file is looked up using the search path.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
+  String contents = gulp_file_to_string (ly_scm2string (name), true);
+  return scm_from_locale_stringn (contents.get_str0 (), contents.length ());
+}
+
+LY_DEFINE (ly_warn, "ly:warn",
+          1, 0, 1, (SCM str, SCM rest),
+          "Scheme callable function to issue the warning @code{msg}. "
+          "The message is formatted with @code{format} and @code{rest}.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
+  progress_indication ("\n");
+
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  warning (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_programming_error, "ly:programming-error",
+          1, 0, 1, (SCM str, SCM rest),
+          "Scheme callable function to issue the warning @code{msg}. "
+          "The message is formatted with @code{format} and @code{rest}.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
+  progress_indication ("\n");
+
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  programming_error (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_dir_p, "ly:dir?",
+          1, 0, 0, (SCM s),
+         "type predicate. A direction is @code{-1}, @code{0} or "
+          "@code{1}, where @code{-1} represents "
+         "left or down and @code{1} represents right or up.")
+{
+  if (scm_is_number (s))
+    {
+      int i = scm_to_int (s);
+      return (i>= -1 && i <= 1)  ? SCM_BOOL_T : SCM_BOOL_F; 
+    }
+  return SCM_BOOL_F;
+}
+
+LY_DEFINE (ly_assoc_get, "ly:assoc-get",
+          2, 1, 0,
+          (SCM key, SCM alist, SCM default_value),
+          "Return value if KEY in ALIST, else DEFAULT-VALUE "
+          "(or #f if not specified).")
+{
+  SCM handle = scm_assoc (key, alist);
+
+  if (default_value == SCM_UNDEFINED)
+    default_value = SCM_BOOL_F;
+  
+  if (scm_is_pair (handle))
+    return scm_cdr (handle);
+  else
+    return default_value;
+}
+
+
+LY_DEFINE (ly_number2string, "ly:number->string",
+          1, 0, 0, (SCM s),
+          "Convert @var{num} to a string without generating many decimals.")
+{
+  SCM_ASSERT_TYPE (scm_is_number (s), s, SCM_ARG1, __FUNCTION__, "number");
+
+  char str[400];                       // ugh.
+
+  if (scm_exact_p (s) == SCM_BOOL_F)
+    {
+      Real r (scm_to_double (s));
+#ifdef __APPLE__
+      if (my_isinf (r) || my_isnan (r))
+#else
+      if (isinf (r) || isnan (r))
+#endif
+       {
+         programming_error ("Infinity or NaN encountered while converting Real number; setting to zero.");
+         r = 0.0;
+       }
+
+      sprintf (str, "%08.4f", r);
+    }
+  else
+    sprintf (str, "%d", scm_to_int (s));
+
+  return scm_makfrom0str (str);
+}
+
+
+
+LY_DEFINE (ly_version,  "ly:version", 0, 0, 0, (),
+         "Return the current lilypond version as a list, e.g. @code{(1 3 127 uu1)}. ")
+{
+  char const* vs = "\'(" MAJOR_VERSION " " MINOR_VERSION " "  PATCH_LEVEL " " MY_PATCH_LEVEL ")" ;
+  
+  return scm_c_eval_string ((char*)vs);
+}
+
+LY_DEFINE (ly_unit,  "ly:unit", 0, 0, 0, (),
+         "Return the unit used for lengths as a string.")
+{
+  return scm_makfrom0str (INTERNAL_UNIT);
+}
+
+
+
+LY_DEFINE (ly_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
+         "Return @var{d} is a number. Used to distinguish length "
+         "variables from normal numbers.")
+{
+  return scm_number_p (d);
+}
+
+/*
+  Debugging mem leaks:
+ */
+LY_DEFINE (ly_protects, "ly:protects",
+          0, 0, 0, (),
+         "Return hash of protected objects.")
+{
+  return scm_protects;
+}
+
+LY_DEFINE (ly_gettext, "ly:gettext",
+          1, 0, 0, (SCM string),
+          "Gettext wrapper.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (string), string, SCM_ARG1,
+                  __FUNCTION__, "string");
+  return scm_makfrom0str (gettext (scm_i_string_chars (string)));
+}
+
+
+
+
+LY_DEFINE (ly_output_backend, "ly:output-backend",
+           0, 0, 0, (),
+           "Return name of output backend.")
+{
+  return scm_makfrom0str (output_backend_global.to_str0 ());
+}
+
+
+LY_DEFINE (ly_output_formats, "ly:output-formats",
+           0, 0, 0, (),
+           "Formats passed to --format as a list of strings, "
+           "used for the output.")
+{
+  Array<String> output_formats = split_string (output_format_global, ',');
+
+  SCM lst = SCM_EOL;
+  int output_formats_count = output_formats.size ();
+  for (int i = 0; i < output_formats_count; i ++)
+    lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
+
+  return lst;
+}
index 524d8e917899ff54489ac5f6aaf9df3f15b8fbb8..b39b56600731a801c82c62004fe20f509a035752 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  lily-guile.cc -- implement assorted guile functions
+  lily-guile.cc -- implement assorted SCM interface functions
 
   source file of the GNU LilyPond music typesetter
 
@@ -7,26 +7,15 @@
                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "lily-guile.hh"
 
 #include <cstdio>
 #include <cstdlib>
-#include <math.h>   /* isinf */
 #include <cstring> /* strdup, strchr */
 #include <cctype>
-
 #include <libintl.h>           // gettext on macos x
 
 #include "version.hh"
-
-/* MacOS S fix:
-   source-file.hh includes cmath which undefines isinf and isnan
-*/
-#ifdef __APPLE__
-inline int my_isinf (Real r) { return isinf (r); }
-inline int my_isnan (Real r) { return isnan (r); }
-#endif
-
+#include "lily-guile.hh"
 #include "libc-extension.hh"
 #include "main.hh"
 #include "file-path.hh"
@@ -121,15 +110,6 @@ gulp_file_to_string (String fn, bool must_exist)
   return result;
 }
 
-LY_DEFINE (ly_gulp_file, "ly:gulp-file",
-          1, 0, 0, (SCM name),
-          "Read the file @var{name}, and return its contents in a string.  "
-          "The file is looked up using the search path.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
-  String contents = gulp_file_to_string (ly_scm2string (name), true);
-  return scm_from_locale_stringn (contents.get_str0 (), contents.length ());
-}
 
 
 extern "C" {
@@ -187,46 +167,6 @@ index_set_cell (SCM s, Direction d, SCM v)
   return s;
 }
   
-LY_DEFINE (ly_warn, "ly:warn",
-          1, 0, 1, (SCM str, SCM rest),
-          "Scheme callable function to issue the warning @code{msg}. "
-          "The message is formatted with @code{format} and @code{rest}.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
-  progress_indication ("\n");
-
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  warning (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_programming_error, "ly:programming-error",
-          1, 0, 1, (SCM str, SCM rest),
-          "Scheme callable function to issue the warning @code{msg}. "
-          "The message is formatted with @code{format} and @code{rest}.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
-  progress_indication ("\n");
-
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  programming_error (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_dir_p, "ly:dir?",
-          1, 0, 0, (SCM s),
-         "type predicate. A direction is @code{-1}, @code{0} or "
-          "@code{1}, where @code{-1} represents "
-         "left or down and @code{1} represents right or up.")
-{
-  if (scm_is_number (s))
-    {
-      int i = scm_to_int (s);
-      return (i>= -1 && i <= 1)  ? SCM_BOOL_T : SCM_BOOL_F; 
-    }
-  return SCM_BOOL_F;
-}
-
 bool
 is_number_pair (SCM p)
 {
@@ -283,23 +223,6 @@ is_direction (SCM s)
   return false;
 }
 
-LY_DEFINE (ly_assoc_get, "ly:assoc-get",
-          2, 1, 0,
-          (SCM key, SCM alist, SCM default_value),
-          "Return value if KEY in ALIST, else DEFAULT-VALUE "
-          "(or #f if not specified).")
-{
-  SCM handle = scm_assoc (key, alist);
-
-  if (default_value == SCM_UNDEFINED)
-    default_value = SCM_BOOL_F;
-  
-  if (scm_is_pair (handle))
-    return scm_cdr (handle);
-  else
-    return default_value;
-}
-
 bool
 is_axis (SCM s)
 {
@@ -375,60 +298,6 @@ ly_scm2offset (SCM s)
                 scm_to_double (scm_cdr (s)));
 }
 
-LY_DEFINE (ly_number2string, "ly:number->string",
-          1, 0, 0, (SCM s),
-          "Convert @var{num} to a string without generating many decimals.")
-{
-  SCM_ASSERT_TYPE (scm_is_number (s), s, SCM_ARG1, __FUNCTION__, "number");
-
-  char str[400];                       // ugh.
-
-  if (scm_exact_p (s) == SCM_BOOL_F)
-    {
-      Real r (scm_to_double (s));
-#ifdef __APPLE__
-      if (my_isinf (r) || my_isnan (r))
-#else
-      if (isinf (r) || isnan (r))
-#endif
-       {
-         programming_error ("Infinity or NaN encountered while converting Real number; setting to zero.");
-         r = 0.0;
-       }
-
-      sprintf (str, "%08.4f", r);
-    }
-  else
-    sprintf (str, "%d", scm_to_int (s));
-
-  return scm_makfrom0str (str);
-}
-
-
-
-LY_DEFINE (ly_version,  "ly:version", 0, 0, 0, (),
-         "Return the current lilypond version as a list, e.g. @code{(1 3 127 uu1)}. ")
-{
-  char const* vs = "\'(" MAJOR_VERSION " " MINOR_VERSION " "  PATCH_LEVEL " " MY_PATCH_LEVEL ")" ;
-  
-  return scm_c_eval_string ((char*)vs);
-}
-
-LY_DEFINE (ly_unit,  "ly:unit", 0, 0, 0, (),
-         "Return the unit used for lengths as a string.")
-{
-  return scm_makfrom0str (INTERNAL_UNIT);
-}
-
-
-
-LY_DEFINE (ly_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
-         "Return @var{d} is a number. Used to distinguish length "
-         "variables from normal numbers.")
-{
-  return scm_number_p (d);
-}
-
 SCM
 ly_deep_copy (SCM src)
 {
@@ -834,48 +703,3 @@ alist_to_hashq (SCM alist)
     }
   return tab; 
 }
-
-/*
-  Debugging mem leaks:
- */
-LY_DEFINE (ly_protects, "ly:protects",
-          0, 0, 0, (),
-         "Return hash of protected objects.")
-{
-  return scm_protects;
-}
-
-LY_DEFINE (ly_gettext, "ly:gettext",
-          1, 0, 0, (SCM string),
-          "Gettext wrapper.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (string), string, SCM_ARG1,
-                  __FUNCTION__, "string");
-  return scm_makfrom0str (gettext (scm_i_string_chars (string)));
-}
-
-
-
-
-LY_DEFINE (ly_output_backend, "ly:output-backend",
-           0, 0, 0, (),
-           "Return name of output backend.")
-{
-  return scm_makfrom0str (output_backend_global.to_str0 ());
-}
-
-
-LY_DEFINE (ly_output_formats, "ly:output-formats",
-           0, 0, 0, (),
-           "Formats passed to --format as a list of strings, "
-           "used for the output.")
-{
-  Array<String> output_formats = split_string (output_format_global, ',');
-
-  SCM lst = SCM_EOL;
-  int output_formats_count = output_formats.size ();
-  for (int i = 0; i < output_formats_count; i ++)
-    lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
-
-  return lst;
-}
index c93366727752f06056251fea8f2e6720ff8e704b..637b88467634b79420da73d3a9bbdc4a5f1ea96e 100644 (file)
@@ -6,6 +6,7 @@
   (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "lily-guile.hh"
 #include "warn.hh"
 #include "main.hh"
 #include "string.hh"