2 afm.cc -- implement Adobe_font_metric
4 source file of the Flower Library
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "molecule.hh"
13 Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
17 for (int i= 256; i--;)
18 ascii_to_metric_idx_.push (-1);
20 for (int i=0; i < fi->numOfChars; i++)
22 AFM_CharMetricInfo * c = fi->cmi + i;
24 ascii_to_metric_idx_[c->code] = i;
25 name_to_metric_dict_[c->name] = i;
31 Adobe_font_metric::make_afm (AFM_Font_info *fi)
33 Adobe_font_metric * fm = new Adobe_font_metric (fi);
35 return fm->self_scm();
39 AFM_CharMetricInfo const *
40 Adobe_font_metric::find_ascii_metric (int a , bool warn) const
42 if (ascii_to_metric_idx_[a] >=0)
44 int code = ascii_to_metric_idx_[a];
47 return font_inf_->cmi + code;
52 warning (_f ("can't find character number: %d", a));
58 AFM_CharMetricInfo const *
59 Adobe_font_metric::find_char_metric (String nm, bool warn) const
61 map<String,int>::const_iterator ai = name_to_metric_dict_.find (nm);
63 if (ai == name_to_metric_dict_.end ())
67 warning (_f ("can't find character called: `%s'", nm.ch_C()));
72 return font_inf_->cmi + (*ai).second;
77 Adobe_font_metric::get_char (int code, Real mag) const
79 AFM_CharMetricInfo const
80 * c = find_ascii_metric (code,false);
81 Box b (Interval (0,0),Interval(0,0));
83 b = afm_bbox_to_box (c->charBBox);
90 read_afm_file (String nm)
92 FILE *f = fopen (nm.ch_C() , "r");
95 int ok = AFM_parseFile (f, &fi, ~1);
99 error (_f ("Error parsing AFM file: %s", nm.ch_C ()));
104 return Adobe_font_metric::make_afm (fi);
109 afm_bbox_to_box (AFM_BBox bb)
111 return Box (Interval (bb.llx, bb.urx)* (1/1000.0),
112 Interval (bb.lly, bb.ury)* (1/1000.0));
117 Adobe_font_metric::~Adobe_font_metric ()
119 AFM_free (font_inf_);
123 Adobe_font_metric::find_by_name (String s, Real mag) const
125 AFM_CharMetricInfo const *cm = find_char_metric (s, false);
134 SCM at = (gh_list (ly_symbol2scm ("char"),
135 gh_int2scm (cm->code),
138 at= fontify_atom ((Font_metric*)this, at);
139 Box b = afm_bbox_to_box (cm->charBBox);
141 return Molecule (b, at);