2 afm.cc -- implement Adobe_font_metric
4 source file of the Flower Library
6 (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "molecule.hh"
12 #include "dimensions.hh"
14 Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
19 for (int i= 256 >? fi->numOfChars; i--;)
20 ascii_to_metric_idx_.push (-1);
22 for (int i=0; i < fi->numOfChars; i++)
24 AFM_CharMetricInfo * c = fi->cmi + i;
27 Some TeX afm files contain code = -1. We don't know why, let's
32 ascii_to_metric_idx_[c->code] = i;
33 name_to_metric_dict_[c->name] = i;
39 Adobe_font_metric::make_afm (AFM_Font_info *fi, unsigned int checksum)
41 Adobe_font_metric * fm = new Adobe_font_metric (fi);
42 fm->checksum_ = checksum;
43 return fm->self_scm ();
47 AFM_CharMetricInfo const *
48 Adobe_font_metric::find_ascii_metric (int a , bool warn) const
50 if (ascii_to_metric_idx_[a] >=0)
52 int code = ascii_to_metric_idx_[a];
55 return font_inf_->cmi + code;
60 warning (_f ("can't find character number: %d", a));
66 AFM_CharMetricInfo const *
67 Adobe_font_metric::find_char_metric (String nm, bool warn) const
69 std::map<String,int>::const_iterator ai = name_to_metric_dict_.find (nm);
71 if (ai == name_to_metric_dict_.end ())
75 warning (_f ("can't find character called: `%s'", nm.to_str0 ()));
80 return font_inf_->cmi + (*ai).second;
84 Adobe_font_metric::count () const
86 return font_inf_->numOfChars ;
90 Adobe_font_metric::get_char (int code) const
92 AFM_CharMetricInfo const
93 * c = find_ascii_metric (code,false);
94 Box b (Interval (0,0),Interval (0,0));
96 b = afm_bbox_to_box (c->charBBox);
102 read_afm_file (String nm)
104 FILE *f = fopen (nm.to_str0 () , "r");
106 char *check_key = "TfmCheckSum";
107 fgets (s, sizeof (s), f);
110 if (strncmp (s, check_key, strlen (check_key)) == 0)
112 sscanf (s + strlen (check_key), "%ud", &cs);
121 int ok = AFM_parseFile (f, &fi, ~1);
125 error (_f ("Error parsing AFM file: `%s'", nm.to_str0 ()));
130 return Adobe_font_metric::make_afm (fi, cs);
135 actually, AFMs will be printers point, usually, but our .py script dumps
139 afm_bbox_to_box (AFM_BBox bb)
141 return Box (Interval (bb.llx, bb.urx)* (1/1000.0) PT,
142 Interval (bb.lly, bb.ury)* (1/1000.0) PT);
147 Adobe_font_metric::~Adobe_font_metric ()
149 AFM_free (font_inf_);
153 return a molecule, without fontification
156 Adobe_font_metric::find_by_name (String s) const
158 AFM_CharMetricInfo const *cm = find_char_metric (s, false);
163 Why don't we return empty?
171 SCM at = (scm_list_n (ly_symbol2scm ("char"),
172 scm_int2num (cm->code),
175 // at= fontify_atom ((Font_metric*)this, at);
176 Box b = afm_bbox_to_box (cm->charBBox);
178 return Molecule (b, at);