/* 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 "table.h" #include #include #include namespace ttf { /** The 'name' table */ class NameTable : public Table { public: NameTable(Source& source, int header_index); enum class Identifier { COPYRIGHT_NOTICE, FONT_FAMILY, FONT_SUBFAMILY, UNIQUE_SUBFAMILY_IDENTIFICATION, FULL_NAME, NAME_TABLE_VERSION, POSTSCRIPT_NAME, TRADEMARK_NOTICE, MANUFACTURER_NAME, DESIGNER, DESCRIPTION, VENDOR_URL, DESIGNER_URL, LICENSE, LICENSE_URL, RESERVED, PREFERRED_FAMILY, PREFERRED_SUBFAMILY, COMPATIBLE_FULL, SAMPLE_TEXT, OPENTYPE_0, OPENTYPE_1, OPENTYPE_2, OPENTYPE_3, OPENTYPE_4, VARIATIONS_PREFIX, }; using Name = boost::variant2::variant; std::vector names(Identifier id) const; void set_names(Identifier id, std::string const& name, std::wstring const& wname); void write(Sink& header_sink, Sink&& data_sink) const override; private: class NameRecord { public: explicit NameRecord(Source& table_source, Source& name_source, int header_index); NameRecord(int header_index_, uint16_t platform_id_, uint16_t platform_specific_id_, uint16_t language_id_, Identifier name_id_, std::string name_); NameRecord(int header_index_, uint16_t platform_id_, uint16_t platform_specific_id_, uint16_t language_id_, Identifier name_id_, std::wstring name_); void write(Sink& table_sink, Sink& name_sink) const; int header_index; uint16_t platform_id; uint16_t platform_specific_id; uint16_t language_id; uint16_t name_id; uint16_t original_offset = 0; boost::variant2::variant name; }; template std::vector::iterator find(Identifier id) { return std::find_if(_name_records.begin(), _name_records.end(), [id](NameRecord const& record) { return record.name_id == static_cast(id) && boost::variant2::get_if(&record.name); }); } template std::vector::const_iterator find(Identifier id) const { return std::find_if(_name_records.begin(), _name_records.end(), [id](NameRecord const& record) { return record.name_id == static_cast(id) && boost::variant2::get_if(&record.name); }); } uint16_t _format; /** Sorted in order that the strings are written to the file (not necessarily * the order of the header) */ std::vector _name_records; }; }