(parse_symbol_list): Bugfix.
[lilypond/patrick.git] / lily / pfb.cc
blob4af36099383b03ba6653c29bb4be935cc48fc8e5
1 /*
2 pfb.cc -- implement pfb conversion.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
13 #include "program-option.hh"
14 #include "source-file.hh"
15 #include "memory-stream.hh"
16 #include "open-type-font.hh"
17 #include "main.hh"
18 #include "warn.hh"
20 char *
21 pfb2pfa (Byte const *pfb, int length)
23 char *out = new char[1];
24 int olen = 0;
26 Byte const *p = pfb;
27 while (p < pfb + length)
29 if (*p++ != 128)
30 break;
32 Byte type = *p++;
33 if (type == 3)
34 break;
36 unsigned seglen
37 = p[0] | (p[1] << 8)
38 | (p[2] << 16) | (p[3] << 24);
40 p += 4;
41 if (type == 1)
43 out = (char *)realloc (out, olen + seglen + 1);
44 char *outp = out + olen;
45 memcpy (outp, p, seglen);
46 olen += seglen;
47 p += seglen;
49 else if (type == 2)
51 unsigned outlength = (seglen * 2) + (seglen / 32) + 2;
53 out = (char *)realloc (out, olen + outlength + 1);
55 char *outp = out + olen;
56 for (int i = seglen; i--;)
58 sprintf (outp, "%02x", *p++);
59 outp += 2;
60 if (! (i % 32))
62 *outp++ = '\n';
66 olen = outp - out;
70 out[olen] = 0;
72 return out;
75 LY_DEFINE (ly_pfb_to_pfa, "ly:pfb->pfa",
76 1, 0, 0, (SCM pfb_file_name),
77 "Convert the contents of a PFB file to PFA.")
79 SCM_ASSERT_TYPE (scm_is_string (pfb_file_name), pfb_file_name,
80 SCM_ARG1, __FUNCTION__, "string");
82 String file_name = ly_scm2string (pfb_file_name);
83 int len;
85 if (be_verbose_global)
86 progress_indication ("[" + file_name);
88 char *str = gulp_file (file_name, &len);
89 char *pfa = pfb2pfa ((Byte *)str, len);
91 SCM pfa_scm = scm_makfrom0str (pfa);
92 free (pfa);
93 delete str;
94 if (be_verbose_global)
95 progress_indication ("]");
97 return pfa_scm;
101 LY_DEFINE (ly_otf_to_cff, "ly:otf->cff",
102 1, 0, 0, (SCM otf_file_name),
103 "Convert the contents of a OTF file to CFF file, returning it as "
104 " a string.")
106 SCM_ASSERT_TYPE (scm_is_string (otf_file_name), otf_file_name,
107 SCM_ARG1, __FUNCTION__, "string");
109 String file_name = ly_scm2string (otf_file_name);
110 if (be_verbose_global)
111 progress_indication ("[" + file_name);
113 FT_Face face = open_ft_face (file_name);
114 String table = get_otf_table (face, "CFF ");
116 SCM asscm = scm_from_locale_stringn ((char *) table.get_bytes (),
117 table.length ());
119 if (be_verbose_global)
120 progress_indication ("]");
122 return asscm;