sfml.js 1.0.0 → 1.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.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +44 -51
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/src/graphics/font.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import {
|
|
3
|
-
native,
|
|
3
|
+
native,
|
|
4
|
+
type NativeGraphicsHandle,
|
|
5
|
+
type NativeFontMapping,
|
|
4
6
|
} from '../internal/native';
|
|
5
7
|
import { nativeStruct } from '../internal/struct-view';
|
|
6
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
graphicsContext,
|
|
10
|
+
graphicsNative,
|
|
11
|
+
flushGraphics,
|
|
12
|
+
} from '../internal/graphics-state';
|
|
7
13
|
import { type ReadonlyValue as R } from '../internal/value-storage';
|
|
8
14
|
import { InputStream } from '../system/input-stream';
|
|
9
15
|
import { Glyph, glyphFromMapping } from './glyph';
|
|
@@ -54,11 +60,25 @@ export const fontRevision: unique symbol = Symbol('Font.revision');
|
|
|
54
60
|
* @ja 同一フォントリソースへの読み取り専用インターフェース。フォントとグリフテクスチャの寿命を保持します。
|
|
55
61
|
* @ko 동일한 글꼴 리소스의 읽기 전용 인터페이스입니다. 글꼴과 글리프 텍스처의 수명을 유지합니다.
|
|
56
62
|
*/
|
|
57
|
-
export type ReadonlyFont = Readonly<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
export type ReadonlyFont = Readonly<
|
|
64
|
+
Pick<
|
|
65
|
+
Font,
|
|
66
|
+
| typeof graphicsNative
|
|
67
|
+
| typeof fontRevision
|
|
68
|
+
| 'getInfo'
|
|
69
|
+
| 'getGlyph'
|
|
70
|
+
| 'getGlyphById'
|
|
71
|
+
| 'hasGlyph'
|
|
72
|
+
| 'getKerning'
|
|
73
|
+
| 'getAscent'
|
|
74
|
+
| 'getDescent'
|
|
75
|
+
| 'getLineSpacing'
|
|
76
|
+
| 'getUnderlinePosition'
|
|
77
|
+
| 'getUnderlineThickness'
|
|
78
|
+
| 'getTexture'
|
|
79
|
+
| 'isSmooth'
|
|
80
|
+
>
|
|
81
|
+
>;
|
|
62
82
|
|
|
63
83
|
export function fontUnsigned(value: number, maximum = 0xffffffff): number {
|
|
64
84
|
if (!Number.isInteger(value) || value < 0 || value > maximum) {
|
|
@@ -68,23 +88,32 @@ export function fontUnsigned(value: number, maximum = 0xffffffff): number {
|
|
|
68
88
|
}
|
|
69
89
|
|
|
70
90
|
export function textFloat(value: number): number {
|
|
71
|
-
if (typeof value !== 'number')
|
|
91
|
+
if (typeof value !== 'number') {
|
|
92
|
+
throw new TypeError('Expected a number');
|
|
93
|
+
}
|
|
72
94
|
const result = Math.fround(value);
|
|
73
|
-
if (!Number.isFinite(result))
|
|
95
|
+
if (!Number.isFinite(result)) {
|
|
96
|
+
throw new RangeError('Expected a finite float32 value');
|
|
97
|
+
}
|
|
74
98
|
return result;
|
|
75
99
|
}
|
|
76
100
|
|
|
77
101
|
function flag(value: boolean): void {
|
|
78
|
-
if (typeof value !== 'boolean')
|
|
102
|
+
if (typeof value !== 'boolean') {
|
|
103
|
+
throw new TypeError('Expected a boolean');
|
|
104
|
+
}
|
|
79
105
|
}
|
|
80
106
|
|
|
81
107
|
function fontViews(mapping: NativeFontMapping) {
|
|
82
108
|
const { smooth, ...fields } = mapping.fields;
|
|
83
109
|
return {
|
|
84
|
-
info: nativeStruct<FontInfo>(
|
|
85
|
-
{
|
|
110
|
+
info: nativeStruct<FontInfo>(
|
|
111
|
+
{ buffers: mapping.buffers, fields },
|
|
112
|
+
{ family: mapping.family },
|
|
113
|
+
),
|
|
86
114
|
sampling: nativeStruct<{ smooth: boolean }>({
|
|
87
|
-
buffers: mapping.buffers,
|
|
115
|
+
buffers: mapping.buffers,
|
|
116
|
+
fields: { smooth },
|
|
88
117
|
}),
|
|
89
118
|
};
|
|
90
119
|
}
|
|
@@ -115,7 +144,10 @@ export class Font {
|
|
|
115
144
|
if (source !== undefined && !(source instanceof Font)) {
|
|
116
145
|
throw new TypeError('Expected a Font');
|
|
117
146
|
}
|
|
118
|
-
const mapping = native.createFont(
|
|
147
|
+
const mapping = native.createFont(
|
|
148
|
+
graphicsContext(),
|
|
149
|
+
source?.[graphicsNative],
|
|
150
|
+
);
|
|
119
151
|
this[graphicsNative] = mapping.handle;
|
|
120
152
|
this.state = fontViews(mapping);
|
|
121
153
|
}
|
|
@@ -141,7 +173,9 @@ export class Font {
|
|
|
141
173
|
* @ko 인코딩된 글꼴 바이트를 비동기로 열고 성공 여부를 반환합니다.
|
|
142
174
|
*/
|
|
143
175
|
async openFromMemory(data: Uint8Array): Promise<boolean> {
|
|
144
|
-
if (!(data instanceof Uint8Array))
|
|
176
|
+
if (!(data instanceof Uint8Array)) {
|
|
177
|
+
throw new TypeError('Expected a Uint8Array');
|
|
178
|
+
}
|
|
145
179
|
return this.open(data);
|
|
146
180
|
}
|
|
147
181
|
|
|
@@ -153,22 +187,35 @@ export class Font {
|
|
|
153
187
|
* @ko 스트림 시작부터 모든 글꼴 바이트를 읽고 비동기로 엽니다. 성공 여부를 반환하며 스트림 예외는 Promise를 거부합니다.
|
|
154
188
|
*/
|
|
155
189
|
async openFromStream(stream: InputStream): Promise<boolean> {
|
|
156
|
-
if (!(stream instanceof InputStream))
|
|
190
|
+
if (!(stream instanceof InputStream)) {
|
|
191
|
+
throw new TypeError('Expected an InputStream');
|
|
192
|
+
}
|
|
157
193
|
const size = await stream.getSize();
|
|
158
|
-
if (size === undefined || size === 0n)
|
|
194
|
+
if (size === undefined || size === 0n) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
159
197
|
if (typeof size !== 'bigint' || size < 0n || size > 0x7fffffffn) {
|
|
160
198
|
throw new RangeError('Font stream size exceeds the buffer limit');
|
|
161
199
|
}
|
|
162
200
|
const position = await stream.seek(0n);
|
|
163
|
-
if (position === undefined)
|
|
164
|
-
|
|
201
|
+
if (position === undefined) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
if (position !== 0n) {
|
|
205
|
+
throw new RangeError('Font stream must seek to its beginning');
|
|
206
|
+
}
|
|
165
207
|
const bytes = new Uint8Array(Number(size));
|
|
166
208
|
let offset = 0;
|
|
167
209
|
while (offset < bytes.length) {
|
|
168
210
|
const count = await stream.read(bytes.subarray(offset));
|
|
169
|
-
if (count === undefined || count === 0n)
|
|
170
|
-
|
|
171
|
-
|
|
211
|
+
if (count === undefined || count === 0n) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (
|
|
215
|
+
typeof count !== 'bigint' ||
|
|
216
|
+
count < 0n ||
|
|
217
|
+
count > BigInt(bytes.length - offset)
|
|
218
|
+
) {
|
|
172
219
|
throw new RangeError('Invalid font stream read count');
|
|
173
220
|
}
|
|
174
221
|
offset += Number(count);
|
|
@@ -182,7 +229,9 @@ export class Font {
|
|
|
182
229
|
* @ja 現在のフォント情報の読み取り専用ビューを返します。
|
|
183
230
|
* @ko 현재 글꼴 정보의 읽기 전용 뷰를 반환합니다.
|
|
184
231
|
*/
|
|
185
|
-
getInfo(): FontInfo {
|
|
232
|
+
getInfo(): FontInfo {
|
|
233
|
+
return this.state.info;
|
|
234
|
+
}
|
|
186
235
|
|
|
187
236
|
/**
|
|
188
237
|
* Gets the cached glyph for a Unicode code point; size and outline thickness
|
|
@@ -192,10 +241,20 @@ export class Font {
|
|
|
192
241
|
* @ko Unicode 코드 포인트의 캐시된 글리프를 가져옵니다. 글자 크기와 윤곽선 두께는 픽셀 단위이며 bold는 굵게 표시할지
|
|
193
242
|
* 제어합니다.
|
|
194
243
|
*/
|
|
195
|
-
getGlyph(
|
|
196
|
-
|
|
244
|
+
getGlyph(
|
|
245
|
+
codePoint: number,
|
|
246
|
+
characterSize: number,
|
|
247
|
+
bold: boolean,
|
|
248
|
+
outlineThickness = 0,
|
|
249
|
+
): R<Glyph> {
|
|
197
250
|
fontUnsigned(codePoint, 0x10ffff);
|
|
198
|
-
return this.glyph(
|
|
251
|
+
return this.glyph(
|
|
252
|
+
codePoint,
|
|
253
|
+
characterSize,
|
|
254
|
+
bold,
|
|
255
|
+
outlineThickness,
|
|
256
|
+
false,
|
|
257
|
+
);
|
|
199
258
|
}
|
|
200
259
|
|
|
201
260
|
/**
|
|
@@ -205,8 +264,12 @@ export class Font {
|
|
|
205
264
|
* @ja フォント内部のグリフ番号でグリフを取得します。サイズと輪郭の太さはピクセル単位です。
|
|
206
265
|
* @ko 글꼴 내부 글리프 번호로 글리프를 가져옵니다. 글자 크기와 윤곽선 두께는 픽셀 단위입니다.
|
|
207
266
|
*/
|
|
208
|
-
getGlyphById(
|
|
209
|
-
|
|
267
|
+
getGlyphById(
|
|
268
|
+
id: number,
|
|
269
|
+
characterSize: number,
|
|
270
|
+
bold: boolean,
|
|
271
|
+
outlineThickness = 0,
|
|
272
|
+
): R<Glyph> {
|
|
210
273
|
fontUnsigned(id);
|
|
211
274
|
return this.glyph(id, characterSize, bold, outlineThickness, true);
|
|
212
275
|
}
|
|
@@ -221,7 +284,11 @@ export class Font {
|
|
|
221
284
|
fontUnsigned(codePoint, 0x10ffff);
|
|
222
285
|
let exists = this.coverage.get(codePoint);
|
|
223
286
|
if (exists === undefined) {
|
|
224
|
-
exists = native.fontMetric(
|
|
287
|
+
exists = native.fontMetric(
|
|
288
|
+
this[graphicsNative],
|
|
289
|
+
5,
|
|
290
|
+
codePoint,
|
|
291
|
+
) as boolean;
|
|
225
292
|
this.coverage.set(codePoint, exists);
|
|
226
293
|
}
|
|
227
294
|
return exists;
|
|
@@ -233,7 +300,12 @@ export class Font {
|
|
|
233
300
|
* @ja 二つの Unicode コードポイント間のカーニング量をピクセル単位で返します。
|
|
234
301
|
* @ko 두 Unicode 코드 포인트 간의 커닝 양을 픽셀 단위로 반환합니다.
|
|
235
302
|
*/
|
|
236
|
-
getKerning(
|
|
303
|
+
getKerning(
|
|
304
|
+
first: number,
|
|
305
|
+
second: number,
|
|
306
|
+
characterSize: number,
|
|
307
|
+
bold = false,
|
|
308
|
+
): number {
|
|
237
309
|
fontUnsigned(first, 0x10ffff);
|
|
238
310
|
fontUnsigned(second, 0x10ffff);
|
|
239
311
|
fontUnsigned(characterSize);
|
|
@@ -242,8 +314,14 @@ export class Font {
|
|
|
242
314
|
let value = this.kernings.get(key);
|
|
243
315
|
if (value === undefined) {
|
|
244
316
|
flushGraphics();
|
|
245
|
-
value = native.fontMetric(
|
|
246
|
-
|
|
317
|
+
value = native.fontMetric(
|
|
318
|
+
this[graphicsNative],
|
|
319
|
+
6,
|
|
320
|
+
first,
|
|
321
|
+
second,
|
|
322
|
+
characterSize,
|
|
323
|
+
bold,
|
|
324
|
+
) as number;
|
|
247
325
|
this.kernings.set(key, value);
|
|
248
326
|
}
|
|
249
327
|
return value;
|
|
@@ -255,14 +333,18 @@ export class Font {
|
|
|
255
333
|
* @ja 指定ピクセル文字サイズでのアセントをピクセル単位で返します。
|
|
256
334
|
* @ko 지정한 픽셀 글자 크기의 어센트를 픽셀 단위로 반환합니다.
|
|
257
335
|
*/
|
|
258
|
-
getAscent(size: number): number {
|
|
336
|
+
getAscent(size: number): number {
|
|
337
|
+
return this.metric(0, size);
|
|
338
|
+
}
|
|
259
339
|
/**
|
|
260
340
|
* Returns the descent in pixels for the specified pixel character size.
|
|
261
341
|
* @zh 返回指定像素字号的下降度量,单位为像素。
|
|
262
342
|
* @ja 指定ピクセル文字サイズでのディセントをピクセル単位で返します。
|
|
263
343
|
* @ko 지정한 픽셀 글자 크기의 디센트를 픽셀 단위로 반환합니다.
|
|
264
344
|
*/
|
|
265
|
-
getDescent(size: number): number {
|
|
345
|
+
getDescent(size: number): number {
|
|
346
|
+
return this.metric(1, size);
|
|
347
|
+
}
|
|
266
348
|
/**
|
|
267
349
|
* Returns recommended baseline spacing for the specified pixel character
|
|
268
350
|
* size.
|
|
@@ -270,21 +352,27 @@ export class Font {
|
|
|
270
352
|
* @ja 指定ピクセル文字サイズでの推奨ベースライン間隔を返します。
|
|
271
353
|
* @ko 지정한 픽셀 글자 크기의 권장 기준선 간격을 반환합니다.
|
|
272
354
|
*/
|
|
273
|
-
getLineSpacing(size: number): number {
|
|
355
|
+
getLineSpacing(size: number): number {
|
|
356
|
+
return this.metric(2, size);
|
|
357
|
+
}
|
|
274
358
|
/**
|
|
275
359
|
* Returns the underline position relative to the baseline in pixels.
|
|
276
360
|
* @zh 返回下划线相对基线的位置,单位为像素。
|
|
277
361
|
* @ja ベースラインに対する下線位置をピクセル単位で返します。
|
|
278
362
|
* @ko 기준선에 대한 밑줄 위치를 픽셀 단위로 반환합니다.
|
|
279
363
|
*/
|
|
280
|
-
getUnderlinePosition(size: number): number {
|
|
364
|
+
getUnderlinePosition(size: number): number {
|
|
365
|
+
return this.metric(3, size);
|
|
366
|
+
}
|
|
281
367
|
/**
|
|
282
368
|
* Returns the underline thickness in pixels.
|
|
283
369
|
* @zh 返回下划线厚度,单位为像素。
|
|
284
370
|
* @ja 下線の太さをピクセル単位で返します。
|
|
285
371
|
* @ko 밑줄 두께를 픽셀 단위로 반환합니다.
|
|
286
372
|
*/
|
|
287
|
-
getUnderlineThickness(size: number): number {
|
|
373
|
+
getUnderlineThickness(size: number): number {
|
|
374
|
+
return this.metric(4, size);
|
|
375
|
+
}
|
|
288
376
|
|
|
289
377
|
/**
|
|
290
378
|
* Returns a read-only glyph atlas texture reference for the specified pixel
|
|
@@ -300,7 +388,9 @@ export class Font {
|
|
|
300
388
|
if (!texture) {
|
|
301
389
|
flushGraphics();
|
|
302
390
|
texture = fontTextureFromMapping(
|
|
303
|
-
native.getFontTexture(this[graphicsNative], characterSize),
|
|
391
|
+
native.getFontTexture(this[graphicsNative], characterSize),
|
|
392
|
+
this,
|
|
393
|
+
);
|
|
304
394
|
this.textures.set(characterSize, texture);
|
|
305
395
|
}
|
|
306
396
|
return texture;
|
|
@@ -314,7 +404,9 @@ export class Font {
|
|
|
314
404
|
*/
|
|
315
405
|
setSmooth(smooth: boolean): void {
|
|
316
406
|
flag(smooth);
|
|
317
|
-
if (smooth === this.state.sampling.smooth)
|
|
407
|
+
if (smooth === this.state.sampling.smooth) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
318
410
|
flushGraphics();
|
|
319
411
|
native.setFontSmooth(this[graphicsNative], smooth);
|
|
320
412
|
}
|
|
@@ -324,22 +416,35 @@ export class Font {
|
|
|
324
416
|
* @ja フォントテクスチャで平滑化フィルタリングが有効かを返します。
|
|
325
417
|
* @ko 글꼴 텍스처의 부드러운 필터링 사용 여부를 반환합니다.
|
|
326
418
|
*/
|
|
327
|
-
isSmooth(): boolean {
|
|
419
|
+
isSmooth(): boolean {
|
|
420
|
+
return this.state.sampling.smooth;
|
|
421
|
+
}
|
|
328
422
|
|
|
329
423
|
private metric(metric: number, size: number): number {
|
|
330
424
|
fontUnsigned(size);
|
|
331
425
|
let values = this.metrics.get(size);
|
|
332
|
-
if (!values)
|
|
426
|
+
if (!values) {
|
|
427
|
+
this.metrics.set(size, (values = []));
|
|
428
|
+
}
|
|
333
429
|
let value = values[metric];
|
|
334
430
|
if (value === undefined) {
|
|
335
|
-
value = native.fontMetric(
|
|
431
|
+
value = native.fontMetric(
|
|
432
|
+
this[graphicsNative],
|
|
433
|
+
metric,
|
|
434
|
+
size,
|
|
435
|
+
) as number;
|
|
336
436
|
values[metric] = value;
|
|
337
437
|
}
|
|
338
438
|
return value;
|
|
339
439
|
}
|
|
340
440
|
|
|
341
|
-
private glyph(
|
|
342
|
-
|
|
441
|
+
private glyph(
|
|
442
|
+
id: number,
|
|
443
|
+
size: number,
|
|
444
|
+
bold: boolean,
|
|
445
|
+
outline: number,
|
|
446
|
+
byId: boolean,
|
|
447
|
+
): R<Glyph> {
|
|
343
448
|
fontUnsigned(size);
|
|
344
449
|
flag(bold);
|
|
345
450
|
outline = textFloat(outline);
|
|
@@ -347,8 +452,16 @@ export class Font {
|
|
|
347
452
|
let glyph = this.glyphs.get(key);
|
|
348
453
|
if (!glyph) {
|
|
349
454
|
flushGraphics();
|
|
350
|
-
const value = glyphFromMapping(
|
|
351
|
-
|
|
455
|
+
const value = glyphFromMapping(
|
|
456
|
+
native.getFontGlyph(
|
|
457
|
+
this[graphicsNative],
|
|
458
|
+
id,
|
|
459
|
+
size,
|
|
460
|
+
bold,
|
|
461
|
+
outline,
|
|
462
|
+
byId,
|
|
463
|
+
),
|
|
464
|
+
);
|
|
352
465
|
glyph = value;
|
|
353
466
|
this.glyphs.set(key, glyph);
|
|
354
467
|
}
|
|
@@ -358,11 +471,17 @@ export class Font {
|
|
|
358
471
|
private open(input: string | Uint8Array): Promise<boolean> {
|
|
359
472
|
return new Promise((resolve, reject) => {
|
|
360
473
|
native.openFont(input, (error, data) => {
|
|
361
|
-
if (error)
|
|
362
|
-
|
|
474
|
+
if (error) {
|
|
475
|
+
return reject(error);
|
|
476
|
+
}
|
|
477
|
+
if (!data) {
|
|
478
|
+
return resolve(false);
|
|
479
|
+
}
|
|
363
480
|
try {
|
|
364
481
|
flushGraphics();
|
|
365
|
-
this.state = fontViews(
|
|
482
|
+
this.state = fontViews(
|
|
483
|
+
native.commitFont(this[graphicsNative], data),
|
|
484
|
+
);
|
|
366
485
|
this[fontRevision]++;
|
|
367
486
|
this.glyphs.clear();
|
|
368
487
|
this.metrics.clear();
|
|
@@ -370,7 +489,9 @@ export class Font {
|
|
|
370
489
|
this.coverage.clear();
|
|
371
490
|
this.textures.clear();
|
|
372
491
|
resolve(true);
|
|
373
|
-
} catch (error) {
|
|
492
|
+
} catch (error) {
|
|
493
|
+
reject(error);
|
|
494
|
+
}
|
|
374
495
|
});
|
|
375
496
|
});
|
|
376
497
|
}
|
|
@@ -46,7 +46,9 @@ abstract class Matrix<K extends Kind> extends GlslValue<K, Float32Array> {
|
|
|
46
46
|
// Copy the nine SFML entries as bits, including signed zero and NaN.
|
|
47
47
|
const input = new Uint32Array(data.buffer, data.byteOffset, 16);
|
|
48
48
|
const output = new Uint32Array(values.buffer);
|
|
49
|
-
for (let i = 0; i < 9; i++)
|
|
49
|
+
for (let i = 0; i < 9; i++) {
|
|
50
|
+
output[i] = input[transform3Indices[i]];
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
} else if (source instanceof Matrix) {
|
|
52
54
|
copyArray(values, source[glslStorage]);
|
|
@@ -61,14 +63,18 @@ abstract class Matrix<K extends Kind> extends GlslValue<K, Float32Array> {
|
|
|
61
63
|
* @ja 列優先の行列データの変更可能な共有ビュー。
|
|
62
64
|
* @ko 열 우선 행렬 데이터의 수정 가능한 공유 뷰입니다.
|
|
63
65
|
*/
|
|
64
|
-
get array(): Float32Array {
|
|
66
|
+
get array(): Float32Array {
|
|
67
|
+
return this[glslStorage];
|
|
68
|
+
}
|
|
65
69
|
/**
|
|
66
70
|
* Copies an array of the same length into existing matrix storage.
|
|
67
71
|
* @zh 复制同长度数组到矩阵的现有存储。
|
|
68
72
|
* @ja 同じ長さの配列を行列の既存ストレージにコピーします。
|
|
69
73
|
* @ko 길이가 같은 배열을 기존 행렬 저장 공간에 복사합니다.
|
|
70
74
|
*/
|
|
71
|
-
set array(source: ArrayLike<number>) {
|
|
75
|
+
set array(source: ArrayLike<number>) {
|
|
76
|
+
copyArray(this[glslStorage], source);
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
/**
|