]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
patch::: 1.3.136.jcn3
[lilypond.git] / lily / font-metric.cc
1 /*   
2   font-metric.cc --  implement Font_metric
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8     Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
9  */
10
11 #include <math.h>
12 #include <ctype.h>
13
14 #include "warn.hh"
15 #include "molecule.hh"
16 #include "ly-smobs.icc"
17 #include "font-metric.hh"
18 #include "string.hh"
19
20 Box
21 Font_metric::text_dimension (String text) const
22 {
23   Interval ydims;
24   Real w=0.0;
25   
26   for (int i = 0; i < text.length_i (); i++) 
27     {
28       
29       switch (text[i]) 
30         {
31         case '\\':
32           for (i++; (i < text.length_i ()) && !isspace (text[i]) 
33                  && text[i]!='{' && text[i]!='}'; i++)
34             ;
35           // ugh.
36           i--; // Compensate for the increment in the outer loop!
37           break;
38         case '{':  // Skip '{' and '}'
39         case '}':
40           break;
41         
42         default: 
43           Box b = get_char ((unsigned char)text[i]);
44           
45           // Ugh, use the width of 'x' for unknown characters
46           if (b[X_AXIS].length () == 0) 
47             b = get_char ((unsigned char)'x');
48           
49           w += b[X_AXIS].length ();
50           ydims.unite (b[Y_AXIS]);
51           break;
52         }
53     }
54   if (ydims.empty_b ())
55     ydims = Interval (0,0);
56
57   return Box (Interval (0, w), ydims);
58 }
59
60
61
62 Font_metric::~Font_metric ()
63 {
64 }
65
66 Font_metric::Font_metric ()
67 {
68   description_ = SCM_EOL;
69
70   smobify_self ();
71 }
72
73 Font_metric::Font_metric (Font_metric const &s)
74 {
75 }
76
77
78 Box 
79 Font_metric::get_char (int)const
80 {
81   return Box (Interval (0,0),Interval (0,0));
82 }
83
84
85 SCM
86 Font_metric::mark_smob (SCM s)
87 {
88   Font_metric * m = (Font_metric*) SCM_CELL_WORD_1 (s);
89   return m->description_;
90 }
91
92 int
93 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
94 {
95   Font_metric *m = unsmob_metrics (s);
96   scm_puts ("#<Font_metric ", port);
97   scm_write (m->description_, port);
98   scm_puts (">", port);
99   return 1;
100 }
101
102
103 IMPLEMENT_UNSMOB (Font_metric, metrics);
104 IMPLEMENT_SMOBS (Font_metric);
105 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
106 IMPLEMENT_TYPE_P (Font_metric, "font-metric?");
107
108 Molecule
109 Font_metric::find_by_name (String) const
110 {
111   Molecule m ;
112   return m;
113 }
114
115
116 SCM
117 ly_find_glyph_by_name (SCM font, SCM name)
118 {
119   if (!unsmob_metrics (font) || !gh_string_p (name))
120     {
121       warning ("ly-find-glyph-by-name: invalid argument.");
122       Molecule m;
123       return m.smobbed_copy ();
124     }
125
126   return unsmob_metrics (font)->find_by_name (ly_scm2string (name)).smobbed_copy ();
127 }
128
129
130 static void
131 font_metric_init ()
132 {
133    scm_make_gsubr ("ly-find-glyph-by-name", 2 , 0, 0, (Scheme_function_unknown) ly_find_glyph_by_name);
134 }
135
136 ADD_SCM_INIT_FUNC (font_metric_init, font_metric_init);