From 2fae3e5da24d48acacf8c6b7aac2de836132d0a5 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 11 Oct 2022 16:23:09 +0300 Subject: [PATCH] thumbnailers: new PDF-specialized thumbnailer with options Signed-off-by: Ivailo Monev --- thumbnailers/CMakeLists.txt | 37 ++++++--- thumbnailers/pdf/CMakeLists.txt | 29 +++++++ thumbnailers/pdf/pdfcreator.cpp | 133 ++++++++++++++++++++++++++++++ thumbnailers/pdf/pdfcreator.h | 36 ++++++++ thumbnailers/pdf/pdfcreatorform.ui | 55 ++++++++++++ thumbnailers/pdf/pdfcreatorsettings.kcfg | 19 +++++ thumbnailers/pdf/pdfcreatorsettings.kcfgc | 4 + thumbnailers/pdf/pdfthumbnail.desktop | 9 ++ thumbnailers/ps/gsthumbnail.desktop | 76 +---------------- 9 files changed, 311 insertions(+), 87 deletions(-) create mode 100644 thumbnailers/pdf/CMakeLists.txt create mode 100644 thumbnailers/pdf/pdfcreator.cpp create mode 100644 thumbnailers/pdf/pdfcreator.h create mode 100644 thumbnailers/pdf/pdfcreatorform.ui create mode 100644 thumbnailers/pdf/pdfcreatorsettings.kcfg create mode 100644 thumbnailers/pdf/pdfcreatorsettings.kcfgc create mode 100644 thumbnailers/pdf/pdfthumbnail.desktop diff --git a/thumbnailers/CMakeLists.txt b/thumbnailers/CMakeLists.txt index f3c5c48d..283c8a40 100644 --- a/thumbnailers/CMakeLists.txt +++ b/thumbnailers/CMakeLists.txt @@ -9,13 +9,6 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) endif() -kde4_optional_find_package(GettextPO) -set_package_properties(GettextPO PROPERTIES - DESCRIPTION "A library for processing PO files" - URL "www.gnu.org/software/gettext" - PURPOSE "Required to build the PO thumbnailer" -) - kde4_optional_find_package(Taglib 1.4) set_package_properties(Taglib PROPERTIES DESCRIPTION "Id3 tag reader" @@ -30,25 +23,43 @@ set_package_properties(FFmpegThumbnailer PROPERTIES PURPOSE "Required to build the video thumbnailer" ) +kde4_optional_find_package(Poppler) +set_package_properties(Poppler PROPERTIES + DESCRIPTION "A PDF rendering library" + URL "https://poppler.freedesktop.org" + PURPOSE "Required to build the PDF thumbnailer" +) + +kde4_optional_find_package(GettextPO) +set_package_properties(GettextPO PROPERTIES + DESCRIPTION "A library for processing PO files" + URL "www.gnu.org/software/gettext" + PURPOSE "Required to build the PO thumbnailer" +) + find_program(GHOSTSCRIPT_EXECUTABLE NAMES gs) add_feature_info(thumbnailer_gs GHOSTSCRIPT_EXECUTABLE - "PostScript, PDF and DvI support in thumbnailer" + "PostScript and DvI support in thumbnailer" ) -add_subdirectory(ps) - if(TAGLIB_FOUND) add_subdirectory(audio) endif() +if(FFMPEGTHUMBNAILER_FOUND) + add_subdirectory(ffmpegthumbs) +endif() + +if(Poppler_FOUND) + add_subdirectory(pdf) +endif() + if(GETTEXTPO_FOUND) add_subdirectory(po) endif() -if(FFMPEGTHUMBNAILER_FOUND) - add_subdirectory(ffmpegthumbs) -endif() +add_subdirectory(ps) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/thumbnailers/pdf/CMakeLists.txt b/thumbnailers/pdf/CMakeLists.txt new file mode 100644 index 00000000..19b866a2 --- /dev/null +++ b/thumbnailers/pdf/CMakeLists.txt @@ -0,0 +1,29 @@ +########### next target ############### + +include_directories( + ${POPPLER_INCLUDE_DIR} +) + +set(pdfthumbnail_PART_SRCS pdfcreator.cpp) + +kde4_add_kcfg_files(pdfthumbnail_PART_SRCS pdfcreatorsettings.kcfgc) +kde4_add_plugin(pdfthumbnail ${pdfthumbnail_PART_SRCS}) + +target_link_libraries(pdfthumbnail + ${KDE4_KDECORE_LIBS} + ${KDE4_KIO_LIBS} + ${QT_QTGUI_LIBRARY} + ${POPPLER_LIBRARIES} +) + +install( + TARGETS pdfthumbnail + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +########### install files ############### + +install( + FILES pdfthumbnail.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) diff --git a/thumbnailers/pdf/pdfcreator.cpp b/thumbnailers/pdf/pdfcreator.cpp new file mode 100644 index 00000000..6cbd4de8 --- /dev/null +++ b/thumbnailers/pdf/pdfcreator.cpp @@ -0,0 +1,133 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "pdfcreator.h" +#include "pdfcreatorsettings.h" +#include "ui_pdfcreatorform.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +class PDFCreatorFormWidget : public QWidget, public Ui::PDFCreatorForm +{ + Q_OBJECT +public: + PDFCreatorFormWidget() { setupUi(this); } +}; + + +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + return new PDFCreator(); + } +} + +PDFCreator::PDFCreator() +{ +} + +bool PDFCreator::create(const QString &path, int, int, QImage &img) +{ + const QByteArray pathbytes = QFile::encodeName(path); + poppler::document *popplerdocument = poppler::document::load_from_file(std::string(pathbytes.constData(), pathbytes.size())); + if (!popplerdocument) { + kWarning() << "Could not open" << path; + return false; + } + + if (popplerdocument->pages() < 1) { + kWarning() << "Document has no pages" << path; + delete popplerdocument; + return false; + } + + poppler::page *popplerpage = popplerdocument->create_page(0); + if (!popplerpage) { + kWarning() << "Could not create document page"; + delete popplerdocument; + return false; + } + + PDFCreatorSettings* pdfcreatorsettings = PDFCreatorSettings::self(); + pdfcreatorsettings->readConfig(); + poppler::page_renderer popplerrenderer; + popplerrenderer.set_render_hint(poppler::page_renderer::antialiasing, pdfcreatorsettings->antialiasing()); + popplerrenderer.set_render_hint(poppler::page_renderer::text_antialiasing, pdfcreatorsettings->text_antialiasing()); + popplerrenderer.set_render_hint(poppler::page_renderer::text_hinting, pdfcreatorsettings->text_hinting()); + popplerrenderer.set_image_format(poppler::image::format_argb32); + + const poppler::image popplerimage = popplerrenderer.render_page( + popplerpage, + QX11Info::appDpiX(), QX11Info::appDpiY(), + -1, -1, -1, -1, + poppler::rotate_0 + ); + if (!popplerimage.is_valid()) { + kWarning() << "Could not render page"; + delete popplerpage; + delete popplerdocument; + return false; + } + img = QImage( + reinterpret_cast(popplerimage.const_data()), + popplerimage.width(), popplerimage.height(), + QImage::Format_ARGB32 + ).copy(); + + delete popplerpage; + delete popplerdocument; + return !img.isNull(); +} + +ThumbCreator::Flags PDFCreator::flags() const +{ + return ThumbCreator::None; +} + +QWidget *PDFCreator::createConfigurationWidget() +{ + PDFCreatorSettings* pdfcreatorsettings = PDFCreatorSettings::self(); + PDFCreatorFormWidget* pdfcreatorformwidget = new PDFCreatorFormWidget(); + pdfcreatorformwidget->antialiasingCheckBox->setChecked(pdfcreatorsettings->antialiasing()); + pdfcreatorformwidget->textAntialiasingCheckBox->setChecked(pdfcreatorsettings->text_antialiasing()); + pdfcreatorformwidget->textHintingCheckBox->setChecked(pdfcreatorsettings->text_hinting()); + return pdfcreatorformwidget; +} + +void PDFCreator::writeConfiguration(const QWidget *configurationWidget) +{ + const PDFCreatorFormWidget *pdfcreatorformwidget = qobject_cast(configurationWidget); + Q_ASSERT(pdfcreatorformwidget); + PDFCreatorSettings* pdfcreatorsettings = PDFCreatorSettings::self(); + pdfcreatorsettings->setAntialiasing(pdfcreatorformwidget->antialiasingCheckBox->isChecked()); + pdfcreatorsettings->setText_antialiasing(pdfcreatorformwidget->textAntialiasingCheckBox->isChecked()); + pdfcreatorsettings->setText_hinting(pdfcreatorformwidget->textHintingCheckBox->isChecked()); + pdfcreatorsettings->writeConfig(); +} + +#include "pdfcreator.moc" diff --git a/thumbnailers/pdf/pdfcreator.h b/thumbnailers/pdf/pdfcreator.h new file mode 100644 index 00000000..47280933 --- /dev/null +++ b/thumbnailers/pdf/pdfcreator.h @@ -0,0 +1,36 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef PDFCREATOR_H +#define PDFCREATOR_H + +#include + +class PDFCreator : public ThumbCreator +{ +public: + PDFCreator(); + + bool create(const QString &path, int, int, QImage &img) final; + ThumbCreator::Flags flags() const final; + + QWidget *createConfigurationWidget() final; + void writeConfiguration(const QWidget *configurationWidget) final; +}; + +#endif // PDFCREATOR_H diff --git a/thumbnailers/pdf/pdfcreatorform.ui b/thumbnailers/pdf/pdfcreatorform.ui new file mode 100644 index 00000000..2f3bdd92 --- /dev/null +++ b/thumbnailers/pdf/pdfcreatorform.ui @@ -0,0 +1,55 @@ + + + PDFCreatorForm + + + + 0 + 0 + 270 + 151 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Text antialising + + + + + + + Text hinting + + + + + + + Antialiasing + + + + + + + + diff --git a/thumbnailers/pdf/pdfcreatorsettings.kcfg b/thumbnailers/pdf/pdfcreatorsettings.kcfg new file mode 100644 index 00000000..abd767c3 --- /dev/null +++ b/thumbnailers/pdf/pdfcreatorsettings.kcfg @@ -0,0 +1,19 @@ + + + + + + + + true + + + + true + + + + true + + + \ No newline at end of file diff --git a/thumbnailers/pdf/pdfcreatorsettings.kcfgc b/thumbnailers/pdf/pdfcreatorsettings.kcfgc new file mode 100644 index 00000000..336c8b5e --- /dev/null +++ b/thumbnailers/pdf/pdfcreatorsettings.kcfgc @@ -0,0 +1,4 @@ +File=pdfcreatorsettings.kcfg +ClassName=PDFCreatorSettings +Singleton=true +Mutators=true \ No newline at end of file diff --git a/thumbnailers/pdf/pdfthumbnail.desktop b/thumbnailers/pdf/pdfthumbnail.desktop new file mode 100644 index 00000000..6de3e8b9 --- /dev/null +++ b/thumbnailers/pdf/pdfthumbnail.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Service +Name=PDF Files +X-KDE-ServiceTypes=ThumbCreator +X-KDE-PluginInfo-EnabledByDefault=true +MimeType=application/pdf; +X-KDE-Library=pdfthumbnail +CacheThumbnail=true +Configurable=true diff --git a/thumbnailers/ps/gsthumbnail.desktop b/thumbnailers/ps/gsthumbnail.desktop index 725ac4e4..4107f001 100644 --- a/thumbnailers/ps/gsthumbnail.desktop +++ b/thumbnailers/ps/gsthumbnail.desktop @@ -1,80 +1,8 @@ [Desktop Entry] Type=Service -Name=PostScript, PDF and DVI Files -Name[ar]=ملفات PostScript, PDF و DVI -Name[ast]=Ficheros PostScript, PDF y DVI -Name[bg]=Файлове PostScript, PDF и DVI -Name[br]=Restroù PostScript, PDF ha DVI -Name[bs]=Postskript, PDF i DVI datoteke -Name[ca]=Fitxers PostScript, PDF i DVI -Name[ca@valencia]=Fitxers PostScript, PDF i DVI -Name[cs]=Postscriptové, PDF a DVI soubory -Name[cy]=Ffeiliau PostScript, PDF a DVI -Name[da]=PostScript, PDF- og DVI-filer -Name[de]=PostScript-, PDF- und DVI-Dateien -Name[el]=Αρχεία PostScript, PDF και DVI -Name[en_GB]=PostScript, PDF and DVI Files -Name[eo]=Postskriptaj, PDF kaj DVI dosieroj -Name[es]=Archivos PostScript, PDF y DVI -Name[et]=PostScript-, PDF- ja DVI-failid -Name[eu]=PostScript, PDF eta DVI fitxategiak -Name[fa]=پرونده‌های PostScript، PDF و DVI -Name[fi]=PostScript-, PDF- ja DVI-tiedostot -Name[fr]=Fichiers « PostScript », « PDF » et « DVI » -Name[ga]=Comhaid PostScript, PDF agus DVI -Name[gl]=Ficheiros PostScript, PDF e DVI -Name[he]=קבצי PostScript, PDF ו־DVI -Name[hi]=पोस्ट-स्क्रिप्ट, पीडीएफ तथा डीवीआई फ़ाइलें -Name[hne]=पोस्ट-स्क्रिप्ट, पीडीएफ अउ डीवीआई फाइल मन ल -Name[hr]=Datoteke oblika PostScript, PDF i DVI -Name[hu]=PostScript-, PDF- és DVI-fájlok -Name[ia]=Files PostScript, PDF e DVI -Name[is]=PostScript, PDF og DVI skrár -Name[it]=File PostScript, PDF e DVI -Name[ja]=PostScript, PDF, DVI ファイル -Name[kk]=PostScript, PDF және DVI файлдары -Name[km]=ឯកសារ PostScript, PDF និង DVI -Name[ko]=포스트크스립트, PDF, DVI 파일 -Name[ku]=Pelên PostScript, PDF û DVI -Name[lt]=Postscript, PDF ir DVI failai -Name[lv]=Postscript, PDF un DVI faili -Name[mr]=पोस्टस्क्रिप्ट, PDF व DVI फाईल्स -Name[ms]=PostScript, PDF dan Fail DVI -Name[nb]=PostScript, PDF og DVI filer -Name[nds]=PostScript-, PDF- un DVI-Dateien -Name[ne]=पोष्टस्क्रिप्ट, पीडीएफ र डीभीआई फाइल -Name[nl]=PostScript-, DVI- en PDF-bestanden -Name[nn]=PostScript-, PDF- og DVI-filer -Name[pa]=ਪੋਸਟ-ਸਕ੍ਰਿਪਟ, PDF ਅਤੇ DVI ਫਾਇਲਾਂ -Name[pl]=Pliki PostScript, PDF i DVI -Name[pt]=Ficheiros PostScript, PDF e DVI -Name[pt_BR]=Arquivos PostScript, PDF e DVI -Name[ro]=Fișiere PostScript, PDF și DVI -Name[ru]=Файлы PostScript, PDF и DVI -Name[se]=PostScript-, PDF- ja DVI-fiillat -Name[si]=PostScript, PDF සහ DVI ගොනු -Name[sk]=PostScript, PDF a DVI súbory -Name[sl]=Datoteke PostScript, PDF in DVI -Name[sr]=Постскрипт, ПДФ и ДВИ фајлови -Name[sr@ijekavian]=Постскрипт, ПДФ и ДВИ фајлови -Name[sr@ijekavianlatin]=PostScript, PDF i DVI fajlovi -Name[sr@latin]=PostScript, PDF i DVI fajlovi -Name[sv]=Postscript-, PDF- och DVI-filer -Name[ta]= போஸ்ட்கிரிப்ட், பிடிஃப் மற்றும் டிவிஐ கோப்புகள் -Name[tg]=Файлҳои PostScript, PDF ва DVI -Name[th]=แฟ้ม PDF, DVI และ โพสต์สคริปต์ -Name[tr]=PostScript, PDF ve DVI Dosyaları -Name[ug]=PostScript، PDF ۋە DVI ھۆججەتلىرى -Name[uk]=Файли PostScript, PDF та DVI -Name[uz]=PostScript, PDF va DVI fayllari -Name[uz@cyrillic]=PostScript, PDF ва DVI файллари -Name[vi]=Các tập tin PostScript, PDF và DVI -Name[x-test]=xxPostScript, PDF and DVI Filesxx -Name[zh_CN]=PostScript、PDF 和 DVI 文件 -Name[zh_HK]=PostScript 、PDF 及 DVI 檔案 -Name[zh_TW]=PostScript,PDF 與 DVI 檔 +Name=PostScript and DVI Files X-KDE-ServiceTypes=ThumbCreator X-KDE-PluginInfo-EnabledByDefault=true -MimeType=application/x-dvi;application/postscript;application/pdf;image/x-eps; +MimeType=application/x-dvi;application/postscript;image/x-eps; X-KDE-Library=gsthumbnail CacheThumbnail=true -- 2.11.0