X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fafm.cc;h=3db634c58985b7d6bd1fdeee0872ac00e012179c;hb=762ca4af538f1d566e396a1b52e84a6bc6b919f3;hp=b9224648bec3d5e9612b8bdad1787e130a1dbb81;hpb=89bf299597169eeaa5ed7a215b6e808fa849c8cd;p=lilypond.git diff --git a/lily/afm.cc b/lily/afm.cc index b9224648be..3db634c589 100644 --- a/lily/afm.cc +++ b/lily/afm.cc @@ -3,26 +3,33 @@ source file of the Flower Library - (c) 2000 Han-Wen Nienhuys + (c) 2000--2002 Han-Wen Nienhuys */ #include "afm.hh" #include "warn.hh" #include "molecule.hh" +#include "dimensions.hh" Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi) { checksum_ = 0; font_inf_ = fi; - for (int i= 256; i--;) + for (int i= 256 >? fi->numOfChars; i--;) ascii_to_metric_idx_.push (-1); for (int i=0; i < fi->numOfChars; i++) { AFM_CharMetricInfo * c = fi->cmi + i; - ascii_to_metric_idx_[c->code] = i; + /* + Some TeX afm files contain code = -1. We don't know why, let's + ignore it. + + */ + if (c->code >= 0) + ascii_to_metric_idx_[c->code] = i; name_to_metric_dict_[c->name] = i; } } @@ -33,7 +40,7 @@ Adobe_font_metric::make_afm (AFM_Font_info *fi, unsigned int checksum) { Adobe_font_metric * fm = new Adobe_font_metric (fi); fm->checksum_ = checksum; - return fm->self_scm(); + return fm->self_scm (); } @@ -48,7 +55,7 @@ Adobe_font_metric::find_ascii_metric (int a , bool warn) const return font_inf_->cmi + code; } } - else if (warn ) + else if (warn) { warning (_f ("can't find character number: %d", a)); } @@ -59,13 +66,13 @@ Adobe_font_metric::find_ascii_metric (int a , bool warn) const AFM_CharMetricInfo const * Adobe_font_metric::find_char_metric (String nm, bool warn) const { - map::const_iterator ai = name_to_metric_dict_.find (nm); + std::map::const_iterator ai = name_to_metric_dict_.find (nm); if (ai == name_to_metric_dict_.end ()) { if (warn) { - warning (_f ("can't find character called: `%s'", nm.ch_C())); + warning (_f ("can't find character called: `%s'", nm.ch_C ())); } return 0; } @@ -73,13 +80,18 @@ Adobe_font_metric::find_char_metric (String nm, bool warn) const return font_inf_->cmi + (*ai).second; } +int +Adobe_font_metric::count () const +{ + return font_inf_->numOfChars ; +} Box Adobe_font_metric::get_char (int code) const { AFM_CharMetricInfo const * c = find_ascii_metric (code,false); - Box b (Interval (0,0),Interval(0,0)); + Box b (Interval (0,0),Interval (0,0)); if (c) b = afm_bbox_to_box (c->charBBox); @@ -89,7 +101,7 @@ Adobe_font_metric::get_char (int code) const SCM read_afm_file (String nm) { - FILE *f = fopen (nm.ch_C() , "r"); + FILE *f = fopen (nm.ch_C () , "r"); char s[2048]; char *check_key = "TfmCheckSum"; fgets (s, sizeof (s), f); @@ -110,7 +122,7 @@ read_afm_file (String nm) if (ok) { - error (_f ("Error parsing AFM file: %s", nm.ch_C ())); + error (_f ("Error parsing AFM file: `%s'", nm.ch_C ())); exit (2); } fclose (f); @@ -118,12 +130,16 @@ read_afm_file (String nm) return Adobe_font_metric::make_afm (fi, cs); } - + +/* + actually, AFMs will be printers point, usually, but our .py script dumps + real points. + */ Box afm_bbox_to_box (AFM_BBox bb) { - return Box (Interval (bb.llx, bb.urx)* (1/1000.0), - Interval (bb.lly, bb.ury)* (1/1000.0)); + return Box (Interval (bb.llx, bb.urx)* (1/1000.0) PT, + Interval (bb.lly, bb.ury)* (1/1000.0) PT); } @@ -143,12 +159,16 @@ Adobe_font_metric::find_by_name (String s) const if (!cm) { + /* + Why don't we return empty? + */ + Molecule m; m.set_empty (false); return m; } - SCM at = (gh_list (ly_symbol2scm ("char"), + SCM at = (scm_list_n (ly_symbol2scm ("char"), gh_int2scm (cm->code), SCM_UNDEFINED));