Skip to content

Commit

Permalink
Doc: README - 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
black7375 committed Jan 10, 2023
1 parent 4018361 commit 9e24ff4
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.css linguist-detectable=false
*.otf binary
*.zip binary
17 changes: 17 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# These are supported funding model platforms

## Example
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository
# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
# patreon: # Replace with a single Patreon username
# open_collective: # Replace with a single Open Collective username
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

github: [black7375]
184 changes: 141 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![TypeScript version][ts-badge]][typescript-4-0]
[![TypeScript version][ts-badge]][typescript-4-9]
[![Node.js version][nodejs-badge]][nodejs]
[![APLv2][license-badge]][license]

[![MIT][license-badge]][license]
[![Node.js CI][gha-badge]][gha-ci]
# Font Range

| ![NJ](https://raw.githubusercontent.com/black7375/font-range/master/resource/News_Japanese.gif) | ![NK](https://raw.githubusercontent.com/black7375/font-range/master/resource/News_Korean.gif) | ![NC](https://raw.githubusercontent.com/black7375/font-range/master/resource/News_Chinese.gif) |
Expand All @@ -17,47 +17,41 @@ Google Font provides a subset of [Korean](https://design.google/news/google-font
![Result](https://raw.githubusercontent.com/black7375/font-range/master/resource/Korean_Japanese.png)

## Usage
Google font `CSS file`(include `unicode-range` file) url and `font path` are fine.

```js
fontRange(google_font_css_url, font_path);
fontRange(google_font_css_url, font_path, save_path); // Option1
fontRange(google_font_css_url, font_path, {
savePath: "<SAVE SUBSET PATH>",
format: "<FONT FORMAT>",
nameForamt: "<NAME FORAMT>",
defaultArgs: "<Default Args>",
etcArgs: "<ETC pyftsubset args>"
}); // Option2
```
- `save_path`'s default: `<font_path>`
- `format`'s default: `"woff2"`
- `nameFormat`'s default: `"{NAME}_{INDEX}{EXT}"`
- `defaultArgs`'s default:
```
"--layout-features='*' \
--glyph-names \
--symbol-cmap \
--legacy-cmap \
--notdef-glyph \
--notdef-outline \
--recommended-glyphs \
--name-legacy \
--drop-tables= \
--name-IDs='*' \
--name-languages='*'
"
```
- `etcArgs`'s default: `""`

### Requires
It has dependencies on the following packages:

```sh
pip install fonttools[ufo,woff,unicode] zopfli brotli
pip install fonttools[ufo,woff,unicode] zopfli brotli
```

### CSS URL?
### Basics
This project has three types.
- `fontRange()`: Subset based on `unicode-range` in the CSS file.
- `fontSubset()`: Subset based on text or text file.
- `fontPipe()`: Use `fontRange()` and `fontSubset()` to perform multiple subset operations.

```js
// fontRange
fontRange(font_path, css_url_or_path);
fontRange(font_path, css_url_or_path, save_dir); // Option1
fontRange(font_path, css_url_or_path, { ...options }); // Option2

// fontSubset
fontRange(font_path);
fontRange(font_path, save_dir); // Option1
fontRange(font_path, { ...options }); // Option2

// fontPipe
fontPipe([
{ font_path }, // As `fontSubset(font_path)`
{ font_path, option: { text: "abc" } }, // As `fontSubset(font_path, { text: "abc" })`
{ font_path, option: { textFile: file_path } }, // As `fontSubset(font_path, { textFile: file_path })`
{ font_path, option: { cssFile: css_url_or_path } } // As `fontRange(font_path, css_url_or_path)`
]);
fontPipe([{ font_path1 }, { font_path2 }], "<index>/<total>"); // Sharding option use like `1/2`
```

#### CSS URL?
The URL of [`Noto Sans`](https://www.google.com/get/noto/) is included in the package.

![Noto](https://raw.githubusercontent.com/black7375/font-range/master/resource/Noto_0.png)
Expand All @@ -72,13 +66,117 @@ const targets = {
};
```

### Default Options

List of options available for all function options.

```ts
type Format = "otf" | "ttf" | "woff2" | "woff" | "woff-zopfli";
interface FontDefaultOptionI {
saveDir: string; // Directory to save the generated subset or downloaded CSS
format: Format; // Subset type to create
nameFormat: string; // File name format to create
logFormat: string; // Log format to print
defaultArgs: string[]; // `pyftsubset` option - default
etcArgs: string[]; // `pyftsubset` option - for users
}
```
- `save_dir`'s default: `<font_path>`
- `format`'s default: `"woff2"`
- `nameFormat`'s default: `"{NAME}_{INDEX}{EXT}"`
- `defaultArgs`'s default:
```js
[
"--layout-features=*",
"--glyph-names",
"--symbol-cmap",
"--legacy-cmap",
"--notdef-glyph",
"--notdef-outline",
"--recommended-glyphs",
"--name-legacy",
"--drop-tables=",
"--name-IDs=*",
"--name-languages=*"
]
```
- `etcArgs`'s default: `[]`

### Font Range

It is designed to be able to do a subset using `unicode-range` of CSS.

#### Option

The name of the generated file can be determined from the CSS.

```ts
interface FontRangeOptionI extends FontDefaultOptionI {
fromCSS: "default" | "srcIndex" | "srcName";
}
```
- `default`: The `index` of the file name increases in the generated order
- `srcIndex`: The `index` of the file name uses [`src`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src) in CSS [#9](https://github.com/black7375/font-range/issues/9)
- Based on the first `url()`
- `srcName`: The file name uses [`src`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src) in CSS
- Based on the first `url()`

### Font Subset

It is designed to be able to do a general subset.

#### Option

By default, all letters are included, but you can set the letters to include:

```ts
interface FontSubsetOptionI extends FontDefaultOptionI {
textFile: string; // From text file
text: string; // Letter like `abc`
}
```

### Font Pipe

It offers a simple API when doing a large amount of subsets.

Performance is optimized using worker poll and provides sharding for distributed environments.

#### Option

If `cssFile` has attributes, it is recognized as `fontRange()`.

```ts
interface FontPipeOptionI extends FontRangeOptionI, FontSubsetOptionI {
cssFile: string;
}
```

#### Sharding

You can control sharing using `argument` or `environment variable`.
If both values are used together, `argument` is applied first.

- Argument: Explicitly used through function.
```js
fontPipe([{ font_path1 }, { font_path2 }], "<index>/<total>");
```

- Environment Variable: Make it easy to use in CI, npm scripts, ..etc.
```sh
SHARD=<index>/total
node subset.js
```

## License

Licensed under the APLv2. See the [LICENSE](https://github.com/jsynowiec/node-typescript-boilerplate/blob/master/LICENSE) file for details.
Licensed under the MIT. See the [LICENSE][license] file for details.

[ts-badge]: https://img.shields.io/badge/TypeScript-4.0-blue.svg
[nodejs-badge]: https://img.shields.io/badge/Node.js->=%2012.13-blue.svg
[nodejs]: https://nodejs.org/dist/latest-v12.x/docs/api/
[typescript-4-0]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html
[ts-badge]: https://img.shields.io/badge/TypeScript-4.9-blue.svg
[typescript-4-9]: https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/
[nodejs-badge]: https://img.shields.io/badge/Node.js->=%2016.16-blue.svg
[nodejs]: https://nodejs.org/dist/latest-v18.x/docs/api/
[license-badge]: https://img.shields.io/badge/license-MIT-blue
[license]: https://github.com/black7375/font-range/blob/master/LICENSE
[gha-badge]: https://github.com/black7375/font-range/actions/workflows/nodejs.yml/badge.svg?branch=master
[gha-ci]: https://github.com/black7375/font-range/actions/workflows/nodejs.yml
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "font-range",
"description": " Font subset with google font's ML result.",
"version": "0.2.1",
"version": "1.0.0",
"author": "black7375 <[email protected]>",
"license": "MIT",
"keywords": [
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/black7375/font-range#readme",
"engines": {
"node": ">= 12.13"
"node": ">= 16.16"
},
"devDependencies": {
"@types/command-exists": "^1.2.0",
Expand Down Expand Up @@ -62,7 +62,7 @@
"tslib": "^2.4.1"
},
"volta": {
"node": "19.3.0",
"node": "16.16.0",
"npm": "9.2.0"
},
"packageManager": "[email protected]"
Expand Down

0 comments on commit 9e24ff4

Please sign in to comment.