%define _fontdir %{_datadir}/fonts/%{name}
%define migu_version 20121030
%define inconsolata_version 001.010

Summary: TrueType font designed for programing
Summary(ja): プログラミング用 TrueType フォント
Name: TrueType-ricty
Version: 3.2.4
Release: 1%{?_dist_release}
License: public domain, SIL OFL v1.1, M+ FONT LICENSE, IPA Font License v1.0
Group: User Interface/X
URL: http://save.sys.t.u-tokyo.ac.jp/~yusa/fonts/ricty.html
Source0: Ricty-%{version}.tar.gz
Requires: OpenType-inconsolata >= %{inconsolata_version}
Requires: TrueType-migu >= %{migu_version}

BuildRequires: fontforge
Requires(post): fontforge

BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot

%description
Ricty is a free, TrueType font designed for programing. 

We remark that Ricty fonts is generated in the installation of this package. 


%description -l ja
Ricty は Linux 環境での研究・開発に適したフリーのプログラミング用 
TrueType フォントです。

Ricty フォントは、パッケージのインストール時に生成されます。

%prep
%setup -q -n Ricty-%{version}

%__sed -i -e "s,#!/usr/local/bin/fontforge,#!/usr/bin/fontforge," ricty_discord_patch.pe || exit 1

%build

%install
%__rm -rf $RPM_BUILD_ROOT

%__mkdir_p $RPM_BUILD_ROOT%{_datadir}/%{name}
%__cp -a ricty_discord_patch.pe $RPM_BUILD_ROOT%{_datadir}/%{name}/
%__cp -a ricty_generator.sh $RPM_BUILD_ROOT%{_datadir}/%{name}/

%__mkdir_p $RPM_BUILD_ROOT%{_fontdir}


%clean
%__rm -rf $RPM_BUILD_ROOT

%post
#set -x
echo "Generating Ricty fonts ... "
(cd %{_fontdir}
    %__cp %{_datadir}/%{name}/ricty_discord_patch.pe . || exit 1
    %__cp %{_datadir}/%{name}/ricty_generator.sh . || exit 1
    sh ricty_generator.sh \
        %{_datadir}/fonts/OpenType-inconsolata/Inconsolata.otf \
	%{_datadir}/fonts/TrueType-migu/migu-1m-regular.ttf \
	%{_datadir}/fonts/TrueType-migu/migu-1m-bold.ttf
    %__rm -f ricty_discord_patch.pe ricty_generator.sh ||:
    [ ! -f Ricty-Regular.ttf ] && echo "failed." && exit 1
    [ ! -f Ricty-Bold.ttf ] && echo "failed." && exit 1
)
echo "done."
%__font_install_post %{_fontdir}

%preun
if [ "$1" = 0 ]; then
    %__rm -f %{_fontdir}/Ricty{,Discord}-{Regular,Bold}.ttf ||:
fi

%postun
%__font_install_postun %{_fontdir}

%files
%defattr(-,root,root,-)
%doc README.md
%{_datadir}/%{name}/
# %{_fontdir}/Ricty-Regular.ttf
# %{_fontdir}/Ricty-Bold.ttf
# %{_fontdir}/RictyDiscord-Regular.ttf
# %{_fontdir}/RictyDiscord-Bold.ttf
%{_fontdir}/

%changelog
* Sun Jan 11 2015 Munehiro Yamamoto <munepi@vinelinux.org> 3.2.4-1
- new upstream release

* Mon Jan 13 2014 Munehiro Yamamoto <munepi@vinelinux.org> 3.2.2-1
- new upstream release

* Sat Mar  9 2013 Munehiro Yamamoto <munepi@vinelinux.org> 3.2.1-1
- new upstream release
- supported the new naming rule for Migu fonts

* Thu Jan 12 2012 Munehiro Yamamoto <munepi@vinelinux.org> 3.1.3-1
- new upstream release

* Sat Oct 15 2011 Munehiro Yamamoto <munepi@vinelinux.org> 3.1.2-1
- new upstream release
- set %%migu_version to 20111002

* Wed Jun 22 2011 Munehiro Yamamoto <munepi@vinelinux.org> 3.1.0-2
- added Requires(post): fontforge

* Wed Jun 22 2011 Munehiro Yamamoto <munepi@vinelinux.org> 3.1.0-1
- new upstream release

* Sun Jun  5 2011 Munehiro Yamamoto <munepi@vinelinux.org> 3.0.2-1
- Initial build.
