Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pmndrs/assets
Browse files Browse the repository at this point in the history
  • Loading branch information
drcmda committed Jun 12, 2023
2 parents dbbd658 + e983dfe commit 82b247a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install packages
run: |
brew install imagemagick jq
brew install imagemagick jq fonttools
- uses: actions/setup-node@v3
with:
cache: 'yarn'
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DIST = dist

RESIZE = 512x512
QUALITY = 80
FONTCHARS = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,;.:-_<>$$£!+\"*ç%&/~[]{}()=?\`^\'#€öÖäÄüܧ°
#
# Build TARGETS
Expand Down Expand Up @@ -66,7 +67,7 @@ $(DIST)/%.js: $(SRC)/%.b64
cat $< | jq -c > $@
%.woff.compressed: %.woff
cp $< $@
node ./bin/subset.js $< "$(FONTCHARS)" $@
%.glb.compressed: %.glb
npx gltf-transform optimize $< $*.tmp.glb
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Keep [bundler limitations](https://github.com/rollup/plugins/tree/master/package
### Import (with care ⚠️)
You can of course also directly import the assets, but *do it only in modules that already are split from the main bundle*! It is not recommended for your entry points as it would considerally impede time-to-load.
You can of course also directly import the assets, but _do it only in modules that already are split from the main bundle_! It is not recommended for your entry points as it would considerally impede time-to-load.
```jsx
import city from '@pmndrs/assets/hdri/city.exr'
Expand All @@ -71,7 +71,7 @@ new THREE.EXRLoader().load(city, (texture) => {
# Fonts
The [Inter](https://rsms.me/inter/) font family converted to *.json using [facetype.js](https://gero3.github.io/facetype.js), and *.woff using [fontmin](https://github.com/ecomfe/fontmin) with a subset of `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,;.:-_<>!+"*ç%&/~[]{}()=?``^'#€öÖäÄüܧ°`. Each json is ~30-40kb, each woff ~100-200kb.
The [Inter](https://rsms.me/inter/) font family converted to _.json using [facetype.js](https://gero3.github.io/facetype.js), and _.woff using [fonttools](https://github.com/fonttools/fonttools) with a subset of ` ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,;.:-_<>!+"*ç%&/~[]{}()=?``^'#€öÖäÄüܧ° `. Each json is ~30-40kb, each woff ~15-20kb.
```js
import interJson from '@pmndrs/assets/fonts/inter_regular.json'
Expand All @@ -88,7 +88,7 @@ index: [`src/fonts`](src/fonts)
</a>
</p>

A selection of [Polyhaven](https://polyhaven.com/hdris) HDRIs, resized to 512x512 and converted to EXR with DWAB compression. They are about 7x smaller than the Polyhaven originals. Each hdr is ~100-200kb.
A selection of [Polyhaven](https://polyhaven.com/hdris) HDRIs, resized to 512x512 and converted to EXR with DWAB compression. They are about 7x smaller than the Polyhaven originals. Each exr is ~100-200kb.

```js
import apartment from '@pmndrs/assets/hdri/apartment.exr'
Expand Down Expand Up @@ -130,6 +130,7 @@ Pre-requisites:
- Nodejs
- ImageMagick 7+
- jq
- fonttools
- openssl

```sh
Expand Down
31 changes: 31 additions & 0 deletions bin/subset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

//
// $ node ./bin/subset.js myfont.woff ABCDEFG mysubsetfont.woff
//

import { exec } from 'child_process'

// Function to convert a string to Unicode
const toUnicode = (str) =>
[...str].map((c) => 'U+' + c.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')).join(',')

// Function to call pyftsubset
function subsetFont(fontName, unicodeString, outputName) {
const cmd = `pyftsubset ${fontName} --unicodes=${unicodeString} --flavor=woff --output-file=${outputName}`

exec(cmd, (error, stdout, stderr) => {
if (error) throw error
process.stdout.write(stdout)
})
}

// Get command line arguments
const args = process.argv.slice(2)
if (args.length !== 3) {
console.error('Usage: node subset.js <font name> <characters> <output file name>')
process.exit(1)
}

// Convert to Unicode and call pyftsubset
subsetFont(args[0], toUnicode(args[1]), args[2])

0 comments on commit 82b247a

Please sign in to comment.