]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 0.1.39
[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 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
16 void
17 Atom::print() const
18 {
19 #ifndef NPRINT
20   DOUT << "texstring: " <<tex_<<"\n";
21
22   DOUT << "dim:";
23     for (Axis i=X_AXIS; i < NO_AXES; incr(i))
24       DOUT << axis_name_str(i) << " = " << dim_[i].str();
25
26   DOUT << "\noffset: " << off_.str ();
27 #endif
28 }
29
30 Box
31 Atom::extent() const
32 {
33   Box b (dim_);
34   b.translate (off_);
35   return b;
36 }
37
38
39 Atom::Atom()
40   : dim_ (Interval (0,0),Interval (0,0))
41 {
42   tex_ = "\\unknown";
43 }
44
45 Atom::Atom (String s, Box b)
46   :  dim_ (b)
47 {
48   tex_ = s;
49 }
50
51
52 String
53 Atom::str() const
54 {
55   return "Atom (\'"+tex_+"\', (" + dim_.x().str () + ", "
56     + dim_.y ().str () + "))";
57 }
58
59
60 bool
61 Atom::check_infinity_b ()const
62 {
63   bool ridiculous = false;
64 #ifndef NDEBUG
65   
66   /* infinity checks. */
67   for (int a = X_AXIS; a < NO_AXES; a++)
68     {
69       Axis ax = (Axis)a;
70       if (abs (off_[ax]) >= 100 CM)
71         {
72           warning (_("ridiculous dimension ") + axis_name_str (ax)  + ", "
73                    +print_dimen(off_[ax]));
74           ((Atom*)this)->off_[ax] = 0.0;
75           ridiculous = true;
76         }
77     }
78 #endif
79   return ridiculous;
80 }
81 String
82 Atom::TeX_string() const
83 {
84   String tex_str = tex_;
85   if (check_infinity_b ())
86     tex_str += "\errormark";
87   
88    // whugh.. Hard coded...
89   String s ("\\placebox{");
90   s += print_dimen (off_[Y_AXIS])+"}{";
91   s += print_dimen (off_[X_AXIS]) + "}{";
92   s += tex_str + "}";
93   return s;
94 }
95
96 void
97 Atom::translate_axis (Real r, Axis a)
98 {
99   off_[a] += r;
100   check_infinity_b ();
101 }
102
103 void
104 Atom::translate (Offset o)
105 {
106   off_ += o;
107   check_infinity_b ();
108 }