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