##
##  typefacet.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         typefacet
Summary:      Font Manipulations Tools
URL:          http://charlesmchen.github.com/typefacet/
Vendor:       Matthew Chen
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Typesetting
License:      Apache
Version:      20140323
Release:      20140323

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/typefacet/typefacet-%{version}.zip
Source1:      typefacet-autokern.sh
Patch0:       typefacet.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  python
PreReq:       python

%description
    Typefacet is a collection of tools for manipulating font files. It
    currently mainly provides the autokern(1) utility which reads an old
    font in UFO format, determines kerning information and writes a new
    extended font in UFO format.

%track
    prog typefacet = {
        version   = %{version}
        url       = http://download.openpkg.org/components/versioned/typefacet/
        regex     = typefacet-(__VER__)\.zip
    }

%prep
    %setup -q -n typefacet-master
    %patch -p0

%build
    #   finish patching
    %{l_shtool} subst %{l_value -s -a} \
        python/src-main/tfs/common/TFSProject.py

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/main \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/deps \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/data

    #   avoid blanks in directories
    mv "data/Adobe Glyph List" "data/Adobe-Glyph-List"
    %{l_shtool} subst \
        -e 's;Adobe Glyph List;Adobe-Glyph-List;g' \
        python/src-main/tfs/common/UnicodeCharacterNames.py
    mv "data/ilovetypography kerning pairs.txt" "data/ilovetypography-kerning-pairs.txt"
    %{l_shtool} subst \
        -e 's;ilovetypography kerning pairs\.txt;ilovetypography-kerning-pairs.txt;g' \
        python/src-main/autokern/Autokern.py

    #   remove useless version control directories
    find . -name .svn -type d -print | xargs rm -rf

    #   remove useless test/documentation/example directories
    rm -rf dependencies/DialogKit/documentation
    rm -rf dependencies/DialogKit/examples
    rm -rf dependencies/FontTools/Doc
    rm -rf dependencies/FontTools/Lib/fontTools/ttLib/test
    rm -rf dependencies/FontTools/Mac
    rm -rf dependencies/FontTools/Windows
    rm -rf dependencies/PyYAML/examples
    rm -rf dependencies/PyYAML/lib3
    rm -rf dependencies/PyYAML/tests
    rm -rf dependencies/RoboFab/Data/DemoFont.ufo
    rm -rf dependencies/RoboFab/Documentation
    rm -rf dependencies/RoboFab/Lib/robofab/test
    rm -rf dependencies/RoboFab/TestData
    rm -rf dependencies/Vanilla/Demos
    rm -rf dependencies/Vanilla/Documentation
    rm -rf dependencies/argparse/doc
    rm -rf dependencies/argparse/test
    rm -rf dependencies/pystache/pystache/tests
    rm -rf dependencies/svgwrite/examples
    rm -rf dependencies/svgwrite/tests

    #   install main files
    cp -rp \
        python/src-main/* \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/main/

    #   install data files
    cp -rp \
        data/* \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/data/

    #   install dependencies
    cp -rp \
        dependencies/* \
        $RPM_BUILD_ROOT%{l_prefix}/lib/typefacet/deps/

    #   install wrapper script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE typefacet-autokern.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/typefacet-autokern

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

