%{!?_with_subpixel_rendering: %{!?_without_subpixel_rendering: %define _without_subpixel_rendering --without-subpixel_rendering}}

%{!?with_xfree86:%define with_xfree86 1}

Name:           freetype
Version:        2.12.1
Release:        3
Summary:        FreeType is a freely available software library to render fonts
License:        (FTL or GPLv2+) and BSD and MIT and Public Domain and zlib with acknowledgement
URL:            http://www.freetype.org
Source0:        http://download.savannah.gnu.org/releases/freetype/freetype-%{version}.tar.xz
Source1:        http://download.savannah.gnu.org/releases/freetype/freetype-doc-%{version}.tar.xz
Source2:        http://download.savannah.gnu.org/releases/freetype/ft2demos-%{version}.tar.xz
Source3:        ftconfig.h
#from tests/scripts/download-test-fonts.py:https://github.com/python-pillow/Pillow/files/6622147/As.I.Lay.Dying.zip
Source4:        As.I.Lay.Dying.ttf

Patch1:         backport-freetype-2.5.2-more-demos.patch
Patch6000:      backport-freetype-2.3.0-enable-spr.patch
Patch6001:      backport-freetype-2.2.1-enable-valid.patch
Patch6002:      backport-freetype-2.6.5-libtool.patch
Patch6003:      backport-freetype-2.8-multilib.patch
Patch6004:      backport-freetype-2.10.0-internal-outline.patch
Patch6005:      backport-freetype-2.10.1-debughook.patch
Patch6006:      backport-CVE-2023-2004.patch

BuildRequires:  gcc libX11-devel libpng-devel zlib-devel bzip2-devel meson

Provides:       %{name}-bytecode 
%if %{?_with_subpixel_rendering:1}%{!?_with_subpixel_rendering:0}
Provides:       %{name}-subpixel
%endif

%description
FreeType is written in C, designed to be small,efficient, highly customizable, and portable while capable of producing high-quality
output (glyph images) of most vector and bitmap font formats

%package demos 
Summary: A collection of freetype demos 
Requires: %{name} = %{version}-%{release} 

%description demos 
The FreeType engine is a free and portable font rendering engine,developed to provide advanced font support for a variety of platforms and environments.The demos package includes a set of useful small utilities showing various capabilities of the FreeType library.

%package        devel
Summary:        FreeType development libraries and header files
Requires:       %{name} = %{version}-%{release} pkgconf

%description    devel
The freetype-devel package includes the static libraries and header files
for the FreeType font rendering engine.Install freetype-devel if you want to develop programs which will use
FreeType.

%package        help
Summary:        Documents for freetype
Buildarch:      noarch

%description    help
Man pages and other related for freetype documents.

%prep
%setup   -q  -b 1 -a 2

pushd ft2demos-%{version}
%patch1  -p1 -b .more-demos
popd
%patch6000 -p1
%patch6001 -p1
%patch6002 -p1
%patch6003 -p1
%patch6004 -p1
%patch6005 -p1
%patch6006 -p1

%build
%configure --disable-static --with-zlib=yes --with-bzip2=yes --with-png=yes --enable-freetype-config --with-harfbuzz=no
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' builds/unix/libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' builds/unix/libtool
%make_build

%if %{with_xfree86}
cd ft2demos-%{version}
make TOP_DIR=".."
%endif

%install
%make_install gnulocaledir=$RPM_BUILD_ROOT%{_datadir}/locale
{
  for ftdemo in ftbench ftchkwd ftmemchk ftpatchk fttimer ftdump ftlint ftmemchk ftvalid ; do
      builds/unix/libtool --mode=install install -m 755 ft2demos-%{version}/bin/$ftdemo $RPM_BUILD_ROOT/%{_bindir}
  done
}
%if %{with_xfree86}
{
  for ftdemo in ftdiff ftgamma ftgrid ftmulti ftstring fttimer ftview ; do
      builds/unix/libtool --mode=install install -m 755 ft2demos-%{version}/bin/$ftdemo $RPM_BUILD_ROOT/%{_bindir}
  done
}
%endif

%define wordsize %{__isa_bits}

mv $RPM_BUILD_ROOT%{_includedir}/freetype2/freetype/config/ftconfig.h \
   $RPM_BUILD_ROOT%{_includedir}/freetype2/freetype/config/ftconfig-%{wordsize}.h
install -p -m 644 %{SOURCE3} $RPM_BUILD_ROOT%{_includedir}/freetype2/freetype/config/ftconfig.h

%triggerpostun -- freetype < 2.0.5-3
{
  # ttmkfdir updated - as of 2.0.5-3, on upgrades we need xfs to regenerate
  # things to get the iso10646-1 encoding listed.
  for I in %{_datadir}/fonts/*/TrueType /usr/share/X11/fonts/TTF; do
      [ -d $I ] && [ -f $I/fonts.scale ] && [ -f $I/fonts.dir ] && touch $I/fonts.scale
  done
  exit 0
}

%post -p /sbin/ldconfig

%postun  -p /sbin/ldconfig

%check
mkdir -p tests/data/
cp %{SOURCE4} tests/data/
meson setup out -Dtests=enabled
meson compile -C out
meson test -C out

%files
%{!?_licensedir:%global license %%doc}
%license LICENSE.TXT docs/FTL.TXT docs/GPLv2.TXT
%{_libdir}/libfreetype.so.*

%files demos 
%{_bindir}/ft*

%files devel
%{_datadir}/aclocal/freetype2.m4
%{_includedir}/freetype2/*
%{_libdir}/libfreetype.so
%{_libdir}/pkgconfig/freetype2.pc
%{_bindir}/freetype-config
%exclude %{_libdir}/*.{a,la}

%files help
%doc docs/design
%doc docs/glyphs
%doc docs/reference
%doc docs/tutorial
%doc docs/CHANGES docs/formats.txt docs/ft2faq.html
%doc ChangeLog README
%{_mandir}/man1/*

%changelog
* Tue Nov 14 2023 zhangpan <zhangpan103@h-partners.com> - 2.12.1-3
- enable make check

* Mon Apr 17 2023 zhouwenpei <zhouwenpei1@h-partners.com> - 2.12.1-2
- fix CVE-2023-2004

* Tue Nov 29 2022 zhouwenpei <zhouwenpei1@h-partners.com> - 2.12.1-1
- update to 2.12.1

* Sat May 14 2022 wangkerong <wangkerong@h-paerners.com> - 2.11.0-2
- fix CVE-2022-27404,CVE-2022-27405,CVE-2022-27406

* Fri Dec 10 2021 dongyuzhen <dongyuzhen@huawei.com> - 2.11.0-1
- update to 2.11.0

* Tue Apr 13 2021 hanhui<hanhui15@huawei.com> - 2.10.2-3
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:add community patches

* Tue Dec 08 2020 zhanzhimin <zhanzhimin@huawei.com> - 2.10.2-2
- Type:CVE
- CVE:CVE-2020-15999
- SUG:NA
- DESC:fix CVE-2020-15999

* Mon Jul 20 2020 wangye <wangye70@huawei.com> - 2.10.2-1
- Type:enhancement
- Id:NA
- SUG:NA
- DESC:version update to 2.10.2

* Tue Jan 14 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.9.1-5
- Type:enhancement
- Id:NA
- SUG:NA
- DESC:optimization the spec

* Sat Jan 11 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.9.1-4
- Type:enhancement
- Id:NA
- SUG:NA
- DESC:optimization the spec

* Wed Sep 11 2019 openEuler jimmy<dukaitian@huawei.com> - 2.9.1-3
- Package init jimmy
