]> git.donarmstrong.com Git - lilypond.git/blob - lily/afm.cc
d9984847a60fbcaa0258854ce3e75f598f4114bb
[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--1999 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
28 int &
29 Adobe_font_char_metric::code ()
30 {
31   return C_;
32 }
33
34 Real &
35 Adobe_font_char_metric::width ()
36 {
37   return WX_;
38 }
39
40 Adobe_font_char_metric::Adobe_font_char_metric ()
41 {
42   B_ = Box( Interval(0,0), Interval (0,0));
43   WX_ = 0.0;
44   C_ = 0;
45   C_ = -1;
46 }
47
48 Adobe_font_metric::Adobe_font_metric ()
49 {
50   ItalicAngle_ = 0.0;
51   IsFixedPitch_ = false;
52   UnderlinePosition_ =0.;
53   UnderlineThickness_=0.;
54 }
55
56
57 Box
58 Adobe_font_char_metric::dimensions () const
59 {
60   Box b= B_;
61   
62   b[X_AXIS] *= size_ / 1000.0;
63   b[Y_AXIS] *= size_ / 1000.0;
64
65   return b;
66 }
67
68
69
70 #define APPEND_CHAR_METRIC_ELT(k)  outstr += to_str (#k) + " "  + to_str (k ## _)  + "; "
71
72 String
73 box_str (Box b)
74 {
75   return to_str (b[X_AXIS][SMALLER]) + " " +
76     to_str(b[Y_AXIS][SMALLER]) + " " +
77     to_str (b[X_AXIS][BIGGER]) + " "+
78     to_str (b[Y_AXIS][BIGGER]);
79 }
80
81 #define APPEND_BOX(k)  outstr += to_str (#k) + " "  + box_str (k ## _)  + ";"
82
83 String
84 Adobe_font_char_metric::str () const
85 {
86   String outstr ;
87
88   APPEND_CHAR_METRIC_ELT (C);
89   APPEND_CHAR_METRIC_ELT(N);
90   APPEND_CHAR_METRIC_ELT(WX);
91   
92   APPEND_BOX(B);
93   return outstr + "\n";
94 }
95
96 #define WRITESTRING(k)  outstr += String (#k) + " "  + to_str (k ## _)  + "\n"
97
98 String
99 Adobe_font_metric::str () const
100 {
101   String outstr;
102   WRITESTRING(FontName);
103   WRITESTRING(FullName);
104   WRITESTRING(FamilyName);
105   WRITESTRING(Weight);
106   WRITESTRING(Version);
107   WRITESTRING(Notice);
108   WRITESTRING(EncodingScheme);
109   WRITESTRING(ItalicAngle);
110   WRITESTRING(UnderlineThickness);
111   WRITESTRING(UnderlinePosition);
112   outstr += "FontBBox " +  box_str (FontBBox_) +  "\n";
113
114   for (int i=0; i < char_metrics_.size (); i++)
115     outstr += char_metrics_[i].str ();
116   
117   return outstr;
118 }
119
120 Adobe_font_char_metric dummy_static_char_metric;
121
122 Adobe_font_char_metric const &
123 Adobe_font_metric::find_char (String nm, bool warn) const
124 {
125   if (warn && !name_to_metric_dict_.elem_b (nm))
126     {
127       warning (_f ("can't find character called `%s'", nm.ch_C()));
128       return dummy_static_char_metric;
129     }
130   
131   return char_metrics_[name_to_metric_dict_ [nm]];
132 }
133
134
135 Character_metric *
136 Adobe_font_metric::get_char (int code, bool warn) const
137 {
138   return &find_ascii (code,warn);
139 }
140
141 Adobe_font_char_metric const &
142 Adobe_font_metric::find_ascii (int a , bool warn) const
143 {
144   int  code = ascii_to_metric_idx_[a];
145   if (code>=0)
146     {
147       return char_metrics_[code];
148     }
149   else if (warn )
150     {
151       warning (_f ("can't find character number %d", a));
152     }
153   return dummy_static_char_metric;
154 }