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