1
0
Fork 0
mirror of https://github.com/NixOS/nixos-artwork synced 2024-10-18 00:06:24 -04:00

matrix: default.nix to build icons

This commit is contained in:
Samuel Dionne-Riel 2021-05-21 18:51:38 -04:00
parent f8b0cbdfb9
commit d4a807596c
3 changed files with 154 additions and 0 deletions

75
matrix/build.rb Normal file
View file

@ -0,0 +1,75 @@
#!/usr/bin/env ruby
require "nokogiri"
require "fileutils"
$document = ARGV.first
$out = ENV["out"]
include FileUtils
def save(doc, out)
File.open("icons.src.svg", "w") do |f|
doc.write_xml_to(f, :encoding => "UTF-8")
end
system(
"inkscape",
"icons.src.svg",
"--export-area-page",
"--export-filename=#{out}",
)
rm("icons.src.svg")
end
puts("Matrix Icons Builder...")
puts("=======================\n")
mkdir_p($out)
$doc = Nokogiri::XML::Document.parse(File.read($document))
$doc.element_children.each do |svg|
# Checks we indeed loaded an SVG document...
raise unless svg.name == "svg"
# First hide everything.
svg.element_children.select {|el| el.name == "g"}.each do |el|
el["style"] = "display:none"
end
# Then prepare exports for this category
svg.element_children.select {|el| el.name == "g"}.each do |el|
type = el["inkscape:label"]
# Skip an unneeded category
next if type == "DO NOT PRINT"
# Show the current layer
el["style"] = ""
# But first hide everything but the background
el.element_children.each do |child|
if child["inkscape:label"].match(/^\$BACKGROUND/)
child["style"] = ""
else
child["style"] = "display:none"
end
end
el.element_children.each do |child|
next if child["inkscape:label"].match(/^\$BACKGROUND/)
# Show the layer
child["style"] = ""
name = child["inkscape:label"]
save($doc, File.join($out, "#{type}-#{name}.png"))
# Hide the layer
child["style"] = "display:none"
end
# Hide the current layer again
el["style"] = "display:none"
end
end

70
matrix/default.nix Normal file
View file

@ -0,0 +1,70 @@
# This uses a pinned Nixpkgs so the software
# used for the export (inkscape) and fonts used
# for the export stay proper.
{ pkgs ? import ./pkgs.nix {} }:
let
FONTCONFIG_FILE = pkgs.callPackage (
{ symlinkJoin
, writeText
, encode-sans
}:
let
mkFontsDir = fonts: symlinkJoin {
name = "fonts-dir";
paths = fonts;
};
fontsDir = mkFontsDir [
encode-sans
];
in
writeText "fonts.conf" ''
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<fontconfig>
<dir>${fontsDir}</dir>
<!-- Default rendering settings -->
<match target="pattern">
<edit mode="append" name="hinting">
<bool>true</bool>
</edit>
<edit mode="append" name="autohint">
<bool>true</bool>
</edit>
<edit mode="append" name="hintstyle">
<const>hintslight</const>
</edit>
<edit mode="append" name="antialias">
<bool>true</bool>
</edit>
</match>
</fontconfig>
''
) {};
in
# Yes, you can callPackage something else than a path!
pkgs.callPackage (
{ runCommandNoCC, inkscape, encode-sans, FONTCONFIG_FILE, ruby }:
runCommandNoCC "nixos-artwork-matrix-icons" {
nativeBuildInputs = [
inkscape
ruby
];
inherit FONTCONFIG_FILE;
} ''
ruby ${./build.rb} ${./icons.src.svg}
''
) {
inherit FONTCONFIG_FILE;
ruby = pkgs.ruby.withPackages(p: [
p.nokogiri
]);
}

9
matrix/pkgs.nix Normal file
View file

@ -0,0 +1,9 @@
let
rev = "d42cd445dde587e9a993cd9434cb43da07c4c5de";
sha256 = "0dzrn97srxyw5a3g7hf8chwccxns5z3aij23hc0fch7ygc8w0gq0";
tarball = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256;
};
in
builtins.trace "Using default Nixpkgs revision '${rev}'..." (import tarball)