]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb.cc
Web-ja: update introduction
[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 "international.hh"
28 #include "program-option.hh"
29 #include "source-file.hh"
30 #include "memory-stream.hh"
31 #include "open-type-font.hh"
32 #include "main.hh"
33 #include "warn.hh"
34
35 vector<char>
36 pfb2pfa (const vector<char> &pfb)
37 {
38   vector<char> out;
39
40   vector<char>::const_iterator p = pfb.begin ();
41   while (p < pfb.end ())
42     {
43       if (static_cast<Byte>(*p++) != 128)
44         {
45           error (_ ("Segment header of the Type 1 (PFB) font is broken."));
46           break;
47         }
48
49       Byte type = static_cast<Byte>(*p++);
50       if (type == 3)
51         break;
52
53       size_t seglen = static_cast<Byte>(*p++);
54       seglen |= (static_cast<Byte>(*p++) << 8);
55       seglen |= (static_cast<Byte>(*p++) << 16);
56       seglen |= (static_cast<Byte>(*p++) << 24);
57       if ((p + seglen) > pfb.end ())
58         {
59           error (_ ("Segment length of the Type 1 (PFB) font is too long."));
60           break;
61         }
62
63       if (type == 1)
64         {
65           copy (p, p + seglen, back_inserter (out));
66           p += seglen;
67         }
68       else if (type == 2)
69         {
70           stringstream ss;
71
72           ss << hex << setfill ('0');
73
74           for (size_t i = seglen; i > 0; --i)
75             {
76               ss << setw (2) << static_cast<int>(static_cast<Byte>(*p++));
77               if (! (i % 32))
78                 ss << '\n';
79             }
80
81           string str = ss.str ();
82           copy (str.begin (), str.end (), back_inserter (out));
83         }
84       else
85         {
86           error (_ ("Segment type of the Type 1 (PFB) font is unknown."));
87           break;
88         }
89     }
90
91   return out;
92 }