]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
release: 1.3.101
[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--2000 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 "molecule.hh"
15 #include "ly-smobs.icc"
16 #include "font-metric.hh"
17 #include "string.hh"
18
19 Box
20 Font_metric::text_dimension (String text) const
21 {
22   Interval ydims;
23   Real w=0.0;
24   
25   for (int i = 0; i < text.length_i (); i++) 
26     {
27       
28       switch (text[i]) 
29         {
30         case '\\':
31           for (i++; (i < text.length_i ()) && !isspace(text[i]) 
32                  && text[i]!='{' && text[i]!='}'; i++)
33             ;
34           // ugh.
35           i--; // Compensate for the increment in the outer loop!
36           break;
37         case '{':  // Skip '{' and '}'
38         case '}':
39           break;
40         
41         default: 
42           Box b = get_char ((unsigned char)text[i]);
43           
44           // Ugh, use the width of 'x' for unknown characters
45           if (b[X_AXIS].length () == 0) 
46             b = get_char ((unsigned char)'x');
47           
48           w += b[X_AXIS].length ();
49           ydims.unite (b[Y_AXIS]);
50           break;
51         }
52     }
53   if (ydims.empty_b ())
54     ydims = Interval (0,0);
55
56   return Box(Interval (0, w), ydims);
57 }
58
59
60 Box
61 Scaled_font_metric::text_dimension (String t) const
62 {
63   Box b (orig_l_->text_dimension (t));
64
65   b.scale (magnification_f_);
66   return b;
67 }
68
69 Font_metric::~Font_metric ()
70 {
71 }
72
73 Font_metric::Font_metric ()
74 {
75   description_ = SCM_EOL;
76
77   smobify_self ();
78 }
79
80 Font_metric::Font_metric (Font_metric const &)
81 {
82 }
83
84
85 Box 
86 Font_metric::get_char (int )const
87 {
88   return Box (Interval(0,0),Interval (0,0));
89 }
90
91
92 SCM
93 Font_metric::mark_smob (SCM s)
94 {
95   Font_metric * m = (Font_metric*) SCM_CELL_WORD_1(s);
96   return m->description_;
97 }
98
99 int
100 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
101 {
102   Font_metric *m = unsmob_metrics (s);
103   scm_puts ("#<Font_metric ", port);
104   scm_write (m->description_, port);
105   scm_puts (">", port);
106   return 1;
107 }
108
109
110 IMPLEMENT_UNSMOB (Font_metric, metrics);
111 IMPLEMENT_SMOBS (Font_metric);
112 IMPLEMENT_DEFAULT_EQUAL_P(Font_metric);
113 IMPLEMENT_TYPE_P (Font_metric, "font-metric?");
114
115 Molecule
116 Font_metric::find_by_name (String) const
117 {
118   Molecule m ;
119   return m;
120 }
121
122
123