blob: e9ce85ddd5a23143afc348f0bbd239df5c0f8b30 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
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/>.
*/
#pragma once
#include "table.h"
#include <boost/filesystem.hpp>
#include <fmt/format.h>
namespace ttf {
class NameTable;
class InvalidScalerType : public std::runtime_error
{
public:
InvalidScalerType(uint32_t scalar_type) : std::runtime_error(fmt::format("Invalid scaler type 0x{0:x}", scalar_type)) {}
};
class Font
{
public:
/** Read and parse a TTF font from a file */
Font(boost::filesystem::path const& ttf_file);
/** Read and parse a TTF font from a block of memory */
Font(uint8_t const* data, int size);
Font(Source& source);
/** Write the font to a file */
void write(boost::filesystem::path const& ttf_file) const;
std::shared_ptr<NameTable> name_table();
private:
void read_source(Source& source);
uint32_t _scalar_type = 0;
uint16_t _num_tables = 0;
/* Tables in the order that their data appears in the file
* (not necessarily the same order as the headers)
*/
std::vector<std::shared_ptr<Table>> _tables;
};
}
|