]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 0.1.24
[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 String
60 Atom::TeX_string() const
61 {
62   String tex_str = tex_;
63   Offset off = off_;
64
65   /* infinity checks. */
66   for (int a = X_AXIS; a < NO_AXES; a++)
67     {
68       Axis ax = (Axis)a;
69       if (abs (off[ax]) >= 100 CM)
70         {
71           warning (_("ridiculous dimension ") + axis_name_str (ax)  + ", "
72                    +print_dimen(off[ax]));
73           off[ax] = 0.0;
74           tex_str += "\errormark";
75         }
76     }
77   // whugh.. Hard coded...
78   String s ("\\placebox{");
79   s += print_dimen (off[Y_AXIS])+"}{";
80   s += print_dimen (off[X_AXIS]) + "}{";
81   s += tex_str + "}";
82   return s;
83 }
84
85 void
86 Atom::translate_axis (Real r, Axis a)
87 {
88   off_[a] += r;
89 }
90
91 void
92 Atom::translate (Offset o)
93 {
94   off_ += o;
95 }