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
36using 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 */
53font_info::font_info() : d(new font_info_private()) { }
54
55font_info::font_info(font_info_private &dd) : d(&dd) { }
56
57/**
58 Copy constructor.
59 */
60font_info::font_info(const font_info &fi) : d(new font_info_private(*fi.d)) { }
61
62/**
63 Destructor.
64 */
65font_info::~font_info()
66{
67 delete d;
68}
69
70/**
71 \returns the name of the font
72 */
73std::string font_info::name() const
74{
75 return d->font_name;
76}
77
78/**
79 \returns the file name of the font, in case the font is not embedded nor subset
80 */
81std::string font_info::file() const
82{
83 return d->font_file;
84}
85
86/**
87 \returns whether the font is totally embedded in the %document
88 */
89bool font_info::is_embedded() const
90{
91 return d->is_embedded;
92}
93
94/**
95 \returns whether there is a subset of the font embedded in the %document
96 */
97bool font_info::is_subset() const
98{
99 return d->is_subset;
100}
101
102/**
103 \returns the type of the font
104 */
105font_info::type_enum font_info::type() const
106{
107 return d->type;
108}
109
110/**
111 Assignment operator.
112 */
113font_info &font_info::operator=(const font_info &fi)
114{
115 if (this != &fi) {
116 *d = *fi.d;
117 }
118 return *this;
119}
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
131poppler::font_iterator *it = doc->create_font_iterator();
132while (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
137delete it;
138\endcode
139 */
140
141font_iterator::font_iterator(int start_page, document_private *dd) : d(new font_iterator_private(start_page, dd)) { }
142
143/**
144 Destructor.
145 */
146font_iterator::~font_iterator()
147{
148 delete d;
149}
150
151/**
152 \returns the fonts of the current page and advances to the next one.
153 */
154std::vector<font_info> font_iterator::next()
155{
156 if (!has_next()) {
157 return std::vector<font_info>();
158 }
159
160 ++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 const std::vector<FontInfo *> items = d->font_info_scanner.scan(nPages: 1);
167 std::vector<font_info> fonts;
168 fonts.reserve(n: items.size());
169 for (FontInfo *entry : items) {
170 fonts.push_back(x: font_info(*new font_info_private(entry)));
171 delete entry;
172 }
173 return fonts;
174}
175
176/**
177 \returns whether the iterator has more pages to advance to
178*/
179bool font_iterator::has_next() const
180{
181 return d->current_page < d->total_pages;
182}
183
184/**
185 \returns the current page
186*/
187int font_iterator::current_page() const
188{
189 return d->current_page;
190}
191

source code of poppler/cpp/poppler-font.cpp