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/text.ts
CHANGED
|
@@ -1,21 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
|
-
native,
|
|
2
|
+
native,
|
|
3
|
+
type NativeGraphicsHandle,
|
|
3
4
|
type NativeGlyphProcessor,
|
|
4
5
|
} from '../internal/native';
|
|
5
6
|
import {
|
|
6
|
-
dispatchDrawable,
|
|
7
|
+
dispatchDrawable,
|
|
8
|
+
flushGraphics,
|
|
9
|
+
graphicsNative,
|
|
10
|
+
recordVertices,
|
|
11
|
+
vertexArrayBytes,
|
|
7
12
|
} from '../internal/graphics-state';
|
|
8
13
|
import {
|
|
9
|
-
withTransformable,
|
|
14
|
+
withTransformable,
|
|
15
|
+
transformableState,
|
|
16
|
+
type TransformableState,
|
|
10
17
|
} from '../internal/transformable';
|
|
11
|
-
import {
|
|
12
|
-
|
|
18
|
+
import {
|
|
19
|
+
mutableValue,
|
|
20
|
+
type ReadonlyValue as R,
|
|
21
|
+
} from '../internal/value-storage';
|
|
22
|
+
import {
|
|
23
|
+
ShapedGlyphBuffer,
|
|
24
|
+
ShapedGlyphView,
|
|
25
|
+
} from '../internal/shaped-glyph';
|
|
13
26
|
import { TextIndices } from '../internal/text-indices';
|
|
14
27
|
import { Vector2f } from '../system/vector2';
|
|
15
28
|
import { SFMLError } from '../system/error';
|
|
16
29
|
import { Color } from './color';
|
|
17
30
|
import { Drawable } from './drawable';
|
|
18
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
Font,
|
|
33
|
+
fontRevision,
|
|
34
|
+
fontUnsigned,
|
|
35
|
+
textFloat,
|
|
36
|
+
type ReadonlyFont,
|
|
37
|
+
} from './font';
|
|
19
38
|
import type { Glyph } from './glyph';
|
|
20
39
|
import { FloatRect } from './rect';
|
|
21
40
|
import { RenderStates, CoordinateType } from './render-states';
|
|
@@ -318,7 +337,10 @@ export interface GlyphAppearance {
|
|
|
318
337
|
* @ja グリフの外観を同期的に変更するコールバック。実行中は同じ Text のジオメトリを変更または照会してはいけません。
|
|
319
338
|
* @ko 글리프 외형을 동기적으로 수정하는 콜백입니다. 실행 중에는 동일한 Text의 기하 구조를 수정하거나 조회하면 안 됩니다.
|
|
320
339
|
*/
|
|
321
|
-
export type GlyphPreProcessor = (
|
|
340
|
+
export type GlyphPreProcessor = (
|
|
341
|
+
glyph: ShapedGlyph,
|
|
342
|
+
appearance: GlyphAppearance,
|
|
343
|
+
) => void;
|
|
322
344
|
|
|
323
345
|
/**
|
|
324
346
|
* Initial text parameters.
|
|
@@ -351,7 +373,9 @@ export interface TextOptions {
|
|
|
351
373
|
}
|
|
352
374
|
|
|
353
375
|
function colorInteger(value: R<Color>): number {
|
|
354
|
-
if (!(value instanceof Color))
|
|
376
|
+
if (!(value instanceof Color)) {
|
|
377
|
+
throw new TypeError('Expected a Color');
|
|
378
|
+
}
|
|
355
379
|
return value.toInteger();
|
|
356
380
|
}
|
|
357
381
|
|
|
@@ -475,11 +499,15 @@ class TextResource extends Drawable {
|
|
|
475
499
|
this.processor = options.processor;
|
|
476
500
|
} else {
|
|
477
501
|
const init = options as TextOptions;
|
|
478
|
-
if (!init || !(init.font instanceof Font))
|
|
502
|
+
if (!init || !(init.font instanceof Font)) {
|
|
503
|
+
throw new TypeError('Expected Text options with a Font');
|
|
504
|
+
}
|
|
479
505
|
this.font = init.font;
|
|
480
506
|
}
|
|
481
|
-
const mapping = native.createText(
|
|
482
|
-
|
|
507
|
+
const mapping = native.createText(
|
|
508
|
+
this.font[graphicsNative],
|
|
509
|
+
options instanceof TextResource ? options[graphicsNative] : undefined,
|
|
510
|
+
);
|
|
483
511
|
this[graphicsNative] = mapping.handle;
|
|
484
512
|
this.floats = new Float32Array(mapping.buffer);
|
|
485
513
|
this.words = new Uint32Array(mapping.buffer);
|
|
@@ -487,18 +515,26 @@ class TextResource extends Drawable {
|
|
|
487
515
|
this.geometry = new Uint8Array(mapping.geometry);
|
|
488
516
|
this.bounds = new Float32Array(mapping.bounds);
|
|
489
517
|
this[transformableState] = {
|
|
490
|
-
handle: mapping.transformable,
|
|
518
|
+
handle: mapping.transformable,
|
|
519
|
+
values: new Float32Array(mapping.transform),
|
|
491
520
|
};
|
|
492
521
|
if (options instanceof TextResource) {
|
|
493
|
-
if (
|
|
522
|
+
if (
|
|
523
|
+
!this.geometry[0] &&
|
|
524
|
+
options.revision === this.font[fontRevision]
|
|
525
|
+
) {
|
|
494
526
|
this.vertices = new VertexArray(options.vertices);
|
|
495
527
|
this.outline = new VertexArray(options.outline);
|
|
496
528
|
this.revision = options.revision;
|
|
497
529
|
}
|
|
498
530
|
} else {
|
|
499
531
|
const init = options as TextOptions;
|
|
500
|
-
if (init.string !== undefined)
|
|
501
|
-
|
|
532
|
+
if (init.string !== undefined) {
|
|
533
|
+
this.setString(init.string);
|
|
534
|
+
}
|
|
535
|
+
if (init.characterSize !== undefined) {
|
|
536
|
+
this.setCharacterSize(init.characterSize);
|
|
537
|
+
}
|
|
502
538
|
}
|
|
503
539
|
}
|
|
504
540
|
|
|
@@ -510,7 +546,9 @@ class TextResource extends Drawable {
|
|
|
510
546
|
*/
|
|
511
547
|
setString(this: TextResource, value: string): void {
|
|
512
548
|
this.checkIdle();
|
|
513
|
-
if (typeof value !== 'string')
|
|
549
|
+
if (typeof value !== 'string') {
|
|
550
|
+
throw new TypeError('Expected a string');
|
|
551
|
+
}
|
|
514
552
|
if (value !== this.string) {
|
|
515
553
|
this.string = value;
|
|
516
554
|
this.indices = undefined;
|
|
@@ -523,7 +561,9 @@ class TextResource extends Drawable {
|
|
|
523
561
|
* @ja 現在の JS 文字列を返します。
|
|
524
562
|
* @ko 현재 JS 문자열을 반환합니다.
|
|
525
563
|
*/
|
|
526
|
-
getString(): string {
|
|
564
|
+
getString(): string {
|
|
565
|
+
return this.string;
|
|
566
|
+
}
|
|
527
567
|
/**
|
|
528
568
|
* Sets the font and retains its reference.
|
|
529
569
|
* @zh 设置字体并保留其引用。
|
|
@@ -532,8 +572,13 @@ class TextResource extends Drawable {
|
|
|
532
572
|
*/
|
|
533
573
|
setFont(this: TextResource, font: ReadonlyFont): void {
|
|
534
574
|
this.checkIdle();
|
|
535
|
-
if (!(font instanceof Font))
|
|
536
|
-
|
|
575
|
+
if (!(font instanceof Font)) {
|
|
576
|
+
throw new TypeError('Expected a Font');
|
|
577
|
+
}
|
|
578
|
+
if (font !== this.font) {
|
|
579
|
+
this.font = font;
|
|
580
|
+
this.geometry[0] = 1;
|
|
581
|
+
}
|
|
537
582
|
}
|
|
538
583
|
/**
|
|
539
584
|
* Returns a read-only reference to the current font.
|
|
@@ -541,147 +586,192 @@ class TextResource extends Drawable {
|
|
|
541
586
|
* @ja 現在のフォントへの読み取り専用参照を返します。
|
|
542
587
|
* @ko 현재 글꼴의 읽기 전용 참조를 반환합니다.
|
|
543
588
|
*/
|
|
544
|
-
getFont(): ReadonlyFont {
|
|
589
|
+
getFont(): ReadonlyFont {
|
|
590
|
+
return this.font;
|
|
591
|
+
}
|
|
545
592
|
/**
|
|
546
593
|
* Sets the character size in pixels.
|
|
547
594
|
* @zh 设置像素字号。
|
|
548
595
|
* @ja 文字サイズをピクセル単位で設定します。
|
|
549
596
|
* @ko 글자 크기를 픽셀 단위로 설정합니다.
|
|
550
597
|
*/
|
|
551
|
-
setCharacterSize(this: TextResource, size: number): void {
|
|
598
|
+
setCharacterSize(this: TextResource, size: number): void {
|
|
599
|
+
this.set(0, fontUnsigned(size));
|
|
600
|
+
}
|
|
552
601
|
/**
|
|
553
602
|
* Returns the character size in pixels.
|
|
554
603
|
* @zh 返回像素字号。
|
|
555
604
|
* @ja 文字サイズをピクセル単位で返します。
|
|
556
605
|
* @ko 글자 크기를 픽셀 단위로 반환합니다.
|
|
557
606
|
*/
|
|
558
|
-
getCharacterSize(): number {
|
|
607
|
+
getCharacterSize(): number {
|
|
608
|
+
return this.words[0];
|
|
609
|
+
}
|
|
559
610
|
/**
|
|
560
611
|
* Sets the letter spacing factor; 1 is the default spacing.
|
|
561
612
|
* @zh 设置字间距倍率,1 为默认间距。
|
|
562
613
|
* @ja 文字間隔の倍率を設定します。1 は既定の間隔です。
|
|
563
614
|
* @ko 자간 배율을 설정합니다. 1은 기본 간격입니다.
|
|
564
615
|
*/
|
|
565
|
-
setLetterSpacing(this: TextResource, factor: number): void {
|
|
616
|
+
setLetterSpacing(this: TextResource, factor: number): void {
|
|
617
|
+
this.set(1, textFloat(factor));
|
|
618
|
+
}
|
|
566
619
|
/**
|
|
567
620
|
* Returns the letter spacing factor.
|
|
568
621
|
* @zh 返回字间距倍率。
|
|
569
622
|
* @ja 文字間隔の倍率を返します。
|
|
570
623
|
* @ko 자간 배율을 반환합니다.
|
|
571
624
|
*/
|
|
572
|
-
getLetterSpacing(): number {
|
|
625
|
+
getLetterSpacing(): number {
|
|
626
|
+
return this.floats[1];
|
|
627
|
+
}
|
|
573
628
|
/**
|
|
574
629
|
* Sets the line spacing factor; 1 is the font's default line spacing.
|
|
575
630
|
* @zh 设置行间距倍率,1 为字体默认行距。
|
|
576
631
|
* @ja 行間隔の倍率を設定します。1 はフォント既定の行間隔です。
|
|
577
632
|
* @ko 줄 간격 배율을 설정합니다. 1은 글꼴의 기본 줄 간격입니다.
|
|
578
633
|
*/
|
|
579
|
-
setLineSpacing(this: TextResource, factor: number): void {
|
|
634
|
+
setLineSpacing(this: TextResource, factor: number): void {
|
|
635
|
+
this.set(2, textFloat(factor));
|
|
636
|
+
}
|
|
580
637
|
/**
|
|
581
638
|
* Returns the line spacing factor.
|
|
582
639
|
* @zh 返回行间距倍率。
|
|
583
640
|
* @ja 行間隔の倍率を返します。
|
|
584
641
|
* @ko 줄 간격 배율을 반환합니다.
|
|
585
642
|
*/
|
|
586
|
-
getLineSpacing(): number {
|
|
643
|
+
getLineSpacing(): number {
|
|
644
|
+
return this.floats[2];
|
|
645
|
+
}
|
|
587
646
|
/**
|
|
588
647
|
* Sets TextStyle bit flags, combining styles such as bold and italic.
|
|
589
648
|
* @zh 设置 TextStyle 位标志,可组合粗体、斜体等样式。
|
|
590
649
|
* @ja TextStyle ビットフラグを設定します。太字や斜体などを組み合わせられます。
|
|
591
650
|
* @ko TextStyle 비트 플래그를 설정하며 굵게, 기울임꼴 등의 스타일을 조합할 수 있습니다.
|
|
592
651
|
*/
|
|
593
|
-
setStyle(this: TextResource, style: TextStyle): void {
|
|
652
|
+
setStyle(this: TextResource, style: TextStyle): void {
|
|
653
|
+
this.set(3, fontUnsigned(style, 15));
|
|
654
|
+
}
|
|
594
655
|
/**
|
|
595
656
|
* Returns the text style bit flags.
|
|
596
657
|
* @zh 返回文本样式位标志。
|
|
597
658
|
* @ja テキストスタイルのビットフラグを返します。
|
|
598
659
|
* @ko 텍스트 스타일 비트 플래그를 반환합니다.
|
|
599
660
|
*/
|
|
600
|
-
getStyle(): TextStyle {
|
|
661
|
+
getStyle(): TextStyle {
|
|
662
|
+
return this.words[3];
|
|
663
|
+
}
|
|
601
664
|
/**
|
|
602
665
|
* Copies the fill color; existing geometry is only recolored.
|
|
603
666
|
* @zh 复制填充颜色;已有几何仅重新着色。
|
|
604
667
|
* @ja 塗りつぶし色をコピーします。既存ジオメトリは色のみを更新します。
|
|
605
668
|
* @ko 채우기 색상을 복사합니다. 기존 기하 구조는 색상만 갱신합니다.
|
|
606
669
|
*/
|
|
607
|
-
setFillColor(this: TextResource, color: R<Color>): void {
|
|
670
|
+
setFillColor(this: TextResource, color: R<Color>): void {
|
|
671
|
+
this.setColor(4, colorInteger(color));
|
|
672
|
+
}
|
|
608
673
|
/**
|
|
609
674
|
* Returns a copy of the fill color.
|
|
610
675
|
* @zh 返回填充颜色副本。
|
|
611
676
|
* @ja 塗りつぶし色のコピーを返します。
|
|
612
677
|
* @ko 채우기 색상 복사본을 반환합니다.
|
|
613
678
|
*/
|
|
614
|
-
getFillColor(): Color {
|
|
679
|
+
getFillColor(): Color {
|
|
680
|
+
return new Color(this.colors.getUint32(16));
|
|
681
|
+
}
|
|
615
682
|
/**
|
|
616
683
|
* Copies the outline color; existing geometry is only recolored.
|
|
617
684
|
* @zh 复制轮廓颜色;已有几何仅重新着色。
|
|
618
685
|
* @ja 輪郭色をコピーします。既存ジオメトリは色のみを更新します。
|
|
619
686
|
* @ko 윤곽선 색상을 복사합니다. 기존 기하 구조는 색상만 갱신합니다.
|
|
620
687
|
*/
|
|
621
|
-
setOutlineColor(this: TextResource, color: R<Color>): void {
|
|
688
|
+
setOutlineColor(this: TextResource, color: R<Color>): void {
|
|
689
|
+
this.setColor(5, colorInteger(color));
|
|
690
|
+
}
|
|
622
691
|
/**
|
|
623
692
|
* Returns a copy of the outline color.
|
|
624
693
|
* @zh 返回轮廓颜色副本。
|
|
625
694
|
* @ja 輪郭色のコピーを返します。
|
|
626
695
|
* @ko 윤곽선 색상 복사본을 반환합니다.
|
|
627
696
|
*/
|
|
628
|
-
getOutlineColor(): Color {
|
|
697
|
+
getOutlineColor(): Color {
|
|
698
|
+
return new Color(this.colors.getUint32(20));
|
|
699
|
+
}
|
|
629
700
|
/**
|
|
630
701
|
* Sets the outline thickness in pixels.
|
|
631
702
|
* @zh 设置轮廓像素厚度。
|
|
632
703
|
* @ja 輪郭の太さをピクセル単位で設定します。
|
|
633
704
|
* @ko 윤곽선 두께를 픽셀 단위로 설정합니다.
|
|
634
705
|
*/
|
|
635
|
-
setOutlineThickness(this: TextResource, thickness: number): void {
|
|
706
|
+
setOutlineThickness(this: TextResource, thickness: number): void {
|
|
707
|
+
this.set(6, textFloat(thickness));
|
|
708
|
+
}
|
|
636
709
|
/**
|
|
637
710
|
* Returns the outline thickness in pixels.
|
|
638
711
|
* @zh 返回轮廓像素厚度。
|
|
639
712
|
* @ja 輪郭の太さをピクセル単位で返します。
|
|
640
713
|
* @ko 윤곽선 두께를 픽셀 단위로 반환합니다.
|
|
641
714
|
*/
|
|
642
|
-
getOutlineThickness(): number {
|
|
715
|
+
getOutlineThickness(): number {
|
|
716
|
+
return this.floats[6];
|
|
717
|
+
}
|
|
643
718
|
/**
|
|
644
719
|
* Sets the alignment of multiline text.
|
|
645
720
|
* @zh 设置多行文本的对齐方式。
|
|
646
721
|
* @ja 複数行テキストの配置を設定します。
|
|
647
722
|
* @ko 여러 줄 텍스트의 정렬을 설정합니다.
|
|
648
723
|
*/
|
|
649
|
-
setLineAlignment(this: TextResource, alignment: LineAlignment): void {
|
|
724
|
+
setLineAlignment(this: TextResource, alignment: LineAlignment): void {
|
|
725
|
+
this.set(7, fontUnsigned(alignment, 3));
|
|
726
|
+
}
|
|
650
727
|
/**
|
|
651
728
|
* Returns line alignment.
|
|
652
729
|
* @zh 返回行对齐方式。
|
|
653
730
|
* @ja 行の配置を返します。
|
|
654
731
|
* @ko 행 정렬을 반환합니다.
|
|
655
732
|
*/
|
|
656
|
-
getLineAlignment(): LineAlignment {
|
|
733
|
+
getLineAlignment(): LineAlignment {
|
|
734
|
+
return this.words[7];
|
|
735
|
+
}
|
|
657
736
|
/**
|
|
658
737
|
* Sets horizontal or vertical writing direction.
|
|
659
738
|
* @zh 设置横排或竖排方向。
|
|
660
739
|
* @ja 横書きまたは縦書きの方向を設定します。
|
|
661
740
|
* @ko 가로쓰기 또는 세로쓰기 방향을 설정합니다.
|
|
662
741
|
*/
|
|
663
|
-
setTextOrientation(
|
|
742
|
+
setTextOrientation(
|
|
743
|
+
this: TextResource,
|
|
744
|
+
orientation: TextOrientation,
|
|
745
|
+
): void {
|
|
746
|
+
this.set(8, fontUnsigned(orientation, 2));
|
|
747
|
+
}
|
|
664
748
|
/**
|
|
665
749
|
* Returns text writing direction.
|
|
666
750
|
* @zh 返回文本排版方向。
|
|
667
751
|
* @ja テキストの組版方向を返します。
|
|
668
752
|
* @ko 텍스트 쓰기 방향을 반환합니다.
|
|
669
753
|
*/
|
|
670
|
-
getTextOrientation(): TextOrientation {
|
|
754
|
+
getTextOrientation(): TextOrientation {
|
|
755
|
+
return this.words[8];
|
|
756
|
+
}
|
|
671
757
|
/**
|
|
672
758
|
* Sets the glyph cluster grouping strategy for shaping.
|
|
673
759
|
* @zh 设置整形时的字形簇分组策略。
|
|
674
760
|
* @ja シェーピング時のグリフクラスターのグループ化方針を設定します。
|
|
675
761
|
* @ko 셰이핑 시 글리프 클러스터 그룹화 방식을 설정합니다.
|
|
676
762
|
*/
|
|
677
|
-
setClusterGrouping(this: TextResource, grouping: ClusterGrouping): void {
|
|
763
|
+
setClusterGrouping(this: TextResource, grouping: ClusterGrouping): void {
|
|
764
|
+
this.set(9, fontUnsigned(grouping, 2));
|
|
765
|
+
}
|
|
678
766
|
/**
|
|
679
767
|
* Returns the glyph cluster grouping strategy.
|
|
680
768
|
* @zh 返回字形簇分组策略。
|
|
681
769
|
* @ja グリフクラスターのグループ化方針を返します。
|
|
682
770
|
* @ko 글리프 클러스터 그룹화 방식을 반환합니다.
|
|
683
771
|
*/
|
|
684
|
-
getClusterGrouping(): ClusterGrouping {
|
|
772
|
+
getClusterGrouping(): ClusterGrouping {
|
|
773
|
+
return this.words[9];
|
|
774
|
+
}
|
|
685
775
|
|
|
686
776
|
/**
|
|
687
777
|
* Sets a synchronous glyph appearance callback, or null to remove it; the
|
|
@@ -690,7 +780,10 @@ class TextResource extends Drawable {
|
|
|
690
780
|
* @ja 同期グリフ外観コールバックを設定し、null で解除します。コールバックはジオメトリ再構築時に実行されます。
|
|
691
781
|
* @ko 동기 글리프 외형 콜백을 설정하며 null은 해제합니다. 콜백은 기하 구조를 재구성할 때 실행됩니다.
|
|
692
782
|
*/
|
|
693
|
-
setGlyphPreProcessor(
|
|
783
|
+
setGlyphPreProcessor(
|
|
784
|
+
this: TextResource,
|
|
785
|
+
processor: GlyphPreProcessor | null,
|
|
786
|
+
): void {
|
|
694
787
|
this.checkIdle();
|
|
695
788
|
if (processor !== null && typeof processor !== 'function') {
|
|
696
789
|
throw new TypeError('Expected a glyph pre-processor or null');
|
|
@@ -709,10 +802,14 @@ class TextResource extends Drawable {
|
|
|
709
802
|
getShapedGlyphs(): readonly ShapedGlyph[] {
|
|
710
803
|
this.prepare();
|
|
711
804
|
if (!this.glyphs) {
|
|
712
|
-
const buffer = new ShapedGlyphBuffer(
|
|
805
|
+
const buffer = new ShapedGlyphBuffer(
|
|
806
|
+
native.getTextGlyphs(this[graphicsNative]),
|
|
807
|
+
);
|
|
713
808
|
const indices = this.getIndices();
|
|
714
|
-
this.glyphs = Array.from(
|
|
715
|
-
|
|
809
|
+
this.glyphs = Array.from(
|
|
810
|
+
{ length: buffer.length },
|
|
811
|
+
(_, index) => new ShapedGlyphView(buffer, index, indices),
|
|
812
|
+
);
|
|
716
813
|
}
|
|
717
814
|
return this.glyphs;
|
|
718
815
|
}
|
|
@@ -723,7 +820,10 @@ class TextResource extends Drawable {
|
|
|
723
820
|
* @ja 変更可能な塗りつぶし頂点データを返します。次のジオメトリ再構築後は再取得が必要です。
|
|
724
821
|
* @ko 수정 가능한 채우기 꼭짓점 데이터를 반환합니다. 다음 기하 구조 재구성 후 다시 가져와야 합니다.
|
|
725
822
|
*/
|
|
726
|
-
getVertexData(): VertexArray {
|
|
823
|
+
getVertexData(): VertexArray {
|
|
824
|
+
this.prepare();
|
|
825
|
+
return this.vertices;
|
|
826
|
+
}
|
|
727
827
|
/**
|
|
728
828
|
* Returns mutable outline vertex data; retrieve it again after the next
|
|
729
829
|
* geometry rebuild.
|
|
@@ -731,7 +831,10 @@ class TextResource extends Drawable {
|
|
|
731
831
|
* @ja 変更可能な輪郭頂点データを返します。次のジオメトリ再構築後は再取得が必要です。
|
|
732
832
|
* @ko 수정 가능한 윤곽선 꼭짓점 데이터를 반환합니다. 다음 기하 구조 재구성 후 다시 가져와야 합니다.
|
|
733
833
|
*/
|
|
734
|
-
getOutlineVertexData(): VertexArray {
|
|
834
|
+
getOutlineVertexData(): VertexArray {
|
|
835
|
+
this.prepare();
|
|
836
|
+
return this.outline;
|
|
837
|
+
}
|
|
735
838
|
/**
|
|
736
839
|
* Returns the local axis-aligned bounds of the shaped text.
|
|
737
840
|
* @zh 返回整形后文本的局部轴对齐包围框。
|
|
@@ -757,32 +860,54 @@ class TextResource extends Drawable {
|
|
|
757
860
|
* @ko 전체 배치를 얻으려면 getShapedGlyphs()를 사용하세요.
|
|
758
861
|
*/
|
|
759
862
|
findCharacterPos(this: Text, index: number): Vector2f {
|
|
760
|
-
if (!Number.isSafeInteger(index) || index < 0)
|
|
863
|
+
if (!Number.isSafeInteger(index) || index < 0) {
|
|
864
|
+
throw new RangeError('Invalid character index');
|
|
865
|
+
}
|
|
761
866
|
this.prepare();
|
|
762
867
|
flushGraphics();
|
|
763
868
|
return this.getTransform().transformPoint(
|
|
764
|
-
new Vector2f(
|
|
869
|
+
new Vector2f(
|
|
870
|
+
...native.findTextCharacter(this[graphicsNative], index),
|
|
871
|
+
),
|
|
872
|
+
);
|
|
765
873
|
}
|
|
766
874
|
|
|
767
|
-
protected draw(
|
|
875
|
+
protected draw(
|
|
876
|
+
this: Text,
|
|
877
|
+
target: RenderTarget,
|
|
878
|
+
states: RenderStates,
|
|
879
|
+
): void {
|
|
768
880
|
this.prepare();
|
|
769
881
|
const combined = new RenderStates(states);
|
|
770
882
|
combined.transform.combine(this.getTransform());
|
|
771
883
|
combined.texture = this.font.getTexture(this.getCharacterSize());
|
|
772
884
|
combined.coordinateType = CoordinateType.Pixels;
|
|
773
885
|
if (this.outline.getVertexCount()) {
|
|
774
|
-
target[recordVertices](
|
|
775
|
-
this.outline
|
|
886
|
+
target[recordVertices](
|
|
887
|
+
this.outline[vertexArrayBytes],
|
|
888
|
+
this.outline.getPrimitiveType(),
|
|
889
|
+
combined,
|
|
890
|
+
);
|
|
776
891
|
}
|
|
777
892
|
if (this.vertices.getVertexCount()) {
|
|
778
|
-
target[recordVertices](
|
|
779
|
-
this.vertices
|
|
893
|
+
target[recordVertices](
|
|
894
|
+
this.vertices[vertexArrayBytes],
|
|
895
|
+
this.vertices.getPrimitiveType(),
|
|
896
|
+
combined,
|
|
897
|
+
);
|
|
780
898
|
}
|
|
781
899
|
}
|
|
782
900
|
|
|
783
|
-
[dispatchDrawable](
|
|
784
|
-
|
|
785
|
-
|
|
901
|
+
[dispatchDrawable](
|
|
902
|
+
this: Text,
|
|
903
|
+
target: RenderTarget,
|
|
904
|
+
states: RenderStates,
|
|
905
|
+
): void {
|
|
906
|
+
if (this.draw === TextResource.prototype.draw) {
|
|
907
|
+
this.draw(target, states);
|
|
908
|
+
} else {
|
|
909
|
+
super[dispatchDrawable](target, states);
|
|
910
|
+
}
|
|
786
911
|
}
|
|
787
912
|
|
|
788
913
|
/**
|
|
@@ -794,9 +919,11 @@ class TextResource extends Drawable {
|
|
|
794
919
|
*/
|
|
795
920
|
private set(index: number, value: number): void {
|
|
796
921
|
this.checkIdle();
|
|
797
|
-
const data =
|
|
798
|
-
? this.floats : this.words;
|
|
799
|
-
if (data[index] === value)
|
|
922
|
+
const data =
|
|
923
|
+
index === 1 || index === 2 || index === 6 ? this.floats : this.words;
|
|
924
|
+
if (data[index] === value) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
800
927
|
data[index] = value;
|
|
801
928
|
this.geometry[0] = 1;
|
|
802
929
|
}
|
|
@@ -810,10 +937,14 @@ class TextResource extends Drawable {
|
|
|
810
937
|
*/
|
|
811
938
|
private setColor(index: 4 | 5, value: number): void {
|
|
812
939
|
this.checkIdle();
|
|
813
|
-
if (this.colors.getUint32(index * 4) === value)
|
|
940
|
+
if (this.colors.getUint32(index * 4) === value) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
814
943
|
this.colors.setUint32(index * 4, value);
|
|
815
944
|
// SFML recolors existing geometry without reshaping or running callbacks.
|
|
816
|
-
if (this.geometry[0] || !this.vertices)
|
|
945
|
+
if (this.geometry[0] || !this.vertices) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
817
948
|
const vertices = index === 4 ? this.vertices : this.outline;
|
|
818
949
|
const bytes = vertices[vertexArrayBytes];
|
|
819
950
|
for (let offset = 8; offset < bytes.length; offset += 20) {
|
|
@@ -830,7 +961,11 @@ class TextResource extends Drawable {
|
|
|
830
961
|
* @ko 전처리기 콜백 안에서 실행되면 예외를 던집니다.
|
|
831
962
|
*/
|
|
832
963
|
private checkIdle(): void {
|
|
833
|
-
if (this.preparing)
|
|
964
|
+
if (this.preparing) {
|
|
965
|
+
throw new SFMLError(
|
|
966
|
+
'Cannot update or query text geometry in its glyph pre-processor',
|
|
967
|
+
);
|
|
968
|
+
}
|
|
834
969
|
}
|
|
835
970
|
|
|
836
971
|
/**
|
|
@@ -852,7 +987,9 @@ class TextResource extends Drawable {
|
|
|
852
987
|
*/
|
|
853
988
|
private prepare(): void {
|
|
854
989
|
this.checkIdle();
|
|
855
|
-
if (!this.geometry[0] && this.revision === this.font[fontRevision])
|
|
990
|
+
if (!this.geometry[0] && this.revision === this.font[fontRevision]) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
856
993
|
this.preparing = true;
|
|
857
994
|
try {
|
|
858
995
|
let callback: NativeGlyphProcessor | null = null;
|
|
@@ -864,28 +1001,46 @@ class TextResource extends Drawable {
|
|
|
864
1001
|
let outlineColor = new Color(outline);
|
|
865
1002
|
const appearance: GlyphAppearance = {
|
|
866
1003
|
style,
|
|
867
|
-
get fillColor() {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
set
|
|
1004
|
+
get fillColor() {
|
|
1005
|
+
return fillColor;
|
|
1006
|
+
},
|
|
1007
|
+
set fillColor(value) {
|
|
1008
|
+
fillColor = new Color(value);
|
|
1009
|
+
},
|
|
1010
|
+
get outlineColor() {
|
|
1011
|
+
return outlineColor;
|
|
1012
|
+
},
|
|
1013
|
+
set outlineColor(value) {
|
|
1014
|
+
outlineColor = new Color(value);
|
|
1015
|
+
},
|
|
871
1016
|
outlineThickness: thickness,
|
|
872
1017
|
};
|
|
873
|
-
processor(
|
|
874
|
-
new ShapedGlyphBuffer(glyph), 0, indices),
|
|
1018
|
+
processor(
|
|
1019
|
+
new ShapedGlyphView(new ShapedGlyphBuffer(glyph), 0, indices),
|
|
1020
|
+
appearance,
|
|
1021
|
+
);
|
|
875
1022
|
return new Float64Array([
|
|
876
|
-
fontUnsigned(appearance.style, 15),
|
|
877
|
-
colorInteger(appearance.
|
|
1023
|
+
fontUnsigned(appearance.style, 15),
|
|
1024
|
+
colorInteger(appearance.fillColor),
|
|
1025
|
+
colorInteger(appearance.outlineColor),
|
|
1026
|
+
textFloat(appearance.outlineThickness),
|
|
878
1027
|
]);
|
|
879
1028
|
};
|
|
880
1029
|
}
|
|
881
1030
|
flushGraphics();
|
|
882
|
-
const layout = native.prepareText(
|
|
883
|
-
this
|
|
1031
|
+
const layout = native.prepareText(
|
|
1032
|
+
this[graphicsNative],
|
|
1033
|
+
this.font[graphicsNative],
|
|
1034
|
+
this.string,
|
|
1035
|
+
callback,
|
|
1036
|
+
);
|
|
884
1037
|
this.vertices = vertexArrayFromMapping(layout.vertices);
|
|
885
1038
|
this.outline = vertexArrayFromMapping(layout.outline);
|
|
886
1039
|
this.glyphs = undefined;
|
|
887
1040
|
this.revision = this.font[fontRevision];
|
|
888
|
-
} finally {
|
|
1041
|
+
} finally {
|
|
1042
|
+
this.preparing = false;
|
|
1043
|
+
}
|
|
889
1044
|
}
|
|
890
1045
|
}
|
|
891
1046
|
|