%global commit0 411334c8e630acf858569602cbf5c19deba00878
%global shortcommit0 %(c=%{commit0}; echo ${c:0:7})

%global commit4 bc5e67d5121426e8f02b02d8a825c72d297a9a79
%global shortcommit4 %(c=%{commit4}; echo ${c:0:7})

%global fontname emojitwo
%global Fontname EmojiTwo


Name:           %{fontname}-fonts
Version:        20180222git%{shortcommit4}
Release:        1%{?dist}
Summary:        Color emoji font with a flat style

# In noto-emoji-fonts source
## noto-emoji code is in ASL 2.0 license
## Emoji fonts are under OFL license
### third_party color-emoji code is in BSD license
### third_party region-flags code is in Public Domain license
# In emojitwo source
## Artwork is Creative Commons Attribution 4.0 International
## Non-artwork is MIT
License:        OFL and ASL 2.0 and CC-BY and MIT
URL:            https://emojitwo.github.io/
Source0:        https://github.com/googlei18n/noto-emoji/archive/%{commit0}.tar.gz#/noto-emoji-%{shortcommit0}.tar.gz
Source2:        %{fontname}.metainfo.xml
Source4:        https://github.com/%{Fontname}/%{fontname}/archive/%{commit4}.tar.gz#/%{fontname}-%{shortcommit4}.tar.gz

Patch0:         noto-emoji-use-system-pngquant.patch

BuildArch:      noarch
BuildRequires:  ImageMagick
BuildRequires:  cairo-devel
BuildRequires:  fontpackages-devel
BuildRequires:  fonttools
BuildRequires:  libappstream-glib
BuildRequires:  nototools
BuildRequires:  pngquant
BuildRequires:  python2-devel
BuildRequires:  python2dist(fonttools)
BuildRequires:  zopfli

Requires:       fontpackages-filesystem

Obsoletes:      eosrei-emojione-fonts


%description
Maintained fork of the last fully free version of Ranks.com's Emoji One font.


%prep
%autosetup -n noto-emoji-%{commit0}
rm -rf third_party/pngquant

tar -xf %{SOURCE4}
sed 's/Noto Color Emoji/Emoji Two/; s/Noto Color Emoji/%{Fontname}/; s/Copyright .* Google Inc\./Ranks.com with contributions from the EmojiTwo community./; s/ Version .*/ %{version}/; s/.*is a trademark.*/      Emoji One is a trademark of Ranks.com./; s/Google, Inc\./Ranks.com and the EmojiTwo community/; s,http://www.google.com/get/noto/,https://emojitwo.github.io/,; s/.*is licensed under.*/      Creative Commons Attribution 4.0 International/; s,http://scripts.sil.org/OFL,http://creativecommons.org/licenses/by/4.0/,' NotoColorEmoji.tmpl.ttx.tmpl > %{Fontname}.tmpl.ttx.tmpl
pushd %{fontname}-%{commit4}/png/128/
for png in *.png; do
    mv $png emoji_u${png//-/_}
done
popd


%build
# Prevent python 2 crash in Koji when outputting Unicode characters:
export LANG=C.UTF-8

make %{?_smp_mflags} OPT_CFLAGS="$RPM_OPT_FLAGS" EMOJI=%{Fontname} EMOJI_SRC_DIR=%{fontname}-%{commit4}/png/128 FLAGS=


%install
install -m 0755 -d %{buildroot}%{_fontdir}
install -m 0644 -p %{Fontname}.ttf %{buildroot}%{_fontdir}

mkdir -p %{buildroot}%{_datadir}/metainfo
install -m 0644 -p %{SOURCE2} %{buildroot}%{_datadir}/metainfo


%check
appstream-util validate-relax --nonet %{buildroot}%{_datadir}/metainfo/%{fontname}.metainfo.xml


%_font_pkg %{Fontname}.ttf
%license LICENSE %{fontname}-%{commit4}/LICENSE.md
%doc %{fontname}-%{commit4}/CONTRIBUTING.md %{fontname}-%{commit4}/README.md
%{_datadir}/metainfo/%{fontname}.metainfo.xml


%changelog
* Mon Mar  5 2018 Peter Oliver <rpm@mavit.org.uk> - 20180222gitbc5e67d-1
- Update to latest Git snapshot.

* Tue Feb 20 2018 Peter Oliver <rpm@mavit.org.uk> - 20171213gitb851e20-2
- Validate metainfo.

* Tue Feb  6 2018 Peter Oliver <rpm@mavit.org.uk> - 20171213gitb851e20-1
- Update to latest Git snapshot.

* Tue Feb  6 2018 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-6
- Unbundle nototools.

* Tue Jan 16 2018 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-5
- Use C.UTF-8 locale.

* Tue Nov 21 2017 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-4
- Specify that this is an emoji font in the appstream metadata.

* Mon Nov 20 2017 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-3
- Obsolete Emoji One.

* Thu Nov 16 2017 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-2
- Add a screenshot to the AppData.

* Thu Nov  9 2017 Peter Oliver <rpm@mavit.org.uk> - 20171019git0c16521-1
- Initial version, based on google-noto-emoji-fonts package.