OSDN Git Service

thumbnailers: new PDF-specialized thumbnailer with options
authorIvailo Monev <xakepa10@gmail.com>
Tue, 11 Oct 2022 13:23:09 +0000 (16:23 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 11 Oct 2022 13:24:30 +0000 (16:24 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
thumbnailers/CMakeLists.txt
thumbnailers/pdf/CMakeLists.txt [new file with mode: 0644]
thumbnailers/pdf/pdfcreator.cpp [new file with mode: 0644]
thumbnailers/pdf/pdfcreator.h [new file with mode: 0644]
thumbnailers/pdf/pdfcreatorform.ui [new file with mode: 0644]
thumbnailers/pdf/pdfcreatorsettings.kcfg [new file with mode: 0644]
thumbnailers/pdf/pdfcreatorsettings.kcfgc [new file with mode: 0644]
thumbnailers/pdf/pdfthumbnail.desktop [new file with mode: 0644]
thumbnailers/ps/gsthumbnail.desktop

index f3c5c48..283c8a4 100644 (file)
@@ -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 (file)
index 0000000..19b866a
--- /dev/null
@@ -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 (file)
index 0000000..6cbd4de
--- /dev/null
@@ -0,0 +1,133 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+    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 <QFile>
+#include <QX11Info>
+#include <QImage>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kdemacros.h>
+
+#include <poppler/cpp/poppler-document.h>
+#include <poppler/cpp/poppler-page.h>
+#include <poppler/cpp/poppler-page-renderer.h>
+
+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<const uchar*>(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<const PDFCreatorFormWidget*>(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 (file)
index 0000000..4728093
--- /dev/null
@@ -0,0 +1,36 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+    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 <kio/thumbcreator.h>
+
+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 (file)
index 0000000..2f3bdd9
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PDFCreatorForm</class>
+ <widget class="QWidget" name="PDFCreatorForm">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>270</width>
+    <height>151</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="3" column="0" colspan="2">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <widget class="QCheckBox" name="textAntialiasingCheckBox">
+     <property name="text">
+      <string>Text antialising</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="2">
+    <widget class="QCheckBox" name="textHintingCheckBox">
+     <property name="text">
+      <string>Text hinting</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="2">
+    <widget class="QCheckBox" name="antialiasingCheckBox">
+     <property name="text">
+      <string>Antialiasing</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/thumbnailers/pdf/pdfcreatorsettings.kcfg b/thumbnailers/pdf/pdfcreatorsettings.kcfg
new file mode 100644 (file)
index 0000000..abd767c
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
+<kcfg>
+    <kcfgfile name="pdfcreatorrc"/>
+    <group name="General">
+      <entry name="antialiasing" type="bool">
+          <label>Antialias</label>
+          <default>true</default>
+      </entry>
+      <entry name="text_antialiasing" type="bool">
+          <label>Text antialias</label>
+          <default>true</default>
+      </entry>
+      <entry name="text_hinting" type="bool">
+          <label>Text hinting</label>
+          <default>true</default>
+      </entry>
+    </group>
+</kcfg>
\ No newline at end of file
diff --git a/thumbnailers/pdf/pdfcreatorsettings.kcfgc b/thumbnailers/pdf/pdfcreatorsettings.kcfgc
new file mode 100644 (file)
index 0000000..336c8b5
--- /dev/null
@@ -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 (file)
index 0000000..6de3e8b
--- /dev/null
@@ -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
index 725ac4e..4107f00 100644 (file)
@@ -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