]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
release: 1.3.119
[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
61 Font_metric::~Font_metric ()
62 {
63 }
64
65 Font_metric::Font_metric ()
66 {
67   description_ = SCM_EOL;
68
69   smobify_self ();
70 }
71
72 Font_metric::Font_metric (Font_metric const &s)
73 {
74 }
75
76
77 Box 
78 Font_metric::get_char (int )const
79 {
80   return Box (Interval(0,0),Interval (0,0));
81 }
82
83
84 SCM
85 Font_metric::mark_smob (SCM s)
86 {
87   Font_metric * m = (Font_metric*) SCM_CELL_WORD_1(s);
88   return m->description_;
89 }
90
91 int
92 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
93 {
94   Font_metric *m = unsmob_metrics (s);
95   scm_puts ("#<Font_metric ", port);
96   scm_write (m->description_, port);
97   scm_puts (">", port);
98   return 1;
99 }
100
101
102 IMPLEMENT_UNSMOB (Font_metric, metrics);
103 IMPLEMENT_SMOBS (Font_metric);
104 IMPLEMENT_DEFAULT_EQUAL_P(Font_metric);
105 IMPLEMENT_TYPE_P (Font_metric, "font-metric?");
106
107 Molecule
108 Font_metric::find_by_name (String) const
109 {
110   Molecule m ;
111   return m;
112 }
113
114
115