]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb.cc
438fe78497e8b3ddc6c259803e87197f7b4d0053
[lilypond.git] / lily / pfb.cc
1 /*
2   pfb.cc -- implement pfb conversion.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include <cstdlib>
10 #include <cstdio>
11 #include <cstring>
12 using namespace std;
13
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"
20
21 char *
22 pfb2pfa (Byte const *pfb, int length)
23 {
24   char *out = (char*) malloc(sizeof(char));
25   int olen = 0;
26
27   Byte const *p = pfb;
28   while (p < pfb + length)
29     {
30       if (*p++ != 128)
31         break;
32
33       Byte type = *p++;
34       if (type == 3)
35         break;
36
37       unsigned seglen
38         = p[0] | (p[1] << 8)
39         | (p[2] << 16) | (p[3] << 24);
40
41       p += 4;
42       if (type == 1)
43         {
44           out = (char *)realloc (out, olen + seglen + 1);
45           char *outp = out + olen;
46           memcpy (outp, p, seglen);
47           olen += seglen;
48           p += seglen;
49         }
50       else if (type == 2)
51         {
52           unsigned outlength = (seglen * 2) + (seglen / 32) + 2;
53
54           out = (char *)realloc (out, olen + outlength + 1);
55
56           char *outp = out + olen;
57           for (int i = seglen; i--;)
58             {
59               sprintf (outp, "%02x", *p++);
60               outp += 2;
61               if (! (i % 32))
62                 *outp++ = '\n';
63             }
64
65           olen = outp - out;
66         }
67     }
68   out[olen] = 0;
69
70   return out;
71 }
72