appleFonts: Add fonts from MobileAssets
This commit is contained in:
parent
03880ef039
commit
0fa9c60778
1
apple/assets.json
Normal file
1
apple/assets.json
Normal file
File diff suppressed because one or more lines are too long
36
apple/default.nix
Normal file
36
apple/default.nix
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{ lib, fetchurl, stdenvNoCC, unzip }:
|
||||||
|
let
|
||||||
|
root = lib.importJSON ./assets.json;
|
||||||
|
|
||||||
|
mkExtraFont = family: data: {
|
||||||
|
name = lib.replaceStrings [ " " ] [ "-" ] family;
|
||||||
|
value = stdenvNoCC.mkDerivation {
|
||||||
|
name = family;
|
||||||
|
srcs = map fetchurl data.assets;
|
||||||
|
|
||||||
|
dontUnpack = true;
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/share/fonts/apple
|
||||||
|
|
||||||
|
i=0
|
||||||
|
for src in $srcs; do
|
||||||
|
mkdir $i
|
||||||
|
${unzip}/bin/unzip -d $i $src
|
||||||
|
cp -v -t $out/share/fonts/apple $i/AssetData/*.{ttc,ttf,otf}
|
||||||
|
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
license = licenses.unfree;
|
||||||
|
platforms = platforms.all;
|
||||||
|
description = "${family} fonts as downloadable from macOS";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
extra = lib.mapAttrs' mkExtraFont root.extra;
|
||||||
|
allExtra = (mkExtraFont "All Extra" root.all_extra).value;
|
||||||
|
}
|
58
apple/update.py
Executable file
58
apple/update.py
Executable file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i python3 -p python3Packages.requests
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import plistlib
|
||||||
|
import requests
|
||||||
|
from typing import Dict, Any, List
|
||||||
|
|
||||||
|
assets = plistlib.loads(
|
||||||
|
requests.get(
|
||||||
|
"https://mesu.apple.com/assets/com_apple_MobileAsset_Font7/com_apple_MobileAsset_Font7.xml"
|
||||||
|
).content
|
||||||
|
)["Assets"]
|
||||||
|
|
||||||
|
families: Dict[str, Any] = dict()
|
||||||
|
all_assets: List[Dict[str, str]] = []
|
||||||
|
for asset in assets:
|
||||||
|
# Period used for extra PUA font
|
||||||
|
names = set(
|
||||||
|
[
|
||||||
|
info["FontFamilyName"]
|
||||||
|
for info in asset["FontInfo4"]
|
||||||
|
if not info["FontFamilyName"].startswith(".")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
name = names.pop()
|
||||||
|
|
||||||
|
# There seems to be some support for things other than SHA-1 but I haven't seen it
|
||||||
|
hsh = "sha1-" + base64.b64encode(asset["_Measurement"]).decode("utf-8")
|
||||||
|
url = asset["__BaseURL"] + asset["__RelativePath"]
|
||||||
|
asset_obj = {
|
||||||
|
"url": url,
|
||||||
|
"hash": hsh,
|
||||||
|
}
|
||||||
|
all_assets.append(asset_obj)
|
||||||
|
version = asset["_CompatibilityVersion"]
|
||||||
|
|
||||||
|
if len(names) > 1:
|
||||||
|
print("Multiple family names found in asset:", ", ".join(names))
|
||||||
|
if name in families:
|
||||||
|
other_version = families[name]["version"]
|
||||||
|
if version == other_version:
|
||||||
|
families[name]["assets"].append(asset_obj)
|
||||||
|
continue
|
||||||
|
elif int(version) < int(other_version):
|
||||||
|
print(f"Duplicate asset found for family {name}, skipping")
|
||||||
|
continue
|
||||||
|
|
||||||
|
families[name] = {
|
||||||
|
"assets": [asset_obj],
|
||||||
|
"version": version,
|
||||||
|
}
|
||||||
|
|
||||||
|
with open("assets.json", "w") as f:
|
||||||
|
json.dump(
|
||||||
|
{"extra": families, "all_extra": {"assets": all_assets, "version": "mixed"}}, f
|
||||||
|
)
|
|
@ -127,6 +127,7 @@
|
||||||
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
|
name = replaceStrings [ " " ] [ "-" ] (toLower font.name);
|
||||||
value = buildLocalFont font;
|
value = buildLocalFont font;
|
||||||
}) localFonts);
|
}) localFonts);
|
||||||
|
appleFonts = final.callPackage ./apple { };
|
||||||
});
|
});
|
||||||
} // flake-utils.lib.eachDefaultSystem (system:
|
} // flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
|
@ -136,7 +137,13 @@
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
packages = pkgs.extraFonts;
|
packages = builtins.listToAttrs (map (name: {
|
||||||
|
inherit name;
|
||||||
|
value = pkgs.${name} // {
|
||||||
|
type = "derivation";
|
||||||
|
name = "dummy-attrset";
|
||||||
|
};
|
||||||
|
}) [ "extraFonts" "appleFonts" ]);
|
||||||
formatter = pkgs.nixfmt;
|
formatter = pkgs.nixfmt;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue