%global debug_package %{nil}

Name:           djpdf
%global forgeurl https://github.com/Unrud/%{name}
Version:        0.5.7
%forgemeta

%global app_id com.github.unrud.%{name}

Release:        1%{?dist}
Summary:        Create small, searchable PDFs from scanned documents
License:        GPL-3.0-or-later
URL:            %{forgeurl}
Source:         %{forgesource}

BuildRequires:  ImageMagick-devel
BuildRequires:  desktop-file-utils
BuildRequires:  exempi-devel
BuildRequires:  gettext
BuildRequires:  hicolor-icon-theme
BuildRequires:  leptonica-devel
BuildRequires:  libappstream-glib
BuildRequires:  make
BuildRequires:  meson
BuildRequires:  ninja-build
BuildRequires:  python3-devel
BuildRequires:  python3-rpm-macros

%description
Create small, searchable PDFs from scanned documents. The program divides images
into bitonal foreground images (text) and a color background image, then compresses
them separately. An invisible OCR text layer is added, making the PDF searchable.

Color and grayscale scans need some preparation for good results. Recommended
tools are Scan Tailor or GIMP.

A GUI and command line interface are included.

#------------------------------------------------------------------

%package        gui
Summary:        Graphical user interface for %{name}

Requires:       python3-%{name} = %{version}
Requires:       python3-pyside6
Requires:       python3-dbus
Requires:       python3-pillow

Requires:       qt6-qtbase
Requires:       qt6-qtdeclarative

%description    gui
Create small, searchable PDFs from scanned documents. The program divides images
into bitonal foreground images (text) and a color background image, then compresses
them separately. An invisible OCR text layer is added, making the PDF searchable.

Color and grayscale scans need some preparation for good results. Recommended
tools are Scan Tailor or GIMP.

This package contains the graphical user interface for %{name}

%files          gui -f %{name}gui.lang
%{_bindir}/scans2pdf-gui
%{_datadir}/%{name}gui
%{_datadir}/applications/%{app_id}.desktop
%{_datadir}/icons/hicolor/*/apps/%{app_id}.png
%{_metainfodir}/%{app_id}.metainfo.xml

#------------------------------------------------------------------

%package -n     python3-%{name}
Summary:        Python library and command line interface for %{name}

Requires:       ImageMagick
Requires:       jbig2enc
Requires:       exempi
Requires:       qpdf
Requires:       tesseract

%description -n python3-%{name}
Create small, searchable PDFs from scanned documents. The program divides images
into bitonal foreground images (text) and a color background image, then compresses
them separately. An invisible OCR text layer is added, making the PDF searchable.

Color and grayscale scans need some preparation for good results. Recommended
tools are Scan Tailor or GIMP.

This package contains the python library and command line interface for %{name}

%files       -n python3-%{name} -f %{pyproject_files}
%{_bindir}/%{name}-json
%{_bindir}/hocr-json
%{_bindir}/scans2pdf
%{_bindir}/scans2pdf-json

#------------------------------------------------------------------

%prep
%forgeautosetup -p1

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

%meson
%meson_build

%install
%pyproject_install
%pyproject_save_files %{name}

%meson_install
%py_byte_compile %{python3} %{buildroot}%{_datadir}/%{name}gui/scans2pdf_gui/*.py

%find_lang %{name}gui

%check
%pyproject_check_import %{name}
desktop-file-validate %{buildroot}%{_datadir}/applications/%{app_id}.desktop
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/%{app_id}.metainfo.xml

#------------------------------------------------------------------

%changelog
* Sun Nov 17 2024 Hazel Bunny <hazel_bunny@disroot.org> - 0.5.7-1
- initial package