pa_font 0.1.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/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/paFont.cjs +1221 -0
- package/dist/paFont.cjs.map +1 -0
- package/dist/paFont.js +1215 -0
- package/dist/paFont.js.map +1 -0
- package/paFont.d.ts +100 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hanyongpa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
```
|