]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
eba9660c922c8e1fb3cfdeece3e20509e4162363
[lilypond.git] / lily / atom.cc
1 /*
2   atom.cc -- implement Atom
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "atom.hh"
9 #include "tex.hh"
10 #include "interval.hh"
11 #include "dimen.hh"
12 #include "string.hh"
13 #include "varray.hh"
14 #include "debug.hh"
15 #include "main.hh"
16
17 inline bool
18 Atom::check_infinity_b ()const
19 {
20   bool ridiculous = false;
21 #ifndef NDEBUG
22   
23   /* infinity checks. */
24   for (int a = X_AXIS; a < NO_AXES; a++)
25     {
26       Axis ax = (Axis)a;
27       if (abs (off_[ax]) >= 100 CM)
28         {
29           warning (_("ridiculous dimension ") + axis_name_str (ax)  + ", "
30                    +print_dimen(off_[ax]));
31           
32           if (experimental_features_global_b)
33             assert (false);
34
35           ((Atom*)this)->off_[ax] = 0.0;
36           ridiculous = true;
37         }
38     }
39 #endif
40   return ridiculous;
41 }
42
43
44 void
45 Atom::print() const
46 {
47 #ifndef NPRINT
48   DOUT << "texstring: " <<tex_<<"\n";
49
50   DOUT << "dim:";
51     for (Axis i=X_AXIS; i < NO_AXES; incr(i))
52       DOUT << axis_name_str(i) << " = " << dim_[i].str();
53
54   DOUT << "\noffset: " << off_.str ();
55 #endif
56 }
57
58 Box
59 Atom::extent() const
60 {
61   Box b (dim_);
62   b.translate (off_);
63   return b;
64 }
65
66
67 Atom::Atom()
68   : dim_ (Interval (0,0),Interval (0,0))
69 {
70   tex_ = "\\unknown";
71 }
72
73 Atom::Atom (String s, Box b)
74   :  dim_ (b)
75 {
76   tex_ = s;
77 }
78
79
80 String
81 Atom::str() const
82 {
83   return "Atom (\'"+tex_+"\', (" + dim_.x().str () + ", "
84     + dim_.y ().str () + "))";
85 }
86
87
88 String
89 Atom::TeX_string() const
90 {
91   String tex_str = tex_;
92   if (check_infinity_b ())
93     tex_str += "\errormark";
94   
95    // whugh.. Hard coded...
96   String s ("\\placebox{");
97   s += print_dimen (off_[Y_AXIS])+"}{";
98   s += print_dimen (off_[X_AXIS]) + "}{";
99   s += tex_str + "}";
100   return s;
101 }
102
103 void
104 Atom::translate_axis (Real r, Axis a)
105 {
106   off_[a] += r;
107   check_infinity_b ();
108 }
109
110 void
111 Atom::translate (Offset o)
112 {
113   off_ += o;
114   check_infinity_b ();
115 }