%global gettext_package FontForge
%global gittag0 20200314

Name:           fontforge
Version:        20200314
Release:        6
Summary:        Outline and bitmap font editor
License:        GPLv3+
URL:            http://fontforge.github.io/
Source0:        https://github.com/fontforge/%{name}/archive/%{gittag0}.tar.gz#/%{name}-%{version}.tar.gz

Patch0001:      fontforge-20200314-Call-gdk_set_allowed_backends-before-gdk_init.patch
Patch0002:      fontforge-20200314-sphinx-make-changes-to-support-Sphinx-3.patch

Requires:       xdg-utils potrace hicolor-icon-theme
BuildRequires:  gcc-c++ cmake libjpeg-devel libtiff-devel libpng-devel giflib-devel libxml2-devel
BuildRequires:  freetype-devel desktop-file-utils libuninameslist-devel libXt-devel xorg-x11-proto-devel
BuildRequires:  gettext pango-devel cairo-devel libspiro-devel python3-devel readline-devel
BuildRequires:  libappstream-glib woff2-devel shared-mime-info gtk3-devel python3-sphinx

%description
FontForge (former PfaEdit) is a font editor for outline and bitmap
fonts. It supports a range of font formats, including PostScript
(ASCII and binary Type 1, some Type 3 and Type 0), TrueType, OpenType
(Type2) and CID-keyed fonts.

%package devel
Summary: Development files for fontforge
Requires: %{name} = %{version}-%{release}
Requires: %{name}-help = %{version}-%{release}
Requires: pkgconfig

%description devel
This package includes the library files you will need to compile
applications against fontforge.

%package help
Summary: Documentation files for %{name}
BuildArch: noarch
Provides:  %{name}-doc = %{version}-%{release}
Obsoletes: %{name}-doc < %{version}-%{release}

%description help
This package contains documentation files for %{name}.

%prep
%autosetup -n %{name}-%{version} -p1

# Remove tests that requires Internet access
sed -i '45d;83d;101d;102d;114d;115d;125d' tests/CMakeLists.txt
rm tests/test003.pe tests/test130.pe tests/test0101.py tests/test929.py
# Remove tests for s390x
rm tests/test0004.py tests/test1009.py tests/test1010.py

%build
rm -rf build && mkdir build
pushd build
export CFLAGS="%{optflags} -fno-strict-aliasing"

%cmake .. -DCMAKE_BUILD_TYPE=Release \
          -DENABLE_WOFF2=ON \
          -DENABLE_DOCS=NO

%{make_build}
popd

%install
pushd build
%{make_install}
popd


desktop-file-install \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications            \
  --add-category X-Fedora                                  \
  desktop/org.fontforge.FontForge.desktop

# remove unneeded .la and .a files
find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
find $RPM_BUILD_ROOT -name '*.a' -exec rm -f {} ';'

rm -f %{buildroot}%{_datadir}/doc/fontforge/{.buildinfo,.nojekyll}
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.appdata.xml

# Find translations
%find_lang %{gettext_package}

%check
pushd build
make check
popd

%files -f %{gettext_package}.lang
%doc AUTHORS
%license LICENSE COPYING.gplv3
%{_bindir}/*
%{_libdir}/lib*.so.*
%{_datadir}/applications/*FontForge.desktop
%{_datadir}/fontforge
%{_datadir}/icons/hicolor/*/apps/org.fontforge.FontForge*
%{_datadir}/pixmaps/org.fontforge.FontForge*
%{_datadir}/mime/packages/fontforge.xml
%{_metainfodir}/org.fontforge.FontForge.appdata.xml
%{python3_sitearch}/fontforge.so
%{python3_sitearch}/psMat.so

%files devel
%{_libdir}/lib*.so

%files help
%doc %{_pkgdocdir}
%{_mandir}/man1/*.1*

%changelog
* Tue Jul 13 2021 wangyue <wangyue92@huawei.com> - 20200314-6
- remove useless glib buildrequire
- move %find_lang to correct stage

* Tue Jun 15 2021 baizhonggui <baizhonggui@huawei.com> - 20200314-5
- Fix building error: Could not open %files file /home/abuild/rpmbuild/BUILD/fontforge-20200314/FontForge.lang:No such file or directory
- Add glib in BuildRequires

* Fri May 21 2021 wutao <wutao61@huawei.com> - 20200314-4
- update release

* Wed Dec 16 2020 Ge Wang <wangge20@huawei.com> - 20200314-2
- change install require autotrace to potrace

* Sat Aug 1 2020 xiaoweiwei <xiaoweiwei5@huawei.com> - 20200314-1
- upgrade to 20200314

* Mon Jun 22 2020 yanan li <liyanan032@huawei.com> - 20170731-13
- Solve fontforge 20170731 build fails with python3.8.

* Thu Apr 3 2020 zhujunhao <zhujunhao5@huawei.com> - 20170731-12
- Modify build option

* Thu Dec 12 2019 lihao <lihao129@huawei.com> - 20170731-11
- Package Init

