Tool for displaying available color profiles

This commit is contained in:
Jakub Melka 2020-10-25 14:56:31 +01:00
parent f43459b88e
commit 59c09c9095
3 changed files with 143 additions and 0 deletions

View File

@ -44,6 +44,7 @@ SOURCES += \
pdftoolabstractapplication.cpp \
pdftoolattachments.cpp \
pdftoolaudiobook.cpp \
pdftoolcolorprofiles.cpp \
pdftoolfetchtext.cpp \
pdftoolinfo.cpp \
pdftoolinfofonts.cpp \
@ -69,6 +70,7 @@ HEADERS += \
pdftoolabstractapplication.h \
pdftoolattachments.h \
pdftoolaudiobook.h \
pdftoolcolorprofiles.h \
pdftoolfetchtext.h \
pdftoolinfo.h \
pdftoolinfofonts.h \

View File

@ -0,0 +1,105 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdftoolcolorprofiles.h"
#include "pdfcms.h"
namespace pdftool
{
static PDFToolColorProfiles s_colorProfilesApplication;
QString PDFToolColorProfiles::getStandardString(StandardString standardString) const
{
switch (standardString)
{
case Command:
return "color-profiles";
case Name:
return PDFToolTranslationContext::tr("Color Profiles List");
case Description:
return PDFToolTranslationContext::tr("Show list of available color profiles.");
default:
Q_ASSERT(false);
break;
}
return QString();
}
int PDFToolColorProfiles::execute(const PDFToolOptions& options)
{
PDFOutputFormatter formatter(options.outputStyle, options.outputCodec);
formatter.beginDocument("color-profiles", PDFToolTranslationContext::tr("Available Color Profiles"));
formatter.endl();
auto writeColorProfileList = [&formatter](QString name, QString caption, const pdf::PDFColorProfileIdentifiers& profiles)
{
if (profiles.empty())
{
// Jakub Melka: Do nothing, no profile available
return;
}
formatter.beginTable(name, caption);
formatter.beginTableHeaderRow("header");
formatter.writeTableHeaderColumn("no", PDFToolTranslationContext::tr("No."), Qt::AlignLeft);
formatter.writeTableHeaderColumn("name", PDFToolTranslationContext::tr("Name"), Qt::AlignLeft);
formatter.writeTableHeaderColumn("id", PDFToolTranslationContext::tr("Identifier"), Qt::AlignLeft);
formatter.endTableHeaderRow();
QLocale locale;
int ref = 1;
for (const pdf::PDFColorProfileIdentifier& profile : profiles)
{
formatter.beginTableRow("color-profile", ref);
formatter.writeTableColumn("no", locale.toString(ref), Qt::AlignRight);
formatter.writeTableColumn("name", profile.name);
formatter.writeTableColumn("id", profile.id);
formatter.endTableRow();
++ref;
}
formatter.endTable();
formatter.endl();
};
pdf::PDFCMSManager cmsManager(nullptr);
writeColorProfileList("output-profiles", PDFToolTranslationContext::tr("Output Profiles"), cmsManager.getOutputProfiles());
writeColorProfileList("gray-profiles", PDFToolTranslationContext::tr("Gray Profiles"), cmsManager.getGrayProfiles());
writeColorProfileList("rgb-profiles", PDFToolTranslationContext::tr("RGB Profiles"), cmsManager.getRGBProfiles());
writeColorProfileList("cmyk-profiles", PDFToolTranslationContext::tr("CMYK Profiles"), cmsManager.getCMYKProfiles());
formatter.endDocument();
PDFConsole::writeText(formatter.getString(), options.outputCodec);
return ExitSuccess;
}
PDFToolAbstractApplication::Options PDFToolColorProfiles::getOptionsFlags() const
{
return ConsoleFormat;
}
} // namespace pdftool

View File

@ -0,0 +1,36 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFTOOLCOLORPROFILES_H
#define PDFTOOLCOLORPROFILES_H
#include "pdftoolabstractapplication.h"
namespace pdftool
{
class PDFToolColorProfiles : public PDFToolAbstractApplication
{
public:
virtual QString getStandardString(StandardString standardString) const override;
virtual int execute(const PDFToolOptions& options) override;
virtual Options getOptionsFlags() const override;
};
} // namespace pdftool
#endif // PDFTOOLCOLORPROFILES_H