%{lua: --[[------------------------------------------------------------------------------------------------ File: iosevka-fonts-all.lua Copyright 🄯 2016—2023 Van de Bugger. SPDX-License-Identifier: FSFAP --]]------------------------------------------------------------------------------------------------ if not _iosevka_loaded_ then function cat( ... ) return join( '-', grep( function ( it ) return it ~= nill and it ~= "" end, { ... } ) ) end function x( first, ... ) local rest = { ... } if # rest == 0 then return flatten( first ) end rest = x( unpack( rest ) ) local result = {} for i, f in ipairs( first ) do for j, r in ipairs( rest ) do push( result, cat( f, r ) ) end end return result end -- Iosevka font parameters: spacings = { 'prop', -- Quasi-proportional (original Aile and Etoile). 'full', -- Full-width and half-width glyphs. 'term', -- ?? 'mono', -- All non-combining characters have the same width. 'hard', -- Half-width glyphs only + no ligatures. } serifs = { 'sans', -- Sans-serif. 'slab', -- Serif. } families = x( spacings, serifs ) weights = { 'thin', 'extralight', 'light', 'regular', 'medium', 'semibold', 'bold', 'extrabold', 'heavy', } widths = { 'normal', 'condensed', } slopes = { 'upright', 'oblique', 'italic', } styles = x( weights, widths, slopes ) obsoletes = { -- Uniform family name -- = Original family name [ "prop-sans" ] = "aile", [ "prop-slab" ] = "etoile", [ "full-sans" ] = "", [ "full-slab" ] = "slab", [ "term-sans" ] = "term", [ "term-slab" ] = "term-slab", [ "hard-sans" ] = "fixed", [ "hard-slab" ] = "fixed-slab", } function is_one_of( item, array ) for i, v in ipairs( array ) do if item == v then return true end end return false end --[[-- Parse configuration file and return configuration. Configuration looks like: config = { prop-sans = { weights = { regular = true, bold = true, ... }, widths = { normal = true, condensed = true, }, slopes = { upright = true, italic = true, ... }, }, prop-slab = { ... }, ... } --]]-- function parse_config_file( path ) local lines = slurp( path ) local params = { spacings, serifs, weights, widths, slopes } local config = {} local function vivify( table, key ) if table[ key ] == nil then table[ key ] = {} end return table[ key ] end for n, line in ipairs( lines ) do local function error( format, ... ) die( "%s:%d: %s\n>>> %s", path, n, sprintf( format, ... ), line ) end if string.match( line, "^ *$" ) then -- Empty line, nothing to do. elseif string.match( line, "^ *#" ) then -- Comment, nothing to do else -- Font line. local parts = split( "-", trim( line ) ) if # parts < 5 then error( "Too few parts, five parts expected" ) elseif # parts > 5 then error( "Too many parts, five parts expected" ) else for i, part in ipairs( parts ) do if part == "" then error( "Empty part" ) elseif part == "*" then parts[ i ] = params[ i ]; else local braces = string.match( part, "^{(.*)}$" ) if braces then parts[ i ] = split( ",", braces ) else parts[ i ] = { part } end end end for i = # parts + 1, # params do parts[ i ] = params[ i ]; end for i, part in ipairs( parts ) do for j, word in ipairs( parts[ i ] ) do if not is_one_of( word, params[ i ] ) then error( "Invalid word: %s", word ) end end end for i, family in ipairs( x( parts[ 1 ], parts[ 2 ] ) ) do family = vivify( config, family ) for j, weight in ipairs( parts[ 3 ] ) do vivify( family, 'weights' )[ weight ] = true end for j, width in ipairs( parts[ 4 ] ) do vivify( family, 'widths' )[ width ] = true end for j, slope in ipairs( parts[ 5 ] ) do vivify( family, 'slopes' )[ slope ] = true end end end end end return config end --[[-- Converts configuration to series of command-line options to pass it to external scripts. Options look like: '--prop-sans={regular,bold,...}-{normal,condensed}-{upright,italic,...}' ... --]]-- function options( config ) local result = {} for i, family in ipairs( families ) do if config[ family ] then push( result, sprintf( "'--%s={%s}-{%s}-{%s}'", -- Single quotes are important to avoid shell brace expansion. family, join( ',', keys( config[ family ].weights ) ), join( ',', keys( config[ family ].widths ) ), join( ',', keys( config[ family ].slopes ) ) ) ) end end return result end --[[-- If value is nil, the function is synonym for `%{with name}`. If value is non-nil and true, the function defines the value used by `%{with name}`, so the macro `%{with name}` will be evaluated to true. If value is non-nil and false, the function undefines the value used by `%{with name}`, so the macro `%{with name}` will be evaluated to false. --]]-- function with( name, value ) local var = 'with_' .. subst( name, '-', '_' ) if value == nil then return defined( var ) else unset( var, 0 ) if value then set( var, '--with ' .. subst( name, '_', '-' ) ) end end end _iosevka_loaded_ = 1 end } # end of file #