]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/tfm.hh
12648f58127b860c5abc110394113edfaeaae65f
[lilypond.git] / lily / include / tfm.hh
1 /*
2   tfm.hh -- declare Tex_font_metric
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7
8
9   revamped code from GNU Fontutils-0.6
10 */
11
12 /*
13   TODO: aren't there standard libs?  Ideally it is better to just link
14   to a C-library.  */
15
16 #ifndef TFM_HH
17 #define TFM_HH
18
19 #include "array.hh"
20 #include "font-metric.hh"
21
22 /* The type.  */
23 typedef long Fix;
24
25 /* A character code.  Perhaps someday we will allow for 16-bit
26    character codes, but for now we are restricted to 256 characters per
27    font (like TeX and PostScript).  */
28 typedef unsigned char Char_code;
29
30 /* Used in file formats.  */
31 typedef int Byte_count;
32
33 /* The restriction to 256 characters in a TFM file is part of the file
34    format, so this number should only be changed in the (very unlikely)
35    event that the file format changes.  */
36 #define TFM_SIZE 256
37
38 /* Fontwide information.  All real values are in printer's points:
39    72.27 points = 1 inch.  */
40
41 /* TFM_MIN_DESIGNSIZE <= designsize < TFM_MAX_DESIGNSIZE.  */
42 #define TFM_MIN_DESIGNSIZE 1.0
43 #define TFM_MAX_DESIGNSIZE 2048
44
45 /* The maximum number of global font parameters we allow.  */
46 #define TFM_MAX_FONTDIMENS 30
47
48 /* The maximum length of a codingscheme string.  */
49 #define TFM_MAX_CODINGSCHEME_LENGTH 39
50
51 /* Define symbolic names for the numbers of the parameters we
52    recognize.  Some numbers have more than one name.  */
53 #define TFM_SLANT_PARAMETER 1
54 #define TFM_SPACE_PARAMETER 2
55 #define TFM_STRETCH_PARAMETER 3
56 #define TFM_SHRINK_PARAMETER 4
57 #define TFM_XHEIGHT_PARAMETER 5
58 #define TFM_QUAD_PARAMETER 6
59 #define TFM_EXTRASPACE_PARAMETER 7
60 #define TFM_NUM1_PARAMETER 8
61 #define TFM_NUM2_PARAMETER 9
62 #define TFM_NUM3_PARAMETER 10
63 #define TFM_DENOM1_PARAMETER 11
64 #define TFM_DENOM2_PARAMETER 12
65 #define TFM_SUP1_PARAMETER 13
66 #define TFM_SUP2_PARAMETER 14
67 #define TFM_SUP3_PARAMETER 15
68 #define TFM_SUB1_PARAMETER 16
69 #define TFM_SUB2_PARAMETER 17
70 #define TFM_SUPDROP_PARAMETER 18
71 #define TFM_SUBDROP_PARAMETER 19
72 #define TFM_DELIM1_PARAMETER 20
73 #define TFM_DELIM2_PARAMETER 21
74 #define TFM_AXISHEIGHT_PARAMETER 22
75 #define TFM_DEFAULTRULETHICKNESS_PARAMETER 8
76 #define TFM_BIGOPSPACING1_PARAMETER 9
77 #define TFM_BIGOPSPACING2_PARAMETER 10
78 #define TFM_BIGOPSPACING3_PARAMETER 11
79 #define TFM_BIGOPSPACING4_PARAMETER 12
80 #define TFM_BIGOPSPACING5_PARAMETER 13
81
82 /* These are not in any of the standard TeX fonts, but the information
83    is useful nevertheless.  */
84 #define TFM_LEADINGHEIGHT_PARAMETER 23
85 #define TFM_LEADINGDEPTH_PARAMETER 24
86 #define TFM_FONTSIZE_PARAMETER 25
87 #define TFM_VERSION_PARAMETER 26
88
89 struct Tfm_header
90 {
91   Byte_count char_info_pos;
92   Byte_count width_pos;
93   Byte_count height_pos;
94   Byte_count depth_pos;
95   Byte_count italic_correction_pos;
96   Byte_count lig_kern_pos;
97   Byte_count kern_pos;
98   unsigned param_word_count;
99 };
100
101 struct Tfm_info
102 {
103   Char_code first_charcode, last_charcode;
104   U32 checksum;
105   Real design_size;
106   String coding_scheme;
107   unsigned parameter_count;
108   // Real parameters [Tex_font_metric::MAX_FONTDIMENS];
109   Real parameters [TFM_MAX_FONTDIMENS];
110 };
111
112 /* When typesetting, the current character + `character' leads to
113    `ligature'.  The TFM format was extended in 1990 to allow for more
114    complicated ligatures than this, but we do not make those
115    distinctions.  */
116 struct Tfm_ligature
117 {
118   Char_code character;
119   Char_code ligature;
120 };
121
122 /* Similarly for kerns.  */
123 struct Tfm_kern
124 {
125   Char_code character;
126   Real kern;
127 };
128
129 struct Tex_font_char_metric
130 {
131   bool exists_;
132   Char_code code_;
133   Real width_, height_, depth_, italic_correction_;
134   Fix width_fix_, height_fix_, depth_fix_, italic_correction_fix_;
135   Array<Tfm_kern> kerns_;
136   Array<Tfm_ligature> ligatures_;
137
138   Tex_font_char_metric ();
139
140   Box dimensions () const;
141 };
142
143 class Tex_font_metric : public Simple_font_metric
144 {
145   DECLARE_CLASSNAME(Tex_font_metric);
146 public:
147   static SCM make_tfm (String file_name);
148
149   virtual int count () const;
150   virtual Box get_ascii_char (int) const;
151   virtual Real design_size () const;
152   virtual void derived_mark () const;
153   virtual int name_to_index (String) const;
154   virtual String font_name () const;
155
156   Tfm_info const &info () const;
157
158 protected:
159   Tfm_info info_;
160   Tfm_header header_;
161   Array<Tex_font_char_metric> char_metrics_;
162   Array<int> ascii_to_metric_idx_;
163   SCM encoding_table_;
164   String font_name_;
165 private:
166   Tex_font_char_metric const *find_ascii (int ascii, bool warn = true) const;
167   Tex_font_metric ();
168 };
169
170 #endif /* TFM_HH */
171