pa_font 0.1.3 → 0.2.0
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 +63 -0
- 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
|
@@ -28,6 +28,50 @@ const regions = shape.toRegions();
|
|
|
28
28
|
const points = shape.toPoints({ step: 8 });
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
## Paragraph Layout
|
|
32
|
+
|
|
33
|
+
`font.paragraph(...)`는 `pretext.js` 기반으로 자동 줄바꿈되는 문단 레이아웃을 만들고,
|
|
34
|
+
같은 문단을 canvas 텍스트 렌더링과 `paFont` geometry 변환에 같이 쓸 수 있습니다.
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const paragraph = font.paragraph("캔버스에서 자동 줄바꿈되는 문단입니다.", {
|
|
38
|
+
x: 40,
|
|
39
|
+
y: 80,
|
|
40
|
+
width: 420,
|
|
41
|
+
size: 32,
|
|
42
|
+
fontFamily: "MyFont",
|
|
43
|
+
fontWeight: 400,
|
|
44
|
+
lineHeight: 1.4,
|
|
45
|
+
align: "left",
|
|
46
|
+
whiteSpace: "normal",
|
|
47
|
+
engine: "pretext",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
paragraph.drawText(ctx, {
|
|
51
|
+
fillStyle: "#111",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const shape = paragraph.toShape();
|
|
55
|
+
const regions = paragraph.toRegions({ step: 6, openWidth: 1 });
|
|
56
|
+
const points = paragraph.toPoints({ step: 8, openWidth: 1 });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
폭이 바뀌면 문단만 다시 레이아웃할 수 있습니다.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const mobile = paragraph.relayout({ width: 280 });
|
|
63
|
+
mobile.drawText(ctx);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
정밀한 `paFont` export용으로는 `layout: "native"`를 사용할 수 있습니다.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const exact = paragraph.toShape({
|
|
70
|
+
layout: "native",
|
|
71
|
+
step: 4,
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
31
75
|
## Core Flow
|
|
32
76
|
|
|
33
77
|
1. `paFont.load(...)`로 폰트를 로드합니다.
|
|
@@ -74,6 +118,25 @@ const font = await paFont.load(bytes);
|
|
|
74
118
|
|
|
75
119
|
텍스트 폭과 bounding box만 빠르게 계산합니다.
|
|
76
120
|
|
|
121
|
+
### `font.paragraph(value, options)`
|
|
122
|
+
|
|
123
|
+
문단 레이아웃 객체 `paParagraph`를 만듭니다.
|
|
124
|
+
|
|
125
|
+
자주 쓰는 옵션:
|
|
126
|
+
|
|
127
|
+
- `width`: 문단 폭
|
|
128
|
+
- `lineHeight`: 숫자 `<= 10`이면 배수, 그보다 크면 절대 px
|
|
129
|
+
- `fontFamily`, `fontWeight`, `fontStyle`, `font`: canvas text 측정/렌더링용 폰트 설정
|
|
130
|
+
- `align`: `left | center | right | justify`
|
|
131
|
+
- `whiteSpace`: `normal | pre-wrap | nowrap`
|
|
132
|
+
- `engine`: `pretext | native`
|
|
133
|
+
|
|
134
|
+
주의:
|
|
135
|
+
|
|
136
|
+
- `drawText()`는 canvas 텍스트 렌더링을 사용합니다.
|
|
137
|
+
- `fontFamily` 또는 `font`는 브라우저에 실제 등록된 폰트와 맞아야 합니다.
|
|
138
|
+
- `paragraph.toShape()`, `paragraph.toRegions()`, `paragraph.toPoints()`는 같은 문단 레이아웃을 `paFont` geometry로 변환합니다.
|
|
139
|
+
|
|
77
140
|
### `shape.toShape({ step, openWidth })`
|
|
78
141
|
|
|
79
142
|
hole 열기와 재샘플링을 적용한 뒤 새 `PAShape`를 반환합니다.
|