/* Copyright (C) 2026 Carl Hetherington 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 . */ #include "collection.h" #include "util.h" #include #include #include using namespace ttf; Collection::Collection(boost::filesystem::path const& ttf_file) { boost::filesystem::ifstream str(ttf_file, std::ios::binary); std::vector data(boost::filesystem::file_size(ttf_file)); str.read(reinterpret_cast(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)); } }