/
TextEntity.ts
2126 lines (1718 loc) · 56 KB
/
TextEntity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Entity from "./Entity";
import Primitive from "./Primitive";
import GLEnv from "./GLEnv";
import Mesh from "./Mesh";
import Scene from "./Scene";
import Texture from "./Texture";
import TextMaterial from "./TextMaterial";
import SimpleTextMaterial from "./SimpleTextMaterial";
import GeoMath, { Vector3, Vector4, Matrix } from "./GeoMath";
import GeoPoint from "./GeoPoint";
import RenderStage from "./RenderStage";
import AltitudeMode from "./AltitudeMode";
import EntityRegion from "./EntityRegion";
import Dom from "./util/Dom";
import Color from "./util/Color";
import BindingBlock from "./animation/BindingBlock";
import EasyBindingBlock from "./animation/EasyBindingBlock";
import Type from "./animation/Type";
import AbstractPointEntity from "./AbstractPointEntity";
/**
* テキストエンティティ
*/
class TextEntity extends AbstractPointEntity<TextEntity.TextEntry> {
private _text_parent_props: TextEntity.ParentProps;
private _primitive_producer?: TextEntity.PrimitiveProducer;
/**
* @param scene 所属可能シーン
* @param opts オプション集合
*/
constructor( scene: Scene, opts: TextEntity.Option = {} )
{
super( scene, opts );
// テキストの親プロパティ
this._text_parent_props = {
font_style: "normal",
font_weight: "normal",
font_size: TextEntity.DEFAULT_FONT_SIZE,
font_family: TextEntity.DEFAULT_FONT_FAMILY,
color: TextEntity.DEFAULT_COLOR,
stroke_color: TextEntity.DEFAULT_STROKE_COLOR,
stroke_width: TextEntity.DEFAULT_STROKE_WIDTH,
bg_color: TextEntity.DEFAULT_BG_COLOR,
enable_stroke: false,
enable_bg: false
};
// @ts-ignore
const block = this._animation as EasyBindingBlock;
block.addDescendantUnbinder( () => { this._unbindDescendantAnimations(); } );
this._setupAnimationBindingBlock();
// 生成情報から設定
if ( opts && opts.json ) {
this._setupByJson( opts.json );
}
}
override getPrimitiveProducer()
{
return this._primitive_producer;
}
override onChangeAltitudeMode( prev_mode: AltitudeMode )
{
if ( this._primitive_producer ) {
this._primitive_producer.onChangeAltitudeMode();
}
}
/**
* EasyBindingBlock.DescendantUnbinder 処理
*/
private _unbindDescendantAnimations()
{
// すべてのエントリーを解除
for ( let entry of this._entries ) {
entry.animation.unbindAllRecursively();
}
}
/**
* アニメーションの BindingBlock を初期化
*/
private _setupAnimationBindingBlock()
{
const block = this._animation; // 実体は EasyBindingBlock
const number = Type.find( "number" );
const string = Type.find( "string" );
const vector3 = Type.find( "vector3" );
// パラメータ名: font_style
// パラメータ型: string
// フォントスタイル
block.addEntry( "font_style", [string], null, (value: TextEntity.FontStyle) => {
this.setFontStyle( value );
} );
// パラメータ名: font_weight
// パラメータ型: string
// フォントの太さ
block.addEntry( "font_weight", [string], null, (value: TextEntity.FontWeight) => {
this.setFontWeight( value );
} );
// パラメータ名: font_size
// パラメータ型: number
// フォントの大きさ
block.addEntry( "font_size", [number], null, (value: number) => {
this.setFontSize( value );
} );
// パラメータ名: color
// パラメータ型: vector3
// テキストの色
block.addEntry( "color", [vector3], null, (value: Vector3) => {
this.setColor( value );
} );
// パラメータ名: stroke_color
// パラメータ型: vector3
// 縁の色
block.addEntry( "stroke_color", [vector3], null, (value: Vector3) => {
this.setStrokeColor( value );
} );
// パラメータ名: stroke_width
// パラメータ型: number
// 縁の線幅
block.addEntry( "stroke_width", [number], null, (value: number) => {
this.setStrokeLineWidth( value );
} );
}
/**
* フォントスタイルを設定
* @param style フォントスタイル
*/
setFontStyle( style: TextEntity.FontStyle )
{
this._setValueProperty( "font_style", style );
}
/**
* @summary フォントの太さを設定
* @param weight フォントの太さ
*/
setFontWeight( weight: TextEntity.FontWeight )
{
this._setValueProperty( "font_weight", weight );
}
/**
* フォントの大きさを設定
* @param size フォントの大きさ (Pixels)
*/
setFontSize( size: number )
{
this._setValueProperty( "font_size", size );
}
/**
* フォントファミリーを設定
* @param family フォントファミリー
* @see https://developer.mozilla.org/ja/docs/Web/CSS/font-family
*/
setFontFamily( family: string )
{
this._setValueProperty( "font_family", family );
}
/**
* テキストの色を設定
* @param color テキストの色
*/
setColor( color: Vector3 | Vector4 )
{
this._setColorProperty( "color", color );
}
/**
* テキスト縁の色を設定
* @param color 縁の色
*/
setStrokeColor( color: Vector3 | Vector4 )
{
this._setColorProperty( "stroke_color", color );
}
/**
* テキスト縁の太さを設定
* @param width 縁の線幅
*/
setStrokeLineWidth( width: number )
{
this._setValueProperty( "stroke_width", width );
}
/**
* テキスト縁を有効にするかどうか
* @param enable trueなら有効
*/
setEnableStroke( enable: boolean )
{
this._setValueProperty( "enable_stroke", enable );
this._primitive_producer = new TextEntity.PrimitiveProducer( this );
}
/**
* テキスト背景の色を設定
* @param color テキストの色
*/
setBackgroundColor( color: Vector3 | Vector4 )
{
this._setColorProperty( "bg_color", color );
}
/**
* テキスト背景を有効にするかどうか
* @param enable trueなら有効
*/
setEnableBackground( enable: boolean )
{
this._setValueProperty( "enable_bg", enable );
this._primitive_producer = new TextEntity.PrimitiveProducer( this );
}
/**
* テキストを追加
* @param text テキスト
* @param position 位置
* @param props プロパティ
* @return 追加したEntry
*/
addText( text: string, position: GeoPoint, props: TextEntity.EntryOption ): TextEntity.TextEntry
{
var entry = new TextEntity.TextEntry( this, text, position, props );
this._entries.push( entry );
this._primitive_producer = new TextEntity.PrimitiveProducer( this );
this._primitive_producer.onAddTextEntry();
return entry;
}
/**
* 専用マテリアルを取得
*/
private _getTextMaterial( render_target: RenderStage.RenderTarget )
{
var scene = this.scene;
if ( render_target === RenderStage.RenderTarget.SCENE ) {
if ( !scene._TextEntity_text_material ) {
// scene にマテリアルをキャッシュ
scene._TextEntity_text_material = new TextMaterial( scene.glenv );
}
return scene._TextEntity_text_material;
}
else if (render_target === RenderStage.RenderTarget.RID) {
if ( !scene._TextEntity_text_material_pick ) {
// scene にマテリアルをキャッシュ
scene._TextEntity_text_material_pick = new TextMaterial( scene.glenv, { ridMaterial: true } );
}
return scene._TextEntity_text_material_pick;
}
else {
throw new Error("unknown render target: " + render_target);
}
}
/**
* テキストだけを描画する専用マテリアルを取得
*/
private _getSimpleTextMaterial( render_target: RenderStage.RenderTarget )
{
var scene = this.scene;
if ( render_target === RenderStage.RenderTarget.SCENE ) {
if ( !scene._SimpleTextEntity_text_material ) {
// scene にマテリアルをキャッシュ
scene._SimpleTextEntity_text_material = new SimpleTextMaterial( scene.glenv );
}
return scene._SimpleTextEntity_text_material;
}
else if (render_target === RenderStage.RenderTarget.RID) {
if ( !scene._SimpleTextEntity_text_material_pick ) {
// scene にマテリアルをキャッシュ
scene._SimpleTextEntity_text_material_pick = new SimpleTextMaterial( scene.glenv, { ridMaterial: true } );
}
return scene._SimpleTextEntity_text_material_pick;
}
else {
throw new Error("unknown render target: " + render_target);
}
}
private _setValueProperty( name: string, value: any )
{
var props = this._text_parent_props;
if ( props[name] != value ) {
props[name] = value;
if ( this._primitive_producer ) {
this._primitive_producer.onChangeParentProperty();
}
}
}
private _setColorProperty( name: string, value: Vector3 | Vector4 )
{
var dst = this._text_parent_props[name] as Vector4;
if ( dst[0] !== value[0] || dst[1] !== value[1] || dst[2] !== value[2] ) {
Color.premultiply( value, dst );
if ( this._primitive_producer ) {
this._primitive_producer.onChangeParentProperty();
}
}
}
private _setupByJson( json: TextEntity.Json )
{
var position = new GeoPoint();
for ( let entry of json.entries ) {
position.setFromArray( entry.position );
this.addText( entry.text, position, entry );
}
if ( json.font_style !== undefined ) this.setFontStyle( json.font_style );
if ( json.font_weight !== undefined ) this.setFontWeight( json.font_weight );
if ( json.font_size !== undefined ) this.setFontSize( json.font_size );
if ( json.font_family !== undefined ) this.setFontFamily( json.font_family );
if ( json.color !== undefined ) this.setColor( json.color );
if ( json.stroke_color !== undefined ) this.setStrokeColor ( json.stroke_color );
if ( json.stroke_width !== undefined ) this.setStrokeLineWidth ( json.stroke_width );
if ( json.enable_stroke !== undefined ) this.setEnableStroke ( json.enable_stroke );
if ( json.bg_color !== undefined ) this.setBackgroundColor( json.bg_color );
if ( json.enable_bg !== undefined ) this.setEnableBackground ( json.enable_bg );
}
private _enableStroke( )
{
return this._text_parent_props["enable_stroke"];
}
/**
* IDでEntryを取得
* @param id ID
* @return IDが一致するEntry(無ければundefined)
*/
getEntry( id: string ): TextEntity.TextEntry | undefined
{
return this._entries.find((entry) => entry.id === id);
}
}
namespace TextEntity {
export interface Option extends Entity.Option {
/**
* 生成情報
*/
json?: TextEntity.Json;
}
export interface Json extends Entity.Json {
entries: EntryJson[];
font_style?: FontStyle;
font_weight?: FontWeight;
font_size?: number;
font_family?: string;
stroke_color?: Vector3 | Vector4;
stroke_width?: number;
color?: Vector3 | Vector4;
bg_color?: Vector3 | Vector4;
enable_bg?: boolean;
enable_stroke?: boolean,
}
export interface EntryJson {
position: [ x: number, y: number, z: number ];
text: string;
}
export interface ParentProps {
font_style: FontStyle;
font_weight: FontWeight;
font_size: number;
font_family: string;
color: Vector4;
stroke_color: Vector4;
stroke_width: number;
bg_color: Vector4;
enable_stroke: boolean;
enable_bg: boolean,
[name: string]: any,
}
export type FontStyle = "normal" | "italic" | "oblique";
export type FontWeight = "normal" | "bold";
export const DEFAULT_FONT_SIZE = 16;
export const DEFAULT_FONT_FAMILY = "sans-serif";
export const DEFAULT_COLOR = Color.createColor([1.0, 1.0, 1.0]);
export const DEFAULT_STROKE_COLOR = Color.createColor([0.0, 0.0, 0.0]);
export const DEFAULT_STROKE_WIDTH = 0.48;
export const DEFAULT_BG_COLOR = Color.createColor([0.3, 0.3, 0.3]);
export const DEFAULT_TEXT_UPPER = 1.1;
export const DEFAULT_TEXT_LOWER = 0.38;
export const SAFETY_PIXEL_MARGIN = 1;
export const MAX_IMAGE_WIDTH = 4096;
/**
* @summary TextEntity の PrimitiveProducer
*
* TODO: relative で標高の変化のたびにテクスチャを生成する必要はないので
* Layout でのテクスチャの生成とメッシュの生成を分離する
*
* @private
*/
export class PrimitiveProducer extends Entity.PrimitiveProducer {
private _glenv: GLEnv;
private _dirty: boolean;
private _transform: Matrix;
private _properties: {
enable_bg: boolean;
image?: Texture;
};
private _primitive: Primitive;
private _pickPrimitive: Primitive;
private _primitives: Primitive[];
private _pickPrimitives: Primitive[];
/**
* @param {mapray.TextEntity} entity
*/
constructor( entity: TextEntity )
{
super( entity );
this._glenv = entity.scene.glenv;
this._dirty = true;
// プリミティブの要素
this._transform = GeoMath.setIdentity( GeoMath.createMatrix() );
this._properties = {
enable_bg: false,
image: undefined // テキスト画像
};
// プリミティブ
var material = null, pickMaterial = null;
if ( this._isSimpleText() ) {
// @ts-ignore
material = entity._getSimpleTextMaterial( RenderStage.RenderTarget.SCENE );
// @ts-ignore
pickMaterial = entity._getSimpleTextMaterial( RenderStage.RenderTarget.RID );
} else {
// @ts-ignore
material = entity._getTextMaterial( RenderStage.RenderTarget.SCENE );
// @ts-ignore
pickMaterial = entity._getTextMaterial( RenderStage.RenderTarget.RID );
}
var primitive = new Primitive( this._glenv, null, material, this._transform );
primitive.properties = this._properties;
this._primitive = primitive;
var pickPrimitive = new Primitive( this._glenv, null, pickMaterial, this._transform );
pickPrimitive.properties = this._properties;
this._pickPrimitive = pickPrimitive;
// プリミティブ配列
this._primitives = [];
this._pickPrimitives = [];
}
override getEntity(): TextEntity {
return super.getEntity() as TextEntity;
}
override createRegions()
{
const region = new EntityRegion();
// @ts-ignore
for ( let {position} of this.entity._entries ) {
region.addPoint( position );
}
return [region];
}
override onChangeElevation( regions: EntityRegion[] )
{
this._dirty = true;
}
override getPrimitives( stage: RenderStage )
{
this._updatePrimitive();
return stage.getRenderTarget() === RenderStage.RenderTarget.SCENE ? this._primitives : this._pickPrimitives;
}
/**
* 親プロパティが変更されたことを通知
*/
onChangeParentProperty()
{
this._dirty = true;
}
/**
* 子プロパティが変更されたことを通知
*/
onChangeChildProperty()
{
this._dirty = true;
}
/**
* 高度モードが変更されたことを通知
*/
onChangeAltitudeMode()
{
this._dirty = true;
}
/**
* テキストが追加されたことを通知
*/
onAddTextEntry()
{
// 変化した可能性がある
this.needToCreateRegions();
this._dirty = true;
}
get transform(): Matrix {
return this._transform;
}
/**
* プリミティブの更新
*
* @desc
* 入力:
* this.entity._entries
* this._dirty
* 出力:
* this._transform
* this._properties.image
* this._primitive.mesh
* this._primitives
* this._dirty
*
* @return this._primitives
*/
private _updatePrimitive(): Primitive[] | undefined
{
if ( !this._dirty ) {
// 更新する必要はない
return;
}
this._updateProperties();
const entity = this.getEntity();
// @ts-ignore
if ( entity._entries.length == 0 ) {
this._primitives = [];
this._pickPrimitives = [];
this._dirty = false;
return;
}
// 各エントリーの GOCS 位置を生成 (平坦化配列)
var gocs_array = this._createFlatGocsArray();
// プリミティブの更新
// primitive.transform
this._updateTransform( gocs_array );
var layout = new Layout( this, gocs_array );
if ( !layout.isValid() ) {
// 更新に失敗
this._primitives = [];
this._dirty = false;
return this._primitives;
}
// テクスチャ設定
var properties = this._properties;
if ( properties.image ) {
properties.image.dispose();
}
properties.image = layout.texture;
// メッシュ生成
var vtype = [];
if ( this._isSimpleText() ) {
vtype = [
{ name: "a_position", size: 3 },
{ name: "a_offset", size: 2 },
{ name: "a_texcoord", size: 2 },
{ name: "a_color", size: 4 }
];
} else {
vtype = [
{ name: "a_position", size: 3 },
{ name: "a_offset", size: 2 },
{ name: "a_texcoord", size: 2 },
];
}
var mesh_data = {
vtype,
vertices: layout.vertices,
indices: layout.indices
};
var mesh = new Mesh( this._glenv, mesh_data );
// メッシュ設定
// primitive.mesh
var primitive = this._primitive;
if ( primitive.mesh ) {
primitive.mesh.dispose();
}
primitive.mesh = mesh;
var pickPrimitive = this._pickPrimitive;
if ( pickPrimitive.mesh ) {
pickPrimitive.mesh.dispose();
}
pickPrimitive.mesh = mesh;
// 更新に成功
this._primitives = [primitive];
this._pickPrimitives = [pickPrimitive];
this._dirty = false;
return;
}
/**
* @summary プロパティを更新
*
* @desc
* <pre>
* 入力:
* this.entity
* 出力:
* this._properties
* </pre>
*
* @private
*/
_updateProperties()
{
let entity = this.getEntity();
let props = this._properties;
// @ts-ignore
props.enable_bg = entity._text_parent_props.enable_bg;
}
/**
* プリミティブの更新
*
* 条件:
* this.entity._entries.length > 0
* 入力:
* this.entity._entries.length
* 出力:
* this._transform
*
* @param gocs_array GOCS 平坦化配列
*/
private _updateTransform( gocs_array: Float64Array )
{
// @ts-ignore
var num_entries = this.getEntity()._entries.length;
var xsum = 0;
var ysum = 0;
var zsum = 0;
for ( let i = 0; i < num_entries; ++i ) {
let ibase = 3*i;
xsum += gocs_array[ibase];
ysum += gocs_array[ibase + 1];
zsum += gocs_array[ibase + 2];
}
// 変換行列の更新
var transform = this._transform;
transform[12] = xsum / num_entries;
transform[13] = ysum / num_entries;
transform[14] = zsum / num_entries;
}
/**
* GOCS 平坦化配列を取得
*
* 入力: this.entity._entries
*
* @return GOCS 平坦化配列
*/
private _createFlatGocsArray(): Float64Array
{
// @ts-ignore
const num_points = this.getEntity()._entries.length;
return GeoPoint.toGocsArray( this._getFlatGeoPoints_with_Absolute(), num_points,
new Float64Array( 3 * num_points ) );
}
/**
* @summary GeoPoint 平坦化配列を取得 (絶対高度)
*
* 入力: this.entity._entries
*
* @return {number[]} GeoPoint 平坦化配列
* @private
*/
_getFlatGeoPoints_with_Absolute()
{
const owner = this.getEntity();
// @ts-ignore
const entries = owner._entries;
const num_points = entries.length;
const flat_array = new Float64Array( 3 * num_points );
// flat_array[] に経度要素と緯度要素を設定
for ( let i = 0; i < num_points; ++i ) {
let pos = entries[i].position;
flat_array[3*i] = pos.longitude;
flat_array[3*i + 1] = pos.latitude;
}
switch ( owner.altitude_mode ) {
case AltitudeMode.RELATIVE:
case AltitudeMode.CLAMP:
// flat_array[] の高度要素に現在の標高を設定
owner.scene.viewer.getExistingElevations( num_points, flat_array, 0, 3, flat_array, 2, 3 );
if ( owner.altitude_mode === AltitudeMode.RELATIVE ) {
// flat_array[] の高度要素に相対高度を加える
for ( let i = 0; i < num_points; ++i ) {
flat_array[3*i + 2] += entries[i].position.altitude;
}
}
break;
default: // AltitudeMode.ABSOLUTE
// flat_array[] の高度要素に絶対高度を設定
for ( let i = 0; i < num_points; ++i ) {
flat_array[3*i + 2] = entries[i].position.altitude;
}
break;
}
return flat_array;
}
/**
* @summary シンプルテキストモードかどうかを確認
*
* @return {boolean} シンプルテキストモードならtrue.
* @private
*/
_isSimpleText()
{
let entity = this.getEntity();
let enable = true;
// check enable bg color or stroke;
// @ts-ignore
if ( entity._text_parent_props.enable_bg || entity._text_parent_props.enable_stroke ) {
enable = false;
}
// check enable stroke
let i = 0;
// @ts-ignore
const entries = entity._entries;
while ( enable && entries.length > i ) {
let entry = entries[i] as TextEntry;
enable = !entry.enable_stroke;
i++;
}
return enable;
}
}
/**
* テキスト要素
*/
export class TextEntry extends AbstractPointEntity.Entry {
private _owner: TextEntity;
private _text: string;
private _position: GeoPoint;
private _props: EntryProps;
private _animation: BindingBlock;
/**
* @param owner 所有者
* @param text テキスト
* @param position 位置
* @param props プロパティ
*/
constructor( owner: TextEntity, text: string, position: GeoPoint, props: EntryOption ) {
super();
this._owner = owner;
this._text = text;
this._position = position.clone();
// animation.BindingBlock
// @ts-ignore
this._animation = new EasyBindingBlock();
this._setupAnimationBindingBlock();
this._props = Object.assign( {}, props ) as TextEntity.EntryProps; // props の複製
this._copyColorProperty( "color" ); // deep copy
this._copyColorProperty( "stroke_color" ); // deep copy
this._copyColorProperty( "bg_color" ); // deep copy
}
override get animation(): BindingBlock {
return this._animation;
}
/**
* @summary テキスト
* @type {string}
* @readonly
* @package
*/
get text()
{
return this._text;
}
/**
* 位置
* @internal
*/
override get position(): GeoPoint
{
return this._position;
}
/**
* ID
*/
override get id(): string
{
return this._props.hasOwnProperty( "id" ) ? this._props.id as string : "";
}
/**
* フォントサイズ (Pixels)
* @internal
*/
get size(): number
{
var props = this._props;
// @ts-ignore
var parent = this._owner._text_parent_props;
return props.font_size || parent.font_size;
}
/**
* テキストの色
* @internal
*/
get color(): Vector4
{
var props = this._props;
// @ts-ignore
var parent = this._owner._text_parent_props;
return props.color || parent.color;
}
/**
* フォント
* @internal
* @see https://developer.mozilla.org/ja/docs/Web/CSS/font
*/
get font(): string
{
var props = this._props;
// @ts-ignore
var parent = this._owner._text_parent_props;
var style = props.font_style || parent.font_style;
var variant = "normal";
var weight = props.font_weight || parent.font_weight;
var family = props.font_family || parent.font_family;
return style + " " + variant + " " + weight + " " + this.size + "px " + family;
}
/**
* テキスト縁の色
* @internal
*/
get stroke_color(): Vector4
{
var props = this._props;
// @ts-ignore
var parent = this._owner._text_parent_props;
return props.stroke_color || parent.stroke_color;
}
/**
* 縁の幅 (Pixels)
* @internal
*/
get stroke_width(): number
{
var props = this._props;
// @ts-ignore
var parent = this._owner._text_parent_props;
return props.stroke_width || parent.stroke_width;