@awayjs/scene 0.13.244 → 0.13.246

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.
Files changed (41) hide show
  1. package/bundle/awayjs-scene.umd.js +62 -103
  2. package/bundle/awayjs-scene.umd.js.map +1 -1
  3. package/bundle/awayjs-scene.umd.min.js.map +1 -1
  4. package/bundle/awayjs-scene.umd.min.js.map.map +1 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/base/Timeline.d.ts +4 -6
  9. package/dist/lib/base/Timeline.d.ts.map +1 -1
  10. package/dist/lib/base/Timeline.js +7 -19
  11. package/dist/lib/display/MovieClip.d.ts +2 -2
  12. package/dist/lib/display/MovieClip.d.ts.map +1 -1
  13. package/dist/lib/display/MovieClip.js +2 -5
  14. package/dist/lib/display/Skybox.d.ts +1 -0
  15. package/dist/lib/display/Skybox.d.ts.map +1 -1
  16. package/dist/lib/display/Skybox.js +1 -0
  17. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +7 -4
  18. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts.map +1 -1
  19. package/dist/lib/factories/DefaultSceneGraphFactory.js +10 -4
  20. package/dist/lib/factories/ISceneGraphFactory.d.ts +7 -8
  21. package/dist/lib/factories/ISceneGraphFactory.d.ts.map +1 -1
  22. package/dist/lib/managers/DefaultFontManager.d.ts.map +1 -1
  23. package/dist/lib/managers/DefaultFontManager.js +3 -4
  24. package/dist/lib/text/HTMLTextProcessor.js +1 -1
  25. package/dist/lib/text/TextFormat.d.ts +3 -3
  26. package/dist/lib/text/TextFormat.d.ts.map +1 -1
  27. package/dist/lib/text/TextFormat.js +37 -69
  28. package/index.ts +1 -2
  29. package/lib/base/Timeline.ts +9 -21
  30. package/lib/display/MovieClip.ts +4 -4
  31. package/lib/display/Skybox.ts +2 -0
  32. package/lib/factories/DefaultSceneGraphFactory.ts +12 -8
  33. package/lib/factories/ISceneGraphFactory.ts +9 -9
  34. package/lib/managers/DefaultFontManager.ts +3 -6
  35. package/lib/text/HTMLTextProcessor.ts +1 -1
  36. package/lib/text/TextFormat.ts +43 -75
  37. package/package.json +1 -1
  38. package/dist/lib/base/ISymbolDecoder.d.ts +0 -8
  39. package/dist/lib/base/ISymbolDecoder.d.ts.map +0 -1
  40. package/dist/lib/base/ISymbolDecoder.js +0 -0
  41. package/lib/base/ISymbolDecoder.ts +0 -11
@@ -39,7 +39,7 @@ var PUBLIC_FIELDS = [
39
39
  'size', 'color',
40
40
  'bold', 'italic',
41
41
  'underline', 'leading',
42
- 'letterSpacing', 'font_table'
42
+ 'letterSpacing'
43
43
  ];
44
44
  var TextFormat = /** @class */ (function (_super) {
45
45
  __extends(TextFormat, _super);
@@ -97,9 +97,10 @@ var TextFormat = /** @class */ (function (_super) {
97
97
  if (indent === void 0) { indent = null; }
98
98
  if (leading === void 0) { leading = null; }
99
99
  var _this = _super.call(this) || this;
100
+ _this.fontLookUpMode = FontLookUpMode.DEFAULT;
100
101
  // flag marked that format is changed.
101
102
  _this._updateID = 0;
102
- _this._textFormatDirty = false;
103
+ _this._fontTableDirty = true;
103
104
  /**
104
105
  * Specifies custom tab stops as an array of non-negative integers. Each tab
105
106
  * stop is specified in pixels. If custom tab stops are not specified
@@ -107,7 +108,6 @@ var TextFormat = /** @class */ (function (_super) {
107
108
  */
108
109
  //todo: not used with in tesselated-font-table yet
109
110
  _this.tabStops = [];
110
- _this.fontLookUpMode = FontLookUpMode.DEFAULT;
111
111
  _this._size = size;
112
112
  _this._color = color;
113
113
  _this._bold = bold;
@@ -120,15 +120,11 @@ var TextFormat = /** @class */ (function (_super) {
120
120
  _this._rightMargin = rightMargin;
121
121
  _this._indent = indent;
122
122
  _this._leading = leading;
123
- _this._letterSpacing = null;
124
- _this._font_table = null;
125
123
  if (typeof font === 'string') {
126
- _this._setFontFromString(font);
127
- return _this;
124
+ _this.font_name = font;
128
125
  }
129
- else if (font) {
130
- _this._font = font;
131
- _this._textFormatDirty = true;
126
+ else {
127
+ _this.font = font;
132
128
  }
133
129
  return _this;
134
130
  }
@@ -286,7 +282,7 @@ var TextFormat = /** @class */ (function (_super) {
286
282
  this._updateID++;
287
283
  }
288
284
  this._bold = value;
289
- this._textFormatDirty = true;
285
+ this._fontTableDirty = true;
290
286
  },
291
287
  enumerable: true,
292
288
  configurable: true
@@ -300,7 +296,7 @@ var TextFormat = /** @class */ (function (_super) {
300
296
  this._updateID++;
301
297
  }
302
298
  this._italic = value;
303
- this._textFormatDirty = true;
299
+ this._fontTableDirty = true;
304
300
  },
305
301
  enumerable: true,
306
302
  configurable: true
@@ -320,10 +316,8 @@ var TextFormat = /** @class */ (function (_super) {
320
316
  });
321
317
  Object.defineProperty(TextFormat.prototype, "font_table", {
322
318
  get: function () {
323
- if (!this._font_table || this._textFormatDirty) {
324
- this.font; // getter makes sure a font exists !
319
+ if (!this._font_table || this._fontTableDirty)
325
320
  this.update_font_table();
326
- }
327
321
  return this._font_table;
328
322
  },
329
323
  set: function (value) {
@@ -331,7 +325,7 @@ var TextFormat = /** @class */ (function (_super) {
331
325
  // font_table is only ever set in parser or when using label-data
332
326
  // after using "bold" or "itaic" font_table should never be set directly
333
327
  this._font_table = value;
334
- this._textFormatDirty = false;
328
+ this._fontTableDirty = false;
335
329
  },
336
330
  enumerable: true,
337
331
  configurable: true
@@ -341,11 +335,27 @@ var TextFormat = /** @class */ (function (_super) {
341
335
  var _a;
342
336
  return (_a = this.font) === null || _a === void 0 ? void 0 : _a.name;
343
337
  },
338
+ set: function (value) {
339
+ var _a;
340
+ if (((_a = this.font) === null || _a === void 0 ? void 0 : _a.name) == value)
341
+ return;
342
+ if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
343
+ this._font = DefaultFontManager.getFont(value);
344
+ }
345
+ else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
346
+ this._font = DeviceFontManager.getDeviceFont(value);
347
+ }
348
+ else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
349
+ this._font = DefaultFontManager.getFont_CFF(value);
350
+ }
351
+ this._fontTableDirty = true;
352
+ this._updateID++;
353
+ },
344
354
  enumerable: true,
345
355
  configurable: true
346
356
  });
347
357
  TextFormat.prototype.update_font_table = function () {
348
- this._textFormatDirty = false;
358
+ this._fontTableDirty = false;
349
359
  var stylename = FontStyleName.STANDART;
350
360
  if (this._italic && !this._bold)
351
361
  stylename = FontStyleName.ITALIC;
@@ -354,73 +364,31 @@ var TextFormat = /** @class */ (function (_super) {
354
364
  else if (this._italic && this._bold)
355
365
  stylename = FontStyleName.BOLDITALIC;
356
366
  if (this._font) {
357
- var newFontTable = this.font.get_font_table(stylename, TesselatedFontTable.assetType, null, true);
358
- if (this._font_table && !newFontTable) {
359
- // if we have a font-table, and we switch to invalid style,
360
- // we just keep the existing font-table
367
+ var font_table = this._font.get_font_table(stylename, TesselatedFontTable.assetType, null, true);
368
+ // if we have a font-table, and we switch to invalid style,
369
+ // we just keep the existing font-table
370
+ if (this._font_table && !font_table)
361
371
  return;
362
- }
363
- this._font_table = newFontTable ? newFontTable : Font.emptyFontTable;
364
- return;
372
+ this._font_table = font_table ? font_table : Font.emptyFontTable;
365
373
  }
366
374
  };
367
375
  Object.defineProperty(TextFormat.prototype, "font", {
368
376
  get: function () {
369
- if (this._font) {
370
- return this._font;
371
- }
372
- if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
373
- this._font = DefaultFontManager.getFont(null);
374
- }
375
- else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
376
- this._font = DeviceFontManager.getDeviceFont(null);
377
- }
378
- else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
379
- this._font = DefaultFontManager.getFont_CFF(null);
380
- }
381
- else {
382
- console.warn('[TextFormat] - unsupported FontLookUpMode', this.fontLookUpMode);
383
- }
384
- this._font_table = null;
385
- this._textFormatDirty = true;
386
377
  return this._font;
387
378
  },
388
379
  set: function (value) {
389
- this._textFormatDirty = true;
390
- if (typeof value === 'string') {
391
- this._setFontFromString(value);
380
+ if (this._font == value)
392
381
  return;
393
- }
394
- if (value !== this._font) {
395
- this._updateID++;
396
- }
397
- if (value) {
398
- this._font = value;
399
- return;
400
- }
401
- this._font = null;
402
- this._font_table = null;
382
+ this._font = value;
383
+ this._fontTableDirty = true;
384
+ this._updateID++;
403
385
  },
404
386
  enumerable: true,
405
387
  configurable: true
406
388
  });
407
- TextFormat.prototype._setFontFromString = function (font_name) {
408
- var asset;
409
- if (this.fontLookUpMode == FontLookUpMode.DEFAULT) {
410
- asset = DefaultFontManager.getFont(font_name);
411
- }
412
- else if (this.fontLookUpMode == FontLookUpMode.DEVICE) {
413
- asset = DeviceFontManager.getDeviceFont(font_name);
414
- }
415
- else if (this.fontLookUpMode == FontLookUpMode.EMBED_CFF) {
416
- asset = DefaultFontManager.getFont_CFF(font_name);
417
- }
418
- this.font = asset;
419
- this._textFormatDirty = true;
420
- };
421
389
  TextFormat.prototype.clone = function () {
422
390
  var clonedFormat = new TextFormat(this._font, this._size, this._color, this._bold, this._italic, this._underline, this.url, this.link_target, this._align, this._leftMargin, this._rightMargin, this._indent, this._leading);
423
- clonedFormat.font_table = this._font_table;
391
+ clonedFormat.font_table = this._font_table; //investigate why this needs to be copied
424
392
  return clonedFormat;
425
393
  };
426
394
  TextFormat.prototype.equal = function (format) {
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- console.debug('AwayJS - Scene - 0.13.244');
1
+ console.debug('AwayJS - Scene - 0.13.246');
2
2
 
3
3
  export { IDisplayObjectAdapter } from './lib/adapters/IDisplayObjectAdapter';
4
4
  export { IMovieClipAdapter } from './lib/adapters/IMovieClipAdapter';
@@ -6,7 +6,6 @@ export { IFilter } from './lib/adapters/IFilter';
6
6
 
7
7
  export { IBitmapDrawable } from './lib/base/IBitmapDrawable';
8
8
  export { IFrameScript } from './lib/base/IFrameScript';
9
- export { ISymbolDecoder } from './lib/base/ISymbolDecoder';
10
9
  export { Timeline } from './lib/base/Timeline';
11
10
  export { TimelineActionType } from './lib/base/TimelineActionType';
12
11
 
@@ -1,19 +1,20 @@
1
1
  import { WaveAudio, ColorTransform, IAsset, Matrix3D } from '@awayjs/core';
2
+ import { BlendMode } from '@awayjs/stage';
3
+ import { HierarchicalProperty } from '@awayjs/view';
2
4
  import { Graphics } from '@awayjs/graphics';
5
+
3
6
  import { IDisplayObjectAdapter } from '../adapters/IDisplayObjectAdapter';
7
+ import { IFilter } from '../adapters/IFilter';
4
8
  import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
5
9
  import { MovieClip } from '../display/MovieClip';
6
10
  import { Sprite } from '../display/Sprite';
7
11
  import { MorphSprite } from '../display/MorphSprite';
8
12
  import { DisplayObject } from '../display/DisplayObject';
9
13
  import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
14
+ import { ISceneGraphFactory } from '../factories/ISceneGraphFactory';
10
15
  import { IFrameLabel } from './IFrameLabel';
11
16
  import { TimelineActionType as AType } from './TimelineActionType';
12
- import { IFilter } from '../adapters/IFilter';
13
- import { BlendMode } from '@awayjs/stage';
14
- import { ISymbolDecoder } from './ISymbolDecoder';
15
17
  import { IFrameScript } from './IFrameScript';
16
- import { HierarchicalProperty } from '@awayjs/view';
17
18
 
18
19
  const BLEND_MODES = [
19
20
  '', BlendMode.NORMAL, BlendMode.LAYER,
@@ -50,7 +51,6 @@ export class Timeline {
50
51
  [AType.START_AUDIO]: Timeline.start_audio
51
52
  };
52
53
 
53
- private _symbolDecoder: ISymbolDecoder;
54
54
  private _blocked: boolean;
55
55
 
56
56
  public _update_indices: number[] = [];
@@ -120,7 +120,7 @@ export class Timeline {
120
120
  **/
121
121
  private _initalMcID: number;
122
122
 
123
- constructor() {
123
+ constructor(readonly factory: ISceneGraphFactory) {
124
124
 
125
125
  this._initalMcID = -1;
126
126
  this.numKeyFrames = 0;
@@ -137,14 +137,6 @@ export class Timeline {
137
137
  this.keyframe_to_frameidx = {};
138
138
  }
139
139
 
140
- public get symbolDecoder(): ISymbolDecoder {
141
- return this._symbolDecoder;
142
- }
143
-
144
- public set symbolDecoder(value: ISymbolDecoder) {
145
- this._symbolDecoder = value;
146
- }
147
-
148
140
  public resetScripts() {
149
141
  this._framescripts = {};
150
142
  this._framescripts_translated = {};
@@ -155,10 +147,6 @@ export class Timeline {
155
147
  */
156
148
  public init(): void {
157
149
 
158
- if (!this._symbolDecoder) {
159
- console.warn('[Timeline] - init - no _symbolDecoder is set');
160
- }
161
-
162
150
  if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) {
163
151
  return;
164
152
  }
@@ -245,7 +233,7 @@ export class Timeline {
245
233
  if (checkForTranslation && !this._framescripts_translated[frame_idx]) {
246
234
  // todo: cleanup so we can retrieve className of target_mc without hacks
247
235
  const name = (<any>target_mc).className ? (<any>target_mc).className : target_mc.name;
248
- this._framescripts[frame_idx] = this.symbolDecoder.prepareFrameScriptsForAVM1(
236
+ this._framescripts[frame_idx] = this.factory.createFrameScripts(
249
237
  this._framescripts[frame_idx],
250
238
  frame_idx,
251
239
  name,
@@ -266,7 +254,7 @@ export class Timeline {
266
254
  }
267
255
 
268
256
  public getChildInstance(symbolID: number, sessionID: number) {
269
- return this.symbolDecoder.createChildInstanceForTimeline(this, symbolID, sessionID);
257
+ return this.factory.createChildInstanceForTimeline(this, symbolID, sessionID);
270
258
  }
271
259
 
272
260
  public extractHitArea(target_mc: MovieClip): DisplayObjectContainer {
@@ -480,7 +468,7 @@ export class Timeline {
480
468
  idx, this.add_child_stream);
481
469
  continue;
482
470
  }
483
- const childAsset: IAsset = this._symbolDecoder.createChildInstanceForTimeline(this,
471
+ const childAsset: IAsset = this.factory.createChildInstanceForTimeline(this,
484
472
  this.add_child_stream[idx + 2], this.add_child_stream[idx]);
485
473
  (<IMovieClipAdapter>target_mc.adapter).addTimelineChildAtDepth(<DisplayObject>childAsset,
486
474
  this.add_child_stream[idx + 1]);
@@ -39,10 +39,10 @@ export class MovieClip extends Sprite {
39
39
 
40
40
  public static assetType: string = '[asset MovieClip]';
41
41
 
42
- public static getNewMovieClip(timeline: Timeline = null): MovieClip {
42
+ public static getNewMovieClip(timeline: Timeline): MovieClip {
43
43
  if (MovieClip._movieClips.length) {
44
44
  const movieClip: MovieClip = MovieClip._movieClips.pop();
45
- movieClip.timeline = timeline || new Timeline();
45
+ movieClip.timeline = timeline;
46
46
  movieClip.graphics = Graphics.getGraphics();
47
47
  return movieClip;
48
48
  }
@@ -154,7 +154,7 @@ export class MovieClip extends Sprite {
154
154
  return 0;
155
155
  }
156
156
 
157
- constructor(timeline: Timeline = null, spriteMode = false) {
157
+ constructor(timeline: Timeline, spriteMode = false) {
158
158
  super();
159
159
 
160
160
  this._soundVolume = 1;
@@ -200,7 +200,7 @@ export class MovieClip extends Sprite {
200
200
  this.currentFrameIndex = 1;
201
201
  };
202
202
 
203
- this._timeline = timeline || new Timeline();
203
+ this._timeline = timeline;
204
204
 
205
205
  if (spriteMode) {
206
206
  this.transformToSprite();
@@ -37,6 +37,8 @@ export class Skybox extends DisplayObjectContainer implements IMaterial {
37
37
 
38
38
  public alphaThreshold: number = 0;
39
39
 
40
+ public alphaBlending: boolean = true;
41
+
40
42
  /**
41
43
  *
42
44
  */
@@ -1,25 +1,25 @@
1
- import { Image2D, DefaultGraphicsFactory } from '@awayjs/stage';
2
-
1
+ import { IAsset } from '@awayjs/core';
2
+ import { Image2D, DefaultStageFactory } from '@awayjs/stage';
3
3
  import { IMaterial } from '@awayjs/renderer';
4
-
4
+ import { Graphics } from '@awayjs/graphics';
5
5
  import { MethodMaterial } from '@awayjs/materials';
6
6
 
7
7
  import { Timeline } from '../base/Timeline';
8
+ import { IFrameScript } from '../base/IFrameScript';
8
9
  import { Billboard } from '../display/Billboard';
9
10
  import { TextField } from '../display/TextField';
10
11
  import { MovieClip } from '../display/MovieClip';
11
12
  import { Sprite } from '../display/Sprite';
12
13
  import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
13
14
  import { PrefabBase } from '../prefabs/PrefabBase';
14
-
15
15
  import { ISceneGraphFactory } from './ISceneGraphFactory';
16
- import { Graphics } from '@awayjs/graphics';
17
- import { IFrameScript } from '../base/IFrameScript';
18
16
 
19
- export class DefaultSceneGraphFactory extends DefaultGraphicsFactory implements ISceneGraphFactory {
17
+ export class DefaultSceneGraphFactory extends DefaultStageFactory implements ISceneGraphFactory {
18
+
19
+ readonly awaySymbols: NumberMap<IAsset> = {};
20
20
 
21
21
  createMovieClip(timeline: Timeline = null, symbol: any = null): MovieClip {
22
- return new MovieClip(timeline);
22
+ return new MovieClip(timeline || new Timeline(this));
23
23
  }
24
24
 
25
25
  createSprite(prefab: PrefabBase = null, graphics: Graphics = null, symbol: any = null): Sprite {
@@ -50,4 +50,8 @@ export class DefaultSceneGraphFactory extends DefaultGraphicsFactory implements
50
50
  createFrameScripts(scripts: IFrameScript[], frameIdx: number, objName: string, objID: number): IFrameScript[] {
51
51
  throw ('[DefaultSceneGraphFactory] - createFrameScripts should be overwritten by AVM');
52
52
  }
53
+
54
+ createChildInstanceForTimeline(timeline: Timeline, symbolID: number, sessionID: number): IAsset {
55
+ throw ('[DefaultSceneGraphFactory] - createChildInstanceForTimeline should be overwritten by AVM');
56
+ }
53
57
  }
@@ -1,16 +1,17 @@
1
- import { Image2D, IGraphicsFactory } from '@awayjs/stage';
2
- import { IMaterial } from '@awayjs/renderer';
1
+ import { IAsset } from '@awayjs/core';
2
+ import { IMaterial, IMaterialFactory } from '@awayjs/renderer';
3
+ import { Graphics } from '@awayjs/graphics';
4
+
3
5
  import { Timeline } from '../base/Timeline';
6
+ import { IFrameScript } from '../base/IFrameScript';
4
7
  import { Billboard } from '../display/Billboard';
5
8
  import { TextField } from '../display/TextField';
6
9
  import { MovieClip } from '../display/MovieClip';
7
10
  import { Sprite } from '../display/Sprite';
8
- import { PrefabBase } from '../prefabs/PrefabBase';
9
11
  import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
10
- import { Graphics } from '@awayjs/graphics';
11
- import { IFrameScript } from '../base/IFrameScript';
12
+ import { PrefabBase } from '../prefabs/PrefabBase';
12
13
 
13
- export interface ISceneGraphFactory extends IGraphicsFactory
14
+ export interface ISceneGraphFactory extends IMaterialFactory
14
15
  {
15
16
  createMovieClip(timelime?: Timeline, symbol?: any): MovieClip;
16
17
 
@@ -22,8 +23,7 @@ export interface ISceneGraphFactory extends IGraphicsFactory
22
23
 
23
24
  createBillboard(material?: IMaterial, symbol?: any): Billboard;
24
25
 
25
- createMaterial(image?: Image2D, alpha?: number, symbol?: any): IMaterial;
26
- createMaterial(color?: number, alpha?: number, symbol?: any): IMaterial;
27
-
28
26
  createFrameScripts(scripts: IFrameScript[], frameIdx: number, objName: string, objID: number): IFrameScript[];
27
+
28
+ createChildInstanceForTimeline(timeline: Timeline, symbolID: number, sessionID: number): IAsset;
29
29
  }
@@ -88,12 +88,9 @@ export class DefaultFontManager {
88
88
  }
89
89
 
90
90
  public static getFont(fontName: string, namespace: string = undefined): Font {
91
-
92
- //console.log('[DefaultFontManager] - getFont', fontName);
93
-
94
- if (!fontName) {
95
- return DeviceFontManager.getDeviceFont(fontName);
96
- }
91
+ // return null if no fontName supplied
92
+ if (!fontName)
93
+ return null;
97
94
 
98
95
  // hack for dynamic fonts: first check if reguested font-name is a classname that was registered
99
96
  if (this._registered_fonts_by_className[fontName]) {
@@ -325,7 +325,7 @@ export class HTMLTextProcessor {
325
325
  const value = (<any>myChild.attributes).face ?
326
326
  (<any>myChild.attributes).face : (<any>myChild.attributes).FACE;
327
327
  newProps_values[newProps_values.length] = value;
328
- newProps_names[newProps_names.length] = 'font';
328
+ newProps_names[newProps_names.length] = 'font_name';
329
329
  }
330
330
  }
331
331
 
@@ -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.244",
3
+ "version": "0.13.246",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",