X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftfm-reader.cc;h=c7ca5ee6c9eb40928e8b5db93dd1d10dd58a5b7d;hb=f803dfe5c67d7a51f3b9b347f41fe43005963810;hp=31fea32ab275276ee93c52511bbc324390ca2c4b;hpb=82731e802565546441c401a84a13b486e54eb760;p=lilypond.git diff --git a/lily/tfm-reader.cc b/lily/tfm-reader.cc index 31fea32ab2..c7ca5ee6c9 100644 --- a/lily/tfm-reader.cc +++ b/lily/tfm-reader.cc @@ -1,47 +1,36 @@ -/* - tfm-reader.cc -- implement Tex_font_metric_reader - +/* + tfm-reader.cc -- implement Tex_font_metric_reader + source file of the GNU LilyPond music typesetter - - (c) 1999 Jan Nieuwenhuizen - + + (c) 1999--2005 Jan Nieuwenhuizen + some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c - */ +*/ #include "tfm-reader.hh" + #include "string-convert.hh" -#include "debug.hh" #include "warn.hh" -#define format_str String_convert::form_str -#define FIX_UNITY (1 << 20) +#define format_string String_convert::form_string +#define FIX_UNITY \ + (1 << 20) static const Real fix_to_real (Fix f); - -Tex_font_metric_reader::Tex_font_metric_reader (Tex_font_metric* fp, String name) +Tex_font_metric_reader::Tex_font_metric_reader (String name) : input_ (name) { - tfm_l_=fp; - tfm_l_->clear (TFM_SIZE); + + for (int i = 0; i < TFM_SIZE; i++) + ascii_to_metric_idx_.push (-1); + read_header (); read_params (); read_char_metrics (); - -} - -Tex_font_metric * -Tex_font_metric_reader::read_file (String name) -{ - Tex_font_metric * tfmp = new Tex_font_metric; - Tex_font_metric_reader tfm_reader (tfmp, name); - - return tfmp; } - - - static const Real fix_to_real (Fix f) { @@ -52,7 +41,7 @@ fix_to_real (Fix f) /* Most quantities are fixed-point fractions. */ Real -Tex_font_metric_reader::get_U32_fix_f () +Tex_font_metric_reader::get_U32_fix () { return fix_to_real (input_.get_U32 ()); } @@ -60,16 +49,16 @@ Tex_font_metric_reader::get_U32_fix_f () /* Dimensions are a `Fix' scaled by the design size. */ Real -Tex_font_metric_reader::get_U32_fix_scaled_f () +Tex_font_metric_reader::get_U32_fix_scaled () { - return get_U32_fix_f () * tfm_l_->info_.design_size; + return get_U32_fix () * info_.design_size; } String -Tex_font_metric_reader::get_bcpl_str () +Tex_font_metric_reader::get_bcpl_string () { U8 length_u8 = input_.get_U8 (); - String str = input_.get_str (length_u8); + String str = input_.get_string (length_u8); return str; } @@ -83,8 +72,8 @@ Tex_font_metric_reader::read_header () (void) file_length; U16 header_length = input_.get_U16 (); - tfm_l_->info_.first_charcode = input_.get_U16 (); - tfm_l_->info_.last_charcode = input_.get_U16 (); + info_.first_charcode = input_.get_U16 (); + info_.last_charcode = input_.get_U16 (); U16 width_word_count = input_.get_U16 (); U16 height_word_count = input_.get_U16 (); U16 depth_word_count = input_.get_U16 (); @@ -94,39 +83,36 @@ Tex_font_metric_reader::read_header () (void)kern_word_count; U16 extensible_word_count = input_.get_U16 (); (void)extensible_word_count; - - tfm_l_->header_.param_word_count = input_.get_U16 (); - tfm_l_->info_.parameter_count = tfm_l_->header_.param_word_count; - - tfm_l_->header_.char_info_pos = (6 + header_length) * 4; - tfm_l_->header_.width_pos = tfm_l_->header_.char_info_pos - + (tfm_l_->info_.last_charcode - - tfm_l_->info_.first_charcode + 1) * 4; - tfm_l_->header_.height_pos = tfm_l_->header_.width_pos + width_word_count * 4; - tfm_l_->header_.depth_pos = tfm_l_->header_.height_pos + height_word_count * 4; - tfm_l_->header_.italic_correction_pos = tfm_l_->header_.depth_pos - + depth_word_count * 4; - tfm_l_->header_.lig_kern_pos = tfm_l_->header_.italic_correction_pos + + header_.param_word_count = input_.get_U16 (); + info_.parameter_count = header_.param_word_count; + + header_.char_info_pos = (6 + header_length) * 4; + header_.width_pos = header_.char_info_pos + + (info_.last_charcode + - info_.first_charcode + 1) * 4; + header_.height_pos = header_.width_pos + width_word_count * 4; + header_.depth_pos = header_.height_pos + height_word_count * 4; + header_.italic_correction_pos = header_.depth_pos + + depth_word_count * 4; + header_.lig_kern_pos = header_.italic_correction_pos + italic_correction_word_count * 4; - tfm_l_->header_.kern_pos = tfm_l_->header_.lig_kern_pos + lig_kern_word_count * 4; + header_.kern_pos = header_.lig_kern_pos + lig_kern_word_count * 4; /* We don't care about the extensible table. */ if (header_length < 2) - error (_f ("TFM header of `%s' has only %u word(s)", - input_.name_str ().ch_C (), header_length)); + /* Not using ngettext's plural feature here, as this message is + more of a programming error. */ + error (_f ("TFM header of `%s' has only %u word (s)", + input_.name_string ().to_str0 (), header_length)); - tfm_l_->info_.checksum = input_.get_U32 (); - tfm_l_->info_.design_size = get_U32_fix_f (); + info_.checksum = input_.get_U32 (); + info_.design_size = get_U32_fix (); /* Although the coding scheme might be interesting to the caller, the font family and face byte probably aren't. So we don't read them. */ - tfm_l_->info_.coding_scheme = header_length > 2 - ? get_bcpl_str () : "unspecified"; - - DEBUG_OUT << format_str ("TFM checksum = %u, design_size = %fpt, coding scheme = `%s'.\n", - tfm_l_->info_.checksum, - tfm_l_->info_.design_size, - tfm_l_->info_.coding_scheme.ch_C ()); + info_.coding_scheme = header_length > 2 + ? get_bcpl_string () : "unspecified"; } /* Although TFM files are only usable by TeX if they have at least seven @@ -139,35 +125,30 @@ void Tex_font_metric_reader::read_params () { /* If we have no font parameters at all, we're done. */ - if (tfm_l_->header_.param_word_count == 0) + if (header_.param_word_count == 0) return; //brrr /* Move to the beginning of the parameter table in the file. */ - input_.seek_ch_C (-4 * tfm_l_->header_.param_word_count); + input_.seek_str0 (-4 * header_.param_word_count); /* It's unlikely but possible that this TFM file has more fontdimens than we can deal with. */ - if (tfm_l_->header_.param_word_count > TFM_MAX_FONTDIMENS) + if (header_.param_word_count > TFM_MAX_FONTDIMENS) { warning (_f ("%s: TFM file has %u parameters, which is more than the %u I can handle", - input_.name_str ().ch_C (), - tfm_l_->header_.param_word_count, + input_.name_string ().to_str0 (), + header_.param_word_count, TFM_MAX_FONTDIMENS)); - tfm_l_->header_.param_word_count = TFM_MAX_FONTDIMENS; + header_.param_word_count = TFM_MAX_FONTDIMENS; } /* The first parameter is different than all the rest, because it isn't scaled by the design size. */ - tfm_l_->info_.parameters[(TFM_SLANT_PARAMETER) - 1] = get_U32_fix_f (); + info_.parameters[ (TFM_SLANT_PARAMETER) - 1] = get_U32_fix (); - for (Char_code i = 2; i <= tfm_l_->header_.param_word_count; i++) - tfm_l_->info_.parameters[i - 1] = get_U32_fix_scaled_f (); - -#ifdef PRINT - for (Char_code i = 1; i <= tfm_l_->header_.param_word_count; i++) - DEBUG_OUT << format_str ("TFM parameter %d: %.3f", i, tfm_l_->info_.parameters[i - 1]); -#endif + for (Char_code i = 2; i <= header_.param_word_count; i++) + info_.parameters[i - 1] = get_U32_fix_scaled (); } /* Read every character in the TFM file, storing the result in the @@ -176,12 +157,12 @@ Tex_font_metric_reader::read_params () void Tex_font_metric_reader::read_char_metrics () { - for (int i = tfm_l_->info_.first_charcode; i <= tfm_l_->info_.last_charcode; i++) + for (int i = info_.first_charcode; i <= info_.last_charcode; i++) { Tex_font_char_metric tfm_char = read_char_metric (i); - if (tfm_char.exists_b_) - tfm_l_->ascii_to_metric_idx_[tfm_char.code_] = tfm_l_->char_metrics_.size (); - tfm_l_->char_metrics_.push (tfm_char); + if (tfm_char.exists_) + ascii_to_metric_idx_[tfm_char.code_] = char_metrics_.size (); + char_metrics_.push (tfm_char); } } @@ -196,23 +177,22 @@ Tex_font_metric_reader::read_char_metric (Char_code code) /* If the character is outside the declared bounds in the file, don't try to read it. */ - if (code < tfm_l_->info_.first_charcode || code > tfm_l_->info_.last_charcode) + if (code < info_.first_charcode || code > info_.last_charcode) return tfm_char; - + //brr /* Move to the appropriate place in the `char_info' array. */ - input_.seek_ch_C (tfm_l_->header_.char_info_pos + (code - tfm_l_->info_.first_charcode) * 4); + input_.seek_str0 (header_.char_info_pos + (code - info_.first_charcode) * 4); /* Read the character. */ tfm_char = read_char (); - if (tfm_char.exists_b_) + if (tfm_char.exists_) tfm_char.code_ = code; return tfm_char; } - /* We assume we are positioned at the beginning of a `char_info' word. We read that word to get the indexes into the dimension tables; then we go read the tables to get the values (if the character exists). */ @@ -236,14 +216,14 @@ Tex_font_metric_reader::read_char () Tex_font_char_metric tfm_char; -#define GET_CHAR_DIMEN(d) \ - if (d##_index != 0) \ - { \ - input_.seek_ch_C (tfm_l_->header_.##d##_pos + d##_index*4); \ - tfm_char.d##_fix_ = input_.get_U32 (); \ - tfm_char.d##_ = fix_to_real (tfm_char.d##_fix_) \ - * tfm_l_->info_.design_size; \ - } +#define GET_CHAR_DIMEN(d) \ + if (d##_index != 0) \ + { \ + input_.seek_str0 (header_.d##_pos + d##_index * 4); \ + tfm_char.d##_fix_ = input_.get_U32 (); \ + tfm_char.d##_ = fix_to_real (tfm_char.d##_fix_) \ + * info_.design_size; \ + } GET_CHAR_DIMEN (width); GET_CHAR_DIMEN (height); @@ -254,19 +234,12 @@ Tex_font_metric_reader::read_char () the first and last character codes given in the header. We've already assumed that's true (or we couldn't be positioned at a `char_info_word'). */ - tfm_char.exists_b_ = width_index != 0; - -#ifdef PRINT - DEBUG_OUT << format_str (" width = %f, height = %f, ", - tfm_char.width_, tfm_char.height_); - DEBUG_OUT << format_str ("depth = %f, ic = %f.\n", - tfm_char.depth, tfm_char.italic_correction); -#endif + tfm_char.exists_ = width_index != 0; if (tag == 1) { - input_.seek_ch_C (tfm_l_->header_.lig_kern_pos + remainder * 4); - read_lig_kern_program (&tfm_char.ligature_arr_, &tfm_char.kern_arr_); + input_.seek_str0 (header_.lig_kern_pos + remainder * 4); + read_lig_kern_program (&tfm_char.ligatures_, &tfm_char.kerns_); } /* We don't handle the other tags. */ @@ -281,7 +254,7 @@ Tex_font_metric_reader::read_char () #define KERN_FLAG 128 void -Tex_font_metric_reader::read_lig_kern_program (Array * ligature_arr_p, Array * kern_arr_p) +Tex_font_metric_reader::read_lig_kern_program (Array *ligatures, Array *kerns) { bool end_b; @@ -293,39 +266,26 @@ Tex_font_metric_reader::read_lig_kern_program (Array * ligature_ar bool kern_step_b = input_.get_U8 () >= KERN_FLAG; U8 remainder = input_.get_U8 (); -#ifdef PRINT - DEBUG_OUT << format_str (" if next = %u (%c), ", next_char, next_char); -#endif - if (kern_step_b) { Tfm_kern kern_element; kern_element.character = next_char; - char const* old_pos = input_.pos_ch_C (); - input_.seek_ch_C (tfm_l_->header_.kern_pos + remainder * 4); - kern_element.kern = get_U32_fix_scaled_f (); + char const *old_pos = input_.pos_str0 (); + input_.seek_str0 (header_.kern_pos + remainder * 4); + kern_element.kern = get_U32_fix_scaled (); input_.set_pos (old_pos); - kern_arr_p->push (kern_element); - -#ifdef PRINT - DEBUG_OUT << format_str ("kern %f.\n", kern_element.kern); -#endif + kerns->push (kern_element); } else { Tfm_ligature ligature_element; ligature_element.character = next_char; ligature_element.ligature = remainder; - ligature_arr_p->push (ligature_element); - -#ifdef PRINT - DEBUG_OUT format_str ("ligature %d (hex %x).\n", - ligature_element.ligature, - ligature_element.ligature); -#endif + ligatures->push (ligature_element); } - } while (!end_b); + } + while (!end_b); }