]> git.donarmstrong.com Git - lilypond.git/blob - lily/afm.cc
release: 1.3.19
[lilypond.git] / lily / afm.cc
1 /*   
2   afm.cc --  implement Adobe_font_metric
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "afm.hh"
11 #include "box.hh"
12 #include "direction.hh"
13 #include "debug.hh"
14
15 Box &
16 Adobe_font_char_metric::bbox ()
17 {
18   return B_;
19 }
20
21 String &
22 Adobe_font_char_metric::name ()
23 {
24   return N_;
25 }
26
27 int &
28 Adobe_font_char_metric::code ()
29 {
30   return C_;
31 }
32
33 Real &
34 Adobe_font_char_metric::width ()
35 {
36   return WX_;
37 }
38
39 Adobe_font_char_metric::Adobe_font_char_metric ()
40 {
41   B_ = Box( Interval(0,0), Interval (0,0));
42   WX_ = 0.0;
43   C_ = 0;
44   C_ = -1;
45 }
46
47 Adobe_font_metric::Adobe_font_metric ()
48 {
49   ItalicAngle_ = 0.0;
50   IsFixedPitch_ = false;
51   UnderlinePosition_ =0.;
52   UnderlineThickness_=0.;
53 }
54
55
56 Box
57 Adobe_font_char_metric::dimensions () const
58 {
59   Box b= B_;
60   
61   b[X_AXIS] *= size_ / 1000.0;
62   b[Y_AXIS] *= size_ / 1000.0;
63
64   return b;
65 }
66
67
68
69 #define APPEND_CHAR_METRIC_ELT(k)  outstr += to_str (#k) + " "  + to_str (k ## _)  + "; "
70
71 String
72 box_str (Box b)
73 {
74   return to_str (b[X_AXIS][SMALLER]) + " " +
75     to_str(b[Y_AXIS][SMALLER]) + " " +
76     to_str (b[X_AXIS][BIGGER]) + " "+
77     to_str (b[Y_AXIS][BIGGER]);
78 }
79
80 #define APPEND_BOX(k)  outstr += to_str (#k) + " "  + box_str (k ## _)  + ";"
81
82 String
83 Adobe_font_char_metric::str () const
84 {
85   String outstr ;
86
87   APPEND_CHAR_METRIC_ELT (C);
88   APPEND_CHAR_METRIC_ELT(N);
89   APPEND_CHAR_METRIC_ELT(WX);
90   
91   APPEND_BOX(B);
92   return outstr + "\n";
93 }
94
95 #define WRITESTRING(k)  outstr += String (#k) + " "  + to_str (k ## _)  + "\n"
96
97 String
98 Adobe_font_metric::str () const
99 {
100   String outstr;
101   WRITESTRING(FontName);
102   WRITESTRING(FullName);
103   WRITESTRING(FamilyName);
104   WRITESTRING(Weight);
105   WRITESTRING(Version);
106   WRITESTRING(Notice);
107   WRITESTRING(EncodingScheme);
108   WRITESTRING(ItalicAngle);
109   WRITESTRING(UnderlineThickness);
110   WRITESTRING(UnderlinePosition);
111   outstr += "FontBBox " +  box_str (FontBBox_) +  "\n";
112
113   for (int i=0; i < char_metrics_.size (); i++)
114     outstr += char_metrics_[i].str ();
115   
116   return outstr;
117 }
118
119 Adobe_font_char_metric dummy_static_char_metric;
120
121 Adobe_font_char_metric const &
122 Adobe_font_metric::find_char (String nm, bool warn) const
123 {
124   if (!name_to_metric_dict_.elem_b (nm))
125     {
126       if (warn)
127         {
128           warning (_f ("Can't find character called: `%s'", nm.ch_C()));
129         }
130       return dummy_static_char_metric;
131     }
132   
133   return char_metrics_[name_to_metric_dict_ [nm]];
134 }
135
136
137 Character_metric const *
138 Adobe_font_metric::get_char (int code, bool warn) const
139 {
140   return &find_ascii (code,warn);
141 }
142
143 Adobe_font_char_metric const &
144 Adobe_font_metric::find_ascii (int a , bool warn) const
145 {
146   int  code = ascii_to_metric_idx_[a];
147   if (code>=0)
148     {
149       return char_metrics_[code];
150     }
151   else if (warn )
152     {
153       warning (_f ("Can't find character number: %d", a));
154     }
155   return dummy_static_char_metric;
156 }