]> git.donarmstrong.com Git - lilypond.git/blob - lily/all-font-metrics.cc
release: 1.1.27
[lilypond.git] / lily / all-font-metrics.cc
1 #include "pointer.hh"
2 #include "main.hh"
3 #include "all-fonts.hh"
4 #include "debug.hh"
5 #include "warn.hh"
6 #include "afm.hh"
7 #include "tfm.hh"
8
9 const char * default_font_sz_ = "cmr10";
10
11
12
13 All_font_metrics::All_font_metrics (String path)
14 {
15   search_path_.parse_path (path);
16 }
17
18
19 Adobe_font_metric *
20 All_font_metrics::find_afm (String name)
21 {
22   if (!afm_p_dict_.elem_b (name))
23     {
24       String path = name  + ".afm";
25       path = search_path_.find (path);
26       if (path.empty_b ())
27         return 0;
28       
29       *mlog << "[" << path;
30       Adobe_font_metric
31         * afm_p = new Adobe_font_metric (read_afm_file (path));
32       *mlog << "]" << flush ;
33
34       afm_p_dict_[name] = afm_p;
35     }
36   return afm_p_dict_[name];  
37 }
38
39 Tex_font_metric *
40 All_font_metrics::find_tfm (String name)
41 {
42   if (!tfm_p_dict_.elem_b (name))
43     {
44       String path = name  + ".tfm";
45       path = search_path_.find (path);
46       if (path.empty_b ())
47         return 0;
48       
49       *mlog << "[" << path;
50       Tex_font_metric   * tfm_p = new Tex_font_metric;
51       tfm_p->read_file (path);
52       *mlog << "]" << flush ;
53
54       tfm_p_dict_[name] = tfm_p;
55     }
56   return tfm_p_dict_[name];  
57 }
58
59
60 Font_metric *
61 All_font_metrics::find_font (String name)
62 {  Font_metric * f=0;
63   f = find_tfm (name);
64   if (f)
65     return f;
66
67   f= find_afm (name);
68   if (f)
69     return f;
70
71   f =  find_tfm (default_font_sz_);
72   if (f)
73     return f;
74   String s = _f("Can't find default font `%s\', giving up.", default_font_sz_);
75   s += String ("\n") + _f ("search path = %s", search_path_.str ());
76   error (s);
77 }