Jakub Jirutka e0e709a090 community/font-noto: fix fontconfig configs (again)
* Fix error "Having multiple values in <test> isn't supported and may
  not work as expected" in a few configs (e.g. 45-noto-devanagari.conf).
* Fix duplicated "Noto Noto".
* Remove "fonthashint" - it seems to be redudant, it's already
  included in the font metadata.
* Remove matching by language - it seems to be redundant, languages
  are included in the font metadata and fontconfig takes them into
  account.
* Replace match/edit with alias/prefer which is more clear.
* Split configs to family->generic (45-) and generic->family aka
  preferables (58-). The latter should be *after* the user and local
  system overrides to have *lower* priority, i.e. the user can override
  the fonts preferred for each generic.
2022-06-20 23:54:28 +02:00

78 lines
1.7 KiB
Ruby
Executable File

#!/usr/bin/ruby
require 'erb'
require 'fileutils'
require 'json'
require 'shellwords'
include FileUtils
def die!(msg)
warn msg
exit 1
end
def render_template(template, attrs = {})
context = Class.new(OpenStruct).new(**attrs).instance_eval('binding')
ERB.new(template, trim_mode: '-').result(context)
end
def gen_font_confs(fonts, out_dir = '.')
out_dir = File.expand_path(out_dir)
mkdir_p(out_dir)
Dir.chdir(__dir__) do
template = File.read('45-noto.xml.erb')
fonts.each do |subpkg, data|
conf_name = "45-noto#{'-' + subpkg if subpkg != '@'}.conf"
conf = if File.exists?(conf_name)
File.read(conf_name)
else
render_template(template, data: data)
end
File.write(File.join(out_dir, conf_name), conf)
end
end
Dir.chdir(__dir__) do
template = File.read('58-noto.xml.erb')
data = fonts
.values
.flat_map { _1['fonts'] }
.group_by { _1['alias'] }
conf = render_template(template, data: data)
File.write(File.join(out_dir, '58-noto.conf'), conf)
cp '58-noto-math.conf', File.join(out_dir, '58-noto-math.conf')
end
end
fonts = JSON.load_file(File.join(__dir__, 'noto-meta.json'))
case (action = ARGV[0])
when 'list-subpkgs'
puts fonts.keys.select { _1 != '@' }.sort_by { [-_1.size, _1] }
when 'gen-font-confs'
gen_font_confs(fonts, ARGV[1])
when 'pkgdesc', 'font-basenames'
key = ARGV[1].sub(/^font-noto-/, '')
data = fonts[key] or die! "unknown font subpkgname: #{ARGV[1]}"
case action
when 'pkgdesc'
puts data['pkgdesc']
when 'font-basenames'
puts data['fonts'].map { _1['family'].gsub(' ', '') }
end
else
die! "invalid action: #{action}"
end