# ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # File: iosevka-fonts-all.pm # Copyright 🄯 2016—2023 Van de Bugger. # SPDX-License-Identifier: FSFAP # ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― package Iosevka::Util; use v5.30.0; use warnings; use parent qw( Exporter ); use Getopt::Long qw(); use Path::Tiny qw( path ); our @EXPORT = qw( @Spacings @Serifs @Families @Weights @Widths @Slopes @Styles X hash tc cat indent rpmname generic get_options path ); # Iosevka parameters and their values: our @Spacings = qw( prop full term mono hard ); our @Serifs = qw( sans slab ); our @Families = X( \@Spacings, \@Serifs ); our @Weights = qw( thin extralight light regular medium semibold bold extrabold heavy ); our @Widths = qw( condensed normal ); our @Slopes = qw( upright oblique italic ); our @Styles = X( \@Weights, \@Widths, \@Slopes ); sub X { my ( $first, @rest ) = @_; if ( @rest ) { @rest = X( @rest ); my @result; for my $f ( @$first ) { for my $r ( @rest ) { push( @result, "$f-$r" ); }; }; return @result; } else { return ( @$first ); }; }; # Converts array to hash: keys are given by the array, values are 1. sub hash(@) { return map( { $_ => 1 } @_ ); }; # Returns titlecase string (the first letter of each word is in upper case, other letters are in # lower case). sub tc($) { my ( $str ) = @_; return lc( $str ) =~ s{\b(\w)}{ uc( $1 ) }gre; }; # Join items, use space as joiner. Undefined and empty items are ignored, they do not cause # multiple spaces in a row, e. g. cat( "A", "", "B" ) is "A B", not "A B". sub cat(@) { my ( @items ) = @_; return join( ' ', grep( { defined( $_ ) && $_ ne "" } @items ) ); }; # Returns indented text. sub indent($;$) { my ( $text, $indent ) = @_; $indent //= 1; if ( $indent > 0 ) { my $pad = " " x $indent; $text =~ s{^}{$pad}gm; }; return $text; }; # Construct package name from font family name by replacing spaces with dashes and converting # everything to lower case. sub rpmname($) { my ( $family ) = @_; return lc( $family =~ s{ }{-}gr ); }; # Returns generic font name for the given Iosevka font name. Generic name for "Prop Sans" is # "sans-serif", for "Prop Slab" is "serif", for other fonts — "monospace". sub generic($) { my ( $family ) = @_; if ( $family =~ m{\bprop\b}i && $family =~ m{\bsans\b}i || $family =~ m{\baile\b}i ) { return 'sans-serif'; } elsif ( $family =~ m{\bprop\b}i && $family =~ m{\bslab\b}i || $family =~ m{\betoile\b}i ) { return 'serif'; } else { return 'monospace'; }; }; sub get_options { local $SIG{ __WARN__ } = sub { die "$0: " . $_[ 0 ]; }; Getopt::Long::GetOptions( @_ ) or die; }; 1; # end of file #