diff --git a/PdfTool/PdfTool.pro b/PdfTool/PdfTool.pro index e362630..f4c768f 100644 --- a/PdfTool/PdfTool.pro +++ b/PdfTool/PdfTool.pro @@ -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 \ diff --git a/PdfTool/pdftoolcolorprofiles.cpp b/PdfTool/pdftoolcolorprofiles.cpp new file mode 100644 index 0000000..368dc92 --- /dev/null +++ b/PdfTool/pdftoolcolorprofiles.cpp @@ -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 . + +#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 diff --git a/PdfTool/pdftoolcolorprofiles.h b/PdfTool/pdftoolcolorprofiles.h new file mode 100644 index 0000000..f6fe24d --- /dev/null +++ b/PdfTool/pdftoolcolorprofiles.h @@ -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 . + +#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