Skip to content

Commit

Permalink
add font-noto package (#38921)
Browse files Browse the repository at this point in the history
adds font-noto package

---------

Signed-off-by: kranurag7 <81210977+kranurag7@users.noreply.github.com>
Signed-off-by: Batuhan Apaydin <batuhan.apaydin@chainguard.dev>
Co-authored-by: Batuhan Apaydin <batuhan.apaydin@chainguard.dev>
  • Loading branch information
kranurag7 and developer-guy authored Feb 19, 2025
1 parent 54f4be3 commit d2ae284
Show file tree
Hide file tree
Showing 7 changed files with 2,035 additions and 0 deletions.
213 changes: 213 additions & 0 deletions font-noto.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package:
name: font-noto
version: 2025.02.01
epoch: 0
description: Noto fonts
dependencies:
runtime:
- fontconfig
copyright:
- license: Apache-2.0

environment:
contents:
packages:
- busybox
- jq
- ruby

data:
- name: subpkgs
items:
nyiakeng-puachue-hmong:
canadian-aboriginal:
indic-siyaq-numbers:
khitan-small-script:
hanifi-rohingya:
mayan-numerals:
gunjala-gondi:
masaram-gondi:
mende-kikakui:
nastaliq-urdu:
ottoman-siyaq:
cypro-minoan:
meetei-mayek:
naskh-arabic:
pahawh-hmong:
rashi-hebrew:
sora-sompeng:
syloti-nagri:
dives-akuru:
kufi-arabic:
medefaidrin:
nag-mundari:
nandinagari:
new-tai-lue:
pau-cin-hau:
signwriting:
warang-citi:
chorasmian:
devanagari:
historical:
old-uyghur:
saurashtra:
bassa-vah:
malayalam:
mongolian:
samaritan:
sundanese:
armenian:
balinese:
buginese:
cherokee:
duployan:
ethiopic:
fangsong:
georgian:
gujarati:
gurmukhi:
javanese:
kayah-li:
ol-chiki:
tagbanwa:
tifinagh:
vithkuqi:
znamenny:
bengali:
elbasan:
grantha:
hanunoo:
kannada:
makasar:
myanmar:
sharada:
sinhala:
soyombo:
symbols:
tibetan:
tirhuta:
arabic:
chakma:
coptic:
hebrew:
kaithi:
khojki:
lepcha:
rejang:
syriac:
tangsa:
telugu:
thaana:
wancho:
yezidi:
adlam:
bamum:
batak:
buhid:
khmer:
limbu:
music:
nushu:
oriya:
osage:
tamil:
ahom:
cham:
kawi:
lisu:
math:
miao:
modi:
newa:
test:
thai:
toto:
lao:
mro:
nko:
tai:
vai:
yi:

pipeline:
- uses: git-checkout
with:
expected-commit: 5f3fe2540d34dfb13929aadc717d90b7066a7198
repository: https://github.com/notofonts/notofonts.github.io
tag: noto-monthly-release-${{package.version}}

- runs: |
mkdir -p conf.d
./noto-meta gen-font-confs conf.d/
mkdir -p ${{targets.contextdir}}/etc/fonts/conf.avail/
mkdir -p ${{targets.contextdir}}/usr/share/fonts/noto/
cp fonts/*/hinted/ttf/*.ttf ${{targets.contextdir}}/usr/share/fonts/noto/
cp conf.d/*.conf ${{targets.contextdir}}/etc/fonts/conf.avail/
mkdir -p ${{targets.contextdir}}/etc/fonts/conf.d
for f in "${{targets.destdir}}/etc/fonts/conf.avail/"*.conf; do
full_filename=$(basename "$f")
ln -s /etc/fonts/conf.avail/$full_filename ${{targets.contextdir}}/etc/fonts/conf.d/$full_filename
done
subpackages:
- name: ${{package.name}}-common
description: Common files for Noto font families
pipeline:
- runs: |
mkdir -p ${{targets.contextdir}}/etc/fonts/conf.avail
mkdir -p ${{targets.contextdir}}/etc/fonts/conf.d
cp conf.d/58-noto.conf ${{targets.contextdir}}/etc/fonts/conf.avail/58-noto.conf
cp conf.d/58-noto.conf ${{targets.contextdir}}/etc/fonts/conf.d/58-noto.conf
ln -sf /etc/fonts/conf.avail/58-noto.conf ${{targets.contextdir}}/etc/fonts/conf.d/58-noto.conf
- range: subpkgs
name: ${{package.name}}-${{range.key}}
dependencies:
runtime:
- ${{package.name}}-common
- fontconfig
description: ${{range.key}} font package
pipeline:
- runs: |
mkdir -p ${{targets.contextdir}}/usr/share/fonts/noto
for font in $(./noto-meta font-basenames "${{range.key}}"); do
find "${{targets.destdir}}/usr/share/fonts/" -name "$font-*.ttf" -exec cp {} "${{targets.contextdir}}/usr/share/fonts/" \;
done
# Create directories for font configuration
mkdir -p "${{targets.contextdir}}/etc/fonts/conf.d/"
mkdir -p "${{targets.contextdir}}/etc/fonts/conf.avail/"
# Process the configuration files
for f in "${{targets.destdir}}/etc/fonts/conf.avail/"*.conf; do
full_filename=$(basename "$f")
font_name=$(echo "$full_filename" | sed -E 's/^[^-]+-[^-]+-([^.]+)\.conf/\1/')
# Only continue if the font name matches the basename
if [ "${{range.key}}" != "$font_name" ]; then
continue
fi
# Copy the config file to the context directory
cp "${{targets.destdir}}/etc/fonts/conf.avail/$full_filename" "${{targets.contextdir}}/etc/fonts/conf.avail/$full_filename"
# Create a symbolic link for the config file
ln -s "/etc/fonts/conf.avail/$full_filename" "${{targets.contextdir}}/etc/fonts/conf.d/$full_filename"
done
test:
environment:
contents:
packages:
- fontconfig
pipeline:
- runs: stat "/usr/share/fonts/noto"
- runs: find "/usr/share/fonts/noto" -name "*.ttf" -exec fc-scan {} \;

update:
enabled: true
github:
identifier: notofonts/notofonts.github.io
strip-prefix: noto-monthly-release-
use-tag: true
tag-filter: noto-monthly-release-
24 changes: 24 additions & 0 deletions font-noto/45-noto-math.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- Noto Sans Math -->
<match>
<test name="family">
<string>math</string>
</test>
<test name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Noto Sans Math</string>
</edit>
</match>

<alias>
<family>Noto Sans Math</family>
<default>
<family>math</family>
<family>sans-serif</family>
</default>
</alias>
</fontconfig>
12 changes: 12 additions & 0 deletions font-noto/45-noto.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<% data['fonts'].each do |font| -%>
<alias>
<family><%= font['family'] %></family>
<default>
<family><%= font['alias'] %></family>
</default>
</alias>
<% end -%>
</fontconfig>
29 changes: 29 additions & 0 deletions font-noto/58-noto-math.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
| This should be after 50-user.conf and 51-local.conf to not override user
| and local system overrides, and before 60-generic.conf to take precedence
| over the font-config's default preferables.
|-->
<description>Set Noto Sans Math as a preferable font for math</description>

<alias>
<family>math</family>
<prefer>
<family>Noto Sans Math</family>
</prefer>
</alias>

<match>
<test name="family">
<string>math</string>
</test>
<test name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Noto Sans Math</string>
</edit>
</match>
</fontconfig>
23 changes: 23 additions & 0 deletions font-noto/58-noto.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
| This should be after 50-user.conf and 51-local.conf to not override user
| and local system overrides, and before 60-latin.conf and 65-nonlatin.conf
| to take precedence over the font-config's default preferables (although
| Noto is on the top there, extra language variants are missing).
|-->
<description>Set Noto fonts as preferable</description>

<% data.each do |falias, fonts| -%>
<alias>
<family><%= falias %></family>
<prefer>
<% fonts.each do |font| -%>
<family><%= font['family'] %></family>
<% end -%>
</prefer>
</alias>

<% end -%>
</fontconfig>
78 changes: 78 additions & 0 deletions font-noto/noto-meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/ruby
require 'erb'
require 'fileutils'
require 'json'
require 'ostruct'
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.exist?(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
Loading

0 comments on commit d2ae284

Please sign in to comment.