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