From: Han-Wen Nienhuys Date: Mon, 28 Aug 2006 15:55:21 +0000 (+0000) Subject: * lily/all-font-metrics.cc: remove TFM support. X-Git-Tag: release/2.10.0-2~335 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c9304b1bc2dee05b71604443c77252717d2b56a6;p=lilypond.git * lily/all-font-metrics.cc: remove TFM support. * lily/include/tfm.hh: remove TFM support, TFM reader. * lily/include/binary-source-file.hh: remove Binary_source_file. --- diff --git a/ChangeLog b/ChangeLog index a83ed89be5..dae968bb71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-28 Han-Wen Nienhuys + + * lily/all-font-metrics.cc: remove TFM support. + + * lily/include/tfm.hh: remove TFM support, TFM reader. + + * lily/include/binary-source-file.hh: remove Binary_source_file. + 2006-08-27 Graham Percival * Documentation/topdocs/NEWS.itely: add @c marker for diff --git a/Documentation/topdocs/NEWS.tely b/Documentation/topdocs/NEWS.tely index d786ae4796..254570f11c 100644 --- a/Documentation/topdocs/NEWS.tely +++ b/Documentation/topdocs/NEWS.tely @@ -80,7 +80,7 @@ This feature was sponsored by Steve Doonan. @item Lyric extenders now have tunable padding. -This feature was sponsored by David Griffel +This feature was sponsored by David Griffel. @item Instrument changes are better supported: names in the margin can be diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index f7334849b8..4159cd5a32 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -13,14 +13,12 @@ #include "open-type-font.hh" #include "pango-font.hh" #include "scm-hash.hh" -#include "tfm.hh" #include "warn.hh" static char const *default_font_str0_ = "cmr10"; All_font_metrics::All_font_metrics (string path) { - tfm_dict_ = new Scheme_hash_table; otf_dict_ = new Scheme_hash_table; #if HAVE_PANGO_FT2 @@ -42,7 +40,6 @@ All_font_metrics::All_font_metrics (string path) All_font_metrics::~All_font_metrics () { - tfm_dict_->unprotect (); otf_dict_->unprotect (); #if HAVE_PANGO_FT2 @@ -156,57 +153,11 @@ All_font_metrics::find_otf (string name) return dynamic_cast (unsmob_metrics (val)); } -Tex_font_metric * -All_font_metrics::find_tfm (string name) -{ - SCM sname = ly_symbol2scm (name.c_str ()); - SCM name_string = scm_makfrom0str (name.c_str ()); - SCM val; - if (!tfm_dict_->try_retrieve (sname, &val)) - { - string file_name; - - if (file_name.empty ()) - { - /* FIXME: should add "cork-" prefix to lm* fonts. How to do - that, cleanly? */ - string p = kpathsea_find_file (name, "tfm"); - if (p.length ()) - file_name = p; - } - - if (file_name.empty ()) - file_name = search_path_.find (name + ".tfm"); - if (file_name.empty ()) - return 0; - - if (be_verbose_global) - progress_indication ("[" + file_name); - - val = Tex_font_metric::make_tfm (file_name); - - if (be_verbose_global) - progress_indication ("]"); - - unsmob_metrics (val)->file_name_ = file_name; - unsmob_metrics (val)->description_ = scm_cons (name_string, - scm_from_double (1.0)); - tfm_dict_->set (sname, val); - unsmob_metrics (val)->unprotect (); - } - - return dynamic_cast (unsmob_metrics (val)); -} - Font_metric * All_font_metrics::find_font (string name) { Font_metric *f = find_otf (name); - if (!f) - { - f = find_tfm (name); - } if (!f) { @@ -216,9 +167,6 @@ All_font_metrics::find_font (string name) string def_name = default_font_str0_; - if (!f) - f = find_tfm (def_name); - if (!f) { error (_f ("can't find default font: `%s'", def_name.c_str ())); diff --git a/lily/binary-source-file.cc b/lily/binary-source-file.cc deleted file mode 100644 index 3a8728694c..0000000000 --- a/lily/binary-source-file.cc +++ /dev/null @@ -1,98 +0,0 @@ -/* - binary-source-file.cc -- implement Binary_source_file - - source file of the LilyPond music typesetter - - (c) 1997--2006 Jan Nieuwenhuizen -*/ - -#include // INT_MAX -using namespace std; - -#include "binary-source-file.hh" -#include "string-convert.hh" - -Binary_source_file::Binary_source_file (string &file_name_string) - : Source_file (file_name_string) -{ -} - -Binary_source_file::~Binary_source_file () -{ -} - -string -Binary_source_file::quote_input (char const *pos_str0) const -{ - assert (this); - if (!contains (pos_str0)) - return ""; - - char const *begin_str0 = max (pos_str0 - 8, c_str ()); - char const *end_str0 = min (pos_str0 + 7, c_str () + length ()); - - string pre_string (begin_str0, pos_str0 - begin_str0); - pre_string = String_convert::bin2hex (pre_string); - for (ssize i = 2; i < pre_string.length (); i += 3) - pre_string = pre_string.substr (0, i) - + " " + pre_string.substr (i, NPOS); - string post_string (pos_str0, end_str0 - pos_str0); - post_string = String_convert::bin2hex (post_string); - for (ssize i = 2; i < post_string.length (); i += 3) - post_string = post_string.substr (0, i) - + " " + post_string.substr (i, NPOS); - - string str = pre_string - + to_string ('\n') - + to_string (' ', pre_string.length () + 1) - + post_string; - return str; -} - -int -Binary_source_file::get_line (char const *pos_str0) const -{ - if (!contains (pos_str0)) - return 0; - - return pos_str0 - c_str (); -} - -U8 -Binary_source_file::get_U8 () -{ -#if 0 // FIXME - return *(U8 *)forward_str0 (1); -#endif - assert (false); - return 0; -} - -U16 -Binary_source_file::get_U16 () -{ - U16 b; - - b = get_U8 () << 8; - b |= get_U8 (); - - return b; -} - -/* - naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun) -*/ - -U32 -Binary_source_file::get_U32 () -{ - U32 b; - - b = get_U8 () << 24; - b |= get_U8 () << 16; - b |= get_U8 () << 8; - b |= get_U8 (); - - return b; -} - diff --git a/lily/include/all-font-metrics.hh b/lily/include/all-font-metrics.hh index 59cc9f86ea..c8c0de2f0a 100644 --- a/lily/include/all-font-metrics.hh +++ b/lily/include/all-font-metrics.hh @@ -23,7 +23,6 @@ */ class All_font_metrics { - Scheme_hash_table *tfm_dict_; Scheme_hash_table *otf_dict_; File_path search_path_; @@ -44,7 +43,6 @@ public: Real scale); #endif - Tex_font_metric *find_tfm (string); Font_metric *find_font (string name); Open_type_font *find_otf (string name); SCM font_descriptions () const; diff --git a/lily/include/binary-source-file.hh b/lily/include/binary-source-file.hh deleted file mode 100644 index b0a3ed357f..0000000000 --- a/lily/include/binary-source-file.hh +++ /dev/null @@ -1,27 +0,0 @@ -// -// binary-source-file.hh -- declare Binary_source_file -// -// (c) 1997--2006 Jan Nieuwenhuizen - -#ifndef BINARY_SOURCE_FILE_HH -#define BINARY_SOURCE_FILE_HH - -#include "source-file.hh" - -class Binary_source_file : public Source_file -{ -public: - Binary_source_file (string &file_name_string); - virtual ~Binary_source_file (); - - U8 get_U8 (); - U16 get_U16 (); - U32 get_U32 (); - Byte get_Byte () {return get_U8 (); } - int get_int () { return get_U32 (); } - - virtual string quote_input (char const *pos_str0) const; - virtual int get_line (char const *pos_str0) const; -}; - -#endif // BINARY_SOURCE_FILE_ diff --git a/lily/include/kpath.hh b/lily/include/kpath.hh index baffaf1ffc..f71d891537 100644 --- a/lily/include/kpath.hh +++ b/lily/include/kpath.hh @@ -12,7 +12,6 @@ #include "std-string.hh" string kpathsea_find_tfm (char const *name); -void initialize_kpathsea (char *av0); #endif /* KPATH_HH */ diff --git a/lily/include/tfm-reader.hh b/lily/include/tfm-reader.hh deleted file mode 100644 index 91433ad7af..0000000000 --- a/lily/include/tfm-reader.hh +++ /dev/null @@ -1,44 +0,0 @@ -/* - tfm-reader.hh -- declare Tex_font_metric_reader - - source file of the GNU LilyPond music typesetter - - (c) 1999--2006 Jan Nieuwenhuizen - - - revamped code from GNU Fontutils-0.6 -*/ - -#ifndef TFM_READER_HH -#define TFM_READER_HH - -#include "tfm.hh" -#include "binary-source-file.hh" - -class Tex_font_metric_reader -{ -private: - Real get_U32_fix (); - Real get_U32_fix_scaled (); - string get_bcpl_string (); - void read_header (); - void read_params (); - void read_char_metrics (); - Tex_font_char_metric read_char_metric (Char_code code); - Tex_font_char_metric read_char (); - void read_lig_kern_program (vector *ligatures, - vector *kerns); - - Binary_source_file input_; - -public: - Tex_font_metric_reader (string name); - - Tfm_info info_; - Tfm_header header_; - vector char_metrics_; - vector ascii_to_metric_idx_; -}; - -#endif /* TFM_READER_HH */ - diff --git a/lily/include/tfm.hh b/lily/include/tfm.hh deleted file mode 100644 index 4aa4845d7d..0000000000 --- a/lily/include/tfm.hh +++ /dev/null @@ -1,173 +0,0 @@ -/* - tfm.hh -- declare Tex_font_metric - - source file of the GNU LilyPond music typesetter - - (c) 1999--2006 Jan Nieuwenhuizen - - - revamped code from GNU Fontutils-0.6 -*/ - -/* - TODO: aren't there standard libs? Ideally it is better to just link - to a C-library. */ - -#ifndef TFM_HH -#define TFM_HH - -#include "std-vector.hh" -#include "font-metric.hh" - -/* The type. */ -typedef long Fix; - -/* A character code. Perhaps someday we will allow for 16-bit - character codes, but for now we are restricted to 256 characters per - font (like TeX and PostScript). */ -typedef unsigned char Char_code; - -/* Used in file formats. */ -typedef int Byte_count; - -/* The restriction to 256 characters in a TFM file is part of the file - format, so this number should only be changed in the (very unlikely) - event that the file format changes. */ -#define TFM_SIZE 256 - -/* Fontwide information. All real values are in printer's points: - 72.27 points = 1 inch. */ - -/* TFM_MIN_DESIGNSIZE <= designsize < TFM_MAX_DESIGNSIZE. */ -#define TFM_MIN_DESIGNSIZE 1.0 -#define TFM_MAX_DESIGNSIZE 2048 - -/* The maximum number of global font parameters we allow. */ -#define TFM_MAX_FONTDIMENS 30 - -/* The maximum length of a codingscheme string. */ -#define TFM_MAX_CODINGSCHEME_LENGTH 39 - -/* Define symbolic names for the numbers of the parameters we - recognize. Some numbers have more than one name. */ -#define TFM_SLANT_PARAMETER 1 -#define TFM_SPACE_PARAMETER 2 -#define TFM_STRETCH_PARAMETER 3 -#define TFM_SHRINK_PARAMETER 4 -#define TFM_XHEIGHT_PARAMETER 5 -#define TFM_QUAD_PARAMETER 6 -#define TFM_EXTRASPACE_PARAMETER 7 -#define TFM_NUM1_PARAMETER 8 -#define TFM_NUM2_PARAMETER 9 -#define TFM_NUM3_PARAMETER 10 -#define TFM_DENOM1_PARAMETER 11 -#define TFM_DENOM2_PARAMETER 12 -#define TFM_SUP1_PARAMETER 13 -#define TFM_SUP2_PARAMETER 14 -#define TFM_SUP3_PARAMETER 15 -#define TFM_SUB1_PARAMETER 16 -#define TFM_SUB2_PARAMETER 17 -#define TFM_SUPDROP_PARAMETER 18 -#define TFM_SUBDROP_PARAMETER 19 -#define TFM_DELIM1_PARAMETER 20 -#define TFM_DELIM2_PARAMETER 21 -#define TFM_AXISHEIGHT_PARAMETER 22 -#define TFM_DEFAULTRULETHICKNESS_PARAMETER 8 -#define TFM_BIGOPSPACING1_PARAMETER 9 -#define TFM_BIGOPSPACING2_PARAMETER 10 -#define TFM_BIGOPSPACING3_PARAMETER 11 -#define TFM_BIGOPSPACING4_PARAMETER 12 -#define TFM_BIGOPSPACING5_PARAMETER 13 - -/* These are not in any of the standard TeX fonts, but the information - is useful nevertheless. */ -#define TFM_LEADINGHEIGHT_PARAMETER 23 -#define TFM_LEADINGDEPTH_PARAMETER 24 -#define TFM_FONTSIZE_PARAMETER 25 -#define TFM_VERSION_PARAMETER 26 - -struct Tfm_header -{ - Byte_count char_info_pos; - Byte_count width_pos; - Byte_count height_pos; - Byte_count depth_pos; - Byte_count italic_correction_pos; - Byte_count lig_kern_pos; - Byte_count kern_pos; - unsigned param_word_count; -}; - -struct Tfm_info -{ - Char_code first_charcode, last_charcode; - U32 checksum; - Real design_size; - string coding_scheme; - unsigned parameter_count; - // Real parameters [Tex_font_metric::MAX_FONTDIMENS]; - Real parameters [TFM_MAX_FONTDIMENS]; -}; - -/* When typesetting, the current character + `character' leads to - `ligature'. The TFM format was extended in 1990 to allow for more - complicated ligatures than this, but we do not make those - distinctions. */ -struct Tfm_ligature -{ - Char_code character; - Char_code ligature; -}; - -/* Similarly for kerns. */ -struct Tfm_kern -{ - Char_code character; - Real kern; -}; - -struct Tex_font_char_metric -{ - bool exists_; - Char_code code_; - Real width_, height_, depth_, italic_correction_; - Fix width_fix_, height_fix_, depth_fix_, italic_correction_fix_; - vector kerns_; - vector ligatures_; - - Tex_font_char_metric (); - - Box dimensions () const; -}; - -class Tex_font_metric : public Simple_font_metric -{ - DECLARE_CLASSNAME(Tex_font_metric); - -public: - static SCM make_tfm (string file_name); - - vsize count () const; - Box get_ascii_char (vsize) const; - Real design_size () const; - void derived_mark () const; - vsize name_to_index (string) const; - string font_name () const; - - Tfm_info const &info () const; - -protected: - Tfm_info info_; - Tfm_header header_; - vector char_metrics_; - vector ascii_to_metric_idx_; - SCM encoding_table_; - string font_name_; - -private: - Tex_font_char_metric const *find_ascii (vsize ascii, bool warn = true) const; - Tex_font_metric (); -}; - -#endif /* TFM_HH */ - diff --git a/lily/tfm-reader.cc b/lily/tfm-reader.cc deleted file mode 100644 index 58e5b124d3..0000000000 --- a/lily/tfm-reader.cc +++ /dev/null @@ -1,310 +0,0 @@ -/* - tfm-reader.cc -- implement Tex_font_metric_reader - - source file of the GNU LilyPond music typesetter - - (c) 1999--2006 Jan Nieuwenhuizen - - - some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c -*/ - -#include "tfm-reader.hh" - -#include "international.hh" -#include "string-convert.hh" -#include "warn.hh" - -#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 (string name) - : input_ (name) -{ - - for (vsize i = 0; i < TFM_SIZE; i++) - ascii_to_metric_idx_.push_back (VPOS); - - read_header (); - read_params (); - read_char_metrics (); -} - -static const Real -fix_to_real (Fix f) -{ - Real r = f / FIX_UNITY + ((Real) (f % FIX_UNITY) / (Real) FIX_UNITY); - return r; -} - -/* Most quantities are fixed-point fractions. */ - -Real -Tex_font_metric_reader::get_U32_fix () -{ - return fix_to_real (input_.get_U32 ()); -} - -/* Dimensions are a `Fix' scaled by the design size. */ - -Real -Tex_font_metric_reader::get_U32_fix_scaled () -{ - return get_U32_fix () * info_.design_size; -} - -string -Tex_font_metric_reader::get_bcpl_string () -{ - string str; - -#if 0 // FIXME. - U8 length_u8 = input_.get_U8 (); - string str = input_.get_string (length_u8); -#endif - return str; -} - -/* Here we read the information at the beginning of the file. We store - the result into the static variables `global_info' and - `tfm_header'. */ -void -Tex_font_metric_reader::read_header () -{ - U16 file_length = input_.get_U16 (); - (void) file_length; - U16 header_length = 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 (); - U16 italic_correction_word_count = input_.get_U16 (); - U16 lig_kern_word_count = input_.get_U16 (); - U16 kern_word_count = input_.get_U16 (); - (void)kern_word_count; - U16 extensible_word_count = input_.get_U16 (); - (void)extensible_word_count; - - 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; - header_.kern_pos = header_.lig_kern_pos + lig_kern_word_count * 4; - /* We don't care about the extensible table. */ - - if (header_length < 2) - /* 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 ().c_str (), header_length)); - - 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. */ - info_.coding_scheme = header_length > 2 - ? get_bcpl_string () : "unspecified"; -} - -/* Although TFM files are only usable by TeX if they have at least seven - parameters, that is not a requirement of the file format itself, so - we don't impose it. And they can have many more than seven, of - course. We do impose a limit of TFM_MAX_FONT_PARAMETERS. We assume - that `tfm_header' has already been filled in. */ - -void -Tex_font_metric_reader::read_params () -{ - /* If we have no font parameters at all, we're done. */ - if (header_.param_word_count == 0) - return; - - //brrr - /* Move to the beginning of the parameter table in the file. */ - -#if 0 - // FIXME. - input_.seek_str0 (-4 * header_.param_word_count); -#endif - - /* It's unlikely but possible that this TFM file has more fontdimens - than we can deal with. */ - 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_string ().c_str (), - 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. */ - info_.parameters[ (TFM_SLANT_PARAMETER) - 1] = get_U32_fix (); - - 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 - static `tfm_char_table'. We return a copy of that variable. */ - -void -Tex_font_metric_reader::read_char_metrics () -{ - 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_) - ascii_to_metric_idx_[tfm_char.code_] = char_metrics_.size (); - char_metrics_.push_back (tfm_char); - } -} - -/* Read the character CODE. If the character doesn't exist, return - NULL. If it does, save the information in `tfm_char_table', as well - as returning it. */ - -Tex_font_char_metric -Tex_font_metric_reader::read_char_metric (Char_code code) -{ - Tex_font_char_metric tfm_char; - - /* If the character is outside the declared bounds in the file, don't - try to read it. */ - if (code < info_.first_charcode || code > info_.last_charcode) - return tfm_char; - -#if 0 // FIXME. - //brr - /* Move to the appropriate place in the `char_info' array. */ - input_.seek_str0 (header_.char_info_pos + (code - info_.first_charcode) * 4); -#endif - - /* Read the character. */ - tfm_char = read_char (); - - 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). */ - -Tex_font_char_metric -Tex_font_metric_reader::read_char () -{ - /* Read the char_info word. */ - U8 width_index = input_.get_U8 (); - - U8 packed; - packed = input_.get_U8 (); - U8 height_index = (packed & 0xf0) >> 4; - U8 depth_index = packed & 0x0f; - - packed = input_.get_U8 (); - U8 italic_correction_index = (packed & 0xfc) >> 6; - U8 tag = packed & 0x3; - - U8 remainder = input_.get_U8 (); - - Tex_font_char_metric tfm_char; - - // FIXME. -#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); - GET_CHAR_DIMEN (depth); - GET_CHAR_DIMEN (italic_correction); - - /* The other condition for a character existing is that it be between - 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_ = width_index != 0; - - if (tag == 1) - { -#if 0 // FIXME. - input_.seek_str0 (header_.lig_kern_pos + remainder * 4); -#endif - read_lig_kern_program (&tfm_char.ligatures_, &tfm_char.kerns_); - } - - /* We don't handle the other tags. */ - return tfm_char; -} - -/* Read a ligature/kern program at the current position, storing the - result into *LIGATURE and *KERN. We don't distinguish all the kinds - of ligatures that Metafont can output. */ - -#define STOP_FLAG 128 -#define KERN_FLAG 128 - -void -Tex_font_metric_reader::read_lig_kern_program (vector *ligatures, vector *kerns) -{ - bool end_b; - - do - { - end_b = input_.get_U8 () >= STOP_FLAG; - - U8 next_char = input_.get_U8 (); - bool kern_step_b = input_.get_U8 () >= KERN_FLAG; - U8 remainder = input_.get_U8 (); - - if (kern_step_b) - { - Tfm_kern kern_element; - kern_element.character = next_char; - -#if 0 - char const *old_pos = input_.pos_str0 (); - input_.seek_str0 (header_.kern_pos + remainder * 4); -#endif - - kern_element.kern = get_U32_fix_scaled (); - - // FIXME - /// input_.set_pos (old_pos); - - kerns->push_back (kern_element); - } - else - { - Tfm_ligature ligature_element; - ligature_element.character = next_char; - ligature_element.ligature = remainder; - ligatures->push_back (ligature_element); - } - } - while (!end_b); -} - diff --git a/lily/tfm.cc b/lily/tfm.cc deleted file mode 100644 index 3f415802e4..0000000000 --- a/lily/tfm.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - tfm.cc -- implement Tex_font_metric - - source file of the GNU LilyPond music typesetter - - (c) 1999--2006 Jan Nieuwenhuizen - - some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c -*/ - -#include "tfm.hh" - -#include "dimensions.hh" -#include "file-name.hh" -#include "international.hh" -#include "string-convert.hh" -#include "tfm-reader.hh" -#include "warn.hh" - -static Tex_font_char_metric dummy_static_char_metric; - -Tex_font_char_metric::Tex_font_char_metric () -{ - exists_ = false; - code_ = 0;; - width_ = 0; - height_ = 0; - depth_ = 0; - italic_correction_ = 0; - width_fix_ = 0; - height_fix_ = 0; - depth_fix_ = 0; - italic_correction_fix_ = 0; -} - -Box -Tex_font_char_metric::dimensions () const -{ - if (!exists_) - { - Box b; - b.set_empty (); - return b; - } - - Real d = -depth_; - Real point_constant = 1 PT; - - return Box (Interval (0, width_ * point_constant), - Interval (min (d, height_) * point_constant, - max (d, height_) * point_constant)); -} - -Tex_font_metric::Tex_font_metric () -{ - encoding_table_ = SCM_EOL; -} - -void -Tex_font_metric::derived_mark () const -{ - scm_gc_mark (encoding_table_); -} - -Tex_font_char_metric const * -Tex_font_metric::find_ascii (vsize ascii, bool warn) const -{ - if (ascii != VPOS && ascii < ascii_to_metric_idx_.size () - && ascii_to_metric_idx_[ascii] != VPOS) - return &char_metrics_[ascii_to_metric_idx_ [ascii]]; - else if (warn) - warning (_f ("can't find ascii character: %d", ascii)); - return &dummy_static_char_metric; -} - -/* UGH: glyphs need not be consecutive in TFM. */ -vsize -Tex_font_metric::count () const -{ - for (vsize i = ascii_to_metric_idx_.size (); i--;) - if (ascii_to_metric_idx_[i] != VPOS) - return i + 1; - return 0; -} - -Box -Tex_font_metric::get_ascii_char (vsize a) const -{ - Box b = find_ascii (a)->dimensions (); - return b; -} - -SCM -Tex_font_metric::make_tfm (string file_name) -{ - Tex_font_metric *tfm = new Tex_font_metric; - Tex_font_metric_reader reader (file_name); - - tfm->info_ = reader.info_; - tfm->header_ = reader.header_; - tfm->char_metrics_ = reader.char_metrics_; - tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_; - - File_name fn (file_name); - tfm->font_name_ = fn.base_; - return tfm->self_scm (); -} - -Tfm_info const & -Tex_font_metric::info () const -{ - return info_; -} - -Real -Tex_font_metric::design_size () const -{ - return info_.design_size * point_constant; -} - -string -Tex_font_metric::font_name () const -{ - return font_name_; -} - -vsize -Tex_font_metric::name_to_index (string) const -{ - assert (false); - return 0; -}