@awayjs/scene 0.13.226 → 0.13.232

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 (42) hide show
  1. package/bundle/awayjs-scene.umd.js +865 -387
  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.js +1 -1
  6. package/dist/lib/Settings.d.ts +3 -0
  7. package/dist/lib/Settings.d.ts.map +1 -1
  8. package/dist/lib/Settings.js +14 -0
  9. package/dist/lib/display/TextField.d.ts +36 -5
  10. package/dist/lib/display/TextField.d.ts.map +1 -1
  11. package/dist/lib/display/TextField.js +227 -138
  12. package/dist/lib/image/SceneImage2D.d.ts.map +1 -1
  13. package/dist/lib/image/SceneImage2D.js +33 -8
  14. package/dist/lib/text/FNTGenerator.d.ts +5 -4
  15. package/dist/lib/text/FNTGenerator.d.ts.map +1 -1
  16. package/dist/lib/text/FNTGenerator.js +15 -11
  17. package/dist/lib/text/FNTGeneratorCanvas.d.ts +23 -0
  18. package/dist/lib/text/FNTGeneratorCanvas.d.ts.map +1 -0
  19. package/dist/lib/text/FNTGeneratorCanvas.js +205 -0
  20. package/dist/lib/text/FNTGeneratrorBase.d.ts +8 -0
  21. package/dist/lib/text/FNTGeneratrorBase.d.ts.map +1 -0
  22. package/dist/lib/text/FNTGeneratrorBase.js +7 -0
  23. package/dist/lib/text/TesselatedFontChar.d.ts +6 -4
  24. package/dist/lib/text/TesselatedFontChar.d.ts.map +1 -1
  25. package/dist/lib/text/TesselatedFontChar.js +8 -3
  26. package/dist/lib/text/TesselatedFontTable.d.ts +19 -3
  27. package/dist/lib/text/TesselatedFontTable.d.ts.map +1 -1
  28. package/dist/lib/text/TesselatedFontTable.js +339 -225
  29. package/dist/lib/text/TextShape.d.ts +6 -3
  30. package/dist/lib/text/TextShape.d.ts.map +1 -1
  31. package/dist/lib/text/TextShape.js +27 -2
  32. package/index.ts +1 -1
  33. package/lib/Settings.ts +20 -1
  34. package/lib/display/TextField.ts +317 -145
  35. package/lib/image/SceneImage2D.ts +81 -9
  36. package/lib/text/FNTGenerator.ts +5 -7
  37. package/lib/text/FNTGeneratorCanvas.ts +288 -0
  38. package/lib/text/FNTGeneratrorBase.ts +11 -0
  39. package/lib/text/TesselatedFontChar.ts +8 -12
  40. package/lib/text/TesselatedFontTable.ts +438 -255
  41. package/lib/text/TextShape.ts +30 -3
  42. package/package.json +1 -1
@@ -1174,6 +1174,20 @@ var Settings = {
1174
1174
  * @description How many pixels can be processed on CPU for `copyPixel` operation for avoid run GPU
1175
1175
  */
1176
1176
  CPU_COPY_PIXELS_COUNT: 64 * 64,
1177
+ /**
1178
+ * @description Quality factor for pre-tesselated font shapes,
1179
+ * values greater 1 no make sense, 1/10 produce normal font result for small fonts (14px)
1180
+ */
1181
+ FONT_TESSELATION_QUALITY: 1 / 10,
1182
+ /**
1183
+ * @description Use unsafe FNT (pre-cached font shapes onto texture)
1184
+ */
1185
+ USE_UNSAFE_FNT: false,
1186
+ /**
1187
+ * @description Precision of text building for rounding a vertices placement of text shape.
1188
+ * Used for correction text blurring when pixel is missposited
1189
+ */
1190
+ TEXT_SHAPE_ROUND_PRECISION: 0.1,
1177
1191
  };
1178
1192
 
1179
1193
  /**
@@ -8443,7 +8457,15 @@ var TesselatedFontChar = /** @class */ (function () {
8443
8457
  if (fill_data === void 0) { fill_data = null; }
8444
8458
  if (stroke_data === void 0) { stroke_data = null; }
8445
8459
  if (fill_data_path === void 0) { fill_data_path = null; }
8460
+ this.fill_data = fill_data;
8461
+ this.stroke_data = stroke_data;
8462
+ this.fill_data_path = fill_data_path;
8446
8463
  this.fnt_channel = 0;
8464
+ /**
8465
+ * What is scale was used for generating last tesselation
8466
+ * Used for reduce a vertices count
8467
+ */
8468
+ this.lastTesselatedScale = 0;
8447
8469
  /**
8448
8470
  * the char_codes that this geom has kerning set for
8449
8471
  */
@@ -8452,9 +8474,6 @@ var TesselatedFontChar = /** @class */ (function () {
8452
8474
  * the kerning values per char_code
8453
8475
  */
8454
8476
  this.kerningValues = [];
8455
- this.fill_data = fill_data;
8456
- this.stroke_data = stroke_data;
8457
- this.fill_data_path = fill_data_path;
8458
8477
  }
8459
8478
  TesselatedFontChar.prototype.dispose = function () {
8460
8479
  if (this.stroke_data) {
@@ -8473,6 +8492,213 @@ var TesselatedFontChar = /** @class */ (function () {
8473
8492
  return TesselatedFontChar;
8474
8493
  }());
8475
8494
 
8495
+ var FNTGeneratorBase = /** @class */ (function () {
8496
+ function FNTGeneratorBase(_stage) {
8497
+ this._stage = _stage;
8498
+ }
8499
+ return FNTGeneratorBase;
8500
+ }());
8501
+
8502
+ var Bounds = /** @class */ (function () {
8503
+ function Bounds() {
8504
+ this.left = Number.MAX_VALUE;
8505
+ this.right = Number.MIN_VALUE;
8506
+ this.top = Number.MAX_VALUE;
8507
+ this.bottom = Number.MIN_VALUE;
8508
+ }
8509
+ Bounds.prototype.grown = function (x, y) {
8510
+ if (x < this.left)
8511
+ this.left = x;
8512
+ if (x > this.right)
8513
+ this.right = x;
8514
+ if (y < this.top)
8515
+ this.top = y;
8516
+ if (y > this.bottom)
8517
+ this.bottom = y;
8518
+ };
8519
+ Bounds.prototype.toRect = function () {
8520
+ return new _awayjs_core.Rectangle(this.left, this.top, this.right - this.left, this.bottom - this.top);
8521
+ };
8522
+ return Bounds;
8523
+ }());
8524
+ var FNTGeneratorCanvas = /** @class */ (function (_super) {
8525
+ __extends(FNTGeneratorCanvas, _super);
8526
+ function FNTGeneratorCanvas(stage, debug) {
8527
+ if (debug === void 0) { debug = false; }
8528
+ var _this = _super.call(this, stage) || this;
8529
+ /**
8530
+ * Debug mode.
8531
+ * Prevent OffscreenCanvas and prevent canvas clear.
8532
+ * Store canvas
8533
+ */
8534
+ _this.debug = false;
8535
+ _this.debug = debug;
8536
+ return _this;
8537
+ }
8538
+ FNTGeneratorCanvas.getCanvasContext = function (width, height, debug) {
8539
+ if (width === void 0) { width = 100; }
8540
+ if (height === void 0) { height = 100; }
8541
+ if (debug === void 0) { debug = false; }
8542
+ var canvas = ('OffscreenCanvas' in self && !debug)
8543
+ ? new self.OffscreenCanvas(width, height)
8544
+ : document.createElement('canvas');
8545
+ canvas.width = width;
8546
+ canvas.height = height;
8547
+ return canvas.getContext('2d', { desynchronized: true, alpha: true });
8548
+ };
8549
+ FNTGeneratorCanvas.freeCanvasContext = function (ctx) {
8550
+ if (ctx.canvas instanceof self.OffscreenCanvas) {
8551
+ return;
8552
+ }
8553
+ // safari bug with canvas leaks
8554
+ ctx.canvas.width = 0;
8555
+ ctx.canvas.height = 0;
8556
+ };
8557
+ FNTGeneratorCanvas.transformChar = function (char) {
8558
+ var fillData = char.fill_data_path;
8559
+ // empty command
8560
+ if (fillData.commands[0].length === 0 && fillData.commands.length === 1) {
8561
+ return null;
8562
+ }
8563
+ var path = new Path2D();
8564
+ var box = new Bounds();
8565
+ for (var i = 0; i < fillData.commands.length; i++) {
8566
+ var data = fillData.data[i];
8567
+ var commands = fillData.commands[i];
8568
+ var pointer = 0;
8569
+ for (var _i = 0, commands_1 = commands; _i < commands_1.length; _i++) {
8570
+ var command = commands_1[_i];
8571
+ switch (command) {
8572
+ case _awayjs_graphics.GraphicsPathCommand.MOVE_TO: {
8573
+ // flash path in twips, transform it
8574
+ var px = data[pointer++] / 20;
8575
+ var py = data[pointer++] / 20;
8576
+ box.grown(px, py);
8577
+ path.moveTo(px, py);
8578
+ break;
8579
+ }
8580
+ case _awayjs_graphics.GraphicsPathCommand.LINE_TO: {
8581
+ var px = data[pointer++] / 20;
8582
+ var py = data[pointer++] / 20;
8583
+ box.grown(px, py);
8584
+ path.lineTo(px, py);
8585
+ break;
8586
+ }
8587
+ case _awayjs_graphics.GraphicsPathCommand.CURVE_TO: {
8588
+ var cx = data[pointer++] / 20;
8589
+ var cy = data[pointer++] / 20;
8590
+ var dx = data[pointer++] / 20;
8591
+ var dy = data[pointer++] / 20;
8592
+ box.grown(cx, cy);
8593
+ box.grown(dx, dy);
8594
+ path.quadraticCurveTo(cx, cy, dx, dy);
8595
+ }
8596
+ }
8597
+ }
8598
+ //path.closePath();
8599
+ }
8600
+ return {
8601
+ path: path,
8602
+ char: char,
8603
+ rect: box.toRect(),
8604
+ };
8605
+ };
8606
+ FNTGeneratorCanvas.sortPatches = function (a, b) {
8607
+ return a.rect.height - b.rect.height;
8608
+ };
8609
+ FNTGeneratorCanvas.render = function (table, context, size, fontSize, padding) {
8610
+ if (fontSize === void 0) { fontSize = 0; }
8611
+ if (padding === void 0) { padding = 0; }
8612
+ var chars = table.get_font_chars();
8613
+ var patches = [];
8614
+ var doublePad = padding * 2;
8615
+ var totalArea = 0;
8616
+ var scale = 1;
8617
+ for (var _i = 0, chars_1 = chars; _i < chars_1.length; _i++) {
8618
+ var char = chars_1[_i];
8619
+ var path = FNTGeneratorCanvas.transformChar(char);
8620
+ if (!path) {
8621
+ continue;
8622
+ }
8623
+ totalArea += (doublePad + path.rect.width) * (doublePad + path.rect.height);
8624
+ patches.push(path);
8625
+ }
8626
+ patches.sort(FNTGeneratorCanvas.sortPatches);
8627
+ // TODO compute valid scale when fontSize is 0
8628
+ if (fontSize) {
8629
+ table.initFontSize(fontSize);
8630
+ scale = /* 20 * table._size_multiply **/ size / table.get_font_em_size();
8631
+ }
8632
+ /**
8633
+ * Render glyphs onto canvas
8634
+ * We will render glyphs as white and background as black transparent
8635
+ */
8636
+ context.save();
8637
+ context.clearRect(0, 0, size, size);
8638
+ context.fillStyle = '#fff';
8639
+ var tx = padding;
8640
+ var ty = padding;
8641
+ var maxHeight = 0;
8642
+ // pack glyph based on size
8643
+ for (var _a = 0, patches_1 = patches; _a < patches_1.length; _a++) {
8644
+ var path = patches_1[_a];
8645
+ if (!path.path) {
8646
+ continue;
8647
+ }
8648
+ // if overflow - jump next location
8649
+ if (tx + path.rect.width + doublePad >= size / scale) {
8650
+ tx = padding;
8651
+ ty += maxHeight + doublePad;
8652
+ maxHeight = 0;
8653
+ }
8654
+ /**
8655
+ * @todo Support multiple channel table data
8656
+ */
8657
+ if (ty + path.rect.height > size / scale) {
8658
+ console.warn('[FNTGeneratorCanvas] Font image overflow, font will corrupted!');
8659
+ }
8660
+ maxHeight = Math.max(path.rect.height, maxHeight);
8661
+ context.setTransform(scale, 0, 0, scale, (tx - path.rect.x) * scale, (ty - path.rect.y) * scale);
8662
+ context.fill(path.path);
8663
+ //context.strokeRect(path.rect.x,path.rect.y, path.rect.width, path.rect.height);
8664
+ path.char.fnt_rect = new _awayjs_core.Rectangle((path.rect.x) / path.char.char_width, (path.rect.y) / table.get_font_em_size(), path.rect.width / path.char.char_width, path.rect.height / table.get_font_em_size());
8665
+ path.char.fnt_uv = new _awayjs_core.Rectangle(tx * scale / size, ty * scale / size, path.rect.width * scale / size, path.rect.height * scale / size);
8666
+ /*
8667
+ path.char.fnt_uv = new Rectangle(
8668
+ (tx - path.rect.x) * scale / size,
8669
+ 1 - (ty - path.rect.y) * scale / scale,
8670
+ path.rect.width * scale / size,
8671
+ path.rect.height * scale / size
8672
+ );*/
8673
+ path.char.fnt_channel = 0;
8674
+ tx += path.rect.width + doublePad;
8675
+ }
8676
+ context.restore();
8677
+ };
8678
+ FNTGeneratorCanvas.prototype.generate = function (font, size, fontSize, padding) {
8679
+ var context = FNTGeneratorCanvas.getCanvasContext(size, size, this.debug);
8680
+ var bitmaps = [];
8681
+ for (var key in font.font_styles) {
8682
+ var table = font.font_styles[key];
8683
+ // render table in context
8684
+ FNTGeneratorCanvas.render(table, context, size, fontSize, padding);
8685
+ var data = context.getImageData(0, 0, size, size);
8686
+ var image = new _awayjs_stage.BitmapImage2D(size, size, true, 0, true, this._stage);
8687
+ image.setPixels(new _awayjs_core.Rectangle(0, 0, size, size), data.data);
8688
+ bitmaps.push(image);
8689
+ table.addFNTChannel(image);
8690
+ }
8691
+ if (!this.debug) {
8692
+ FNTGeneratorCanvas.freeCanvasContext(context);
8693
+ }
8694
+ else {
8695
+ this.canvas = context.canvas;
8696
+ }
8697
+ return bitmaps;
8698
+ };
8699
+ return FNTGeneratorCanvas;
8700
+ }(FNTGeneratorBase));
8701
+
8476
8702
  var ONCE_EMIT_TABLE = Object.create(null);
8477
8703
  function once$1(obj, key) {
8478
8704
  if (key === void 0) { key = ''; }
@@ -8543,59 +8769,19 @@ var TesselatedFontTable = /** @class */ (function (_super) {
8543
8769
  TesselatedFontTable.prototype.getGlyphCount = function () {
8544
8770
  return this._font_chars.length;
8545
8771
  };
8546
- TesselatedFontTable.prototype._drawDebugRect = function (glyph_verts, minx, maxx, miny, maxy) {
8547
- // left
8548
- glyph_verts[glyph_verts.length] = minx;
8549
- glyph_verts[glyph_verts.length] = miny;
8550
- glyph_verts[glyph_verts.length] = minx + 1;
8551
- glyph_verts[glyph_verts.length] = maxy;
8552
- glyph_verts[glyph_verts.length] = minx;
8553
- glyph_verts[glyph_verts.length] = maxy;
8554
- glyph_verts[glyph_verts.length] = minx;
8555
- glyph_verts[glyph_verts.length] = miny;
8556
- glyph_verts[glyph_verts.length] = minx + 1;
8557
- glyph_verts[glyph_verts.length] = miny;
8558
- glyph_verts[glyph_verts.length] = minx + 1;
8559
- glyph_verts[glyph_verts.length] = maxy;
8560
- // right
8561
- glyph_verts[glyph_verts.length] = maxx;
8562
- glyph_verts[glyph_verts.length] = miny;
8563
- glyph_verts[glyph_verts.length] = maxx - 1;
8564
- glyph_verts[glyph_verts.length] = maxy;
8565
- glyph_verts[glyph_verts.length] = maxx;
8566
- glyph_verts[glyph_verts.length] = maxy;
8567
- glyph_verts[glyph_verts.length] = maxx;
8568
- glyph_verts[glyph_verts.length] = miny;
8569
- glyph_verts[glyph_verts.length] = maxx - 1;
8570
- glyph_verts[glyph_verts.length] = miny;
8571
- glyph_verts[glyph_verts.length] = maxx - 1;
8572
- glyph_verts[glyph_verts.length] = maxy;
8573
- // top
8574
- glyph_verts[glyph_verts.length] = minx + 1;
8575
- glyph_verts[glyph_verts.length] = miny;
8576
- glyph_verts[glyph_verts.length] = minx + 1;
8577
- glyph_verts[glyph_verts.length] = miny + 1;
8578
- glyph_verts[glyph_verts.length] = maxx - 1;
8579
- glyph_verts[glyph_verts.length] = miny;
8580
- glyph_verts[glyph_verts.length] = minx + 1;
8581
- glyph_verts[glyph_verts.length] = miny + 1;
8582
- glyph_verts[glyph_verts.length] = maxx - 1;
8583
- glyph_verts[glyph_verts.length] = miny + 1;
8584
- glyph_verts[glyph_verts.length] = maxx - 1;
8585
- glyph_verts[glyph_verts.length] = miny;
8586
- // bottom
8587
- glyph_verts[glyph_verts.length] = minx + 1;
8588
- glyph_verts[glyph_verts.length] = maxy;
8589
- glyph_verts[glyph_verts.length] = minx + 1;
8590
- glyph_verts[glyph_verts.length] = maxy - 1;
8591
- glyph_verts[glyph_verts.length] = maxx - 1;
8592
- glyph_verts[glyph_verts.length] = maxy;
8593
- glyph_verts[glyph_verts.length] = minx + 1;
8594
- glyph_verts[glyph_verts.length] = maxy - 1;
8595
- glyph_verts[glyph_verts.length] = maxx - 1;
8596
- glyph_verts[glyph_verts.length] = maxy - 1;
8597
- glyph_verts[glyph_verts.length] = maxx - 1;
8598
- glyph_verts[glyph_verts.length] = maxy;
8772
+ TesselatedFontTable.prototype.generateFNTData = function (stage) {
8773
+ // already exist
8774
+ if (this._fntSizeLimit > 0) {
8775
+ return;
8776
+ }
8777
+ var generator = new FNTGeneratorCanvas(stage, false);
8778
+ var bitmaps = generator.generate(this.font, this._font_em_size, this._current_size, 4);
8779
+ if (bitmaps && bitmaps.length > 0) {
8780
+ /**
8781
+ * Random value, anyway we render real font dimension ;)
8782
+ */
8783
+ this._fntSizeLimit = this._current_size * 4;
8784
+ }
8599
8785
  };
8600
8786
  TesselatedFontTable.prototype.generateFNTTextures = function (padding, fontSize, texSize) {
8601
8787
  console.log('generateFNTTextures');
@@ -8882,15 +9068,13 @@ var TesselatedFontTable = /** @class */ (function (_super) {
8882
9068
  // need to implement textFormat tabstop
8883
9069
  return (space * 2 * 20) / 20;
8884
9070
  }
8885
- var t_font_char = this.getChar(char_code);
9071
+ var t_font_char = this.getChar(char_code, false);
8886
9072
  if (t_font_char) {
8887
- return (Math.floor(t_font_char.char_width * this._size_multiply * 20)) / 20;
9073
+ return ((t_font_char.char_width * this._size_multiply * 20) | 0) / 20;
8888
9074
  }
8889
- else {
8890
- if (char_code == '9679') {
8891
- t_font_char = this.createPointGlyph_9679();
8892
- return (Math.floor(t_font_char.char_width * this._size_multiply * 20)) / 20;
8893
- }
9075
+ else if (char_code == '9679') {
9076
+ t_font_char = this.createPointGlyph_9679();
9077
+ return ((t_font_char.char_width * this._size_multiply * 20) | 0) / 20;
8894
9078
  }
8895
9079
  return 0;
8896
9080
  };
@@ -9033,28 +9217,14 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9033
9217
  return new _awayjs_core.Point(x - origin_x, this.getLineHeight());
9034
9218
  };
9035
9219
  TesselatedFontTable.prototype.fillTextRun = function (tf, format, startWord, wordCnt) {
9036
- var useFNT = this._fntSizeLimit >= 0 &&
9037
- (this._fntSizeLimit == 0 || this._fntSizeLimit >= format.size);
9038
- var textShape = tf.getTextShapeForIdentifierAndFormat(format.color.toString() + useFNT.toString() + '0', format);
9039
- var fntTextShapesByChannel = {};
9040
- var fntSelectedTextShapesByChannel = {};
9041
- //var currentFNTTextShapeMap:any;
9042
- var argb;
9043
- var mat;
9220
+ var useFNT = this._fntSizeLimit >= 0 && this._fntSizeLimit >= format.size;
9044
9221
  if (useFNT) {
9045
- argb = _awayjs_core.ColorUtils.float32ColorToARGB(format.color);
9046
- mat = new _awayjs_materials.MethodMaterial(this._fnt_channels[0]);
9047
- mat.colorTransform = new _awayjs_core.ColorTransform(argb[1] / 255, argb[2] / 255, argb[3] / 255);
9048
- mat.bothSides = true;
9049
- mat.alphaBlending = true;
9050
- mat.useColorTransform = true;
9051
- mat.style.sampler = new _awayjs_stage.ImageSampler(false, true, true);
9222
+ return this.fillTextRunFNT(tf, format, startWord, wordCnt);
9052
9223
  }
9053
- textShape.fntMaterial = useFNT ? mat : null;
9054
- fntTextShapesByChannel[format.color.toString() + useFNT.toString() + '0'] = textShape;
9224
+ var textShape = this._queryShape(tf, format);
9055
9225
  var textShapeSelected;
9056
9226
  var newFormat;
9057
- var wordsCount = startWord + wordCnt * 5;
9227
+ var wordsCount = startWord + wordCnt;
9058
9228
  var size_multiply = this._size_multiply;
9059
9229
  var select_start = tf.selectionBeginIndex;
9060
9230
  var select_end = tf.selectionEndIndex;
@@ -9062,16 +9232,9 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9062
9232
  if (tf.selectable) {
9063
9233
  newFormat = format.clone();
9064
9234
  newFormat.color = 0xffffff;
9065
- textShapeSelected = tf.getTextShapeForIdentifierAndFormat(useFNT.toString() + '0', newFormat);
9066
- fntSelectedTextShapesByChannel[useFNT.toString() + '0'] = textShapeSelected;
9067
- mat = new _awayjs_materials.MethodMaterial(this._fnt_channels[0]);
9068
- mat.bothSides = true;
9069
- mat.alphaBlending = true;
9070
- mat.useColorTransform = true;
9071
- mat.style.sampler = new _awayjs_stage.ImageSampler(false, true, true);
9072
- textShapeSelected.fntMaterial = useFNT ? mat : null;
9235
+ textShapeSelected = this._queryShape(tf, newFormat);
9073
9236
  if (newFormat.underline && (startWord + 1) < tf.words.length) {
9074
- start_x = tf.words[startWord + 1];
9237
+ start_x = tf.words.get(startWord).x;
9075
9238
  }
9076
9239
  if (tf.selectionEndIndex < tf.selectionBeginIndex) {
9077
9240
  select_start = tf.selectionEndIndex;
@@ -9085,66 +9248,39 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9085
9248
  var underlines = [];
9086
9249
  // loop over all the words and create the text data for it
9087
9250
  // each word provides its own start-x and start-y values, so we can just ignore whitespace-here
9088
- for (var w = startWord; w < wordsCount; w += 5) {
9089
- var x = tf.words[w + 1];
9090
- var y = tf.words[w + 2];
9091
- var startIdx = tf.words[w];
9092
- var charsCount = startIdx + tf.words[w + 4];
9251
+ for (var w = startWord; w < wordsCount; w += 1) {
9252
+ var word = tf.words.get(w);
9253
+ var x = word.x;
9254
+ var y = word.y;
9255
+ var startIdx = word.start;
9256
+ var charsCount = startIdx + word.len;
9093
9257
  for (var c = startIdx; c < charsCount; c++) {
9094
9258
  var curTShape = (tf.isInFocus && c >= select_start && c < select_end) ?
9095
9259
  textShapeSelected : textShape;
9096
- if (tf.chars_codes[c] !== 32 && tf.chars_codes[c] !== 9) {
9097
- var charGlyph = this.getChar(tf.chars_codes[c].toString());
9098
- if (!charGlyph) {
9099
- if (once$1(this, 'miss' + tf.chars_codes[c])) {
9100
- console.debug('[TesselatedFontTable] Error: char not found in fontTable', tf.chars_codes[c], String.fromCharCode(tf.chars_codes[c]));
9101
- }
9102
- continue;
9103
- }
9104
- if (useFNT) {
9105
- // the font should use fnt
9106
- var curFormat = curTShape.format;
9107
- var ctmpTShape = (tf.isInFocus && c >= select_start && c < select_end) ?
9108
- fntSelectedTextShapesByChannel[useFNT.toString() + charGlyph.fnt_channel] :
9109
- fntTextShapesByChannel[curFormat.color.toString() +
9110
- useFNT.toString() + charGlyph.fnt_channel];
9111
- if (!ctmpTShape) {
9112
- var newtextShape = tf.getTextShapeForIdentifierAndFormat(curFormat.color.toString()
9113
- + useFNT.toString() + charGlyph.fnt_channel.toString(), curFormat);
9114
- var argb_1 = _awayjs_core.ColorUtils.float32ColorToARGB(curFormat.color);
9115
- var mat_1 = new _awayjs_materials.MethodMaterial(this._fnt_channels[charGlyph.fnt_channel]);
9116
- mat_1.colorTransform = new _awayjs_core.ColorTransform(argb_1[1] / 255, argb_1[2] / 255, argb_1[3] / 255);
9117
- mat_1.bothSides = true;
9118
- mat_1.alphaBlending = true;
9119
- mat_1.useColorTransform = true;
9120
- mat_1.style.sampler = new _awayjs_stage.ImageSampler(false, true, true);
9121
- newtextShape.fntMaterial = mat_1;
9122
- fntTextShapesByChannel[curFormat.color.toString() +
9123
- useFNT.toString() + charGlyph.fnt_channel] = newtextShape;
9124
- ctmpTShape = newtextShape;
9125
- }
9126
- var x1 = x + ((charGlyph.char_width * size_multiply) * charGlyph.fnt_rect.x);
9127
- var x2 = x1 + ((charGlyph.char_width * size_multiply) * charGlyph.fnt_rect.width);
9128
- var y1 = y + ((this._font_em_size * size_multiply) * charGlyph.fnt_rect.y);
9129
- var y2 = y1 + ((this._font_em_size * size_multiply) * charGlyph.fnt_rect.height);
9130
- throw 'Invalid implementation, verts not raw array';
9131
- }
9132
- else {
9133
- if (curTShape === textShapeSelected) {
9134
- selectedCharEntries.push({
9135
- char: charGlyph, x: x, y: y, selected: true
9136
- });
9137
- selectedBuffSize += charGlyph.fill_data.buffer.byteLength / 4;
9138
- }
9139
- else {
9140
- charEntries.push({
9141
- char: charGlyph, x: x, y: y, selected: false
9142
- });
9143
- textBuffSize += charGlyph.fill_data.buffer.byteLength / 4;
9144
- }
9260
+ var code = tf.chars_codes[c];
9261
+ if (code === 32 || code === 9) {
9262
+ continue;
9263
+ }
9264
+ var charGlyph = this.getChar(code, true);
9265
+ if (!charGlyph) {
9266
+ if (once$1(this, 'miss' + tf.chars_codes[c])) {
9267
+ console.debug('[TesselatedFontTable] Error: char not found in fontTable', tf.chars_codes[c], String.fromCharCode(tf.chars_codes[c]));
9145
9268
  }
9146
- x += charGlyph.char_width * size_multiply;
9269
+ continue;
9270
+ }
9271
+ if (curTShape === textShapeSelected) {
9272
+ selectedCharEntries.push({
9273
+ char: charGlyph, x: x, y: y, selected: true
9274
+ });
9275
+ selectedBuffSize += charGlyph.fill_data.buffer.byteLength / 4;
9276
+ }
9277
+ else {
9278
+ charEntries.push({
9279
+ char: charGlyph, x: x, y: y, selected: false
9280
+ });
9281
+ textBuffSize += charGlyph.fill_data.buffer.byteLength / 4;
9147
9282
  }
9283
+ x += charGlyph.char_width * size_multiply;
9148
9284
  }
9149
9285
  var half_thickness = 0.25 * tf.internalScale.y;
9150
9286
  var topY = y + this.getUnderLineHeight() + half_thickness;
@@ -9184,6 +9320,173 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9184
9320
  textShapeSelected.addChunk(buff);
9185
9321
  }
9186
9322
  };
9323
+ TesselatedFontTable.prototype._cacheKey = function (color, channel) {
9324
+ if (color === void 0) { color = 0xffffff; }
9325
+ if (channel === void 0) { channel = -1; }
9326
+ var fnt = channel >= 0;
9327
+ return "" + color + fnt + (fnt ? channel : 0);
9328
+ };
9329
+ /**
9330
+ * Query shape from TextField cache
9331
+ * @param tf
9332
+ * @param format
9333
+ * @param channel - FNT channel, -1 for regular font
9334
+ * @private
9335
+ */
9336
+ TesselatedFontTable.prototype._queryShape = function (tf, format, channel) {
9337
+ if (channel === void 0) { channel = -1; }
9338
+ var textShape = tf.getTextShapeForIdentifierAndFormat(this._cacheKey(format.color, channel), format);
9339
+ if (channel >= 0 && !textShape.fntMaterial) {
9340
+ var argb = _awayjs_core.ColorUtils.float32ColorToARGB(format.color);
9341
+ var mat = new _awayjs_materials.MethodMaterial(this._fnt_channels[channel]);
9342
+ mat.colorTransform = new _awayjs_core.ColorTransform(argb[1] / 255, argb[2] / 255, argb[3] / 255);
9343
+ mat.bothSides = true;
9344
+ mat.alphaBlending = true;
9345
+ mat.useColorTransform = true;
9346
+ mat.style.sampler = new _awayjs_stage.ImageSampler(false, true, true);
9347
+ textShape.fntMaterial = mat;
9348
+ }
9349
+ return textShape;
9350
+ };
9351
+ /**
9352
+ * Fill text run but use FNT Texture.
9353
+ */
9354
+ TesselatedFontTable.prototype.fillTextRunFNT = function (tf, format, startWord, wordCnt) {
9355
+ var textShape = this._queryShape(tf, format, 0);
9356
+ var charShapesCache = {};
9357
+ var charShapesSelectedCache = {};
9358
+ var wordsCount = startWord + wordCnt;
9359
+ var size_multiply = this._size_multiply;
9360
+ var textShapeSelected;
9361
+ var select_start = tf.selectionBeginIndex;
9362
+ var select_end = tf.selectionEndIndex;
9363
+ var start_x = 0;
9364
+ if (tf.selectable) {
9365
+ var newFormat = format.clone();
9366
+ newFormat.color = 0xffffff;
9367
+ textShapeSelected = this._queryShape(tf, newFormat, 0);
9368
+ charShapesSelectedCache[textShapeSelected.cacheId] = textShapeSelected;
9369
+ if (newFormat.underline && (startWord + 1) < tf.words.length) {
9370
+ start_x = tf.words.get(startWord).x;
9371
+ }
9372
+ if (tf.selectionEndIndex < tf.selectionBeginIndex) {
9373
+ select_start = tf.selectionEndIndex;
9374
+ select_end = tf.selectionBeginIndex;
9375
+ }
9376
+ }
9377
+ charShapesCache[textShape.cacheId] = textShape;
9378
+ var shapeArray = new Map();
9379
+ var underlines = [];
9380
+ // loop over all the words and create the text data for it
9381
+ // each word provides its own start-x and start-y values, so we can just ignore whitespace-here
9382
+ for (var w = startWord; w < wordsCount; w += 1) {
9383
+ var word = tf.words.get(w);
9384
+ var x = word.x;
9385
+ var y = word.y;
9386
+ var startIdx = word.start;
9387
+ var charsCount = startIdx + word.len;
9388
+ var preFilledShape = null;
9389
+ var target = null;
9390
+ var color = 0;
9391
+ var fntID = -1;
9392
+ for (var c = startIdx; c < charsCount; c++) {
9393
+ // space codes
9394
+ if (tf.chars_codes[c] === 32 || tf.chars_codes[c] === 9) {
9395
+ continue;
9396
+ }
9397
+ var charGlyph = this.getChar(tf.chars_codes[c], false);
9398
+ if (!charGlyph) {
9399
+ if (once$1(this, 'miss' + tf.chars_codes[c])) {
9400
+ console.debug('[TesselatedFontTable] Error: char not found in fontTable', tf.chars_codes[c], String.fromCharCode(tf.chars_codes[c]));
9401
+ }
9402
+ continue;
9403
+ }
9404
+ var selected = (tf.isInFocus && c >= select_start && c < select_end);
9405
+ var baseShape = textShape;
9406
+ var cacheStore = charShapesCache;
9407
+ if (selected) {
9408
+ baseShape = textShapeSelected;
9409
+ cacheStore = charShapesSelectedCache;
9410
+ }
9411
+ var curFormat = baseShape.format;
9412
+ var cacheId = preFilledShape ? preFilledShape.cacheId : '';
9413
+ if (!cacheId || color !== curFormat.color || charGlyph.fnt_channel !== fntID) {
9414
+ cacheId = this._cacheKey(curFormat.color, charGlyph.fnt_channel);
9415
+ color = curFormat.color;
9416
+ fntID = charGlyph.fnt_channel;
9417
+ }
9418
+ var fntFilledShape = preFilledShape && preFilledShape.cacheId !== cacheId
9419
+ ? cacheStore[cacheId]
9420
+ : preFilledShape;
9421
+ if (!fntFilledShape) {
9422
+ fntFilledShape = this._queryShape(tf, curFormat, charGlyph.fnt_channel);
9423
+ cacheStore[fntFilledShape.cacheId] = fntFilledShape;
9424
+ }
9425
+ if (preFilledShape !== fntFilledShape || !target) {
9426
+ // FNT is very little, has 6 vertices per shape (instead of 300 ++)
9427
+ // fill it directly
9428
+ target = shapeArray.get(fntFilledShape) || {
9429
+ uv: [],
9430
+ pos: []
9431
+ };
9432
+ shapeArray.set(fntFilledShape, target);
9433
+ preFilledShape = fntFilledShape;
9434
+ }
9435
+ this._emitCharFNT(target, charGlyph, x, y);
9436
+ x += charGlyph.char_width * size_multiply;
9437
+ }
9438
+ /*
9439
+ todo Generate underline for regular shape
9440
+
9441
+ const half_thickness: number = 0.25 * tf.internalScale.y;
9442
+ const topY: number = y + this.getUnderLineHeight() + half_thickness;
9443
+ const bottomY: number = y + this.getUnderLineHeight() - half_thickness;
9444
+
9445
+ if (tf.selectable && newFormat.underline && (startWord + 1) < tf.words.length) {
9446
+ const underBuff = new Float32Array(12);
9447
+
9448
+ underBuff[0] = start_x;
9449
+ underBuff[1] = bottomY;
9450
+ underBuff[2] = start_x;
9451
+ underBuff[3] = topY;
9452
+ underBuff[4] = x;
9453
+ underBuff[5] = topY;
9454
+ underBuff[6] = x;
9455
+ underBuff[7] = topY;
9456
+ underBuff[8] = x;
9457
+ underBuff[9] = bottomY;
9458
+ underBuff[10] = start_x;
9459
+ underBuff[11] = bottomY;
9460
+
9461
+ underlines.push(underBuff);
9462
+ }
9463
+ */
9464
+ } // for word
9465
+ // oh, es5... iterating over map won't working
9466
+ var shapes = Array.from(shapeArray.keys());
9467
+ for (var _i = 0, shapes_1 = shapes; _i < shapes_1.length; _i++) {
9468
+ var shape = shapes_1[_i];
9469
+ var values = shapeArray.get(shape);
9470
+ shape.addChunk(new Float32Array(values.pos), new Float32Array(values.uv));
9471
+ }
9472
+ };
9473
+ TesselatedFontTable.prototype._emitCharFNT = function (target, charGlyph, x, y) {
9474
+ var scale = this._size_multiply;
9475
+ var size = this._font_em_size * scale;
9476
+ var rect = charGlyph.fnt_rect;
9477
+ var uv = charGlyph.fnt_uv;
9478
+ var width = charGlyph.char_width * scale;
9479
+ if (!rect) {
9480
+ // empty chars not have data
9481
+ return;
9482
+ }
9483
+ var x1 = x + width * rect.x * 20;
9484
+ var x2 = x1 + width * rect.width * 20;
9485
+ var y1 = y + size * rect.y * 20;
9486
+ var y2 = y1 + size * rect.height * 20;
9487
+ target.pos.push(x1, y1, x1, y2, x2, y1, x2, y1, x1, y2, x2, y2);
9488
+ target.uv.push(uv.x, uv.y, uv.x, uv.bottom, uv.right, uv.y, uv.right, uv.y, uv.x, uv.bottom, uv.right, uv.bottom);
9489
+ };
9187
9490
  TesselatedFontTable.prototype.createPointGlyph_9679 = function () {
9188
9491
  var verts = [];
9189
9492
  _awayjs_graphics.GraphicsFactoryHelper.drawElipse(this._font_em_size / 2, this._font_em_size / 2, this._font_em_size / 8, this._font_em_size / 8, verts, 0, 360, 5, false);
@@ -9197,92 +9500,122 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9197
9500
  this._font_chars_dic['9679'] = t_font_char;
9198
9501
  return t_font_char;
9199
9502
  };
9200
- TesselatedFontTable.prototype.getChar = function (name) {
9201
- var t_font_char = this._font_chars_dic[name];
9202
- if (!t_font_char) {
9503
+ TesselatedFontTable.prototype.getCharOpenType = function (name) {
9504
+ if (!this._opentype_font) {
9505
+ return null;
9506
+ }
9507
+ var thisGlyph = this._opentype_font.charToGlyph(String.fromCharCode(parseInt(name)));
9508
+ if (!thisGlyph) {
9509
+ return null;
9510
+ }
9511
+ //console.log("got the glyph from opentype");
9512
+ var thisPath = thisGlyph.getPath();
9513
+ var awayPath = new _awayjs_graphics.GraphicsPath();
9514
+ var i = 0;
9515
+ var len = thisPath.commands.length;
9516
+ //awayPath.lineTo(0, 0);
9517
+ //awayPath.moveTo(0,0);//-100);
9518
+ //awayPath.curveTo(100, 250, 200,0);
9519
+ //awayPath.lineTo(150, 100);
9520
+ //awayPath.moveTo(0,20);
9521
+ //awayPath.curveTo(100, 270, 200,20);
9522
+ //awayPath.moveTo(0,-20);
9523
+ //awayPath.moveTo(0,-10);
9524
+ //awayPath.curveTo(100, -110, 200,-10);
9525
+ var startx = 0;
9526
+ var starty = 0;
9527
+ var y_offset = this._ascent;
9528
+ //40 = 66
9529
+ var scale = (this._opentype_font.unitsPerEm / 72);
9530
+ for (i = 0; i < len; i++) {
9531
+ var cmd = thisPath.commands[i];
9532
+ //console.log("cmd", cmd.type, cmd.x, cmd.y, cmd.x1, cmd.y1, cmd.x2, cmd.y2);
9533
+ if (cmd.type === 'M') {
9534
+ awayPath.moveTo(scale * cmd.x, scale * cmd.y + y_offset);
9535
+ startx = scale * cmd.x;
9536
+ starty = scale * cmd.y + y_offset;
9537
+ }
9538
+ else if (cmd.type === 'L') {
9539
+ awayPath.lineTo(scale * cmd.x, scale * cmd.y + y_offset);
9540
+ }
9541
+ else if (cmd.type === 'Q') {
9542
+ awayPath.curveTo(scale * cmd.x1, scale * cmd.y1 + y_offset, scale * cmd.x, scale * cmd.y + y_offset);
9543
+ }
9544
+ else if (cmd.type === 'C') {
9545
+ var mergedX = cmd.x1 + (cmd.x2 - cmd.x1) / 2;
9546
+ var mergedY = cmd.y1 + (cmd.y2 - cmd.y1) / 2;
9547
+ awayPath.curveTo(scale * cmd.x1, scale * cmd.y1 + y_offset, scale * mergedX, scale * mergedY + y_offset);
9548
+ awayPath.curveTo(scale * cmd.x2, scale * cmd.y2 + y_offset, scale * cmd.x, scale * cmd.y + y_offset);
9549
+ }
9550
+ else if (cmd.type === 'Z') {
9551
+ awayPath.lineTo(startx, starty);
9552
+ }
9553
+ }
9554
+ var t_font_char = new TesselatedFontChar(null, null, awayPath);
9555
+ t_font_char.char_width = thisGlyph.advanceWidth; //(1 / thisGlyph.path.unitsPerEm * 72);
9556
+ t_font_char.fill_data = _awayjs_graphics.GraphicsFactoryFills.pathToAttributesBuffer(awayPath, true, null, scale * Settings.FONT_TESSELATION_QUALITY);
9557
+ t_font_char.lastTesselatedScale = scale;
9558
+ if (!t_font_char.fill_data) {
9559
+ if (once$1(this, 'tess' + name)) {
9560
+ console.debug('[TesselatedFontTable] Error:tesselating opentype glyph:', name.charCodeAt(0));
9561
+ }
9562
+ return null;
9563
+ }
9564
+ this._font_chars.push(t_font_char);
9565
+ this._font_chars_dic[name] = t_font_char;
9566
+ };
9567
+ TesselatedFontTable.prototype.getChar = function (name, tesselation) {
9568
+ if (tesselation === void 0) { tesselation = true; }
9569
+ name = '' + name;
9570
+ var fontChar = this._font_chars_dic[name];
9571
+ if (!tesselation && fontChar) {
9572
+ return fontChar;
9573
+ }
9574
+ if (!fontChar) {
9203
9575
  if (this._opentype_font) {
9204
- var thisGlyph = this._opentype_font.charToGlyph(String.fromCharCode(parseInt(name)));
9205
- if (thisGlyph) {
9206
- //console.log("got the glyph from opentype");
9207
- var thisPath = thisGlyph.getPath();
9208
- var awayPath = new _awayjs_graphics.GraphicsPath();
9209
- var i = 0;
9210
- var len = thisPath.commands.length;
9211
- //awayPath.lineTo(0, 0);
9212
- //awayPath.moveTo(0,0);//-100);
9213
- //awayPath.curveTo(100, 250, 200,0);
9214
- //awayPath.lineTo(150, 100);
9215
- //awayPath.moveTo(0,20);
9216
- //awayPath.curveTo(100, 270, 200,20);
9217
- //awayPath.moveTo(0,-20);
9218
- //awayPath.moveTo(0,-10);
9219
- //awayPath.curveTo(100, -110, 200,-10);
9220
- var startx = 0;
9221
- var starty = 0;
9222
- var y_offset = this._ascent;
9223
- //40 = 66
9224
- var scale = (this._opentype_font.unitsPerEm / 72);
9225
- for (i = 0; i < len; i++) {
9226
- var cmd = thisPath.commands[i];
9227
- //console.log("cmd", cmd.type, cmd.x, cmd.y, cmd.x1, cmd.y1, cmd.x2, cmd.y2);
9228
- if (cmd.type === 'M') {
9229
- awayPath.moveTo(scale * cmd.x, scale * cmd.y + y_offset);
9230
- startx = scale * cmd.x;
9231
- starty = scale * cmd.y + y_offset;
9232
- }
9233
- else if (cmd.type === 'L') {
9234
- awayPath.lineTo(scale * cmd.x, scale * cmd.y + y_offset);
9235
- }
9236
- else if (cmd.type === 'Q') {
9237
- awayPath.curveTo(scale * cmd.x1, scale * cmd.y1 + y_offset, scale * cmd.x, scale * cmd.y + y_offset);
9238
- }
9239
- else if (cmd.type === 'C') {
9240
- var mergedX = cmd.x1 + (cmd.x2 - cmd.x1) / 2;
9241
- var mergedY = cmd.y1 + (cmd.y2 - cmd.y1) / 2;
9242
- awayPath.curveTo(scale * cmd.x1, scale * cmd.y1 + y_offset, scale * mergedX, scale * mergedY + y_offset);
9243
- awayPath.curveTo(scale * cmd.x2, scale * cmd.y2 + y_offset, scale * cmd.x, scale * cmd.y + y_offset);
9244
- }
9245
- else if (cmd.type === 'Z') {
9246
- awayPath.lineTo(startx, starty);
9247
- }
9248
- }
9249
- t_font_char = new TesselatedFontChar(null, null, awayPath);
9250
- t_font_char.char_width = thisGlyph.advanceWidth; //(1 / thisGlyph.path.unitsPerEm * 72);
9251
- t_font_char.fill_data = _awayjs_graphics.GraphicsFactoryFills.pathToAttributesBuffer(awayPath, true);
9252
- if (!t_font_char.fill_data) {
9253
- if (once$1(this, 'tess' + name)) {
9254
- console.debug('[TesselatedFontTable] Error:tesselating opentype glyph:', name.charCodeAt(0));
9255
- }
9256
- return null;
9257
- }
9258
- this._font_chars.push(t_font_char);
9259
- this._font_chars_dic[name] = t_font_char;
9260
- }
9576
+ return this.getCharOpenType(name);
9261
9577
  }
9262
9578
  if (name == '9679') {
9263
- t_font_char = this.createPointGlyph_9679();
9264
- }
9265
- }
9266
- else if (t_font_char.fill_data == null &&
9267
- t_font_char.stroke_data == null && t_font_char.fill_data_path != null) {
9268
- // hack for messed up "X": remove the first command if it is moveTo that points to 0,0
9269
- // change the new first command to moveTo
9270
- if (t_font_char.fill_data_path.commands[0][0] == 1 &&
9271
- t_font_char.fill_data_path.data[0][0] == 0 && t_font_char.fill_data_path.data[0][1] == 0) {
9272
- t_font_char.fill_data_path.data[0].shift();
9273
- t_font_char.fill_data_path.data[0].shift();
9274
- t_font_char.fill_data_path.commands[0].shift();
9275
- t_font_char.fill_data_path.commands[0][0] = 2;
9276
- }
9277
- t_font_char.fill_data = _awayjs_graphics.GraphicsFactoryFills.pathToAttributesBuffer(t_font_char.fill_data_path, true);
9278
- if (!t_font_char.fill_data) {
9279
- if (once$1(this, 'tess' + name)) {
9280
- console.debug('[TesselatedFontTable] Error:tesselating glyph:', name.charCodeAt(0));
9281
- }
9282
- return null;
9579
+ return this.createPointGlyph_9679();
9283
9580
  }
9581
+ return null;
9284
9582
  }
9285
- return t_font_char;
9583
+ // tesselation pass
9584
+ var scale = this._size_multiply;
9585
+ var qualityStepScale = Math.max(0.01, Math.round(scale * 100) / 100);
9586
+ if (fontChar.fill_data_path === null) {
9587
+ return null;
9588
+ }
9589
+ // we already has buffer with tesselation scale ratio
9590
+ if (!(fontChar.fill_data == null && fontChar.stroke_data == null)
9591
+ && fontChar.lastTesselatedScale >= qualityStepScale) {
9592
+ return fontChar;
9593
+ }
9594
+ var path = fontChar.fill_data_path;
9595
+ // hack for messed up "X": remove the first command if it is moveTo that points to 0,0
9596
+ // change the new first command to moveTo
9597
+ if (path.commands[0][0] == 1 && path.data[0][0] == 0 && path.data[0][1] == 0) {
9598
+ path.data[0].shift();
9599
+ path.data[0].shift();
9600
+ path.commands[0].shift();
9601
+ path.commands[0][0] = 2;
9602
+ }
9603
+ if (fontChar.fill_data) {
9604
+ // it not have dispose, but clear will drop abstraction if it exist
9605
+ fontChar.fill_data.clear();
9606
+ }
9607
+ fontChar.fill_data = _awayjs_graphics.GraphicsFactoryFills.pathToAttributesBuffer(fontChar.fill_data_path, true, null, qualityStepScale * Settings.FONT_TESSELATION_QUALITY);
9608
+ if (fontChar.lastTesselatedScale > 0) {
9609
+ console.debug('[TesselatedFontTable] Retesselate char from scale:', fontChar.lastTesselatedScale, qualityStepScale, String.fromCharCode(+name));
9610
+ }
9611
+ fontChar.lastTesselatedScale = qualityStepScale;
9612
+ if (!fontChar.fill_data) {
9613
+ if (once$1(this, 'tess' + name)) {
9614
+ console.debug('[TesselatedFontTable] Error:tesselating glyph:', name.charCodeAt(0));
9615
+ }
9616
+ return null;
9617
+ }
9618
+ return fontChar;
9286
9619
  };
9287
9620
  TesselatedFontTable.prototype.setChar = function (name, char_width, fills_data, stroke_data, uses_curves, glyph_idx, fill_data_path) {
9288
9621
  if (fills_data === void 0) { fills_data = null; }
@@ -9310,6 +9643,11 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9310
9643
  this._font_chars.push(t_font_char);
9311
9644
  this._font_chars_dic[name] = t_font_char;
9312
9645
  };
9646
+ TesselatedFontTable.prototype.roundTo = function (val) {
9647
+ var p = Settings.TEXT_SHAPE_ROUND_PRECISION;
9648
+ var invP = 1 / (p || 1);
9649
+ return Math.floor(val * invP) * p;
9650
+ };
9313
9651
  TesselatedFontTable.prototype._fillBuffer = function (buffer, chars, selection) {
9314
9652
  if (selection === void 0) { selection = false; }
9315
9653
  var scale = this._size_multiply;
@@ -9323,8 +9661,8 @@ var TesselatedFontTable = /** @class */ (function (_super) {
9323
9661
  var view = new Float32Array(char.fill_data.buffer);
9324
9662
  var count = view.length;
9325
9663
  for (var v = 0; v < count; v += 2) {
9326
- buffer[offset + v + 0] = view[v + 0] * scale + x;
9327
- buffer[offset + v + 1] = view[v + 1] * scale + y;
9664
+ buffer[offset + v + 0] = this.roundTo(view[v + 0] * scale + x);
9665
+ buffer[offset + v + 1] = this.roundTo(view[v + 1] * scale + y);
9328
9666
  }
9329
9667
  offset += view.length;
9330
9668
  }
@@ -10426,10 +10764,14 @@ var TextSprite = /** @class */ (function (_super) {
10426
10764
  }(Sprite));
10427
10765
 
10428
10766
  var TextShape = /** @class */ (function () {
10429
- function TextShape() {
10767
+ function TextShape(format, cacheId) {
10768
+ this.format = format;
10769
+ this.cacheId = cacheId;
10430
10770
  this.verts = [];
10771
+ this.uvs = [];
10431
10772
  this._length = 0;
10432
10773
  this.verts = [];
10774
+ this.uvs = [];
10433
10775
  }
10434
10776
  Object.defineProperty(TextShape.prototype, "length", {
10435
10777
  get: function () {
@@ -10440,9 +10782,11 @@ var TextShape = /** @class */ (function () {
10440
10782
  return;
10441
10783
  }
10442
10784
  var verts = this.verts;
10785
+ var uvs = this.uvs;
10443
10786
  if (val === 0) {
10444
10787
  this._length = 0;
10445
10788
  verts.length = 0;
10789
+ uvs.length = 0;
10446
10790
  return;
10447
10791
  }
10448
10792
  var index = 0;
@@ -10454,6 +10798,9 @@ var TextShape = /** @class */ (function () {
10454
10798
  if (size < 0) {
10455
10799
  // resize buffer
10456
10800
  verts[index - 1] = verts[index - 1].subarray(0, size + verts[index - 1].length);
10801
+ if (uvs[index - 1]) {
10802
+ uvs[index - 1] = uvs[index - 1].subarray(0, size + uvs[index - 1].length);
10803
+ }
10457
10804
  }
10458
10805
  verts.length = index;
10459
10806
  this._length = val;
@@ -10461,9 +10808,25 @@ var TextShape = /** @class */ (function () {
10461
10808
  enumerable: true,
10462
10809
  configurable: true
10463
10810
  });
10464
- TextShape.prototype.addChunk = function (buffer) {
10811
+ Object.defineProperty(TextShape.prototype, "hasUV", {
10812
+ get: function () {
10813
+ return this.uvs.length > 0;
10814
+ },
10815
+ enumerable: true,
10816
+ configurable: true
10817
+ });
10818
+ TextShape.prototype.addChunk = function (buffer, uvs) {
10819
+ if (this.verts.length !== this.uvs.length && uvs) {
10820
+ throw 'You can\'t mix TextShape with UV and without in same place';
10821
+ }
10822
+ if (uvs && buffer.length !== uvs.length) {
10823
+ throw 'Position buffer and UV buffer should has equal size';
10824
+ }
10465
10825
  this._length += buffer.length;
10466
10826
  this.verts.push(buffer);
10827
+ if (uvs) {
10828
+ this.uvs.push(uvs);
10829
+ }
10467
10830
  };
10468
10831
  Object.defineProperty(TextShape.prototype, "tall", {
10469
10832
  get: function () {
@@ -10897,6 +11260,53 @@ var HTMLTextProcessor = /** @class */ (function () {
10897
11260
  return HTMLTextProcessor;
10898
11261
  }());
10899
11262
 
11263
+ var WordStore = /** @class */ (function () {
11264
+ function WordStore(size) {
11265
+ if (size === void 0) { size = 40; }
11266
+ this.index = -1;
11267
+ this.store = Array.from({ length: size }, function (e) { return ({
11268
+ x: Infinity, y: Infinity, start: 0, width: 0, len: 0
11269
+ }); });
11270
+ }
11271
+ WordStore.prototype.put = function (start, x, y, width, len) {
11272
+ this.index++;
11273
+ var word = this.store[this.index] || (this.store[this.index] = {});
11274
+ word.start = start;
11275
+ word.x = x;
11276
+ word.y = y;
11277
+ word.width = width;
11278
+ word.len = len;
11279
+ return word;
11280
+ };
11281
+ Object.defineProperty(WordStore.prototype, "last", {
11282
+ get: function () {
11283
+ return this.store[this.index];
11284
+ },
11285
+ enumerable: true,
11286
+ configurable: true
11287
+ });
11288
+ Object.defineProperty(WordStore.prototype, "length", {
11289
+ get: function () {
11290
+ return this.index + 1;
11291
+ },
11292
+ set: function (v) {
11293
+ this.index = v - 1;
11294
+ },
11295
+ enumerable: true,
11296
+ configurable: true
11297
+ });
11298
+ WordStore.prototype.get = function (index) {
11299
+ return this.store[index];
11300
+ };
11301
+ WordStore.prototype.free = function () {
11302
+ this.index = -1;
11303
+ };
11304
+ WordStore.prototype.dispose = function () {
11305
+ this.store = null;
11306
+ this.index = 0;
11307
+ };
11308
+ return WordStore;
11309
+ }());
10900
11310
  var MNEMOS = [
10901
11311
  {
10902
11312
  test: /&apos;/g,
@@ -11004,7 +11414,20 @@ var TextField = /** @class */ (function (_super) {
11004
11414
  _this._selectionBeginIndex = 0;
11005
11415
  _this._selectionEndIndex = 0;
11006
11416
  _this._biggestLine = 0;
11417
+ /**
11418
+ * Renderable text, used for computing a glyphs
11419
+ * @private
11420
+ */
11007
11421
  _this._iText = '';
11422
+ /**
11423
+ * Place where is diff is begun to end
11424
+ * @private
11425
+ */
11426
+ _this._iTextDiffStart = 0;
11427
+ /**
11428
+ * Original text passed to field
11429
+ * @private
11430
+ */
11008
11431
  _this._text = '';
11009
11432
  _this._iTextWoLineBreaks = ''; // _iText without line breaks
11010
11433
  _this.inMaskMode = false;
@@ -11017,16 +11440,13 @@ var TextField = /** @class */ (function (_super) {
11017
11440
  _this._shapesDirty = false;
11018
11441
  _this._textShapesDirty = false;
11019
11442
  _this.chars_codes = [];
11020
- _this.chars_codes_prev = [];
11021
11443
  _this.chars_width = [];
11022
11444
  _this.tf_per_char = [];
11023
- _this.tf_per_char_prev = [];
11024
- // we use that for text appending to save verts count before last word verts are added to textShape.
11025
- // Then on text append we clear last word verts because the word may be wrapped to next line
11026
- _this.last_word_vertices_count = 0;
11027
- _this.words = []; // stores offset and length and width for each word
11445
+ // stores offset and length and width for each word
11446
+ _this.words = new WordStore(10);
11028
11447
  _this._textRuns_formats = []; // stores textFormat for each textrun
11029
- _this._textRuns_words = []; // stores words-offset, word-count and width for each textrun
11448
+ // stores words-offset, word-count and width for each textrun
11449
+ _this._textRuns_words = [];
11030
11450
  _this._paragraph_textRuns_indices = []; // stores textFormat for each textrun
11031
11451
  _this._maxWidthLine = 0;
11032
11452
  _this._labelData = null;
@@ -11447,12 +11867,10 @@ var TextField = /** @class */ (function (_super) {
11447
11867
  this._graphics.endFill();
11448
11868
  };
11449
11869
  TextField.prototype.getTextShapeForIdentifierAndFormat = function (id, format) {
11450
- if (this.textShapes.hasOwnProperty(id)) {
11870
+ if (this.textShapes[id]) {
11451
11871
  return this.textShapes[id];
11452
11872
  }
11453
- this.textShapes[id] = new TextShape();
11454
- this.textShapes[id].format = format;
11455
- return this.textShapes[id];
11873
+ return (this.textShapes[id] = new TextShape(format, id));
11456
11874
  };
11457
11875
  Object.defineProperty(TextField.prototype, "autoSize", {
11458
11876
  get: function () {
@@ -11821,14 +12239,19 @@ var TextField = /** @class */ (function (_super) {
11821
12239
  return this._scrollV;
11822
12240
  },
11823
12241
  set: function (value) {
11824
- if (Math.floor(value) == this._scrollV)
12242
+ var rounded = Math.round(value);
12243
+ if (rounded === this._scrollV)
11825
12244
  return;
11826
- this._scrollV = Math.floor(value);
12245
+ this._scrollV = rounded;
11827
12246
  if (this._scrollV > this._maxScrollV)
11828
12247
  this._scrollV = this._maxScrollV;
12248
+ if (this._scrollV <= 0) {
12249
+ this._scrollV = 0;
12250
+ }
11829
12251
  if (!this.textChild) {
11830
12252
  return;
11831
12253
  }
12254
+ // unsafe
11832
12255
  this.textChild.y = -this.lines_start_y[this._scrollV];
11833
12256
  },
11834
12257
  enumerable: true,
@@ -11904,12 +12327,6 @@ var TextField = /** @class */ (function (_super) {
11904
12327
  return;
11905
12328
  this._labelData = null;
11906
12329
  this._text = value;
11907
- /*
11908
- for (let i = 0; i < this._text.length; i++) {
11909
- const charCode = this._text.charCodeAt(i);
11910
- if (this._text)
11911
- console.log("charcodes", this._text[i], this._text.charCodeAt(i));
11912
- }*/
11913
12330
  if (value != '' && ((value.charCodeAt(value.length - 1) == 13) || (value.charCodeAt(value.length - 1) == 10))) {
11914
12331
  value = value.slice(0, value.length - 1);
11915
12332
  }
@@ -12266,6 +12683,7 @@ var TextField = /** @class */ (function (_super) {
12266
12683
  if (this._labelData) {
12267
12684
  this._labelData = null;
12268
12685
  }
12686
+ this._resetParagraph();
12269
12687
  this._clearTextShapes();
12270
12688
  this._textFormat = null;
12271
12689
  };
@@ -12289,20 +12707,10 @@ var TextField = /** @class */ (function (_super) {
12289
12707
  // a whitespace is considered as a word
12290
12708
  if (this._textDirty) {
12291
12709
  this._positionsDirty = true;
12292
- this.chars_codes_prev = Array.from(this.chars_codes);
12293
- this.tf_per_char_prev = Array.from(this.tf_per_char);
12294
- // we do not use last word since last word may changed.
12295
- // For example "Hello w" and "Hello world" both have 3 words but the last word actually changed
12296
- this._words_amount_prev = this.words.length;
12297
- this.chars_codes.length = 0;
12298
- this.chars_width.length = 0;
12710
+ this._lastWordsCount = this.words.length;
12299
12711
  this.char_positions_x.length = 0;
12300
12712
  this.char_positions_y.length = 0;
12301
- this.tf_per_char.length = 0;
12302
12713
  this.words.length = 0;
12303
- this._textRuns_words.length = 0;
12304
- this._textRuns_formats.length = 0;
12305
- this._paragraph_textRuns_indices.length = 0;
12306
12714
  this.lines_wordStartIndices.length = 0;
12307
12715
  this.lines_wordEndIndices.length = 0;
12308
12716
  this.lines_start_y.length = 0;
@@ -12319,10 +12727,7 @@ var TextField = /** @class */ (function (_super) {
12319
12727
  // todo: cleanup usage of _textFormats vs _textFormats
12320
12728
  if (!this._textFormat && this._textFormats.length > 0)
12321
12729
  this._textFormat = this._textFormats[0];
12322
- if (this._iText != '' && this._textFormat != null) {
12323
- //console.log("textlength", this.text.toString().length, this.text.toString());
12324
- this.buildParagraphs();
12325
- }
12730
+ this.buildParagraphs();
12326
12731
  //console.log("TextField buildParagraph", this.id, this._iText);
12327
12732
  //console.log("TextField buildParagraph", this.id, this._autoSize);
12328
12733
  //console.log("TextField buildParagraph", this.id, this._wordWrap);
@@ -12368,18 +12773,6 @@ var TextField = /** @class */ (function (_super) {
12368
12773
  // in this step, the text-shapes are cleared,
12369
12774
  // the data for new text-shapes is collected from the font-tables
12370
12775
  // and the new text-shapes are created and assigned to the graphics
12371
- if (this._textShapesDirty) {
12372
- // do nothing
12373
- }
12374
- else if (this.chars_codes_prev.length == 0) {
12375
- // do nothing
12376
- }
12377
- else if (this.chars_codes_prev.length > this.chars_codes.length) {
12378
- this._textShapesDirty = true;
12379
- }
12380
- else if (this.chars_codes_prev[0] !== this.chars_codes[0]) {
12381
- this._textShapesDirty = true;
12382
- }
12383
12776
  if (this._glyphsDirty) {
12384
12777
  //console.log("TextField buildGlyphs", this.id, this.words);
12385
12778
  if (this._labelData) {
@@ -12421,14 +12814,66 @@ var TextField = /** @class */ (function (_super) {
12421
12814
  }
12422
12815
  this.text = paste;
12423
12816
  };
12817
+ TextField.prototype._resetParagraph = function () {
12818
+ this._textShapesDirty = this._textShapesDirty || this.chars_codes.length > 0;
12819
+ this.tf_per_char.length = 0;
12820
+ this.chars_width.length = 0;
12821
+ this.chars_codes.length = 0;
12822
+ this._paragraph_textRuns_indices.length = 0;
12823
+ this._textRuns_formats.length = 0;
12824
+ this._textRuns_words.length = 0;
12825
+ };
12424
12826
  TextField.prototype.buildParagraphs = function () {
12425
- var thisText = this._iText.toString();
12426
- var f_len = this._textFormatsIdx.length;
12827
+ if (!this._textDirty) {
12828
+ return;
12829
+ }
12830
+ // clear paragraph data when clear
12831
+ if (this._iText === '' || !this._textFormat) {
12832
+ this._resetParagraph();
12833
+ return;
12834
+ }
12835
+ var paragraphIndex = 0;
12836
+ var formatIndex = 0;
12837
+ var wordIndex = 0;
12838
+ var charCodeIndex = 0;
12839
+ // track char mutations between new and older.
12840
+ var codeChanges = 0;
12427
12841
  var linewidth = 0;
12428
12842
  var c_start = 0;
12429
- this._paragraph_textRuns_indices[this._paragraph_textRuns_indices.length] = this._textRuns_formats.length;
12843
+ var thisText = this._iText;
12844
+ var formatsCount = this._textFormatsIdx.length;
12845
+ var paragraphIndices = this._paragraph_textRuns_indices;
12846
+ var textRunFormats = this._textRuns_formats;
12847
+ var textRunWords = this._textRuns_words;
12848
+ var charCodes = this.chars_codes;
12849
+ var charTextFormats = this.tf_per_char;
12850
+ var charWidths = this.chars_width;
12851
+ var pushParagraph = function (formatIndex) {
12852
+ paragraphIndices[paragraphIndex] = formatIndex;
12853
+ paragraphIndex++;
12854
+ };
12855
+ var pushFormat = function (format, updateParagraph) {
12856
+ if (updateParagraph === void 0) { updateParagraph = false; }
12857
+ updateParagraph && pushParagraph(formatIndex);
12858
+ textRunFormats[formatIndex++] = format;
12859
+ return format;
12860
+ };
12861
+ var pushRunEntry = function (word) {
12862
+ textRunWords[wordIndex++] = word;
12863
+ return word;
12864
+ };
12865
+ var pushCharData = function (code, tf, width) {
12866
+ codeChanges += +(code !== charCodes[charCodeIndex]);
12867
+ codeChanges += +(tf !== charTextFormats[charCodeIndex]);
12868
+ codeChanges += +(width !== charWidths[charCodeIndex]);
12869
+ charCodes[charCodeIndex] = code;
12870
+ charTextFormats[charCodeIndex] = tf;
12871
+ charWidths[charCodeIndex] = width;
12872
+ charCodeIndex++;
12873
+ };
12874
+ pushParagraph(formatIndex);
12430
12875
  // loop over all textFormats
12431
- for (var f = 0; f < f_len; f++) {
12876
+ for (var f = 0; f < formatsCount; f++) {
12432
12877
  var word_cnt = 0;
12433
12878
  var whitespace_cnt = 0;
12434
12879
  var startNewWord = true;
@@ -12436,11 +12881,16 @@ var TextField = /** @class */ (function (_super) {
12436
12881
  var maxLineWidth = this._width - (tf.indent + tf.leftMargin + tf.rightMargin);
12437
12882
  tf.font_table.initFontSize(tf.size);
12438
12883
  // if that is last format then it goes till the end of text:
12439
- var c_end = (f === f_len - 1) ? thisText.length : this._textFormatsIdx[f];
12884
+ var c_end = (f === formatsCount - 1) ? thisText.length : this._textFormatsIdx[f];
12440
12885
  if (c_end > c_start) {
12441
12886
  // create a new textrun
12442
- this._textRuns_formats[this._textRuns_formats.length] = tf;
12443
- this._textRuns_words[this._textRuns_words.length] = this.words.length;
12887
+ pushFormat(tf);
12888
+ var run = pushRunEntry({
12889
+ start: this.words.length,
12890
+ count: 0,
12891
+ width: 0,
12892
+ space: 0
12893
+ });
12444
12894
  // loop over all chars for this format
12445
12895
  //console.log("textrun tf = ", tf);
12446
12896
  for (var c = c_start; c < c_end; c++) {
@@ -12464,17 +12914,17 @@ var TextField = /** @class */ (function (_super) {
12464
12914
  }
12465
12915
  var isLineBreak = char_code === 10;
12466
12916
  if (isLineBreak) {
12467
- this._textRuns_words[this._textRuns_words.length] = word_cnt;
12468
- this._textRuns_words[this._textRuns_words.length] = linewidth;
12469
- this._textRuns_words[this._textRuns_words.length] = whitespace_cnt;
12470
- this._paragraph_textRuns_indices[this._paragraph_textRuns_indices.length] =
12471
- this._textRuns_formats.length;
12917
+ run.count = word_cnt;
12918
+ run.width = linewidth;
12919
+ run.space = whitespace_cnt;
12472
12920
  // create a new textrun
12473
- this._textRuns_formats[this._textRuns_formats.length] = tf;
12474
- this._textRuns_words[this._textRuns_words.length] = this.words.length;
12475
- // this.chars_codes[this.chars_codes.length] = 55;
12476
- // this.chars_width[this.chars_width.length] = 0;
12477
- // this.tf_per_char[this.tf_per_char.length] = tf;
12921
+ pushFormat(tf, true);
12922
+ run = pushRunEntry({
12923
+ start: this.words.length,
12924
+ count: 0,
12925
+ width: 0,
12926
+ space: 0
12927
+ });
12478
12928
  startNewWord = true;
12479
12929
  whitespace_cnt = 0;
12480
12930
  word_cnt = 0;
@@ -12484,8 +12934,6 @@ var TextField = /** @class */ (function (_super) {
12484
12934
  linewidth = 0;
12485
12935
  continue;
12486
12936
  }
12487
- this.chars_codes[this.chars_codes.length] = char_code;
12488
- this.tf_per_char[this.tf_per_char.length] = tf;
12489
12937
  var char_width = tf.font_table.getCharWidth(char_code.toString());
12490
12938
  var isSpace = char_code == 9 /* TAB */ || char_code == 32;
12491
12939
  // if this is a letter, and next char is no whitespace, we add the letterSpacing to the letter-width
@@ -12496,7 +12944,7 @@ var TextField = /** @class */ (function (_super) {
12496
12944
  }
12497
12945
  }
12498
12946
  linewidth += char_width;
12499
- this.chars_width[this.chars_width.length] = char_width;
12947
+ pushCharData(char_code, tf, char_width);
12500
12948
  // we create a new word if the char is either:
12501
12949
  // - first char of paragraph
12502
12950
  // - is a whitespace
@@ -12504,69 +12952,51 @@ var TextField = /** @class */ (function (_super) {
12504
12952
  if (isSpace) {
12505
12953
  //console.log("add WhiteSpace");
12506
12954
  whitespace_cnt++;
12507
- this.words[this.words.length] = this.chars_codes.length - 1; // index into chars
12508
- this.words[this.words.length] = 0; // x-position
12509
- this.words[this.words.length] = 0; // y-position
12510
- this.words[this.words.length] = char_width; // word width
12511
- this.words[this.words.length] = 1; // char count
12955
+ this.words.put(charCodeIndex - 1, 0, 0, char_width, 1);
12512
12956
  word_cnt++;
12513
12957
  // we also make sure to begin a new word for next char (could be whitespace again)
12514
12958
  startNewWord = true;
12515
12959
  }
12516
12960
  else {
12517
12961
  // no whitespace
12518
- if (this._autoSize == TextFieldAutoSize.NONE && this._wordWrap) {
12519
- if (this.words[this.words.length - 2] + char_width >= maxLineWidth) {
12962
+ if (word_cnt > 0 && this._autoSize == TextFieldAutoSize.NONE && this._wordWrap) {
12963
+ if (this.words.last.width + char_width >= maxLineWidth) {
12520
12964
  startNewWord = true;
12521
12965
  }
12522
12966
  }
12523
12967
  if (startNewWord) {
12524
12968
  //console.log("startNewWord");
12525
12969
  // create new word (either this is the first char, or the last char was whitespace)
12526
- this.words[this.words.length] = this.chars_codes.length - 1; // index into chars
12527
- this.words[this.words.length] = 0; // x-position
12528
- this.words[this.words.length] = 0; // y-position
12529
- this.words[this.words.length] = char_width; // word width
12530
- this.words[this.words.length] = 1; // char count
12970
+ this.words.put(charCodeIndex - 1, 0, 0, char_width, 1);
12531
12971
  word_cnt++;
12532
12972
  }
12533
12973
  else {
12534
12974
  // update-char length and width of active word.
12535
- this.words[this.words.length - 2] += char_width;
12536
- this.words[this.words.length - 1]++;
12975
+ this.words.last.width += char_width;
12976
+ this.words.last.len += 1;
12537
12977
  }
12538
12978
  startNewWord = false;
12539
12979
  }
12540
12980
  }
12541
- this._textRuns_words[this._textRuns_words.length] = word_cnt;
12542
- this._textRuns_words[this._textRuns_words.length] = linewidth;
12543
- this._textRuns_words[this._textRuns_words.length] = whitespace_cnt;
12981
+ run.count = word_cnt;
12982
+ run.width = linewidth;
12983
+ run.space = whitespace_cnt;
12544
12984
  if (this._maxWidthLine < linewidth) {
12545
12985
  this._maxWidthLine = linewidth;
12546
12986
  }
12547
12987
  }
12548
12988
  c_start = c_end;
12549
12989
  }
12550
- // run through all the chars to check if new text is just old text with some data appended
12551
- if (this.chars_codes_prev.length == 0) {
12552
- return;
12553
- }
12554
- else if (this.chars_codes_prev[0] !== this.chars_codes[0]) {
12555
- this._textShapesDirty = true;
12556
- return;
12557
- }
12558
- for (var c = this.chars_codes.length - 1; c >= 0; c--) {
12559
- var char_code = this.chars_codes[c];
12560
- var tf = this.tf_per_char_prev[c];
12561
- if (
12562
- // this.chars_codes_prev.length <= this.chars_codes.length &&
12563
- this.chars_codes_prev[c] &&
12564
- (this.chars_codes_prev[c] != char_code
12565
- || this.tf_per_char_prev[c]._style_name != tf._style_name)) {
12566
- this._textShapesDirty = true;
12567
- break;
12568
- }
12569
- }
12990
+ this._textShapesDirty = (this._textShapesDirty ||
12991
+ codeChanges > 0 ||
12992
+ charCodes.length !== charCodeIndex);
12993
+ // reduce paragraph count if will be greater that older
12994
+ paragraphIndices.length = paragraphIndex;
12995
+ textRunWords.length = wordIndex;
12996
+ textRunFormats.length = formatIndex;
12997
+ charCodes.length = charCodeIndex;
12998
+ charTextFormats.length = charCodeIndex;
12999
+ charWidths.length = charCodeIndex;
12570
13000
  };
12571
13001
  TextField.prototype.adjustPositionForAutoSize = function (newWidth) {
12572
13002
  var oldSize = this._width;
@@ -12637,12 +13067,12 @@ var TextField = /** @class */ (function (_super) {
12637
13067
  lines_heights[lines_heights.length - 1] = format.font_table.getLineHeight() + format.leading;
12638
13068
  }
12639
13069
  //console.log("process word positions for textrun", tr, "textruns", this._textRuns_words);
12640
- w_len = this._textRuns_words[(tr * 4)] + (this._textRuns_words[(tr * 4) + 1] * 5);
12641
- tr_length += this._textRuns_words[(tr * 4) + 2];
13070
+ w_len = this._textRuns_words[tr].start + this._textRuns_words[tr].count;
13071
+ tr_length += this._textRuns_words[tr].width;
12642
13072
  //console.log(this._textFieldWidth, tr_length, maxLineWidth);
12643
13073
  }
12644
13074
  this.lines_wordStartIndices[this.lines_wordStartIndices.length]
12645
- = this._textRuns_words[(this._paragraph_textRuns_indices[p] * 4)];
13075
+ = this._textRuns_words[this._paragraph_textRuns_indices[p]].start;
12646
13076
  this.lines_wordEndIndices[this.lines_wordEndIndices.length] = w_len;
12647
13077
  this.lines_width[this.lines_width.length] = 0;
12648
13078
  this.lines_numSpacesPerline[this.lines_numSpacesPerline.length] = 0;
@@ -12653,18 +13083,19 @@ var TextField = /** @class */ (function (_super) {
12653
13083
  format = this._textRuns_formats[tr];
12654
13084
  format.font_table.initFontSize(format.size);
12655
13085
  indent = format.indent;
12656
- w_len = this._textRuns_words[(tr * 4)] + (this._textRuns_words[(tr * 4) + 1] * 5);
13086
+ w_len = this._textRuns_words[tr].start + this._textRuns_words[tr].count;
12657
13087
  if (tr_length <= maxLineWidth || !this.wordWrap) {
12658
13088
  //if(tr_length<maxLineWidth || !this.wordWrap){
12659
13089
  // this must be a single textline
12660
13090
  //console.log("just add to line",(tr * 4) , w_len, this.words, this._textRuns_words);
12661
- for (w = this._textRuns_words[(tr * 4)]; w < w_len; w += 5) {
12662
- word_width = this.words[w + 3];
13091
+ for (w = this._textRuns_words[tr].start; w < w_len; w += 1) {
13092
+ var word = this.words.get(w);
13093
+ word_width = word.width;
12663
13094
  linelength += word_width;
12664
- this.lines_wordEndIndices[linecnt] = w + 5;
13095
+ this.lines_wordEndIndices[linecnt] = w + 1;
12665
13096
  this.lines_width[linecnt] += word_width;
12666
13097
  lines_formats[linecnt] = format;
12667
- if (this.chars_codes[this.words[w]] == 32 || this.chars_codes[this.words[w]] == 9) {
13098
+ if (this.chars_codes[word.start] == 32 || this.chars_codes[word.start] == 9) {
12668
13099
  this.lines_numSpacesPerline[linecnt] += 1;
12669
13100
  }
12670
13101
  }
@@ -12673,10 +13104,11 @@ var TextField = /** @class */ (function (_super) {
12673
13104
  //console.log("split lines");
12674
13105
  word_width = 0;
12675
13106
  indent = 0;
12676
- for (w = this._textRuns_words[(tr * 4)]; w < w_len; w += 5) {
12677
- word_width = this.words[w + 3];
13107
+ for (w = this._textRuns_words[tr].start; w < w_len; w += 1) {
13108
+ var word = this.words.get(w);
13109
+ word_width = word.width;
12678
13110
  var isSpace = false;
12679
- if (this.chars_codes[this.words[w]] == 32 || this.chars_codes[this.words[w]] == 9) {
13111
+ if (this.chars_codes[word.start] == 32 || this.chars_codes[word.start] == 9) {
12680
13112
  this.lines_numSpacesPerline[linecnt] += 1;
12681
13113
  isSpace = true;
12682
13114
  }
@@ -12684,14 +13116,14 @@ var TextField = /** @class */ (function (_super) {
12684
13116
  if (isSpace
12685
13117
  || (this.lines_width[linecnt] + word_width) <= (maxLineWidth - indent - (1 * format.font_table.getCharWidth('32')))
12686
13118
  || this.lines_width[linecnt] == 0) {
12687
- this.lines_wordEndIndices[linecnt] = w + 5;
13119
+ this.lines_wordEndIndices[linecnt] = w + 1;
12688
13120
  this.lines_width[linecnt] += word_width;
12689
13121
  lines_formats[linecnt] = format;
12690
13122
  }
12691
13123
  else {
12692
13124
  linecnt++;
12693
13125
  this.lines_wordStartIndices[linecnt] = w;
12694
- this.lines_wordEndIndices[linecnt] = w + 5;
13126
+ this.lines_wordEndIndices[linecnt] = w + 1;
12695
13127
  this.lines_width[linecnt] = word_width;
12696
13128
  this.lines_numSpacesPerline[linecnt] = 0;
12697
13129
  this.lines_height[this.lines_height.length] = lines_heights[lineHeightCnt];
@@ -12763,18 +13195,19 @@ var TextField = /** @class */ (function (_super) {
12763
13195
  this.lines_start_y[l] = offsety;
12764
13196
  this.lines_charIdx_start[l] = charCnt;
12765
13197
  var line_width = 0; //format.leftMargin + format.indent + format.rightMargin;
12766
- for (w = start_idx; w < end_idx; w += 5) {
12767
- this.words[w + 1] = offsetx;
13198
+ for (w = start_idx; w < end_idx; w += 1) {
13199
+ var word = this.words.get(w);
13200
+ word.x = offsetx;
12768
13201
  char_pos = 0;
12769
- start_idx = this.words[w];
12770
- c_len = start_idx + this.words[w + 4];
13202
+ start_idx = word.start;
13203
+ c_len = start_idx + word.len;
12771
13204
  var tf = this.tf_per_char[start_idx];
12772
13205
  tf.font_table.initFontSize(tf.size);
12773
13206
  //console.log("lineHeight", lineHeight);
12774
13207
  //console.log("lineHeight", tf.font_table.getLineHeight()+tf.leading);
12775
13208
  var diff = (lineHeight) - (tf.font_table.getLineHeight() + tf.leading);
12776
13209
  diff = ((diff > 0) ? diff - 2 : 0);
12777
- this.words[w + 2] = offsety + diff;
13210
+ word.y = offsety + diff;
12778
13211
  for (c = start_idx; c < c_len; c++) {
12779
13212
  this.char_positions_x[this.char_positions_x.length] = offsetx + char_pos;
12780
13213
  this.char_positions_y[this.char_positions_y.length] = offsety + diff;
@@ -12967,13 +13400,17 @@ var TextField = /** @class */ (function (_super) {
12967
13400
  if (this._textShapesDirty)
12968
13401
  this._clearTextShapes();
12969
13402
  for (var tr = 0; tr < tr_len; tr++) {
12970
- if (tr_words[(tr * 4) + 1] == 0) {
13403
+ var run = tr_words[tr];
13404
+ if (run.count == 0) {
12971
13405
  continue;
12972
13406
  // } else if (tr_words[(tr * 4)] + tr_words[(tr * 4) + 1] * 5 <= this._words_amount_prev) {
12973
13407
  // continue;
12974
13408
  }
12975
13409
  tr_formats[tr].font_table.initFontSize(tr_formats[tr].size);
12976
- tr_formats[tr].font_table.fillTextRun(this, tr_formats[tr], tr_words[(tr * 4)], tr_words[(tr * 4) + 1]);
13410
+ if (Settings.USE_UNSAFE_FNT) {
13411
+ tr_formats[tr].font_table.generateFNTData(null);
13412
+ }
13413
+ tr_formats[tr].font_table.fillTextRun(this, tr_formats[tr], run.start, run.count);
12977
13414
  }
12978
13415
  var textShape;
12979
13416
  for (var key in this.textShapes) {
@@ -12982,32 +13419,49 @@ var TextField = /** @class */ (function (_super) {
12982
13419
  continue;
12983
13420
  }
12984
13421
  var attr = new _awayjs_stage.Float2Attributes(textShape.length / 2);
12985
- var buffer = new Float32Array(attr.attributesBuffer.buffer);
13422
+ var pos = new Float32Array(attr.attributesBuffer.buffer);
13423
+ var uvAttr = textShape.hasUV ? new _awayjs_stage.Float2Attributes(textShape.length / 2) : null;
13424
+ var uvs = uvAttr ? new Float32Array(uvAttr.attributesBuffer.buffer) : null;
13425
+ //console.log('Build shape size:', textShape.length);
12986
13426
  var offset = 0;
12987
- for (var _i = 0, _a = textShape.verts; _i < _a.length; _i++) {
12988
- var chunk = _a[_i];
12989
- buffer.set(chunk, offset);
13427
+ for (var i = 0; i < textShape.verts.length; i++) {
13428
+ var chunk = textShape.verts[i];
13429
+ pos.set(chunk, offset);
13430
+ if (uvs) {
13431
+ uvs.set(textShape.uvs[i], offset);
13432
+ }
12990
13433
  offset += chunk.length;
12991
13434
  }
13435
+ // hack, merge buffer in single
13436
+ // this helps to avoid a lot of set in incremental filling
13437
+ // but anyway is slow
13438
+ textShape.length = 0;
13439
+ textShape.addChunk(pos, uvs);
12992
13440
  if (textShape.shape) {
12993
13441
  var element = textShape.shape.elements;
12994
- // there are bug with attribyte buffer, when add attr to exist
12995
- element.setPositions(buffer);
13442
+ // there are bug with attribute buffer, when add attr to exist
13443
+ element.setPositions(pos);
13444
+ if (uvs) {
13445
+ element.setUVs(uvs);
13446
+ }
12996
13447
  element.invalidate();
12997
13448
  attr.dispose();
13449
+ if (uvAttr) {
13450
+ uvAttr.dispose();
13451
+ }
12998
13452
  continue;
12999
13453
  }
13000
13454
  var color = this.getTextColorForTextFormat(textShape.format);
13001
- var alpha = _awayjs_core.ColorUtils.float32ColorToARGB(color)[0];
13002
- if (alpha == 0) {
13003
- alpha = 255;
13004
- }
13455
+ var alpha = _awayjs_core.ColorUtils.float32ColorToARGB(color)[0] || 255;
13005
13456
  textShape.elements = new _awayjs_renderer.TriangleElements();
13006
13457
  textShape.elements.setPositions(attr);
13458
+ if (uvAttr) {
13459
+ textShape.elements.setUVs(uvAttr);
13460
+ }
13007
13461
  textShape.elements.invalidate();
13008
13462
  textShape.shape = _awayjs_graphics.Shape.getShape(textShape.elements);
13009
13463
  // has BUG for QWOP, temporarily enable it (default)
13010
- textShape.shape.deepHitCheck = true;
13464
+ textShape.shape.deepHitCheck = false;
13011
13465
  textShape.shape.usages++;
13012
13466
  var sampler = new _awayjs_stage.ImageSampler(false, true, true);
13013
13467
  textShape.shape.style = new _awayjs_renderer.Style();
@@ -13920,10 +14374,7 @@ var TextField = /** @class */ (function (_super) {
13920
14374
  };
13921
14375
  TextField.prototype._clearTextShapes = function () {
13922
14376
  this._textShapesDirty = false;
13923
- this.last_word_vertices_count = 0;
13924
- this.tf_per_char_prev.length = 0;
13925
- this.chars_codes_prev.length = 0;
13926
- this._words_amount_prev = 0;
14377
+ this._lastWordsCount = 0;
13927
14378
  if (this.targetGraphics)
13928
14379
  this.targetGraphics.clear();
13929
14380
  var textShape;
@@ -14238,6 +14689,7 @@ var SceneImage2D = /** @class */ (function (_super) {
14238
14689
  //setup the projection
14239
14690
  SceneImage2D._renderer.disableClear = true;
14240
14691
  SceneImage2D._renderer.view.backgroundAlpha = 0;
14692
+ SceneImage2D._renderer.view.backgroundColor = 0x0;
14241
14693
  SceneImage2D._renderer.view.projection = projection;
14242
14694
  SceneImage2D._renderer.view.projection.transform = new _awayjs_core.Transform();
14243
14695
  SceneImage2D._renderer.view.projection.transform.scaleTo(1, -1, 1);
@@ -14260,6 +14712,7 @@ var SceneImage2D = /** @class */ (function (_super) {
14260
14712
  //setup the projection
14261
14713
  SceneImage2D._billboardRenderer.disableClear = true;
14262
14714
  SceneImage2D._billboardRenderer.view.backgroundAlpha = 0;
14715
+ SceneImage2D._billboardRenderer.view.backgroundColor = 0x0;
14263
14716
  SceneImage2D._billboardRenderer.view.projection = projection;
14264
14717
  SceneImage2D._billboardRenderer.view.projection.transform = new _awayjs_core.Transform();
14265
14718
  SceneImage2D._billboardRenderer.view.projection.transform.moveTo(0, 0, -1000);
@@ -14416,7 +14869,18 @@ var SceneImage2D = /** @class */ (function (_super) {
14416
14869
  this.fillRect(this._rect, this._initalFillColor);
14417
14870
  this._initalFillColor = null;
14418
14871
  }
14419
- this._stage.copyPixels(source, this, sourceRect, destPoint, alphaBitmapData, alphaPoint, mergeAlpha);
14872
+ var compositeSource = source;
14873
+ // merge alpha with source
14874
+ if (alphaBitmapData) {
14875
+ compositeSource = this._stage.filterManager.popTemp(source.width, source.height);
14876
+ //this._stage.filterManager.copyPixels(source, compositeSource, source.rect, source.rect.topLeft);
14877
+ this._stage.filterManager.copyPixels(alphaBitmapData, compositeSource, new _awayjs_core.Rectangle(alphaPoint.x, alphaPoint.y, sourceRect.width, sourceRect.height), new _awayjs_core.Point(0, 0));
14878
+ this._stage.filterManager.copyPixels(source, compositeSource, source.rect, new _awayjs_core.Point(0, 0), true, 'alpha_back');
14879
+ }
14880
+ this._stage.filterManager.copyPixels(compositeSource, this, sourceRect, destPoint, mergeAlpha);
14881
+ if (alphaBitmapData) {
14882
+ this._stage.filterManager.pushTemp(compositeSource);
14883
+ }
14420
14884
  this._imageDataDirty = true;
14421
14885
  };
14422
14886
  SceneImage2D.prototype.threshold = function (source, sourceRect, destPoint, operation, threshold, color, mask, copySource) {
@@ -14536,16 +15000,23 @@ var SceneImage2D = /** @class */ (function (_super) {
14536
15000
  this.fillRect(this._rect, this._initalFillColor);
14537
15001
  this._initalFillColor = null;
14538
15002
  }
15003
+ var stage = this._stage;
15004
+ var mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
15005
+ var supportNativeBlend = !blendMode || mappedBlend !== _awayjs_stage.BlendMode.LAYER || blendMode == _awayjs_stage.BlendMode.LAYER;
15006
+ var useTmp = (!supportNativeBlend || this === source);
15007
+ var target = useTmp ?
15008
+ stage.filterManager.popTemp(this.width, this.height, false)
15009
+ : this;
14539
15010
  var renderer = SceneImage2D._billboardRenderer;
14540
15011
  var root = SceneImage2D._billboardRoot;
14541
15012
  var billboard = SceneImage2D._billboard;
14542
15013
  billboard.sampler.smooth = smoothing;
14543
- renderer.disableClear = true;
14544
- renderer.view.target = this;
14545
- renderer.view.projection.scale = 1000 / this.rect.height;
15014
+ renderer.disableClear = !useTmp;
15015
+ renderer.view.target = target;
15016
+ renderer.view.projection.scale = 1000 / target.height;
14546
15017
  billboard.material.style.image = source;
14547
15018
  // not all blend modes can be used for rendering
14548
- billboard.material.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
15019
+ billboard.material.blendMode = !useTmp ? SceneImage2D._mapSupportedBlendMode(blendMode) : _awayjs_stage.BlendMode.LAYER;
14549
15020
  billboard.material.useColorTransform = !!colorTransform;
14550
15021
  if (matrix) {
14551
15022
  var m = root.transform.matrix3D;
@@ -14555,17 +15026,22 @@ var SceneImage2D = /** @class */ (function (_super) {
14555
15026
  m._rawData[4] = matrix.c;
14556
15027
  m._rawData[5] = -matrix.d;
14557
15028
  m._rawData[12] = matrix.tx;
14558
- m._rawData[13] = this.rect.height - matrix.ty;
15029
+ m._rawData[13] = target.height - matrix.ty;
14559
15030
  root.transform.invalidateComponents();
14560
15031
  }
14561
15032
  else {
14562
15033
  root.transform.rotateTo(0, 0, 0);
14563
15034
  root.transform.scaleTo(1, -1, 1);
14564
- root.transform.moveTo(0, this.rect.height, 0);
15035
+ root.transform.moveTo(0, target.height, 0);
14565
15036
  }
14566
15037
  root.transform.colorTransform = colorTransform;
14567
15038
  //render
14568
15039
  renderer.render();
15040
+ //
15041
+ if (useTmp) {
15042
+ stage.filterManager.copyPixels(target, this, this.rect, TMP_POINT, true, blendMode);
15043
+ stage.filterManager.pushTemp(target);
15044
+ }
14569
15045
  };
14570
15046
  SceneImage2D.prototype._drawAsDisplay = function (source, matrix, colorTransform, blendMode, _clipRect, _smoothing) {
14571
15047
  if (blendMode === void 0) { blendMode = ''; }
@@ -16959,25 +17435,27 @@ var AntiAliasType = /** @class */ (function () {
16959
17435
  return AntiAliasType;
16960
17436
  }());
16961
17437
 
16962
- var FNTGenerator = /** @class */ (function () {
17438
+ var FNTGenerator = /** @class */ (function (_super) {
17439
+ __extends(FNTGenerator, _super);
16963
17440
  function FNTGenerator(stage) {
16964
- this._stage = stage;
17441
+ var _this = _super.call(this, stage) || this;
16965
17442
  //create the projection
16966
17443
  var projection = new _awayjs_core.PerspectiveProjection();
16967
17444
  projection.coordinateSystem = _awayjs_core.CoordinateSystem.RIGHT_HANDED;
16968
17445
  projection.originX = -1;
16969
17446
  projection.originY = 1;
16970
17447
  //create the view
16971
- this._root = new DisplayObjectContainer();
16972
- this._renderer = _awayjs_renderer.RenderGroup
17448
+ _this._root = new DisplayObjectContainer();
17449
+ _this._renderer = _awayjs_renderer.RenderGroup
16973
17450
  .getInstance(new _awayjs_view.View(projection, stage, null, null, null, true), _awayjs_renderer.DefaultRenderer)
16974
- .getRenderer(_awayjs_view.NodePool.getRootNode(this._root, _awayjs_view.BasicPartition).partition);
17451
+ .getRenderer(_awayjs_view.NodePool.getRootNode(_this._root, _awayjs_view.BasicPartition).partition);
16975
17452
  //setup the projection
16976
- this._renderer.view.projection = projection;
16977
- this._renderer.view.projection.transform = new _awayjs_core.Transform();
16978
- this._renderer.view.projection.transform.moveTo(0, 0, -1000);
16979
- this._renderer.view.projection.transform.lookAt(new _awayjs_core.Vector3D());
16980
- this._renderer.renderableSorter = null; //new RenderableSort2D();
17453
+ _this._renderer.view.projection = projection;
17454
+ _this._renderer.view.projection.transform = new _awayjs_core.Transform();
17455
+ _this._renderer.view.projection.transform.moveTo(0, 0, -1000);
17456
+ _this._renderer.view.projection.transform.lookAt(new _awayjs_core.Vector3D());
17457
+ _this._renderer.renderableSorter = null; //new RenderableSort2D();
17458
+ return _this;
16981
17459
  }
16982
17460
  FNTGenerator.prototype.generate = function (font, maxSize, fontSize, padding) {
16983
17461
  var outputBitmap;
@@ -17019,7 +17497,7 @@ var FNTGenerator = /** @class */ (function () {
17019
17497
  return outputBitmaps;
17020
17498
  };
17021
17499
  return FNTGenerator;
17022
- }());
17500
+ }(FNTGeneratorBase));
17023
17501
 
17024
17502
  /**
17025
17503
  * The GridFitType class defines values for grid fitting in the TextField class.
@@ -17886,7 +18364,7 @@ var Scene = /** @class */ (function () {
17886
18364
  _awayjs_graphics.MaterialManager.materialClass = _awayjs_materials.MethodMaterial;
17887
18365
  _awayjs_graphics.MaterialManager.textureClass = _awayjs_renderer.ImageTexture2D;
17888
18366
 
17889
- console.debug('AwayJS - Scene - 0.13.226');
18367
+ console.debug('AwayJS - Scene - 0.13.232');
17890
18368
 
17891
18369
  exports.Timeline = Timeline;
17892
18370
  exports.ControllerBase = ControllerBase;