@awayjs/scene 0.13.223 → 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 (50) hide show
  1. package/bundle/awayjs-scene.umd.js +879 -417
  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/DisplayObjectContainer.d.ts +1 -0
  10. package/dist/lib/display/DisplayObjectContainer.d.ts.map +1 -1
  11. package/dist/lib/display/DisplayObjectContainer.js +4 -2
  12. package/dist/lib/display/TextField.d.ts +36 -5
  13. package/dist/lib/display/TextField.d.ts.map +1 -1
  14. package/dist/lib/display/TextField.js +227 -138
  15. package/dist/lib/image/SceneImage2D.d.ts.map +1 -1
  16. package/dist/lib/image/SceneImage2D.js +35 -8
  17. package/dist/lib/managers/MouseManager.d.ts +1 -1
  18. package/dist/lib/managers/MouseManager.d.ts.map +1 -1
  19. package/dist/lib/managers/MouseManager.js +9 -29
  20. package/dist/lib/text/FNTGenerator.d.ts +5 -4
  21. package/dist/lib/text/FNTGenerator.d.ts.map +1 -1
  22. package/dist/lib/text/FNTGenerator.js +15 -11
  23. package/dist/lib/text/FNTGeneratorCanvas.d.ts +23 -0
  24. package/dist/lib/text/FNTGeneratorCanvas.d.ts.map +1 -0
  25. package/dist/lib/text/FNTGeneratorCanvas.js +205 -0
  26. package/dist/lib/text/FNTGeneratrorBase.d.ts +8 -0
  27. package/dist/lib/text/FNTGeneratrorBase.d.ts.map +1 -0
  28. package/dist/lib/text/FNTGeneratrorBase.js +7 -0
  29. package/dist/lib/text/TesselatedFontChar.d.ts +6 -4
  30. package/dist/lib/text/TesselatedFontChar.d.ts.map +1 -1
  31. package/dist/lib/text/TesselatedFontChar.js +8 -3
  32. package/dist/lib/text/TesselatedFontTable.d.ts +19 -3
  33. package/dist/lib/text/TesselatedFontTable.d.ts.map +1 -1
  34. package/dist/lib/text/TesselatedFontTable.js +339 -225
  35. package/dist/lib/text/TextShape.d.ts +6 -3
  36. package/dist/lib/text/TextShape.d.ts.map +1 -1
  37. package/dist/lib/text/TextShape.js +27 -2
  38. package/index.ts +1 -1
  39. package/lib/Settings.ts +20 -1
  40. package/lib/display/DisplayObjectContainer.ts +4 -2
  41. package/lib/display/TextField.ts +317 -145
  42. package/lib/image/SceneImage2D.ts +84 -9
  43. package/lib/managers/MouseManager.ts +11 -30
  44. package/lib/text/FNTGenerator.ts +5 -7
  45. package/lib/text/FNTGeneratorCanvas.ts +288 -0
  46. package/lib/text/FNTGeneratrorBase.ts +11 -0
  47. package/lib/text/TesselatedFontChar.ts +8 -12
  48. package/lib/text/TesselatedFontTable.ts +438 -255
  49. package/lib/text/TextShape.ts +30 -3
  50. package/package.json +1 -1
@@ -30,6 +30,78 @@ import { ITextfieldAdapter } from '../adapters/ITextfieldAdapter';
30
30
  import { HTMLTextProcessor } from '../text/HTMLTextProcessor';
31
31
  import { TextFormatAlign } from '../text/TextFormatAlign';
32
32
  import { MouseEvent } from '../events/MouseEvent';
33
+ import { Settings } from '../Settings';
34
+
35
+ interface IWord {
36
+ start: number;
37
+ x: number;
38
+ y: number;
39
+ width: number;
40
+ len: number;
41
+ }
42
+
43
+ interface IRunEntry {
44
+ start: number,
45
+ count: number,
46
+ width: number,
47
+ space: number
48
+ }
49
+
50
+ class WordStore {
51
+ store: Array<IWord>;
52
+ index: number = -1;
53
+
54
+ constructor(size = 40) {
55
+ this.store = Array.from({ length: size }, e => ({
56
+ x: Infinity, y: Infinity, start: 0, width: 0, len: 0
57
+ }));
58
+ }
59
+
60
+ public put (
61
+ start: number,
62
+ x: number,
63
+ y: number,
64
+ width: number,
65
+ len: number
66
+ ): IWord {
67
+ this.index++;
68
+
69
+ const word = this.store [this.index] || (this.store [this.index] = {} as IWord);
70
+
71
+ word.start = start;
72
+ word.x = x;
73
+ word.y = y;
74
+ word.width = width;
75
+ word.len = len;
76
+
77
+ return word;
78
+ }
79
+
80
+ public get last(): IWord {
81
+ return this.store[this.index];
82
+ }
83
+
84
+ public get length () {
85
+ return this.index + 1;
86
+ }
87
+
88
+ public set length (v: number) {
89
+ this.index = v - 1;
90
+ }
91
+
92
+ public get (index: number) {
93
+ return this.store[index];
94
+ }
95
+
96
+ public free() {
97
+ this.index = -1;
98
+ }
99
+
100
+ public dispose() {
101
+ this.store = null;
102
+ this.index = 0;
103
+ }
104
+ }
33
105
 
34
106
  const enum CHAR_CODES {
35
107
  TAB = 9,
@@ -164,7 +236,22 @@ export class TextField extends DisplayObjectContainer {
164
236
  private _selectionEndIndex: number = 0;
165
237
  private _biggestLine: number=0;
166
238
 
239
+ /**
240
+ * Renderable text, used for computing a glyphs
241
+ * @private
242
+ */
167
243
  private _iText: string = '';
244
+
245
+ /**
246
+ * Place where is diff is begun to end
247
+ * @private
248
+ */
249
+ private _iTextDiffStart = 0;
250
+
251
+ /**
252
+ * Original text passed to field
253
+ * @private
254
+ */
168
255
  private _text: string = '';
169
256
  private _iTextWoLineBreaks: string = ''; // _iText without line breaks
170
257
  private _textInteractionMode: TextInteractionMode;
@@ -205,20 +292,18 @@ export class TextField extends DisplayObjectContainer {
205
292
  public _textShapesDirty: Boolean = false;
206
293
 
207
294
  public chars_codes: number[] = [];
208
- private chars_codes_prev: number[] = [];
209
295
  public chars_width: number[] = [];
210
296
  public tf_per_char: TextFormat[] = [];
211
- public tf_per_char_prev: TextFormat[] = [];
212
297
 
213
- // we use that for text appending to save verts count before last word verts are added to textShape.
214
- // Then on text append we clear last word verts because the word may be wrapped to next line
215
- public last_word_vertices_count: number = 0;
298
+ // stores offset and length and width for each word
299
+ public words: WordStore = new WordStore(10);
216
300
 
217
- public words: number[]=[]; // stores offset and length and width for each word
301
+ // Amount of words that was before call reconstuct
302
+ /*internal*/ _lastWordsCount: number;
218
303
 
219
304
  private _textRuns_formats: TextFormat[]=[]; // stores textFormat for each textrun
220
- private _textRuns_words: number[]=[]; // stores words-offset, word-count and width for each textrun
221
- public _words_amount_prev: number;
305
+ // stores words-offset, word-count and width for each textrun
306
+ private _textRuns_words: Array<IRunEntry> = [];
222
307
  private _paragraph_textRuns_indices: number[]=[]; // stores textFormat for each textrun
223
308
 
224
309
  private _maxWidthLine: number=0;
@@ -659,12 +744,11 @@ export class TextField extends DisplayObjectContainer {
659
744
  }
660
745
 
661
746
  public getTextShapeForIdentifierAndFormat(id: string, format: TextFormat) {
662
- if (this.textShapes.hasOwnProperty(id)) {
747
+ if (this.textShapes[id]) {
663
748
  return this.textShapes[id];
664
749
  }
665
- this.textShapes[id] = new TextShape();
666
- this.textShapes[id].format = format;
667
- return this.textShapes[id];
750
+
751
+ return (this.textShapes[id] = new TextShape(format, id));
668
752
  }
669
753
 
670
754
  /**
@@ -1348,16 +1432,25 @@ export class TextField extends DisplayObjectContainer {
1348
1432
  }
1349
1433
 
1350
1434
  public set scrollV(value: number) /*int*/ {
1351
- if (Math.floor(value) == this._scrollV)
1435
+ const rounded = Math.round(value);
1436
+
1437
+ if (rounded === this._scrollV)
1352
1438
  return;
1353
- this._scrollV = Math.floor(value);
1439
+
1440
+ this._scrollV = rounded;
1354
1441
 
1355
1442
  if (this._scrollV > this._maxScrollV)
1356
1443
  this._scrollV = this._maxScrollV;
1357
1444
 
1445
+ if (this._scrollV <= 0) {
1446
+ this._scrollV = 0;
1447
+ }
1448
+
1358
1449
  if (!this.textChild) {
1359
1450
  return;
1360
1451
  }
1452
+
1453
+ // unsafe
1361
1454
  this.textChild.y = -this.lines_start_y[this._scrollV];
1362
1455
  }
1363
1456
 
@@ -1479,13 +1572,6 @@ export class TextField extends DisplayObjectContainer {
1479
1572
  this._labelData = null;
1480
1573
  this._text = value;
1481
1574
 
1482
- /*
1483
- for (let i = 0; i < this._text.length; i++) {
1484
- const charCode = this._text.charCodeAt(i);
1485
- if (this._text)
1486
- console.log("charcodes", this._text[i], this._text.charCodeAt(i));
1487
- }*/
1488
-
1489
1575
  if (value != '' && ((value.charCodeAt(value.length - 1) == 13) || (value.charCodeAt(value.length - 1) == 10))) {
1490
1576
  value = value.slice(0, value.length - 1);
1491
1577
  }
@@ -1923,7 +2009,6 @@ export class TextField extends DisplayObjectContainer {
1923
2009
 
1924
2010
  public clear(): void {
1925
2011
  super.clear();
1926
-
1927
2012
  }
1928
2013
 
1929
2014
  /**
@@ -1965,6 +2050,7 @@ export class TextField extends DisplayObjectContainer {
1965
2050
  this._labelData = null;
1966
2051
  }
1967
2052
 
2053
+ this._resetParagraph();
1968
2054
  this._clearTextShapes();
1969
2055
 
1970
2056
  this._textFormat = null;
@@ -1994,22 +2080,10 @@ export class TextField extends DisplayObjectContainer {
1994
2080
 
1995
2081
  if (this._textDirty) {
1996
2082
  this._positionsDirty = true;
1997
-
1998
- this.chars_codes_prev = Array.from(this.chars_codes);
1999
- this.tf_per_char_prev = Array.from(this.tf_per_char);
2000
- // we do not use last word since last word may changed.
2001
- // For example "Hello w" and "Hello world" both have 3 words but the last word actually changed
2002
-
2003
- this._words_amount_prev = this.words.length;
2004
- this.chars_codes.length = 0;
2005
- this.chars_width.length = 0;
2083
+ this._lastWordsCount = this.words.length;
2006
2084
  this.char_positions_x.length = 0;
2007
2085
  this.char_positions_y.length = 0;
2008
- this.tf_per_char.length = 0;
2009
2086
  this.words.length = 0;
2010
- this._textRuns_words.length = 0;
2011
- this._textRuns_formats.length = 0;
2012
- this._paragraph_textRuns_indices.length = 0;
2013
2087
  this.lines_wordStartIndices.length = 0;
2014
2088
  this.lines_wordEndIndices.length = 0;
2015
2089
  this.lines_start_y.length = 0;
@@ -2022,7 +2096,6 @@ export class TextField extends DisplayObjectContainer {
2022
2096
 
2023
2097
  this._maxScrollH = 0;
2024
2098
  this._maxScrollV = 0;
2025
-
2026
2099
  this._maxWidthLine = 0;
2027
2100
 
2028
2101
  // sometimes needed for TLFTextfields
@@ -2030,10 +2103,7 @@ export class TextField extends DisplayObjectContainer {
2030
2103
  if (!this._textFormat && this._textFormats.length > 0)
2031
2104
  this._textFormat = this._textFormats[0];
2032
2105
 
2033
- if (this._iText != '' && this._textFormat != null) {
2034
- //console.log("textlength", this.text.toString().length, this.text.toString());
2035
- this.buildParagraphs();
2036
- }
2106
+ this.buildParagraphs();
2037
2107
 
2038
2108
  //console.log("TextField buildParagraph", this.id, this._iText);
2039
2109
  //console.log("TextField buildParagraph", this.id, this._autoSize);
@@ -2090,16 +2160,6 @@ export class TextField extends DisplayObjectContainer {
2090
2160
  // the data for new text-shapes is collected from the font-tables
2091
2161
  // and the new text-shapes are created and assigned to the graphics
2092
2162
 
2093
- if (this._textShapesDirty) {
2094
- // do nothing
2095
- } else if (this.chars_codes_prev.length == 0) {
2096
- // do nothing
2097
- } else if (this.chars_codes_prev.length > this.chars_codes.length) {
2098
- this._textShapesDirty = true;
2099
- } else if (this.chars_codes_prev[0] !== this.chars_codes[0]) {
2100
- this._textShapesDirty = true;
2101
- }
2102
-
2103
2163
  if (this._glyphsDirty) {
2104
2164
  //console.log("TextField buildGlyphs", this.id, this.words);
2105
2165
  if (this._labelData) {
@@ -2153,17 +2213,79 @@ export class TextField extends DisplayObjectContainer {
2153
2213
  this.text = paste;
2154
2214
  }
2155
2215
 
2216
+ private _resetParagraph() {
2217
+ this._textShapesDirty = this._textShapesDirty || this.chars_codes.length > 0;
2218
+
2219
+ this.tf_per_char.length = 0;
2220
+ this.chars_width.length = 0;
2221
+ this.chars_codes.length = 0;
2222
+ this._paragraph_textRuns_indices.length = 0;
2223
+ this._textRuns_formats.length = 0;
2224
+ this._textRuns_words.length = 0;
2225
+ }
2226
+
2156
2227
  private buildParagraphs() {
2157
- const thisText = this._iText.toString();
2158
- const f_len = this._textFormatsIdx.length;
2228
+ if (!this._textDirty) {
2229
+ return;
2230
+ }
2231
+
2232
+ // clear paragraph data when clear
2233
+ if (this._iText === '' || !this._textFormat) {
2234
+ this._resetParagraph();
2235
+ return;
2236
+ }
2237
+
2238
+ let paragraphIndex = 0;
2239
+ let formatIndex = 0;
2240
+ let wordIndex = 0;
2241
+ let charCodeIndex = 0;
2159
2242
 
2243
+ // track char mutations between new and older.
2244
+ let codeChanges = 0;
2160
2245
  let linewidth = 0;
2161
2246
  let c_start = 0;
2162
2247
 
2163
- this._paragraph_textRuns_indices[this._paragraph_textRuns_indices.length] = this._textRuns_formats.length;
2248
+ const thisText = this._iText;
2249
+ const formatsCount = this._textFormatsIdx.length;
2250
+ const paragraphIndices = this._paragraph_textRuns_indices;
2251
+ const textRunFormats = this._textRuns_formats;
2252
+ const textRunWords = this._textRuns_words;
2253
+ const charCodes = this.chars_codes;
2254
+ const charTextFormats = this.tf_per_char;
2255
+ const charWidths = this.chars_width;
2256
+
2257
+ const pushParagraph = (formatIndex: number) => {
2258
+ paragraphIndices[paragraphIndex] = formatIndex;
2259
+ paragraphIndex++;
2260
+ };
2261
+
2262
+ const pushFormat = (format: TextFormat, updateParagraph = false) => {
2263
+ updateParagraph && pushParagraph(formatIndex);
2264
+ textRunFormats[formatIndex++] = format;
2265
+ return format;
2266
+ };
2267
+
2268
+ const pushRunEntry = (word: IRunEntry) => {
2269
+ textRunWords[wordIndex++] = word;
2270
+ return word;
2271
+ };
2272
+
2273
+ const pushCharData = (code: number, tf: TextFormat, width: number) => {
2274
+ codeChanges += +(code !== charCodes[charCodeIndex]);
2275
+ codeChanges += +(tf !== charTextFormats[charCodeIndex]);
2276
+ codeChanges += +(width !== charWidths[charCodeIndex]);
2277
+
2278
+ charCodes[charCodeIndex] = code;
2279
+ charTextFormats[charCodeIndex] = tf;
2280
+ charWidths[charCodeIndex] = width;
2281
+
2282
+ charCodeIndex++;
2283
+ };
2284
+
2285
+ pushParagraph(formatIndex);
2164
2286
 
2165
2287
  // loop over all textFormats
2166
- for (let f = 0; f < f_len; f++) {
2288
+ for (let f = 0; f < formatsCount; f++) {
2167
2289
  let word_cnt = 0;
2168
2290
  let whitespace_cnt = 0;
2169
2291
  let startNewWord = true;
@@ -2173,13 +2295,20 @@ export class TextField extends DisplayObjectContainer {
2173
2295
 
2174
2296
  tf.font_table.initFontSize(tf.size);
2175
2297
  // if that is last format then it goes till the end of text:
2176
- const c_end = (f === f_len - 1) ? thisText.length : this._textFormatsIdx[f];
2298
+ const c_end = (f === formatsCount - 1) ? thisText.length : this._textFormatsIdx[f];
2177
2299
 
2178
2300
  if (c_end > c_start) {
2179
2301
 
2180
2302
  // create a new textrun
2181
- this._textRuns_formats[this._textRuns_formats.length] = tf;
2182
- this._textRuns_words[this._textRuns_words.length] = this.words.length;
2303
+ pushFormat(tf);
2304
+
2305
+ let run = pushRunEntry({
2306
+ start: this.words.length,
2307
+ count: 0,
2308
+ width: 0,
2309
+ space: 0
2310
+ });
2311
+
2183
2312
  // loop over all chars for this format
2184
2313
  //console.log("textrun tf = ", tf);
2185
2314
  for (let c = c_start; c < c_end; c++) {
@@ -2208,20 +2337,19 @@ export class TextField extends DisplayObjectContainer {
2208
2337
  const isLineBreak = char_code === CHAR_CODES.LF;
2209
2338
 
2210
2339
  if (isLineBreak) {
2340
+ run.count = word_cnt;
2341
+ run.width = linewidth;
2342
+ run.space = whitespace_cnt;
2211
2343
 
2212
- this._textRuns_words[this._textRuns_words.length] = word_cnt;
2213
- this._textRuns_words[this._textRuns_words.length] = linewidth;
2214
- this._textRuns_words[this._textRuns_words.length] = whitespace_cnt;
2215
-
2216
- this._paragraph_textRuns_indices[this._paragraph_textRuns_indices.length] =
2217
- this._textRuns_formats.length;
2218
2344
  // create a new textrun
2219
- this._textRuns_formats[this._textRuns_formats.length] = tf;
2220
- this._textRuns_words[this._textRuns_words.length] = this.words.length;
2345
+ pushFormat(tf, true);
2221
2346
 
2222
- // this.chars_codes[this.chars_codes.length] = 55;
2223
- // this.chars_width[this.chars_width.length] = 0;
2224
- // this.tf_per_char[this.tf_per_char.length] = tf;
2347
+ run = pushRunEntry({
2348
+ start: this.words.length,
2349
+ count: 0,
2350
+ width: 0,
2351
+ space: 0
2352
+ });
2225
2353
 
2226
2354
  startNewWord = true;
2227
2355
  whitespace_cnt = 0;
@@ -2234,9 +2362,6 @@ export class TextField extends DisplayObjectContainer {
2234
2362
  continue;
2235
2363
  }
2236
2364
 
2237
- this.chars_codes[this.chars_codes.length] = char_code;
2238
- this.tf_per_char[this.tf_per_char.length] = tf;
2239
-
2240
2365
  let char_width = tf.font_table.getCharWidth(char_code.toString());
2241
2366
 
2242
2367
  const isSpace = char_code == CHAR_CODES.TAB || char_code == CHAR_CODES.SPACE;
@@ -2250,7 +2375,8 @@ export class TextField extends DisplayObjectContainer {
2250
2375
  }
2251
2376
 
2252
2377
  linewidth += char_width;
2253
- this.chars_width[this.chars_width.length] = char_width;
2378
+
2379
+ pushCharData(char_code, tf, char_width);
2254
2380
 
2255
2381
  // we create a new word if the char is either:
2256
2382
  // - first char of paragraph
@@ -2259,46 +2385,48 @@ export class TextField extends DisplayObjectContainer {
2259
2385
  if (isSpace) {
2260
2386
  //console.log("add WhiteSpace");
2261
2387
  whitespace_cnt++;
2262
- this.words[this.words.length] = this.chars_codes.length - 1; // index into chars
2263
- this.words[this.words.length] = 0; // x-position
2264
- this.words[this.words.length] = 0; // y-position
2265
- this.words[this.words.length] = char_width; // word width
2266
- this.words[this.words.length] = 1; // char count
2388
+ this.words.put(
2389
+ charCodeIndex - 1,
2390
+ 0, 0,
2391
+ char_width,
2392
+ 1
2393
+ );
2267
2394
  word_cnt++;
2268
2395
  // we also make sure to begin a new word for next char (could be whitespace again)
2269
2396
  startNewWord = true;
2270
2397
  } else {
2271
2398
  // no whitespace
2272
2399
 
2273
- if (this._autoSize == TextFieldAutoSize.NONE && this._wordWrap) {
2274
- if (this.words[this.words.length - 2] + char_width >= maxLineWidth) {
2400
+ if (word_cnt > 0 && this._autoSize == TextFieldAutoSize.NONE && this._wordWrap) {
2401
+ if (this.words.last.width + char_width >= maxLineWidth) {
2275
2402
  startNewWord = true;
2276
2403
  }
2277
-
2278
2404
  }
2279
2405
 
2280
2406
  if (startNewWord) {
2281
2407
  //console.log("startNewWord");
2282
2408
  // create new word (either this is the first char, or the last char was whitespace)
2283
- this.words[this.words.length] = this.chars_codes.length - 1; // index into chars
2284
- this.words[this.words.length] = 0; // x-position
2285
- this.words[this.words.length] = 0; // y-position
2286
- this.words[this.words.length] = char_width; // word width
2287
- this.words[this.words.length] = 1; // char count
2409
+ this.words.put(
2410
+ charCodeIndex - 1,
2411
+ 0, 0,
2412
+ char_width,
2413
+ 1
2414
+ );
2415
+
2288
2416
  word_cnt++;
2289
2417
  } else {
2290
2418
  // update-char length and width of active word.
2291
- this.words[this.words.length - 2] += char_width;
2292
- this.words[this.words.length - 1]++;
2419
+ this.words.last.width += char_width;
2420
+ this.words.last.len += 1;
2293
2421
  }
2294
2422
 
2295
2423
  startNewWord = false;
2296
2424
  }
2297
2425
  }
2298
2426
 
2299
- this._textRuns_words[this._textRuns_words.length] = word_cnt;
2300
- this._textRuns_words[this._textRuns_words.length] = linewidth;
2301
- this._textRuns_words[this._textRuns_words.length] = whitespace_cnt;
2427
+ run.count = word_cnt;
2428
+ run.width = linewidth;
2429
+ run.space = whitespace_cnt;
2302
2430
 
2303
2431
  if (this._maxWidthLine < linewidth) {
2304
2432
  this._maxWidthLine = linewidth;
@@ -2308,27 +2436,19 @@ export class TextField extends DisplayObjectContainer {
2308
2436
  c_start = c_end;
2309
2437
  }
2310
2438
 
2311
- // run through all the chars to check if new text is just old text with some data appended
2312
- if (this.chars_codes_prev.length == 0) {
2313
- return;
2314
- } else if (this.chars_codes_prev[0] !== this.chars_codes[0]) {
2315
- this._textShapesDirty = true;
2316
- return;
2317
- }
2318
-
2319
- for (let c = this.chars_codes.length - 1; c >= 0; c--) {
2320
- const char_code = this.chars_codes[c];
2321
- const tf = this.tf_per_char_prev[c];
2439
+ this._textShapesDirty = (
2440
+ this._textShapesDirty ||
2441
+ codeChanges > 0 ||
2442
+ charCodes.length !== charCodeIndex
2443
+ );
2322
2444
 
2323
- if (
2324
- // this.chars_codes_prev.length <= this.chars_codes.length &&
2325
- this.chars_codes_prev[c] &&
2326
- (this.chars_codes_prev[c] != char_code
2327
- || (<any> this.tf_per_char_prev[c])._style_name != (<any>tf)._style_name)) {
2328
- this._textShapesDirty = true;
2329
- break;
2330
- }
2331
- }
2445
+ // reduce paragraph count if will be greater that older
2446
+ paragraphIndices.length = paragraphIndex;
2447
+ textRunWords.length = wordIndex;
2448
+ textRunFormats.length = formatIndex;
2449
+ charCodes.length = charCodeIndex;
2450
+ charTextFormats.length = charCodeIndex;
2451
+ charWidths.length = charCodeIndex;
2332
2452
  }
2333
2453
 
2334
2454
  private adjustPositionForAutoSize(newWidth: number) {
@@ -2413,13 +2533,13 @@ export class TextField extends DisplayObjectContainer {
2413
2533
  }
2414
2534
 
2415
2535
  //console.log("process word positions for textrun", tr, "textruns", this._textRuns_words);
2416
- w_len = this._textRuns_words[(tr * 4)] + (this._textRuns_words[(tr * 4) + 1] * 5);
2417
- tr_length += this._textRuns_words[(tr * 4) + 2];
2536
+ w_len = this._textRuns_words[tr].start + this._textRuns_words[tr].count;
2537
+ tr_length += this._textRuns_words[tr].width;
2418
2538
  //console.log(this._textFieldWidth, tr_length, maxLineWidth);
2419
2539
  }
2420
2540
 
2421
2541
  this.lines_wordStartIndices[this.lines_wordStartIndices.length]
2422
- = this._textRuns_words[(this._paragraph_textRuns_indices[p] * 4)];
2542
+ = this._textRuns_words[this._paragraph_textRuns_indices[p]].start;
2423
2543
  this.lines_wordEndIndices[this.lines_wordEndIndices.length] = w_len;
2424
2544
  this.lines_width[this.lines_width.length] = 0;
2425
2545
  this.lines_numSpacesPerline[this.lines_numSpacesPerline.length] = 0;
@@ -2431,18 +2551,23 @@ export class TextField extends DisplayObjectContainer {
2431
2551
  format = this._textRuns_formats[tr];
2432
2552
  format.font_table.initFontSize(format.size);
2433
2553
  indent = format.indent;
2434
- w_len = this._textRuns_words[(tr * 4)] + (this._textRuns_words[(tr * 4) + 1] * 5);
2554
+ w_len = this._textRuns_words[tr].start + this._textRuns_words[tr].count;
2435
2555
  if (tr_length <= maxLineWidth || !this.wordWrap) {
2436
2556
  //if(tr_length<maxLineWidth || !this.wordWrap){
2437
2557
  // this must be a single textline
2438
2558
  //console.log("just add to line",(tr * 4) , w_len, this.words, this._textRuns_words);
2439
- for (w = this._textRuns_words[(tr * 4)]; w < w_len; w += 5) {
2440
- word_width = this.words[w + 3];
2559
+ for (w = this._textRuns_words[tr].start; w < w_len; w += 1) {
2560
+ const word = this.words.get(w);
2561
+
2562
+ word_width = word.width;
2441
2563
  linelength += word_width;
2442
- this.lines_wordEndIndices[linecnt] = w + 5;
2564
+
2565
+ this.lines_wordEndIndices[linecnt] = w + 1;
2443
2566
  this.lines_width[linecnt] += word_width;
2567
+
2444
2568
  lines_formats[linecnt] = format;
2445
- if (this.chars_codes[this.words[w]] == 32 || this.chars_codes[this.words[w]] == 9) {
2569
+
2570
+ if (this.chars_codes[word.start] == 32 || this.chars_codes[word.start] == 9) {
2446
2571
  this.lines_numSpacesPerline[linecnt] += 1;
2447
2572
  }
2448
2573
  }
@@ -2450,28 +2575,35 @@ export class TextField extends DisplayObjectContainer {
2450
2575
  //console.log("split lines");
2451
2576
  word_width = 0;
2452
2577
  indent = 0;
2453
- for (w = this._textRuns_words[(tr * 4)]; w < w_len; w += 5) {
2454
- word_width = this.words[w + 3];
2578
+
2579
+ for (w = this._textRuns_words[tr].start; w < w_len; w += 1) {
2580
+ const word = this.words.get(w);
2581
+
2582
+ word_width = word.width;
2583
+
2455
2584
  let isSpace: boolean = false;
2456
- if (this.chars_codes[this.words[w]] == 32 || this.chars_codes[this.words[w]] == 9) {
2585
+
2586
+ if (this.chars_codes[word.start] == 32 || this.chars_codes[word.start] == 9) {
2457
2587
  this.lines_numSpacesPerline[linecnt] += 1;
2458
2588
  isSpace = true;
2459
2589
  }
2590
+
2460
2591
  // (1.5* format.font_table.getCharWidth("32")) is to replicate flash behavior
2461
2592
  if (isSpace
2462
2593
  || (this.lines_width[linecnt] + word_width) <= (
2463
2594
  maxLineWidth - indent - (1 * format.font_table.getCharWidth('32')))
2464
2595
  || this.lines_width[linecnt] == 0) {
2465
- this.lines_wordEndIndices[linecnt] = w + 5;
2596
+ this.lines_wordEndIndices[linecnt] = w + 1;
2466
2597
  this.lines_width[linecnt] += word_width;
2467
2598
  lines_formats[linecnt] = format;
2468
2599
  } else {
2469
2600
  linecnt++;
2470
2601
  this.lines_wordStartIndices[linecnt] = w;
2471
- this.lines_wordEndIndices[linecnt] = w + 5;
2602
+ this.lines_wordEndIndices[linecnt] = w + 1;
2472
2603
  this.lines_width[linecnt] = word_width;
2473
2604
  this.lines_numSpacesPerline[linecnt] = 0;
2474
2605
  this.lines_height[this.lines_height.length] = lines_heights[lineHeightCnt];
2606
+
2475
2607
  lines_formats[linecnt] = format;
2476
2608
  indent = format.indent;
2477
2609
  }
@@ -2542,28 +2674,35 @@ export class TextField extends DisplayObjectContainer {
2542
2674
  this.lines_start_y[l] = offsety;
2543
2675
  this.lines_charIdx_start[l] = charCnt;
2544
2676
  let line_width = 0;//format.leftMargin + format.indent + format.rightMargin;
2545
- for (w = start_idx; w < end_idx; w += 5) {
2546
- this.words[w + 1] = offsetx;
2677
+
2678
+ for (w = start_idx; w < end_idx; w += 1) {
2679
+ const word = this.words.get(w);
2680
+
2681
+ word.x = offsetx;
2547
2682
  char_pos = 0;
2548
- start_idx = this.words[w];
2549
- c_len = start_idx + this.words[w + 4];
2683
+ start_idx = word.start;
2684
+ c_len = start_idx + word.len;
2685
+
2550
2686
  const tf = this.tf_per_char[start_idx];
2551
2687
  tf.font_table.initFontSize(tf.size);
2552
2688
  //console.log("lineHeight", lineHeight);
2553
2689
  //console.log("lineHeight", tf.font_table.getLineHeight()+tf.leading);
2554
2690
  let diff = (lineHeight) - (tf.font_table.getLineHeight() + tf.leading);
2555
2691
  diff = ((diff > 0) ? diff - 2 : 0);
2556
- this.words[w + 2] = offsety + diff;
2692
+ word.y = offsety + diff;
2693
+
2557
2694
  for (c = start_idx; c < c_len; c++) {
2558
2695
  this.char_positions_x[this.char_positions_x.length] = offsetx + char_pos;
2559
2696
  this.char_positions_y[this.char_positions_y.length] = offsety + diff;
2560
2697
  char_pos += this.chars_width[c];
2561
2698
  charCnt++;
2562
2699
  }
2700
+
2563
2701
  //console.log("word_width", char_pos, "word:'"+wordstr+"'");
2564
2702
  offsetx += char_pos;//this.words[w + 3];
2565
2703
  line_width += char_pos;//this.words[w + 3];
2566
2704
  }
2705
+
2567
2706
  this.lines_charIdx_end[l] = charCnt;
2568
2707
  //console.log("line_width",line_width);
2569
2708
  offsety += lineHeight;
@@ -2772,15 +2911,22 @@ export class TextField extends DisplayObjectContainer {
2772
2911
  if (this._textShapesDirty) this._clearTextShapes();
2773
2912
 
2774
2913
  for (let tr = 0; tr < tr_len; tr++) {
2775
- if (tr_words[(tr * 4) + 1] == 0) {
2914
+ const run = tr_words[tr];
2915
+
2916
+ if (run.count == 0) {
2776
2917
  continue;
2777
2918
  // } else if (tr_words[(tr * 4)] + tr_words[(tr * 4) + 1] * 5 <= this._words_amount_prev) {
2778
2919
  // continue;
2779
2920
  }
2921
+
2780
2922
  tr_formats[tr].font_table.initFontSize(tr_formats[tr].size);
2781
2923
 
2924
+ if (Settings.USE_UNSAFE_FNT) {
2925
+ (tr_formats[tr].font_table as TesselatedFontTable).generateFNTData(null);
2926
+ }
2927
+
2782
2928
  tr_formats[tr].font_table.fillTextRun(
2783
- this, tr_formats[tr], tr_words[(tr * 4)], tr_words[(tr * 4) + 1]);
2929
+ this, tr_formats[tr], run.start, run.count);
2784
2930
  }
2785
2931
 
2786
2932
  let textShape: TextShape;
@@ -2793,38 +2939,67 @@ export class TextField extends DisplayObjectContainer {
2793
2939
  }
2794
2940
 
2795
2941
  const attr = new Float2Attributes(textShape.length / 2);
2796
- const buffer = new Float32Array(attr.attributesBuffer.buffer);
2942
+ const pos = new Float32Array(attr.attributesBuffer.buffer);
2943
+
2944
+ const uvAttr = textShape.hasUV ? new Float2Attributes(textShape.length / 2) : null;
2945
+ const uvs = uvAttr ? new Float32Array(uvAttr.attributesBuffer.buffer) : null;
2946
+
2947
+ //console.log('Build shape size:', textShape.length);
2797
2948
 
2798
2949
  let offset = 0;
2799
- for (const chunk of textShape.verts) {
2800
- buffer.set(chunk, offset);
2950
+ for (let i = 0; i < textShape.verts.length; i++) {
2951
+ const chunk = textShape.verts[i];
2952
+
2953
+ pos.set(chunk, offset);
2954
+
2955
+ if (uvs) {
2956
+ uvs.set(textShape.uvs[i], offset);
2957
+ }
2958
+
2801
2959
  offset += chunk.length;
2802
2960
  }
2803
2961
 
2962
+ // hack, merge buffer in single
2963
+ // this helps to avoid a lot of set in incremental filling
2964
+ // but anyway is slow
2965
+ textShape.length = 0;
2966
+ textShape.addChunk(pos, uvs);
2967
+
2804
2968
  if (textShape.shape) {
2805
2969
  const element = <TriangleElements> textShape.shape.elements;
2806
- // there are bug with attribyte buffer, when add attr to exist
2807
- element.setPositions(buffer);
2970
+ // there are bug with attribute buffer, when add attr to exist
2971
+ element.setPositions(pos);
2972
+
2973
+ if (uvs) {
2974
+ element.setUVs(uvs);
2975
+ }
2976
+
2808
2977
  element.invalidate();
2809
2978
 
2810
2979
  attr.dispose();
2980
+
2981
+ if (uvAttr) {
2982
+ uvAttr.dispose();
2983
+ }
2811
2984
  continue;
2812
2985
  }
2813
2986
 
2814
2987
  const color = this.getTextColorForTextFormat(textShape.format);
2815
- let alpha = ColorUtils.float32ColorToARGB(color)[0];
2816
-
2817
- if (alpha == 0) {
2818
- alpha = 255;
2819
- }
2988
+ const alpha = ColorUtils.float32ColorToARGB(color)[0] || 255;
2820
2989
 
2821
2990
  textShape.elements = new TriangleElements();
2991
+
2822
2992
  textShape.elements.setPositions(attr);
2993
+
2994
+ if (uvAttr) {
2995
+ textShape.elements.setUVs(uvAttr);
2996
+ }
2997
+
2823
2998
  textShape.elements.invalidate();
2824
2999
 
2825
3000
  textShape.shape = Shape.getShape(textShape.elements);
2826
3001
  // has BUG for QWOP, temporarily enable it (default)
2827
- textShape.shape.deepHitCheck = true;
3002
+ textShape.shape.deepHitCheck = false;
2828
3003
  textShape.shape.usages++;
2829
3004
 
2830
3005
  const sampler: ImageSampler = new ImageSampler(false, true, true);
@@ -3807,10 +3982,7 @@ export class TextField extends DisplayObjectContainer {
3807
3982
  private _clearTextShapes(): void {
3808
3983
  this._textShapesDirty = false;
3809
3984
 
3810
- this.last_word_vertices_count = 0;
3811
- this.tf_per_char_prev.length = 0;
3812
- this.chars_codes_prev.length = 0;
3813
- this._words_amount_prev = 0;
3985
+ this._lastWordsCount = 0;
3814
3986
 
3815
3987
  if (this.targetGraphics)
3816
3988
  this.targetGraphics.clear();