]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
release: 1.3.19
[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 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include <math.h>
11 #include <ctype.h>
12
13 #include "font-metric.hh"
14
15 Box
16 Font_metric::text_dimension (String text) const
17 {
18   Interval ydims;
19   Real w=0.0;
20   
21   for (int i = 0; i < text.length_i (); i++) 
22     {
23       
24       if (text[i]=='\\') 
25         {
26           for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
27             ;
28           // ugh.
29           i--; // Compensate for the increment in the outer loop!
30         }
31       else
32         {
33           Character_metric const *c = get_char ((unsigned char)text[i],false);
34
35           // Ugh, use the width of 'x' for unknown characters
36           if (c->dimensions()[X_AXIS].length () == 0) 
37             c = get_char ((unsigned char)'x',false);
38           
39           w += c->dimensions()[X_AXIS].length ();
40           ydims.unite (c->dimensions()[Y_AXIS]);
41         }
42     }
43   if (ydims.empty_b ())
44     ydims = Interval (0,0);
45
46   return Box(Interval (0, w), ydims);
47 }
48
49
50 Box
51 Scaled_font_metric::text_dimension (String t) const
52 {
53   Real realmag = pow (1.2, magstep_i_);
54   Box b (orig_l_->text_dimension (t));
55
56   return Box(b[X_AXIS]* realmag, b[Y_AXIS]*realmag);
57 }
58
59
60 Box
61 Character_metric::dimensions () const
62 {
63   return Box(Interval(0,0), Interval(0,0));
64 }
65
66 Font_metric::~Font_metric ()
67 {
68   unsmobify_self ();
69 }
70
71 Font_metric::Font_metric ()
72 {
73   self_scm_ = SCM_EOL;
74   name_ = SCM_EOL;
75   smobify_self ();
76 }
77
78 Font_metric::Font_metric (Font_metric const &)
79 {
80 }
81
82 Character_metric::~Character_metric()
83 {
84 }
85
86 Character_metric const *
87 Font_metric::get_char (int, bool)const
88 {
89   return 0;
90 }
91
92 Scaled_font_metric::Scaled_font_metric (Font_metric* m, int s)
93 {
94   magstep_i_ = s;
95   orig_l_ = m;
96 }
97
98 SCM
99 Font_metric::description () const
100 {
101   return gh_cons (name_, gh_int2scm (0));
102 }
103
104
105 SCM
106 Scaled_font_metric::description () const
107 {
108   SCM od = orig_l_->description ();
109   gh_set_cdr_x (od, gh_int2scm (magstep_i_));
110   return od;
111 }
112
113
114 void
115 Font_metric::do_smobify_self ()
116 {
117 }
118
119 SCM
120 Font_metric::mark_smob (SCM s)
121 {
122   Font_metric * m = SMOB_TO_TYPE(Font_metric, s);
123   return m->name_;
124 }
125
126 int
127 Font_metric::print_smob (SCM s, SCM port, scm_print_state * )
128 {
129   Font_metric *m = unsmob_metrics (s);
130   scm_puts ("#<Font_metric ", port);
131   scm_display (m->name_, port);
132   scm_puts (">", port);
133   return 1;
134 }
135
136 Font_metric *
137 unsmob_metrics( SCM s)
138 {
139   if (SMOB_IS_TYPE_B(Font_metric, s))
140     return SMOB_TO_TYPE(Font_metric, s);
141   else
142     return 0;
143 }