X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fafm.cc;h=f09d63bad58ce915cad52de595cfcbc345318fdd;hb=f68bbd7a1ed1b0e7146bbbffcbcbb7f9c9bda3cc;hp=1745b683a35ac6c0217b71e5d3766d722367836a;hpb=2522fadff41b2b07313c4967a4f85c147fe9b9c4;p=lilypond.git diff --git a/lily/afm.cc b/lily/afm.cc index 1745b683a3..f09d63bad5 100644 --- a/lily/afm.cc +++ b/lily/afm.cc @@ -3,7 +3,7 @@ source file of the Flower Library - (c) 2000 Han-Wen Nienhuys + (c) 2000--2001 Han-Wen Nienhuys */ #include "afm.hh" @@ -12,6 +12,7 @@ Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi) { + checksum_ = 0; font_inf_ = fi; for (int i= 256; i--;) @@ -21,18 +22,24 @@ Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi) { 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; } } SCM -Adobe_font_metric::make_afm (AFM_Font_info *fi) +Adobe_font_metric::make_afm (AFM_Font_info *fi, unsigned int checksum) { Adobe_font_metric * fm = new Adobe_font_metric (fi); - - return fm->self_scm(); + fm->checksum_ = checksum; + return fm->self_scm (); } @@ -47,7 +54,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)); } @@ -58,13 +65,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; } @@ -72,13 +79,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 ascii_to_metric_idx_.size (); +} 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); @@ -88,19 +100,33 @@ 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); + + unsigned int cs = 0; + if (strncmp (s, check_key, strlen (check_key)) == 0) + { + sscanf (s + strlen (check_key), "%ud", &cs); + } + else + { + rewind (f); + } + AFM_Font_info * fi; int ok = AFM_parseFile (f, &fi, ~1); 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); - return Adobe_font_metric::make_afm (fi); + return Adobe_font_metric::make_afm (fi, cs); } @@ -133,7 +159,7 @@ Adobe_font_metric::find_by_name (String s) const return m; } - SCM at = (gh_list (ly_symbol2scm ("char"), + SCM at = (scm_listify (ly_symbol2scm ("char"), gh_int2scm (cm->code), SCM_UNDEFINED));