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