-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ feat: add subsets and update structure
- Loading branch information
1 parent
6aa5963
commit a2d4ff8
Showing
35 changed files
with
1,458 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* [0] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.0.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.0.woff) format('woff'); | ||
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; | ||
} | ||
/* [1] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.1.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.1.woff) format('woff'); | ||
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; | ||
} | ||
/* [2] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.2.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.2.woff) format('woff'); | ||
unicode-range: U+1F00-1FFF; | ||
} | ||
/* [3] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.3.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.3.woff) format('woff'); | ||
unicode-range: U+0370-03FF; | ||
} | ||
/* [4] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.4.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.4.woff) format('woff'); | ||
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; | ||
} | ||
/* [5] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.5.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.5.woff) format('woff'); | ||
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; | ||
} | ||
/* [6] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.6.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.6.woff) format('woff'); | ||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* [0] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.0.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.0.woff) format('woff'); | ||
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; | ||
} | ||
/* [1] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.1.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.1.woff) format('woff'); | ||
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; | ||
} | ||
/* [2] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.2.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.2.woff) format('woff'); | ||
unicode-range: U+1F00-1FFF; | ||
} | ||
/* [3] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.3.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.3.woff) format('woff'); | ||
unicode-range: U+0370-03FF; | ||
} | ||
/* [4] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.4.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.4.woff) format('woff'); | ||
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB; | ||
} | ||
/* [5] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.5.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.5.woff) format('woff'); | ||
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; | ||
} | ||
/* [6] */ | ||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
font-weight: 400; | ||
src: url(./woff2-dynamic-subset/Nasalization-Regular.subset.6.woff2) format('woff2'), url(./woff-dynamic-subset/Nasalization-Regular.subset.6.woff) format('woff'); | ||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Copyright (c) Typodermic Fonts Inc, with Reserved Font Name Nasalization. | ||
https://typodermicfonts.com/nasalization/ | ||
*/ | ||
|
||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
src: local('Nasalization'), url('./woff2/Nasalization-Regular.subset.woff2') format('woff2'), local('Nasalization'), url('./woff/Nasalization-Regular.subset.woff') format('woff'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Copyright (c) Typodermic Fonts Inc, with Reserved Font Name Nasalization. | ||
https://typodermicfonts.com/nasalization/ | ||
*/ | ||
|
||
@font-face { | ||
font-family: 'Nasalization'; | ||
font-style: normal; | ||
font-display: swap; | ||
src: local('Nasalization'), url('./woff2/Nasalization-Regular.woff2') format('woff2'), local('Nasalization'), url('./woff/Nasalization-Regular.woff') format('woff'); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "subset-utils", | ||
"version": "1.0.0", | ||
"author": "Ayaan_ <[email protected]>", | ||
"private": true, | ||
"main": "dist/subset.js", | ||
"scripts": { | ||
"subset": "yarn build && node dist/subset.js", | ||
"build": "tsup subset.ts subset-utils.ts" | ||
}, | ||
"dependencies": { | ||
"font-range": "^1.0.2", | ||
"tslib": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"@swc/core": "^1.3.25", | ||
"@types/node": "^18.11.18", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## pip-outdated requirements.txt | ||
# https://pypi.org/project/pip-outdated/ | ||
|
||
appdirs~=1.4.4 | ||
six~=1.16.0 | ||
fs<3,>=2.2.0 | ||
pytz~=2022.7 | ||
fonttools~=4.38.0 | ||
Brotli~=1.0.9 | ||
zopfli~=0.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// == Code from @orioncactus/pretendard/packages/subset-utils == | ||
// == Copyright 2023 by Orioncactus & Black7345 == | ||
|
||
import { basename, extname, join } from 'node:path'; | ||
import { mkdir, access, rm } from 'fs/promises'; | ||
import { fontPipe, FontPipeI } from 'font-range'; | ||
|
||
// == Types =================================================================== | ||
export interface ISubsets<T>{ | ||
(kinds: TSubsetKinds, format: Tformat, fontList: IFontInfo): T | ||
} | ||
export interface IFontInfo { | ||
family: FONTFAMILY; | ||
fontList: string[]; | ||
} | ||
|
||
export type Tformat = "woff" | "woff2" | ||
export type TPathKinds = "Static"; | ||
export type TSubsetKinds = "static" | "glyph" | "dynamic"; | ||
|
||
// == Constants =============================================================== | ||
const STATIC_PATH = join(process.cwd(), "..", "..", "fonts", "truetype"); | ||
const STATIC_OUTPUT_PATH = join(process.cwd(), "..", "..", "fonts", "web" ); | ||
|
||
export enum FONTFAMILY { | ||
Nasalization = "Nasalization" | ||
}; | ||
|
||
const FONTWEIGHTS = [ | ||
"Regular" | ||
]; | ||
|
||
// == Functions =============================================================== | ||
export async function clearDir(outDir: string) { | ||
try { | ||
await access(outDir); | ||
await rm(outDir, { recursive: true, force: true }); | ||
await mkdir(outDir); | ||
} catch(err) { | ||
await mkdir(outDir); | ||
} | ||
} | ||
|
||
function getOutInfo(kinds: TSubsetKinds, format: Tformat) { | ||
switch(kinds) { | ||
case "static": return { | ||
outType: format, | ||
outName: "{NAME}{EXT}" | ||
}; | ||
case "glyph": return { | ||
outType: `${format}-subset`, | ||
outName: "{NAME}.subset{EXT}" | ||
}; | ||
case "dynamic": return { | ||
outType: `${format}-dynamic-subset`, | ||
outName: "{NAME}.subset.{INDEX}{EXT}" | ||
}; | ||
} | ||
} | ||
|
||
async function createOption(kinds: TSubsetKinds, format: Tformat, fontInfo: IFontInfo) { | ||
// Get Infos | ||
const { fontList } = fontInfo; | ||
|
||
const basePath = STATIC_PATH; | ||
const distPath = STATIC_OUTPUT_PATH; | ||
|
||
const { outType, outName } = getOutInfo(kinds, format); | ||
const outDir = join(distPath, outType); | ||
|
||
// Clear Files | ||
await clearDir(outDir); | ||
|
||
// Create Options | ||
const baseLogFormat = "Convert {ORIGIN} -> {OUTPUT}"; | ||
const groupLogFormat = `\n== ${kinds} ${outType} ======\n` + baseLogFormat; | ||
const baseOption = { | ||
format: format === "woff" ? "woff-zopfli" : format, | ||
saveDir: outDir, | ||
nameFormat: outName | ||
}; | ||
const fontOptions = fontList.map((fontFile, i) => { | ||
const logFormat = i === 0 ? groupLogFormat : baseLogFormat; | ||
const fontName = basename(fontFile, extname(fontFile)); | ||
const fontPath = join(basePath, fontFile); | ||
const fontOption = { | ||
fontPath, | ||
option: { | ||
...baseOption, | ||
logFormat | ||
} | ||
} as Required<FontPipeI>; | ||
|
||
if(kinds === "glyph") { | ||
fontOption.option.textFile = join(process.cwd(), "subset_glyphs.txt"); | ||
} | ||
if(kinds === "dynamic") { | ||
fontOption.option.cssFile = join(distPath, fontName + ".css"); | ||
} | ||
return fontOption; | ||
}); | ||
return fontOptions; | ||
} | ||
|
||
// == Main ==================================================================== | ||
export function getFontList(family = FONTFAMILY.Nasalization) { | ||
const extResult = '.ttf'; | ||
const fontList = FONTWEIGHTS.map(weight => family + "-" + weight + extResult); | ||
|
||
return { family, fontList }; | ||
} | ||
|
||
export async function subsets<T>(...subsetList: Parameters<ISubsets<T>>[]) { | ||
const options = subsetList.map(async (info) => await createOption(...info)); | ||
|
||
await fontPipe( | ||
(await Promise.all(options)).flat() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FONTFAMILY, getFontList, subsets } from "./subset-utils"; | ||
|
||
const fontList = getFontList(FONTFAMILY.Nasalization); | ||
|
||
subsets( | ||
// woff | ||
["static", "woff", fontList], | ||
["glyph", "woff", fontList], | ||
["dynamic", "woff", fontList], | ||
|
||
// woff2 | ||
["static", "woff2", fontList], | ||
["glyph", "woff2", fontList], | ||
["dynamic", "woff2", fontList] | ||
); |
Oops, something went wrong.