1/*
2 * Copyright (C) 2008, Pino Toscano <pino@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "fonts.h"
20
21#include <poppler-qt6.h>
22
23#include <QtWidgets/QTableWidget>
24
25static QString yesNoStatement(bool value)
26{
27 return value ? QStringLiteral("yes") : QStringLiteral("no");
28}
29
30FontsDock::FontsDock(QWidget *parent) : AbstractInfoDock(parent)
31{
32 m_table = new QTableWidget(this);
33 setWidget(m_table);
34 setWindowTitle(tr(s: "Fonts"));
35 m_table->setColumnCount(5);
36 m_table->setHorizontalHeaderLabels(QStringList() << tr(s: "Name") << tr(s: "Type") << tr(s: "Embedded") << tr(s: "Subset") << tr(s: "File"));
37 m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
38}
39
40FontsDock::~FontsDock() { }
41
42void FontsDock::fillInfo()
43{
44 const QList<Poppler::FontInfo> fonts = document()->fonts();
45 m_table->setHorizontalHeaderLabels(QStringList() << tr(s: "Name") << tr(s: "Type") << tr(s: "Embedded") << tr(s: "Subset") << tr(s: "File"));
46 m_table->setRowCount(fonts.count());
47 int i = 0;
48 Q_FOREACH (const Poppler::FontInfo &font, fonts) {
49 if (font.name().isNull()) {
50 m_table->setItem(row: i, column: 0, item: new QTableWidgetItem(QStringLiteral("[none]")));
51 } else {
52 m_table->setItem(row: i, column: 0, item: new QTableWidgetItem(font.name()));
53 }
54 m_table->setItem(row: i, column: 1, item: new QTableWidgetItem(font.typeName()));
55 m_table->setItem(row: i, column: 2, item: new QTableWidgetItem(yesNoStatement(value: font.isEmbedded())));
56 m_table->setItem(row: i, column: 3, item: new QTableWidgetItem(yesNoStatement(value: font.isSubset())));
57 m_table->setItem(row: i, column: 4, item: new QTableWidgetItem(font.file()));
58 ++i;
59 }
60}
61
62void FontsDock::documentClosed()
63{
64 m_table->clear();
65 m_table->setRowCount(0);
66 AbstractInfoDock::documentClosed();
67}
68

source code of poppler/qt6/demos/fonts.cpp