]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   
8 */
9
10 #include <cstdlib>
11 #include <cstdio>
12 #include <cstring>
13
14 #include "source-file.hh"
15
16 char *
17 pfb2pfa (Byte const * pfb, int length)
18 {
19   char * out = new char[1];
20   int olen = 0;
21   
22   Byte const * p = pfb;
23   while (p  < pfb + length)  
24     {
25       if (*p++ != 128)
26         break;
27
28       Byte type = *p++;
29       if (type == 3)
30         break ;
31
32       unsigned seglen =
33         p[0] | (p[1] << 8)
34         | (p[2] << 16) | (p[3] << 24);
35
36       p += 4;
37       if (type == 1)
38         {
39           out = (char*)realloc (out, olen + seglen + 1);
40           char* outp = out + olen ;
41           memcpy (outp, p, seglen);
42           olen += seglen; 
43           p += seglen;
44         }
45       else if (type == 2)
46         {
47           unsigned outlength =  (seglen * 2) + (seglen / 32) + 2;
48
49           out = (char*)realloc (out, olen + outlength + 1);
50
51           char * outp = out + olen;
52           for (int i = seglen; i--;)
53             {
54               sprintf (outp, "%02x", *p++);
55               outp += 2;
56               if (!(i % 32))
57                 {
58                   *outp ++ = '\n';
59                 }
60             }
61
62           olen = outp - out;
63         }
64       
65     }
66   out[olen] = 0;
67
68   return out;
69 }
70
71 LY_DEFINE(ly_pfb_to_pfa, "ly:pfb->pfa",
72           1,0,0, (SCM pfb_path),
73           "Convert the contents of a PFB file to PFA."
74           )
75 {
76   SCM_ASSERT_TYPE(scm_is_string (pfb_path), pfb_path,
77                   SCM_ARG1, __FUNCTION__, "string");
78
79   String path = ly_scm2string (pfb_path);
80   int len ; 
81   char *str = gulp_file (path, &len);
82   char *pfa = pfb2pfa ((Byte*)str, len);
83   
84   SCM pfa_scm = scm_makfrom0str(pfa);
85   free (pfa);
86   delete str;
87   return pfa_scm;
88 }
89