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