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