/* 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 . */ #pragma once #include #include #include #include #include #include #include namespace ttf { class Sink; class Source; class InvalidChecksumError : public std::runtime_error { public: InvalidChecksumError() : std::runtime_error("Invalid checksum") {} }; class UnsupportedPlatformIdentifier : public std::runtime_error { public: UnsupportedPlatformIdentifier(uint16_t platform_id) : std::runtime_error(fmt::format("Unsupported string platform ID {}", platform_id)) {} }; class InvalidTableSize : public std::runtime_error { public: InvalidTableSize() : std::runtime_error("Invalid table size") {} }; /** One table in a TTF font */ class Table { public: Table(Source& source, int header_index); /** @return Index of the table's entry in the header. This * is used to preserve header order. */ int header_index() const { return _header_index; } /** @return offset of table within the font file */ uint32_t offset() const { return _offset; } /** @return length of the table in bytes */ uint32_t length() const { return _length; } virtual void write(Sink& header_sink, Sink&& data_sink) const = 0; protected: int _header_index; uint32_t _checksum; uint32_t _offset; uint32_t _length; }; /** A table that we just pass through blindly */ class OtherTable : public Table { public: OtherTable(Source& source, int header_index, uint32_t tag); void write(Sink& header_sink, Sink&& data_sink) const override; protected: uint32_t _tag; std::vector _data; }; /** The 'head' table */ class HeadTable : public Table { public: HeadTable(Source& source, int header_index); void write(Sink& header_sink, Sink&& data_sink) const override; void set_checksum_adjustment(Sink& data_sink, uint32_t adjustment); private: std::vector _data; }; std::shared_ptr make_table(Source& source, int header_index); }