diff options
Diffstat (limited to 'src/collection.cc')
| -rw-r--r-- | src/collection.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/collection.cc b/src/collection.cc new file mode 100644 index 0000000..1482b42 --- /dev/null +++ b/src/collection.cc @@ -0,0 +1,73 @@ +/* + Copyright (C) 2026 Carl Hetherington <cth@carlh.net> + + This file is part of libttf. + + libttf is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + libttf is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libttf. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "collection.h" +#include "util.h" +#include <boost/filesystem.hpp> +#include <boost/filesystem/fstream.hpp> +#include <iostream> + + +using namespace ttf; + + +Collection::Collection(boost::filesystem::path const& ttf_file) +{ + boost::filesystem::ifstream str(ttf_file, std::ios::binary); + std::vector<uint8_t> data(boost::filesystem::file_size(ttf_file)); + str.read(reinterpret_cast<char*>(data.data()), data.size()); + + Source source(data); + read_source(source); +} + + +Collection::Collection(uint8_t const* data, int size) +{ + Source source(data, size); + read_source(source); +} + + +void +Collection::read_source(Source& source) +{ + auto const ttc_tag = source.get_uint32(); + if (ttc_tag != 0x74746366) { + throw InvalidTTCTag(ttc_tag); + } + + auto const major_version = source.get_uint16(); + auto const minor_version = source.get_uint16(); + auto const num_fonts = source.get_uint32(); + + if (num_fonts == 0) { + return; + } + + uint32_t offset = source.get_uint32(); + for (uint32_t i = 0; i < num_fonts; ++i) { + Source font_source(source, offset); + _fonts.push_back(Font(font_source)); + } +} + + |
