/src/poppler/cpp/poppler-font.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2009, Pino Toscano <pino@kde.org> |
3 | | * Copyright (C) 2015, Tamas Szekeres <szekerest@gmail.com> |
4 | | * Copyright (C) 2018, Adam Reichold <adam.reichold@t-online.de> |
5 | | * Copyright (C) 2019, Oliver Sander <oliver.sander@tu-dresden.de> |
6 | | * Copyright (C) 2020, Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp> |
7 | | * Copyright (C) 2025, Albert Astals Cid <aacid@kde.org> |
8 | | * |
9 | | * This program is free software; you can redistribute it and/or modify |
10 | | * it under the terms of the GNU General Public License as published by |
11 | | * the Free Software Foundation; either version 2, or (at your option) |
12 | | * any later version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU General Public License |
20 | | * along with this program; if not, write to the Free Software |
21 | | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
22 | | */ |
23 | | |
24 | | /** |
25 | | \file poppler-font.h |
26 | | */ |
27 | | #include "poppler-font.h" |
28 | | |
29 | | #include "poppler-font-private.h" |
30 | | |
31 | | #include "poppler-document-private.h" |
32 | | |
33 | | #include "FontInfo.h" |
34 | | |
35 | | using namespace poppler; |
36 | | |
37 | | /** |
38 | | \class poppler::font_info poppler-font.h "poppler/cpp/poppler-font.h" |
39 | | |
40 | | The information about a font used in a PDF %document. |
41 | | */ |
42 | | |
43 | | /** |
44 | | \enum poppler::font_info::type_enum |
45 | | |
46 | | The various types of fonts available in a PDF %document. |
47 | | */ |
48 | | |
49 | | /** |
50 | | Constructs an invalid font information. |
51 | | */ |
52 | 0 | font_info::font_info() : d(new font_info_private()) { } |
53 | | |
54 | 41.1k | font_info::font_info(font_info_private &dd) : d(&dd) { } |
55 | | |
56 | | /** |
57 | | Copy constructor. |
58 | | */ |
59 | 8.12M | font_info::font_info(const font_info &fi) : d(new font_info_private(*fi.d)) { } |
60 | | |
61 | | /** |
62 | | Destructor. |
63 | | */ |
64 | | font_info::~font_info() |
65 | 8.16M | { |
66 | 8.16M | delete d; |
67 | 8.16M | } |
68 | | |
69 | | /** |
70 | | \returns the name of the font |
71 | | */ |
72 | | std::string font_info::name() const |
73 | 0 | { |
74 | 0 | return d->font_name; |
75 | 0 | } |
76 | | |
77 | | /** |
78 | | \returns the file name of the font, in case the font is not embedded nor subset |
79 | | */ |
80 | | std::string font_info::file() const |
81 | 0 | { |
82 | 0 | return d->font_file; |
83 | 0 | } |
84 | | |
85 | | /** |
86 | | \returns whether the font is totally embedded in the %document |
87 | | */ |
88 | | bool font_info::is_embedded() const |
89 | 0 | { |
90 | 0 | return d->is_embedded; |
91 | 0 | } |
92 | | |
93 | | /** |
94 | | \returns whether there is a subset of the font embedded in the %document |
95 | | */ |
96 | | bool font_info::is_subset() const |
97 | 0 | { |
98 | 0 | return d->is_subset; |
99 | 0 | } |
100 | | |
101 | | /** |
102 | | \returns the type of the font |
103 | | */ |
104 | | font_info::type_enum font_info::type() const |
105 | 0 | { |
106 | 0 | return d->type; |
107 | 0 | } |
108 | | |
109 | | /** |
110 | | Assignment operator. |
111 | | */ |
112 | | font_info &font_info::operator=(const font_info &fi) |
113 | 0 | { |
114 | 0 | if (this != &fi) { |
115 | 0 | *d = *fi.d; |
116 | 0 | } |
117 | 0 | return *this; |
118 | 0 | } |
119 | | |
120 | | /** |
121 | | \class poppler::font_iterator poppler-font.h "poppler/cpp/poppler-font.h" |
122 | | |
123 | | Reads the fonts in the PDF %document page by page. |
124 | | |
125 | | font_iterator is the way to collect the list of the fonts used in a PDF |
126 | | %document, reading them incrementally page by page. |
127 | | |
128 | | A typical usage of this might look like: |
129 | | \code |
130 | | poppler::font_iterator *it = doc->create_font_iterator(); |
131 | | while (it->has_next()) { |
132 | | std::vector<poppler::font_info> fonts = it->next(); |
133 | | // do domething with the fonts |
134 | | } |
135 | | // after we are done with the iterator, it must be deleted |
136 | | delete it; |
137 | | \endcode |
138 | | */ |
139 | | |
140 | 18.9k | font_iterator::font_iterator(int start_page, document_private *dd) : d(new font_iterator_private(start_page, dd)) { } |
141 | | |
142 | | /** |
143 | | Destructor. |
144 | | */ |
145 | | font_iterator::~font_iterator() |
146 | 18.9k | { |
147 | 18.9k | delete d; |
148 | 18.9k | } |
149 | | |
150 | | /** |
151 | | \returns the fonts of the current page and advances to the next one. |
152 | | */ |
153 | | std::vector<font_info> font_iterator::next() |
154 | 81.9k | { |
155 | 81.9k | if (!has_next()) { |
156 | 0 | return std::vector<font_info>(); |
157 | 0 | } |
158 | | |
159 | 81.9k | ++d->current_page; |
160 | | |
161 | | /* FontInfoScanner::scan() receives a number how many pages to |
162 | | * be scanned from the *current page*, not from the beginning. |
163 | | * We restrict the font scanning to the current page only. |
164 | | */ |
165 | 81.9k | const std::vector<FontInfo *> items = d->font_info_scanner.scan(1); |
166 | 81.9k | std::vector<font_info> fonts; |
167 | 81.9k | fonts.reserve(items.size()); |
168 | 81.9k | for (FontInfo *entry : items) { |
169 | 41.1k | fonts.push_back(font_info(*new font_info_private(entry))); |
170 | 41.1k | delete entry; |
171 | 41.1k | } |
172 | 81.9k | return fonts; |
173 | 81.9k | } |
174 | | |
175 | | /** |
176 | | \returns whether the iterator has more pages to advance to |
177 | | */ |
178 | | bool font_iterator::has_next() const |
179 | 176k | { |
180 | 176k | return d->current_page < d->total_pages; |
181 | 176k | } |
182 | | |
183 | | /** |
184 | | \returns the current page |
185 | | */ |
186 | | int font_iterator::current_page() const |
187 | 0 | { |
188 | 0 | return d->current_page; |
189 | 0 | } |