%define _prefix		/usr
%define texmf		%{_prefix}/share/texmf
%define build_texmf	$RPM_BUILD_ROOT%{texmf}
%define vinepl		vine.pls-1.2
%define tfmdir		%{texmf}/fonts/tfm/ptex

%define exec_texhash	[ -x %{_prefix}/bin/texhash ] && /usr/bin/env - %{_prefix}/bin/texhash 2> /dev/null

Summary: Japanese Virtual Fonts
Summary(ja): 日本語仮想フォントです.
Name: jvf
Version: 2.0
Release: 4%{?_dist_release}
License: distributable
Group: Applications/Publishing
Source0: %{vinepl}.tar.gz
Source1: http://www.matsusaka-u.ac.jp/~okumura/jsclasses/jis-pl.zip
PreReq: sh-utils
Requires: tetex
BuildRequires: nkf
BuildRequires: unzip
BuildRequires: tetex
##!! %{_prefix}/bin/pltotf %{tfmdir}/min5.tfm are provided by tetex
##BuildRequires: %{_prefix}/bin/pltotf %{tfmdir}/min5.tfm
## /usr/bin/makejvf is provided from tetex, which is with ptexenc. 
##BuildRequires: makejvf
BuildArch: noarch
Buildroot: %{_tmppath}/%{name}-%{version}-root
Vendor: Project Vine
Distribution: Vine Linux

%description
Japanese Virtual Fonts required by dvipsk built by makejvf.

%description -l ja
dvipsk の実行に必要な, 日本語仮想フォント(virtual fonts)、
多書体用フォントメトリックです。

%prep
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf $RPM_BUILD_ROOT

%setup -q -n %{vinepl}
unzip -oqq %{SOURCE1}

%build
## Macro definition
mkvf(){ # <$1: jfm name> <$2: jfm name of PS font>
    for size in 5 6 7 8 9 10 ; do
        %{_prefix}/bin/makejvf %{tfmdir}/$1${size}.tfm $2
    done
}

## now, build basic vf fonts
mkvf min rml
mkvf tmin rmlv
mkvf goth gbm
mkvf tgoth gbmv

# jis font metric and vf fonts
for pl in jis jisi tjis tjisi \
          min mini tmin tmini; do
    nkf --jis --overwrite $pl.pl
    %{_prefix}/bin/pltotf $pl.pl
done
ln -sf jis.tfm   jisg.tfm
ln -sf jisi.tfm  jisgi.tfm
ln -sf tjis.tfm  tjisg.tfm
ln -sf tjisi.tfm tjisgi.tfm

%{_prefix}/bin/makejvf  jis.tfm   rml
%{_prefix}/bin/makejvf tjis.tfm   rmlv  # 縦
%{_prefix}/bin/makejvf  jisi.tfm  rmli  # italic
%{_prefix}/bin/makejvf tjisi.tfm  rmlvi

%{_prefix}/bin/makejvf  jisg.tfm  gbm
%{_prefix}/bin/makejvf tjisg.tfm  gbmv
%{_prefix}/bin/makejvf  jisgi.tfm gbmi
%{_prefix}/bin/makejvf tjisgi.tfm gbmvi

## new JIS font metric
# make *.tfm
for pl in jis jisn jis-v jisn-v; do
    %{_prefix}/bin/pltotf $pl.pl
done
ln -sf jis.tfm    jisg.tfm
ln -sf jis-v.tfm  jisg-v.tfm
ln -sf jisn.tfm   jisgn.tfm
ln -sf jisn-v.tfm jisgn-v.tfm

# make *.vf
%{_prefix}/bin/makejvf jis.tfm     rml
%{_prefix}/bin/makejvf jisn.tfm    rmln # 中点修正
%{_prefix}/bin/makejvf jis-v.tfm   rmlv # 縦
%{_prefix}/bin/makejvf jisn-v.tfm  rmlnv

%{_prefix}/bin/makejvf jisg.tfm    gbm
%{_prefix}/bin/makejvf jisgn.tfm   gbmn
%{_prefix}/bin/makejvf jisg-v.tfm  gbmv
%{_prefix}/bin/makejvf jisgn-v.tfm gbmnv


# extrafonts metric and vf fonts
for i in goth gyo pop lei dfmin dfgt dfgyo dfpop dflei lxmin lxgt lxpop lxmgt lxgtb dfminb dfkaib dfpostb dffry dfbrrb ; do
    ln -sf min.tfm    ${i}.tfm
    ln -sf mini.tfm   ${i}i.tfm
    ln -sf tmin.tfm  t${i}.tfm
    ln -sf tmini.tfm t${i}i.tfm
done
for i in min goth gyo pop lei dfmin dfgt dfgyo dfpop dflei lxmin lxgt lxpop lxmgt lxgtb dfminb dfkaib dfpostb dffry dfbrrb; do
    %{_prefix}/bin/makejvf ${i}.tfm ${i}
    %{_prefix}/bin/makejvf ${i}i.tfm ${i}i
    %{_prefix}/bin/makejvf t${i}.tfm t${i}
    %{_prefix}/bin/makejvf t${i}i.tfm t${i}i

#    ln -sf ${i}.vf df${i}.vf
#    ln -sf ${i}i.vf df${i}i.vf
#    ln -sf t${i}.vf dft${i}.vf
#    ln -sf t${i}i.vf dft${i}i.vf
done

# change same file to symbolic link
for f in *.vf; do
    if [ ! -L $f ]; then
	for g in *.vf; do
	    if [ ! -L $g -a $f != $g ]; then
		cmp $f $g > /dev/null && (rm -f $g; ln -s $f $g)
	    fi
	done
    fi
done


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p %{build_texmf}/fonts/{tfm,source,vf}/ptex
cp -dfp *.tfm %{build_texmf}/fonts/tfm/ptex/
cp -dfp *.pl  %{build_texmf}/fonts/source/ptex/
cp -dfp *.vf  %{build_texmf}/fonts/vf/ptex/

%clean
rm -rf $RPM_BUILD_ROOT

%post
%{exec_texhash}
exit 0

%postun
if [ "$1" = 0 ]; then
    %{exec_texhash}
fi
exit 0


%files
%defattr(-,root,root)
%doc README
%{texmf}/fonts/tfm/ptex/
%{texmf}/fonts/source/ptex/
%{texmf}/fonts/vf/ptex/

%changelog
* Wed Oct 07 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-4
- added BuildRequires: unzip
- dropped BuildRequires: %%{_prefix}/bin/pltotf %%{tfmdir}/min5.tfm
  - %%{_prefix}/bin/pltotf %%{tfmdir}/min5.tfm are provided by tetex

* Sun Sep 27 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-3
- added BuildRequires: nkf
- dropped BuildRequires: makejvf
  - /usr/bin/makejvf is provided from tetex, which is with ptexenc
- converted euc-encode to jis-encode for *.pl in vine.pls-1.2

* Sun Jan 11 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0-2
- spec in utf8 (again)

* Fri Aug 15 2008 Shu KONNO <owa@bg.wakwak.com> 2.0-1vl5
- applied new versioning policy, spec in utf-8

* Fri Jan 14 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0-0vl1
- add new dynafont for Vine Linux 3.1CR

* Fri Apr 18 2003 Nobuyuki Tsuchimura <tutimura@nn.iij4u.or.jp> 1.1a-0vl3
- change tetex-ptex -> tetex

* Mon Mar 25 2002 Jun Nishii <jun@vinelinux.org> 1.1a-0vl2
- added symlinks for lxricoh fonts

* Sat Mar 24 2001 Nobuyuki Tsuchimura <tutimura@nn.iij4u.or.jp>
- 1.1a-0vl1
- use symbolic link for same *.vf

* Sat Jan 20 2001 Jun Nishii <jun@vinelinux.org>
- 1.0-6
- cp jis.pl min.pl and fix glue for "「,（,..." in min.pl to use DynaFonts
  Should I rename min.* as dyna.*?

* Fri Jan 21 2000 Jun Nishii <jun@vinelinux.org>
- 1.0-5
- make vfs for dynafonts
- tjis, tjisi, tmin, tmini,...
- correct installation of tfm

* Fri Jan  7 2000 Jun Nishii <jun@vinelinux.org>
- install makejvf

* Fri Oct 29 1999 Norihito Ohmori <ohmori@flatout.org>
- change group
- add defattr(-,root.root)

* Thu Jul 13 1999 Jun Nishii <jun@flatout.org>
- include jis fonts

* Mon Feb 8 1999 Jun Nishii <jun@flatout.org>
- build vfs by makejvf
- obsoletes vfkanji
