#   ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
#   File: iosevka-fonts-all.spec
#   Copyright 🄯 2016—2023 Van de Bugger.
#   SPDX-License-Identifier: FSFAP
#   ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

%{lua: --[[--

    Uniform Iosevka naming
    ----------------------

    Original Iosevka font family names are irregular:

    *   Iosevka
    *   Iosevka Term
    *   Iosevka Fixed
    *   Iosevka Slab
    *   Iosevka Term Slab
    *   Iosevka Fixed Slab
    *   Iosevka Aile
    *   Iosevka Etoile

    Most of slab-serif fonts (but not all) families have word "Slab" in their names, but
    sans-serif font families do not. Iosevka Etoile is a slab serif font family, but it does not
    have "Slab" in the name.

    Default font style names are also irregular: regular weight, normal width and upright slope are
    omitted in the style names, while other weight, width, and slope variants are not:

    *   Iosevka Fixed               # Regular weight, upright slope and normal width are assumed.
    *   Iosevka Fixed Bold          # Upright slope and normal width are assumed.
    *   Iosevka Fixed Bold Italic   # Normal width is assumed.
    *   Iosevka Fixed Bold Italic Extended

    What is wrong in such font family and style names?

    Let's consider an example: You are going to use Iosevka sans-serif font with regular weight,
    normal width, upright slope and open the Font selection dialog. It can filter the list of
    fonts, so you type "iosevka" to filter out non-Iosevka font families. Since sans-serif, regular
    weight, normal width, upright slope are implicit, you cannot filter the list any more, and have
    to search for the desired font in the list of few hundred Iosevka fonts[^number-of-fonts].

    [^number-of-fonts]:
        Most of Iosevka font families consist of 54 fonts (9 weights × 2 width × 3 slopes), Iosevka
        Aile and Iosevka Etoile consist of 27 fonts (9 weights × 3 slopes), so standard set of
        Iosevka fonts consists of 378 fonts total.

    Also note inconsistent Iosevka font width naming: monospace font families (all but Iosevka Aile
    and Iosevka Etoile) have normal and extended widths, but quasi-proportional Iosevka Aile and
    Iosevka Etoile have only normal width. However, Iosevka Aile normal width matches Iosevka
    extended, not Iosevka normal.

    I have renamed Iosevka font families to make them fully regular and uniform:

    ---------------------------------------
    Original name         Uniform name
    ---------------------------------------
    Iosevka               Iosevka Full Sans
    Iosevka Term          Iosevka Term Sans
    Iosevka Fixed         Iosevka Hard Sans
    Iosevka Slab          Iosevka Full Slab
    Iosevka Term Slab     Iosevka Term Slab
    Iosevka Fixed Slab    Iosevka Hard Slab
    Iosevka Aile          Iosevka Prop Sans
    Iosevka Etoile        Iosevka Prop Slab
    ---------------------------------------

    Note that new family names *always* consist of 3 words:

        Iosevka <Spacing> <Serif>

    where <Spacing> is one of:

    *   Prop — (quasi-)proportional fonts.
    *   Full — dual-width fonts with many fullwidth glyphs and ligatures.
    *   Term — dual-width fonts with few fullwidth glyphs and ligatures.
    *   Mono — monospace fonts with ligatures.
    *   Hard — strictly monospace (charcell) fonts without ligatures.

    and <Serif> is either "Sans" or "Slab".

    Uniform font style names are also fully regular, style name *always* consists of 3 words:

        <Weight> <Width> <Slope>

    All 3 words are always explicit, including regular weight, normal width and upright slope. It
    makes selecting a font in the Font selection dialog much more simpler.

    Let's reconsider the example: Uniform name of the font is "Iosevka Full Sans Regular Normal
    Upright", so open the Font selection dialog, then you type "iosevka ful san reg nor up", and
    see *one* font matching the filter criteria.

--]]-- }

%global _vdb_debug_ 0

# Do the magic:
Source1000:                 vdb.lua
%include                    %{S:1000}
Source1001:                 iosevka-fonts-all.lua
%include                    %{S:1001}

%Global Font                Iosevka
%global ver                 19.0.1
%global rel                 0.vdb.1

%global debug_package       %{nil}

Version:                    %{ver}
Release:                    %{rel}%{?dist}
URL:                        https://typeof.net/%{Font}/
Name:                       %{font}-fonts-all
Summary:                    Coders' typeface, built from code
BuildArch:                  noarch
License:                    OFL-1.1

BuildRequires:              fdupes
BuildRequires:              fonts-rpm-macros
BuildRequires:              nodejs >= 14.0.0
BuildRequires:              npm
BuildRequires:              ttfautohint         %{rem: ttfautohint is missed in RHEL 6 and 7.}
BuildRequires:              pandoc
BuildRequires:              perl-interpreter
BuildRequires:              perl(Exporter)
BuildRequires:              perl(FindBin)
BuildRequires:              perl(Getopt::Long)
BuildRequires:              perl(open)
BuildRequires:              perl(Path::Tiny)
BuildRequires:              perl(TOML::Tiny)

Source0:                    https://github.com/be5invis/%{Font}/archive/v%{ver}.tar.gz#/%{Font}-%{ver}.tar.gz
Source1:                    %{name}.conf
Source2:                    %{name}-fontconfs.pl
Source3:                    %{name}-doc.pl
Source4:                    %{name}-build-plan.pl
Source5:                    %{name}.pm
Source6:                    %{name}.css

%global fontorg             net.typeof
%global fontcontact         van.de.bugger@gmail.com
    # Inspite the macro name, it's packager contact, not font author contact.

%global common_description_top  %{text -- \
    %{Font} is set of open-source, serif and sans-serif, quasi-proportional and monospace typeface
    families, designed for writing code, using in terminals, and preparing technical documents.
}

%global common_description_top_mono %{text -- \
    %{common_description_top}

    The %{Font}'s monospace families are provided in Condensed and Normal outfits: Condensed glyphs
    fit more columns within the same screen width. If you prefer more breeze between the
    characters, choose Normal and enjoy.
}

%global common_description_bottom %{text -- \
    **Packager note**

    This is *custom* Iosevka build.

    Iosevka fonts are renamed to make them strictly uniform. A uniform Iosevka font name always
    consists of 6 explicit words, no parts in the font name are assumed or defaulted:

        Iosevka ‹Spacing› ‹Serif› ‹Weight› ‹Width› ‹Slope›

It makes font searching in the Font selection dialog box much easier. For example: if you need an
upright Iosevka font, you just type "iosevka up" to see the list of upright Iosevka fonts. In case
of original Iosevka font names you can filter Italic fonts, but filtering Upright fonts is not
possible.

    Also, in this build some glyphs have non-default shapes.
}

%{lua:

    config = parse_config_file( expand( '%{S:1}' ) )
    set( 'options', join( ' ', options( config ) ) )

    for i, family in ipairs( families ) do
        if config[ family ] then
            spec( sprintf( "Requires: %%{font}-%s-fonts = %%{version}-%%{release}\n", family ) )
        end
    end
}

%description
%{text -- \
    %{common_description_top}

    This is meta-package which provides no fonts but requires all Iosevka fonts. It is a convenient
    way to install all Iosevka fonts.
}

%{lua:

    local n = 0 -- Font number.
    local ver_rel = cat( get( 'ver' ), get( 'rel' ) )
    ids = {}

    -- Declare a font subpackage.
    local function _font( spacing, serif, summary, description )
        local family  = ident( spacing, serif )
        local ifamily = ident( 'iosevka', family )
        dbg( "===== %s =====", family )
        set( 'fontfamily'        .. n, ifamily                                                     )
        set( 'fontsummary'       .. n, shrink( expand( summary ) )                                 )
        set( 'fonts'             .. n, sprintf( "dist/%s/ttf/*.ttf", ifamily )                     )
        set( 'fontconfs'         .. n, sprintf( "??-??-%s.conf", ifamily )                         )
        set( 'fontdescription'   .. n, reflow( expand( description ) )                             )
        set( 'fontpkgheader'     .. n,
            'Requires: %{font}-fonts-common = %{version}-%{release}\n' ..
            (
                obsoletes[ family ]
                    and (
                        'Provides:  ' .. ident( 'iosevka', obsoletes[ family ], 'fonts' ) .. ' = %{version}-%{release}\n' ..
                        'Obsoletes: ' .. ident( 'iosevka', obsoletes[ family ], 'fonts' ) .. ' < 10.2.3\n'
                    )
                    or ''
            )
        )
        n = n + 1
        push( ids, ifamily )
    end

    -- Declare two font subpackages: sans and slab.
    local function font( spacing, summary, description )
        for i, serif in ipairs( serifs ) do
            if config[ ident( spacing, serif ) ] then
                set( 'serif', serif == 'sans' and 'sans-serif' or 'serif' )
                set( 'Serif', tc( serif ) )
                _font( spacing, serif, summary, description )
            end
        end
    end

    font(
        'prop',
        'Quasi-proportional %{serif} font family',
        [[
            %{common_description_top}

            %{Font} Prop %{Serif} is quasi-proportional %{serif} font family, designed for
            documentation preparation and writing. It provides a bit of variety on letter widths:
            some letters (e. g. M, W, Ж, Ш) are slightly wider, some (e. g. i, j, l) narrower.

            %{common_description_bottom}
        ]]
    )
    font(
        'full',
        'Monospace %{serif} font family with ligatures and many fullwidth glyphs',
        [[
            %{common_description_top_mono}

            %{Font} Full %{Serif} is a mostly monospace font family with ligatures. This is not
            strictly monospace, thought: most glyphs (including all Latin, Greek and Cyrillic
            letters and digits) have the same width, but there are many fullwidth glyphs: em dash
            and em space, per mille and per ten thousand signs, arrows, geometric shapes, some math
            symbols and dingbats; these glyphs are twice as wide as regular (halfwidth) glyphs.

            In case of troubles with wide glyphs, try %{Font} Term %{Serif}. If Fonconfig does not
            recognize the font as monospace, try %{Font} Mono %{Serif}. In case of troubles with
            ligatures, try %{Font} Hard %{Serif}.

            %{common_description_bottom}
        ]]
    )
    font(
        'term',
        'Monospace %{serif} font family with ligatures and few fullwidth glyphs',
        [[
            %{common_description_top_mono}

            %{Font} Term %{Serif} is mostly monospace font family with ligatures. Most of the
            glyphs including em dash and em space, per mille and per ten thousand signs, arrows,
            geometric shapes, math symbols and dingbats have exactly the same width. Only *long*
            arrows are fullwidth. Each ligature is as wide as total width of glyphs it is composed
            from.


            If Fonconfig does not recognize the font as monospace, try %{Font} Mono %{Serif}. In
            case of troubles with ligatures, try %{Font} Hard %{Serif}.

            %{common_description_bottom}
        ]]
    )
    font(
        'mono',
        'Monospace %{serif} font family with ligatures',
        [[
            %{common_description_top_mono}

            %{Font} Mono %{Serif} is monospace font family with ligatures. All the glyphs including
            em dash and em space, per mille and per ten thousand signs, arrows, geometric shapes,
            math symbols and dingbats have exactly the same width (*long* arrows are completely
            excluded from the fonts).

            %{Font} Mono %{Serif} is compatible with Fontconfig: it recognizes %{Font} Mono
            %{Serif} as monospace font.

            In case of troubles with ligatures, try %{Font} Hard %{Serif}.

            %{common_description_bottom}
        ]]
    )
    font(
        'hard',
        'Strictly monospace %{serif} font family without ligatures',
        [[
            %{common_description_top_mono}

            %{Font} Hard %{Serif} is strictly monospace font without ligatures. All the glyphs
            including em dash and em space, per mille and per ten thousand signs, arrows, geometric
            shapes, math symbols and dingbats have exactly the same width (*long* arrows are
            completely excluded from the fonts). Ligatures are disabled.

            %{common_description_bottom}
        ]]
    )

}

%package -n %{font}-fonts-common

Summary: %{summary}

%description -n %{font}-fonts-common
%{text -- \
    %{common_description_top}

    This package provides files shared by all Iosevka font families.
}

%package -n %{font}-fonts-doc

Summary: %{summary}

%description -n %{font}-fonts-doc
%{text -- \
    %{common_description_top}

    This package provides Iosevka README.
}

%fontpkg -a -s

%prep
%setup -q -n %{Font}-%{ver}
: ------ Install required JavaScript modules ----- :
%{_bindir}/npm install .

%build
: ----- Generating config files ----- :
%{__perl} %{S:2} %{options}
: ----- Generating private build plan ----- :
%{__perl} %{S:4} %{options}
: ----- Generating README ----- :
%{__mkdir_p} _html
for file in README doc/{stylistic-sets,character-variants,language-specific-ligation-sets,custom-build}; do
    %{__perl} %{S:3} ./$file.md | \
        %{_bindir}/pandoc \
            -s \
            --metadata title="%{Font} %{version}" \
            --metadata lang="en" \
            --css style.css \
            -o _html/$(basename $file).html
done
%{__mv} _html/README.html _html/index.html
%{__cp} %{S:6} _html/style.css
: ----- Building the fonts ----- :
%{_bindir}/npm run build -- %{lua:
    spec( join( ' ', map( function ( it ) return 'ttf::' .. it; end, ids ) ) )
}
%fontbuild -a

%install
%fontinstall -a
# Install for common subpackage:
%_install_D -m u=rwx,go=rx -p -d %{buildroot}%{_licensedir}/%{font}-fonts
%_install_D -m u=rw,go=r   -p -t %{buildroot}%{_licensedir}/%{font}-fonts LICENSE.md
%_install_D -m u=rw,go=r   -p -t %{buildroot}%{_fontconfig_templatedir} ??-00-%{font}-common.conf
%{__mkdir_p} %{buildroot}%{_fontconfig_confdir}
%{__ln_s} -vr \
    %{buildroot}%{_fontconfig_templatedir}/??-00-%{font}-common.conf \
    %{buildroot}%{_fontconfig_confdir}
# Install for doc subpackage:
%_install_D -m u=rwx,go=rx -p -d %{buildroot}%{_docdir}/%{font}-fonts
%_install_D -m u=rw,go=r   -p -t %{buildroot}%{_docdir}/%{font}-fonts _html/*.{html,css}
%_install_D -m u=rwx,go=rx -p -d %{buildroot}%{_docdir}/%{font}-fonts/images
%_install_D -m u=rw,go=r   -p -t %{buildroot}%{_docdir}/%{font}-fonts/images images/*.svg
%fdupes %{buildroot}/%{_docdir}/%{font}-fonts/images

%check
# Fedora 31 and 32:
#   Fedora font macros generate metainfo.xml files which can't pass check. ;-) Let's skip it.
%if 0%{?fedora:%{fedora}} == 0 || 0%{?fedora:%{fedora}} > 32
%fontcheck -a
%endif

%files

%files -n %{font}-fonts-common
    %dir    %{_licensedir}/%{font}-fonts
            %{_licensedir}/%{font}-fonts/*
            %{_fontconfig_templatedir}/??-00-%{font}-common.conf
            %{_fontconfig_confdir}/??-00-%{font}-common.conf

%files -n %{font}-fonts-doc
    %dir    %{_docdir}/%{font}-fonts/
    %doc    %{_docdir}/%{font}-fonts/*.html
    %doc    %{_docdir}/%{font}-fonts/style.css
    %dir    %{_docdir}/%{font}-fonts/images
    %doc    %{_docdir}/%{font}-fonts/images/*.svg

%fontfiles -a

%changelog
* Tue May 09 2023 Van de Bugger - 19.0.1-0.vdb.1
- fontorg and fontcontact macros defined.
- Iosevka 19.0.1.

* Wed Nov 23 2022 Van de Bugger - 16.4.0-0.vdb.1
- Iosevka 16.4.0.

* Mon Oct 03 2022 Van de Bugger - 16.3.0-0.vdb.1
- Iosevka 16.3.0.

* Mon Jul 25 2022 Van de Bugger - 15.6.1-0.vdb.1
- Iosevka 15.6.1.

* Mon Jul 18 2022 Van de Bugger - 15.6.0-0.vdb.1
- Iosevka 15.6.0.
- Required nodejs version updated.
- Package description updated.

* Thu Jul 14 2022 Van de Bugger - 15.5.2-0.vdb.1
- Iosevka 15.5.2.
- Condensed fonts are properly built instead of renaming them by Fontconfig.
- Building doc package updated.
- Obsoleting old packages implemented more correctly.

* Wed Jul 13 2022 Van de Bugger - 10.3.2-0.vdb.1
- Iosevka 10.3.2.
- spec file renamed to iosevka-fonts-all.
- All font renamed to make names fully regular.
- Config file introduced to flexibly select fonts to build.
- Private build plan and config files are generated with Perl scripts.
- Number of packages and fonts drastically reduced.

* Sat Aug 21 2021 Van de Bugger - 9.0.1-0.vdb.1
- Iosevka 9.0.1.

* Mon Aug 16 2021 Van de Bugger - 8.0.2-0.vdb.1
- Iosevka 8.0.2.

* Wed Aug 11 2021 Van de Bugger - 7.2.7-0.vdb.1
- Iosevka 7.2.7.

* Tue Aug 10 2021 Van de Bugger - 6.1.3-0.vdb.2
- F34 enabled.

* Wed May 12 2021 Van de Bugger - 6.1.3-0.vdb.1
- Iosevka 6.1.3.

* Sun May 09 2021 Van de Bugger - 5.0.0-0.vdb.1
- Iosevka 5.0.0.

* Thu May 06 2021 Van de Bugger - 4.2.0-0.vdb.2
- F34 rebuild.

* Mon Jan 04 2021 Van de Bugger - 4.2.0-0.vdb.1
- Iosevka 4.2.0.

* Sat Dec 19 2020 Van de Bugger - 4.0.3-0.vdb.1
- Iosevka 4.0.3.
- Iosevka Aile added.
- Iosevka Etoile added.
- Percent changed to "rings-connected" in all variants.

* Thu Dec 17 2020 Van de Bugger - 4.0.0-0.vdb.1
- Iosevka 4.0.0.
- Dropped obsolete build requirements: otfcc, python, gcc-g++.

* Wed Nov 18 2020 Van de Bugger - 3.7.1-0.vdb.3
- conf files now generated.
- Font's fullnames now are really full. Regular, Normal, and Upright styles are not defaulted but
  explicit.
- If an application requests Iosevka, but Iosevka is not installed, Iosevka Term can be used.
  Iosevka Fixed can serve for both Iosevka and Iosevka Term.

* Thu Nov 12 2020 Van de Bugger - 3.7.1-0.vdb.2
- Autohint parameters dropped. Anyway hints are not used in Linux (?).
- Width of extended font enlarged to be more closer to Source Code Pro.
- All the variants now built by one command to report progress more accurately.

* Thu Nov 12 2020 Van de Bugger - 3.7.1-0.vdb.1
- Iosevka version 3.7.1.

* Tue Nov 10 2020 Van de Bugger - 3.0.0-0.vdb.1
- Iosevka version 3.0.0.
- Spec reworked to use Fedora font macros.

* Thu May 07 2020 Van de Bugger - 2.3.3-0.vdb.1
- Iosevka version 2.3.3.

* Sun Nov 03 2019 Van de Bugger - 2.3.2-0.vdb.1
- Iosevka version 2.3.2.
- ttf files moved from fonts/ to fonts/iosevka/.

* Fri Apr 12 2019 Van de Bugger - 2.2.0-0.2.vdb
- Iosevka 2.2.0 changed shape of %, ‰, and ؊ glyphs: new shape uses small
  rings. In case of large fons size it looks nice, but in case of small
  font size (which occurs more often) old shape is more readable.
  Patch iosevka-2.2.0-style.vdb.patch applied to use old shape.
- The same patch makes hash (#) upright and lowers underscore (_).
- Since it is not official Iosevka SS09 style, name of subpackage changed
  to iosevka-vdb.

* Tue Mar 26 2019 Van de Bugger - 2.2.0-0.1.vdb
- Iosevka version 2.2.0.

* Mon Mar 25 2019 Van de Bugger - 2.1.0-0.1.vdb
- Iosevka version 2.1.0.

* Mon Mar 25 2019 Van de Bugger - 2.0.0-0.1.vdb
- vdb.lua updated, _install_D macro used.
- Rebuilt for F30.
- Note: Release changed in non-backward compatible way.

* Wed Aug 29 2018 Van de Bugger - 2.0.0-1.vdb
- Font updated to version 2.0.0.
- Spec is fully reworked.
- iosevka-fonts now is a meta package which pulls in iosevka-term-ss09.
- iosevka-fonts-common contains license and comman prereqiusities.
- metainfo.xml files installed into metainfo/ directory (not appdata/).
- fontforge, fonttools, and m4 are not required for build anymore.

* Thu Aug 23 2018 Van de Bugger - 1.14.3-1.vdb
- Font updated to version 1.14.3.

* Thu Aug 23 2018 Van de Bugger - 1.14.0-1.vdb
- Font updated to version 1.14.0.
- Patch dropped because family can be specified in the make command line.

* Thu Aug 23 2018 Van de Bugger - 1.13.4-1.vdb
- Font updated to version 1.13.4.
- Updated list of required modules.
- Bug fixed: ligatures were not disabled, as supposed.

* Mon Oct 30 2017 Van de Bugger - 1.13.0-1.vdb
- Font updated to version 1.13.0.
- Updated list of required modules.
- vdb.lua used.

* Sun May 21 2017 Van de Bugger - 1.12.5-1.vdb
- Font updated to version 1.12.5.
- Updated list of required jscript modules.

* Tue Nov 29 2016 Van de Bugger - 1.9.6-1.vdb
- Font updated to version 1.9.6.
- F25 build enabled.
- BuildRequire npm brought back, otherwise build fails.

* Thu Jun 30 2016 Van de Bugger - 1.9.1-2.vdb
- Source0 properly specified.
- All the required js modules are downloaded by one command.
- /usr/bin prefix used in all the commands.

* Wed Jun 29 2016 Van de Bugger - 1.9.1-1.vdb
- Updated to 1.9.1.
- vdb tag added to release number.

* Wed Jun 29 2016 Van de Bugger - 1.9.0-1
- Updated to 1.9.0.
- Spec updated to build on F24. Older Fedoras are not supported any more.
- Since iosevka now provides source tarballs, git tricks dropped.

* Tue Jan 26 2016 Van de Bugger - 1.7.3-1
- Updated to 1.7.3.

* Fri Jan 22 2016 Van de Bugger - 1.7.0-1
- Updated to 1.7.0.
- Iosevka now tags sources, so table of commit ids dropped.

* Thu Jan 7 2016 Van de Bugger - 1.6.1-3
- Updated to 1.6.1.
- Two filesystem requirements added.
- Check for metainfo.xml added.
- git 1.7.10 required.
- Sources patched not to use ttx's -q option: it causes build failure on F21.

* Fri Jan 1 2016 Van de Bugger - 1.6.0-2
- Updated to 1.6.0.
- license clarified, LICENSE file added as documentation.
- metainfo.xml file added to let Gnome Software list the package.

* Fri Jan 1 2016 Van de Bugger - 1.5.5-1
- First release.

# end of file #