Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 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 | 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 | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 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/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 #include <cstdlib> | 20 #include <cstdlib> |
21 #include <cstdio> | 21 #include <cstdio> |
22 #include <cstring> | 22 #include <cstring> |
23 #include <iomanip> | |
24 #include <sstream> | |
23 using namespace std; | 25 using namespace std; |
24 | 26 |
27 #include "international.hh" | |
25 #include "program-option.hh" | 28 #include "program-option.hh" |
26 #include "source-file.hh" | 29 #include "source-file.hh" |
27 #include "memory-stream.hh" | 30 #include "memory-stream.hh" |
28 #include "open-type-font.hh" | 31 #include "open-type-font.hh" |
29 #include "main.hh" | 32 #include "main.hh" |
30 #include "warn.hh" | 33 #include "warn.hh" |
31 | 34 |
32 vector<char> pfb2pfa (const vector<char> &pfb) | 35 vector<char> |
36 pfb2pfa (const vector<char> &pfb) | |
33 { | 37 { |
34 vector<char> out; | 38 vector<char> out; |
35 | 39 |
36 vector<char>::const_iterator p = pfb.begin (); | 40 vector<char>::const_iterator p = pfb.begin (); |
37 while (p < pfb.end ()) | 41 while (p < pfb.end ()) |
38 { | 42 { |
39 if (static_cast<Byte>(*p++) != 128) | 43 if (static_cast<Byte>(*p++) != 128) |
40 break; | 44 { |
45 error (_ ("Segment header of the Type 1 (PFB) font is broken.")); | |
46 break; | |
47 } | |
41 | 48 |
42 Byte type = static_cast<Byte>(*p++); | 49 Byte type = static_cast<Byte>(*p++); |
43 if (type == 3) | 50 if (type == 3) |
44 break; | 51 break; |
45 | 52 |
46 size_t seglen = static_cast<Byte>(*p++); | 53 size_t seglen = static_cast<Byte>(*p++); |
47 seglen |= (static_cast<Byte>(*p++) << 8); | 54 seglen |= (static_cast<Byte>(*p++) << 8); |
48 seglen |= (static_cast<Byte>(*p++) << 16); | 55 seglen |= (static_cast<Byte>(*p++) << 16); |
49 seglen |= (static_cast<Byte>(*p++) << 24); | 56 seglen |= (static_cast<Byte>(*p++) << 24); |
lemzwerg
2016/10/26 13:07:15
I suggest to add a guard against invalid, possibly
| |
57 if ((p + seglen) > pfb.end ()) | |
58 { | |
59 error (_ ("Segment length of the Type 1 (PFB) font is too long.")); | |
60 break; | |
61 } | |
50 | 62 |
51 if (type == 1) | 63 if (type == 1) |
52 { | 64 { |
53 copy (p, p + seglen, back_inserter (out)); | 65 copy (p, p + seglen, back_inserter (out)); |
54 p += seglen; | 66 p += seglen; |
55 } | 67 } |
56 else if (type == 2) | 68 else if (type == 2) |
57 { | 69 { |
70 stringstream ss; | |
71 | |
72 ss << hex << setfill ('0'); | |
73 | |
58 for (size_t i = seglen; i > 0; --i) | 74 for (size_t i = seglen; i > 0; --i) |
59 { | 75 { |
60 char buff[3]; | 76 ss << setw (2) << static_cast<int>(static_cast<Byte>(*p++)); |
61 snprintf (buff, sizeof (buff), "%02x", | |
62 static_cast<int>(static_cast<Byte>(*p++))); | |
lemzwerg
2016/10/26 13:07:15
As above, we should probably add a guard against i
| |
63 out.push_back (buff[0]); | |
64 out.push_back (buff[1]); | |
65 if (! (i % 32)) | 77 if (! (i % 32)) |
66 out.push_back ('\n'); | 78 ss << '\n'; |
67 } | 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; | |
68 } | 88 } |
69 } | 89 } |
70 | 90 |
71 return out; | 91 return out; |
72 } | 92 } |
LEFT | RIGHT |