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