Compile fix.
[lilypond.git] / lily / pfb.cc
blob3cee20618921fe8870ca7c2c3437476159be2f29
1 /*
2 pfb.cc -- implement pfb conversion.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
12 using namespace std;
14 #include "program-option.hh"
15 #include "source-file.hh"
16 #include "memory-stream.hh"
17 #include "open-type-font.hh"
18 #include "main.hh"
19 #include "warn.hh"
21 char *
22 pfb2pfa (Byte const *pfb, int length)
24 char *out = new char[1];
25 int olen = 0;
27 Byte const *p = pfb;
28 while (p < pfb + length)
30 if (*p++ != 128)
31 break;
33 Byte type = *p++;
34 if (type == 3)
35 break;
37 unsigned seglen
38 = p[0] | (p[1] << 8)
39 | (p[2] << 16) | (p[3] << 24);
41 p += 4;
42 if (type == 1)
44 out = (char *)realloc (out, olen + seglen + 1);
45 char *outp = out + olen;
46 memcpy (outp, p, seglen);
47 olen += seglen;
48 p += seglen;
50 else if (type == 2)
52 unsigned outlength = (seglen * 2) + (seglen / 32) + 2;
54 out = (char *)realloc (out, olen + outlength + 1);
56 char *outp = out + olen;
57 for (int i = seglen; i--;)
59 sprintf (outp, "%02x", *p++);
60 outp += 2;
61 if (! (i % 32))
62 *outp++ = '\n';
65 olen = outp - out;
68 out[olen] = 0;
70 return out;