diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-30 13:02:29 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-30 13:02:29 +0100 |
| commit | b365da4229b2a9d0ceef632af6880a38ecb65325 (patch) | |
| tree | b37f7c5d68206c6aab456ec44ac666c7f4b6bdf2 /src/stl_binary_reader.cc | |
| parent | 38a5ff713757b9dc0cb67cb09613182c46dc9657 (diff) | |
Various fixes to STL read/write.
Diffstat (limited to 'src/stl_binary_reader.cc')
| -rw-r--r-- | src/stl_binary_reader.cc | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index 6c02526..d0fc266 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -108,17 +108,49 @@ STLBinaryReader::STLBinaryReader (istream& in) sub.from.set_frame (get_timecode (5)); sub.to.set_frame (get_timecode (9)); sub.vertical_position.line = get_int (13, 1) + i; - - /* XXX: justification, effects */ - /* 8Fh is unused space, so trim the string to the first instance of that */ - size_t unused = lines[i].find_first_of ('\x8f'); - if (unused != string::npos) { - lines[i] = lines[i].substr (0, unused); + string text; + for (size_t j = 0; j < lines[i].size(); ++j) { + + unsigned char const c = static_cast<unsigned char> (lines[i][j]); + + if (c == 0x8f) { + /* Unused space i.e. end of line */ + break; + } + + if (c >= 0x80 && c <= 0x83) { + /* Italic or underline control code */ + sub.text = utf_to_utf<char> (iso6937_to_utf16 (text.c_str())); + _subs.push_back (sub); + text.clear (); + } + + switch (c) { + case 0x80: + sub.italic = true; + break; + case 0x81: + sub.italic = false; + break; + case 0x82: + sub.underline = true; + break; + case 0x83: + sub.underline = false; + break; + default: + text += lines[i][j]; + break; + } } - sub.text = utf_to_utf<char> (iso6937_to_utf16 (lines[i].c_str())); - _subs.push_back (sub); + if (!text.empty ()) { + sub.text = utf_to_utf<char> (iso6937_to_utf16 (text.c_str())); + _subs.push_back (sub); + } + + /* XXX: justification */ } } } |
