]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb.cc
Issue 4989/2: Fix Type 1 (PFB) font embedding
[lilypond.git] / lily / pfb.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <cstdlib>
21 #include <cstdio>
22 #include <cstring>
23 #include <iomanip>
24 #include <sstream>
25 using namespace std;
26
27 #include "program-option.hh"
28 #include "source-file.hh"
29 #include "memory-stream.hh"
30 #include "open-type-font.hh"
31 #include "main.hh"
32 #include "warn.hh"
33
34 vector<char>
35 pfb2pfa (const vector<char> &pfb)
36 {
37   vector<char> out;
38
39   vector<char>::const_iterator p = pfb.begin ();
40   while (p < pfb.end ())
41     {
42       if (static_cast<Byte>(*p++) != 128)
43         break;
44
45       Byte type = static_cast<Byte>(*p++);
46       if (type == 3)
47         break;
48
49       size_t seglen = static_cast<Byte>(*p++);
50       seglen |= (static_cast<Byte>(*p++) << 8);
51       seglen |= (static_cast<Byte>(*p++) << 16);
52       seglen |= (static_cast<Byte>(*p++) << 24);
53
54       if (type == 1)
55         {
56           copy (p, p + seglen, back_inserter (out));
57           p += seglen;
58         }
59       else if (type == 2)
60         {
61           stringstream ss;
62
63           ss << hex << setfill ('0');
64
65           for (size_t i = seglen; i > 0; --i)
66             {
67               ss << setw (2) << static_cast<int>(static_cast<Byte>(*p++));
68               if (! (i % 32))
69                 ss << '\n';
70             }
71
72           string str = ss.str ();
73           copy (str.begin (), str.end (), back_inserter (out));
74         }
75     }
76
77   return out;
78 }