2 afm-reader.cc -- implement Adobe_font_metric_file
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "direction.hh"
12 #include "data-file.hh"
13 #include "string-convert.hh"
17 parse_box (Array<String> a)
21 b[X_AXIS][SMALLER] = a[i++].value_f ();
22 b[Y_AXIS][SMALLER] = a[i++].value_f ();
23 b[X_AXIS][BIGGER] = a[i++].value_f ();
24 b[Y_AXIS][BIGGER] = a[i++].value_f ();
29 strip_leading_white (String c)
34 c = c.cut_str (i, INT_MAX);
38 Adobe_font_char_metric
39 read_char_metric (String s)
41 Adobe_font_char_metric char_metric;
42 Array<String> a= String_convert::split_arr (s, ';');
43 for (int i=0; i < a.size (); i++)
45 String c = strip_leading_white (a[i]);
47 Array<String> b = String_convert::split_arr (c, ' ');
49 char_metric.C_ = b[1].value_i ();
51 char_metric.WX_ = b[1].value_f ();
53 char_metric.N_ = strip_leading_white (b[1]);
55 char_metric.B_ = parse_box (b.slice (1, b.size()));
61 read_char_metrics (Array<Adobe_font_char_metric> &mets, Data_file &input)
63 while (!input.eof_b ())
65 input.gobble_leading_white ();
66 String s= input.get_line ();
67 if (s == "EndCharMetrics")
69 mets.push (read_char_metric (s));
73 #define READSTRING(k) if (key == #k) { \
74 afm.k ## _ = input.get_line (); continue; }
75 #define READBOX(b) if (key == #b) { \
76 afm.b ## _ = read_box (input); continue; }
77 #define READREAL(r) if (key == #r) { \
78 afm.r ## _ = read_real (input); continue; }
81 read_real(Data_file &d)
83 String s = d.get_word ();
90 read_box ( Data_file &d)
93 b[X_AXIS][SMALLER] = read_real (d);
94 b[Y_AXIS][SMALLER] = read_real (d);
95 b[X_AXIS][BIGGER] = read_real (d);
96 b[Y_AXIS][BIGGER] = read_real (d);
103 Data_file input (fn);
105 assert (!input.eof_b ());
107 Adobe_font_metric afm;
109 while (!input.eof_b ())
111 input.gobble_leading_white ();
112 String w = input.get_word ();
113 if (w == "StartFontMetrics")
118 while (!input.eof_b ())
120 input.gobble_leading_white ();
121 String key = input.get_word ();
122 if (key == "Comment")
125 READSTRING(FontName);
126 READSTRING(FullName);
127 READSTRING(FamilyName);
131 READSTRING(EncodingScheme);
132 READREAL(ItalicAngle);
133 READREAL(UnderlineThickness);
134 READREAL(UnderlinePosition);
136 if (key == "StartCharMetrics")
139 read_char_metrics (afm.char_metrics_, input);
141 if (key == "EndFontMetrics")