Skip to content

Commit

Permalink
script for building glyphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gebuz committed Nov 12, 2024
1 parent 7fcc710 commit 17eaa30
Show file tree
Hide file tree
Showing 8,575 changed files with 27,586 additions and 608 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

## Building test files
Start by installing the dependencies with `npm install`. Then create a config with a dataforsyningen.dk token in the root folder (see `config.example.js` for an example config). After that you can build the test files with `npm run test` which will run a server that serves all the test html files at `localhost:8000/test`.

## Building glyphs from fonts
To build glyphs from the fonts in the `fonts` folder, install the depedencies with `npm install` and then run `npm run build-glyphs`.
53 changes: 53 additions & 0 deletions build-glyphs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fontnik from 'fontnik'
import { queue } from 'd3-queue'
import os from 'os'
import { existsSync, writeFileSync, readdirSync, readFileSync, mkdirSync } from 'node:fs'

const fontDir = 'fonts'
const outDir = 'glyphs'
const licenseFileNames = ['OFL.txt' || 'LICENSE']

function writeGlyphs(opts, done) {
fontnik.range(opts, (err, zdata) => {
if (err) {
console.warn(err.toString())
process.exit(1)
}
writeFileSync(`${opts.outDir}/${opts.start}-${opts.end}.pbf`, zdata)
done()
})
}

if (!existsSync(outDir)) {
console.warn('Error: Directory %s does not exist', outDir)
process.exit(1)
}

const q = queue(Math.max(4, os.cpus().length))

const topFolders = readdirSync(fontDir)
for(const topFolder of topFolders) {
const fonts = readdirSync(`${fontDir}/${topFolder}/`)
const license = fonts.find(font => licenseFileNames.includes(font))
const licenseBuffer = readFileSync(`${fontDir}/${topFolder}/${license}`)
for(const font of fonts) {
if (font.match(/[^.]+$/)[0] === 'ttf') {
const fontBuffer = readFileSync(`${fontDir}/${topFolder}/${font}`)
fontnik.load(fontBuffer, (err, faces) => {
const filePath = `${outDir}/${faces[0].family_name} ${faces[0].style_name}`
if (!existsSync(filePath)){
mkdirSync(filePath, { recursive: true })
}
writeFileSync(`${filePath}/LICENSE`, licenseBuffer)
for (let i = 0; i < 65536; (i = i + 256)) {
q.defer(writeGlyphs, {
outDir: filePath,
font: fontBuffer,
start: i,
end: Math.min(i + 255, 65535)
})
}
})
}
}
}
93 changes: 93 additions & 0 deletions fonts/OpenSans/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added fonts/OpenSans/OpenSans-Bold.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-BoldItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-ExtraBold.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-Italic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-Light.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-LightItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-Medium.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-MediumItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-Regular.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-SemiBold.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans-SemiBoldItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-Bold.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-BoldItalic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-ExtraBold.ttf
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-Italic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-Light.ttf
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-Medium.ttf
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-Regular.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_Condensed-SemiBold.ttf
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_SemiCondensed-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_SemiCondensed-Italic.ttf
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_SemiCondensed-Light.ttf
Binary file not shown.
Binary file not shown.
Binary file added fonts/OpenSans/OpenSans_SemiCondensed-Medium.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added glyphs/Open Sans Bold Italic/0-255.pbf
Binary file not shown.
Binary file added glyphs/Open Sans Bold Italic/1024-1279.pbf
Binary file not shown.
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/10240-10495.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 10240-10495
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/10496-10751.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 10496-10751
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/10752-11007.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 10752-11007
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/11008-11263.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 11008-11263
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/11264-11519.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 11264-11519
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/11520-11775.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 11520-11775
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/11776-12031.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 11776-12031
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/12032-12287.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 12032-12287
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/12288-12543.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 12288-12543
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/12544-12799.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 12544-12799
Binary file added glyphs/Open Sans Bold Italic/1280-1535.pbf
Binary file not shown.
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/12800-13055.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 12800-13055
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/13056-13311.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 13056-13311
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/13312-13567.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 13312-13567
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/13568-13823.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 13568-13823
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/13824-14079.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 13824-14079
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/14080-14335.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 14080-14335
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/14336-14591.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 14336-14591
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/14592-14847.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 14592-14847
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/14848-15103.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 14848-15103
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/15104-15359.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 15104-15359
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/1536-1791.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

"
Open Sans Bold Italic 1536-1791
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/15360-15615.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 15360-15615
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/15616-15871.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 15616-15871
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/15872-16127.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 15872-16127
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/16128-16383.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 16128-16383
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/16384-16639.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 16384-16639
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/16640-16895.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 16640-16895
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/16896-17151.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 16896-17151
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/17152-17407.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 17152-17407
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/17408-17663.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 17408-17663
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/17664-17919.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 17664-17919
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/1792-2047.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

"
Open Sans Bold Italic 1792-2047
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/17920-18175.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 17920-18175
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/18176-18431.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 18176-18431
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/18432-18687.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 18432-18687
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/18688-18943.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 18688-18943
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/18944-19199.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 18944-19199
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/19200-19455.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 19200-19455
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/19456-19711.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 19456-19711
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/19712-19967.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 19712-19967
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/19968-20223.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 19968-20223
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/20224-20479.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 20224-20479
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/2048-2303.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

"
Open Sans Bold Italic 2048-2303
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/20480-20735.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 20480-20735
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/20736-20991.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 20736-20991
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/20992-21247.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 20992-21247
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/21248-21503.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 21248-21503
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/21504-21759.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 21504-21759
3 changes: 3 additions & 0 deletions glyphs/Open Sans Bold Italic/21760-22015.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$
Open Sans Bold Italic 21760-22015
Loading

0 comments on commit 17eaa30

Please sign in to comment.