@awayjs/scene 0.13.243 → 0.13.245

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.
@@ -42,13 +42,13 @@ const PUBLIC_FIELDS = [
42
42
  'size', 'color',
43
43
  'bold', 'italic',
44
44
  'underline', 'leading',
45
- 'letterSpacing', 'font_table'
45
+ 'letterSpacing'
46
46
  ];
47
47
 
48
48
  export class TextFormat extends AssetBase {
49
49
  public static assetType: string = '[asset TextFormat]';
50
50
 
51
- public fontLookUpMode: FontLookUpMode;
51
+ public fontLookUpMode: FontLookUpMode = FontLookUpMode.DEFAULT;
52
52
 
53
53
  // flag marked that format is changed.
54
54
  _updateID: number = 0;
@@ -56,7 +56,7 @@ export class TextFormat extends AssetBase {
56
56
  return this._updateID;
57
57
  }
58
58
 
59
- private _textFormatDirty: boolean = false;
59
+ private _fontTableDirty: boolean = true;
60
60
  /**
61
61
  * return true if a certain property was set for this format.
62
62
  *
@@ -294,7 +294,7 @@ export class TextFormat extends AssetBase {
294
294
  }
295
295
 
296
296
  this._bold = value;
297
- this._textFormatDirty = true;
297
+ this._fontTableDirty = true;
298
298
 
299
299
  }
300
300
 
@@ -313,7 +313,7 @@ export class TextFormat extends AssetBase {
313
313
  }
314
314
 
315
315
  this._italic = value;
316
- this._textFormatDirty = true;
316
+ this._fontTableDirty = true;
317
317
  }
318
318
 
319
319
  /**
@@ -347,10 +347,10 @@ export class TextFormat extends AssetBase {
347
347
  */
348
348
  private _font_table: IFontTable;
349
349
  public get font_table(): IFontTable {
350
- if (!this._font_table || this._textFormatDirty) {
351
- this.font; // getter makes sure a font exists !
350
+
351
+ if (!this._font_table || this._fontTableDirty)
352
352
  this.update_font_table();
353
- }
353
+
354
354
  return this._font_table;
355
355
  }
356
356
 
@@ -359,7 +359,7 @@ export class TextFormat extends AssetBase {
359
359
  // font_table is only ever set in parser or when using label-data
360
360
  // after using "bold" or "itaic" font_table should never be set directly
361
361
  this._font_table = value;
362
- this._textFormatDirty = false;
362
+ this._fontTableDirty = false;
363
363
  }
364
364
 
365
365
  /**
@@ -386,9 +386,25 @@ export class TextFormat extends AssetBase {
386
386
  return this.font?.name;
387
387
  }
388
388
 
389
+ public set font_name(value: string) {
390
+ if (this.font?.name == value)
391
+ return;
392
+
393
+ if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
394
+ this._font = DefaultFontManager.getFont(value);
395
+ } else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
396
+ this._font = DeviceFontManager.getDeviceFont(value);
397
+ } else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
398
+ this._font = DefaultFontManager.getFont_CFF(value);
399
+ }
400
+
401
+ this._fontTableDirty = true;
402
+ this._updateID++;
403
+ }
404
+
389
405
  public update_font_table() {
390
406
 
391
- this._textFormatDirty = false;
407
+ this._fontTableDirty = false;
392
408
  let stylename = FontStyleName.STANDART;
393
409
  if (this._italic && !this._bold)
394
410
  stylename = FontStyleName.ITALIC;
@@ -398,53 +414,29 @@ export class TextFormat extends AssetBase {
398
414
  stylename = FontStyleName.BOLDITALIC;
399
415
 
400
416
  if (this._font) {
401
- const newFontTable = this.font.get_font_table(stylename, TesselatedFontTable.assetType, null, true);
402
- if (this._font_table && !newFontTable) {
403
- // if we have a font-table, and we switch to invalid style,
404
- // we just keep the existing font-table
417
+ const font_table = this._font.get_font_table(stylename, TesselatedFontTable.assetType, null, true);
418
+
419
+ // if we have a font-table, and we switch to invalid style,
420
+ // we just keep the existing font-table
421
+ if (this._font_table && !font_table)
405
422
  return;
406
- }
407
- this._font_table = newFontTable ? newFontTable : Font.emptyFontTable;
408
- return;
423
+
424
+ this._font_table = font_table ? font_table : Font.emptyFontTable;
409
425
  }
410
426
  }
411
427
 
412
428
  public get font(): Font {
413
- if (this._font) {
414
- return this._font;
415
- }
416
-
417
- if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
418
- this._font = DefaultFontManager.getFont(null);
419
- } else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
420
- this._font = DeviceFontManager.getDeviceFont(null);
421
- } else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
422
- this._font = DefaultFontManager.getFont_CFF(null);
423
- } else {
424
- console.warn('[TextFormat] - unsupported FontLookUpMode', this.fontLookUpMode);
425
- }
426
- this._font_table = null;
427
- this._textFormatDirty = true;
428
429
  return this._font;
429
430
  }
430
431
 
431
432
  public set font(value: Font) {
432
- this._textFormatDirty = true;
433
- if (typeof value === 'string') {
434
- this._setFontFromString(value);
433
+ if (this._font == value)
435
434
  return;
436
- }
437
435
 
438
- if (value !== this._font) {
439
- this._updateID++;
440
- }
436
+ this._font = value;
441
437
 
442
- if (value) {
443
- this._font = value;
444
- return;
445
- }
446
- this._font = null;
447
- this._font_table = null;
438
+ this._fontTableDirty = true;
439
+ this._updateID++;
448
440
  }
449
441
 
450
442
  /**
@@ -531,13 +523,12 @@ export class TextFormat extends AssetBase {
531
523
  * space between lines.
532
524
  */
533
525
  constructor(
534
- font: string = null, size: number = null, color: number = null, bold: boolean = null,
526
+ font: Font | string = null, size: number = null, color: number = null, bold: boolean = null,
535
527
  italic: boolean = null, underline: boolean = null, url: string = null,
536
528
  link_target: string = null, align: string = null,
537
529
  leftMargin: number = null, rightMargin: number = null, indent: number = null, leading: number = null) {
538
530
  super();
539
531
 
540
- this.fontLookUpMode = FontLookUpMode.DEFAULT;
541
532
  this._size = size;
542
533
  this._color = color;
543
534
  this._bold = bold;
@@ -551,42 +542,19 @@ export class TextFormat extends AssetBase {
551
542
  this._indent = indent;
552
543
  this._leading = leading;
553
544
 
554
- this._letterSpacing = null;
555
-
556
- this._font_table = null;
557
-
558
545
  if (typeof font === 'string') {
559
- this._setFontFromString(font);
560
- return;
561
- } else if (font) {
562
- this._font = font;
563
- this._textFormatDirty = true;
546
+ this.font_name = font;
547
+ } else {
548
+ this.font = font;
564
549
  }
565
-
566
- }
567
-
568
- private _setFontFromString(font_name: string) {
569
-
570
- let asset;
571
-
572
- if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
573
- asset = DefaultFontManager.getFont(font_name);
574
- } else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
575
- asset = DeviceFontManager.getDeviceFont(font_name);
576
- } else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
577
- asset = DefaultFontManager.getFont_CFF(font_name);
578
- }
579
-
580
- this.font = asset;
581
- this._textFormatDirty = true;
582
550
  }
583
551
 
584
552
  public clone(): TextFormat {
585
553
  const clonedFormat: TextFormat = new TextFormat(
586
- <any> this._font, this._size, this._color, this._bold,
554
+ this._font, this._size, this._color, this._bold,
587
555
  this._italic, this._underline,this.url, this.link_target,
588
556
  this._align, this._leftMargin, this._rightMargin, this._indent, this._leading);
589
- clonedFormat.font_table = this._font_table;
557
+ clonedFormat.font_table = this._font_table; //investigate why this needs to be copied
590
558
  return clonedFormat;
591
559
  }
592
560
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.243",
3
+ "version": "0.13.245",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",