pa_font 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -112
- package/dist/paFont.cjs +2746 -1
- package/dist/paFont.cjs.map +1 -1
- package/dist/paFont.js +2746 -2
- package/dist/paFont.js.map +1 -1
- package/paFont.d.ts +67 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# @hanyongpa/pa-font
|
|
2
|
-
|
|
3
|
-
OpenType 폰트를 polygon, region, point 데이터로 바꿔 쓰기 위한 작은 geometry 라이브러리입니다.
|
|
4
|
-
|
|
5
|
-
현재 `package.json` 기준 패키지 이름은 `@hanyongpa/pa-font`로 잡아두었습니다. 실제 publish 전에 원하는 scope나 이름이 있으면 이 값만 바꾸면 됩니다.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @hanyongpa/pa-font
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import paFont from "@hanyongpa/pa-font";
|
|
17
|
-
|
|
18
|
-
const font = await paFont.load("/assets/font.otf");
|
|
19
|
-
|
|
20
|
-
const shape = font.text("안녕", {
|
|
21
|
-
x: 0,
|
|
22
|
-
y: 200,
|
|
23
|
-
size: 160,
|
|
24
|
-
flatten: 1,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const regions = shape.toRegions();
|
|
28
|
-
const points = shape.toPoints({ step: 8 });
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Core Flow
|
|
32
|
-
|
|
33
|
-
1. `paFont.load(...)`로 폰트를 로드합니다.
|
|
34
|
-
2. `font.text(...)` 또는 `font.glyph(...)`로 `PAShape`를 만듭니다.
|
|
35
|
-
3. `shape.toShape(...)`, `shape.toRegions(...)`, `shape.toPoints(...)` 중 필요한 결과를 꺼냅니다.
|
|
36
|
-
|
|
37
|
-
## Loading Fonts
|
|
38
|
-
|
|
39
|
-
브라우저에서 가장 단순한 방식:
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
const font = await paFont.load("/assets/font.otf");
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
모듈 상대 경로를 기준으로 읽고 싶을 때:
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
const font = await paFont.load("./font.otf", {
|
|
49
|
-
base: import.meta.url,
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Node에서 바이트로 읽어 넘길 때:
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
import { readFile } from "node:fs/promises";
|
|
57
|
-
import paFont from "@hanyongpa/pa-font";
|
|
58
|
-
|
|
59
|
-
const bytes = await readFile("./fonts/font.otf");
|
|
60
|
-
const font = await paFont.load(bytes);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Public API
|
|
64
|
-
|
|
65
|
-
### `font.text(value, options)`
|
|
66
|
-
|
|
67
|
-
문자열 전체를 하나의 `PAShape`로 만듭니다.
|
|
68
|
-
|
|
69
|
-
### `font.glyph(value, options)`
|
|
70
|
-
|
|
71
|
-
한 글자만 `PAShape`로 만듭니다.
|
|
72
|
-
|
|
73
|
-
### `font.metrics(value, options)`
|
|
74
|
-
|
|
75
|
-
텍스트 폭과 bounding box만 빠르게 계산합니다.
|
|
76
|
-
|
|
77
|
-
### `shape.toShape({ step, openWidth })`
|
|
78
|
-
|
|
79
|
-
hole 열기와 재샘플링을 적용한 뒤 새 `PAShape`를 반환합니다.
|
|
80
|
-
|
|
81
|
-
### `shape.toRegions({ step, openWidth })`
|
|
82
|
-
|
|
83
|
-
최종 도형을 plain polygon data로 반환합니다.
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
const regions = font.glyph("영", { size: 160 }).toRegions({
|
|
87
|
-
step: 8,
|
|
88
|
-
openWidth: 1,
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### `shape.toPoints({ step, openWidth, includeHoles })`
|
|
93
|
-
|
|
94
|
-
경계를 점 데이터로 샘플링합니다.
|
|
95
|
-
|
|
96
|
-
### `shape.glyphs()`
|
|
97
|
-
|
|
98
|
-
문장 shape를 글자별 shape 배열로 분리합니다.
|
|
99
|
-
|
|
100
|
-
## Build
|
|
101
|
-
|
|
102
|
-
라이브러리 빌드:
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
npm run build
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
패키징 확인:
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
npm run pack:check
|
|
112
|
-
```
|