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