@next2d/text 1.15.0 → 1.16.0

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.
@@ -59,6 +59,8 @@ export declare class TextField extends InteractiveObject {
59
59
  private _$thicknessColor;
60
60
  private _$verticalAlign;
61
61
  private _$createdTextData;
62
+ private _$cacheKeys;
63
+ private _$cacheParams;
62
64
  /**
63
65
  * @constructor
64
66
  * @public
package/dist/TextField.js CHANGED
@@ -3,8 +3,8 @@ import { InteractiveObject, Sprite } from "@next2d/display";
3
3
  import { FocusEvent, Event as Next2DEvent, MouseEvent as Next2DMouseEvent } from "@next2d/events";
4
4
  import { Tween } from "@next2d/ui";
5
5
  import { Rectangle } from "@next2d/geom";
6
- import { $currentPlayer, $DIV, $isSafari, $MOUSE_DOWN, $MOUSE_UP, $MOUSE_WHEEL, $P_TAG, $PREFIX, $rendererWorker, $SCROLL, $textContext, $TOUCH_END, $TOUCH_START, $devicePixelRatio, $document, $RegExp } from "@next2d/util";
7
- import { $doUpdated, $clamp, $getArray, $intToRGBA, $isNaN, $Math, $requestAnimationFrame, $toColorInt, $getMap, $poolFloat32Array6, $boundsMatrix, $multiplicationMatrix, $poolBoundsObject, $multiplicationColor, $Infinity, $Number, $poolArray, $poolFloat32Array8, $generateFontStyle, $getBoundsObject } from "@next2d/share";
6
+ import { $currentPlayer, $DIV, $isSafari, $MOUSE_DOWN, $MOUSE_UP, $MOUSE_WHEEL, $P_TAG, $PREFIX, $rendererWorker, $SCROLL, $textContext, $TOUCH_END, $TOUCH_START, $document, $RegExp } from "@next2d/util";
7
+ import { $cacheStore, $doUpdated, $clamp, $getArray, $intToRGBA, $isNaN, $Math, $requestAnimationFrame, $toColorInt, $getMap, $poolFloat32Array6, $boundsMatrix, $multiplicationMatrix, $poolBoundsObject, $multiplicationColor, $Infinity, $Number, $poolArray, $poolFloat32Array8, $generateFontStyle, $devicePixelRatio, $getBoundsObject } from "@next2d/share";
8
8
  /**
9
9
  * TextField クラスは、テキストの表示と入力用の表示オブジェクトを作成するために使用されます。
10
10
  * プロパティインスペクターを使用して、テキストフィールドにインスタンス名を付けることができます。
@@ -287,6 +287,16 @@ export class TextField extends InteractiveObject {
287
287
  * @private
288
288
  */
289
289
  this._$heightCache = $getMap();
290
+ /**
291
+ * @type {array}
292
+ * @private
293
+ */
294
+ this._$cacheKeys = $getArray();
295
+ /**
296
+ * @type {array}
297
+ * @private
298
+ */
299
+ this._$cacheParams = $getArray(0, 0, 0);
290
300
  }
291
301
  /**
292
302
  * @description 指定されたクラスのストリングを返します。
@@ -1711,8 +1721,7 @@ export class TextField extends InteractiveObject {
1711
1721
  this._$doChanged();
1712
1722
  $doUpdated();
1713
1723
  // cache clear
1714
- const player = $currentPlayer();
1715
- player.cacheStore.removeCache(this._$instanceId);
1724
+ $cacheStore.removeCache(this._$instanceId);
1716
1725
  }
1717
1726
  /**
1718
1727
  * @return {void}
@@ -2027,17 +2036,6 @@ export class TextField extends InteractiveObject {
2027
2036
  default:
2028
2037
  break;
2029
2038
  }
2030
- if (0 > xMin + width || 0 > yMin + height) {
2031
- return;
2032
- }
2033
- // cache current buffer
2034
- const manager = context.frameBuffer;
2035
- const currentAttachment = manager.currentAttachment;
2036
- if (!currentAttachment
2037
- || xMin > currentAttachment.width
2038
- || yMin > currentAttachment.height) {
2039
- return;
2040
- }
2041
2039
  let xScale = +$Math.sqrt(multiMatrix[0] * multiMatrix[0]
2042
2040
  + multiMatrix[1] * multiMatrix[1]);
2043
2041
  if (!$Number.isInteger(xScale)) {
@@ -2059,47 +2057,58 @@ export class TextField extends InteractiveObject {
2059
2057
  yScale = +yScale.toFixed(4);
2060
2058
  }
2061
2059
  const filters = this._$filters || this.filters;
2062
- if (0 > xMin + width || 0 > yMin + height) {
2063
- if (filters.length && this._$canApply(filters)) {
2064
- let filterBounds = $getBoundsObject(0, width, 0, height);
2065
- for (let idx = 0; idx < filters.length; ++idx) {
2066
- filterBounds = filters[idx]
2067
- ._$generateFilterRect(filterBounds, xScale, yScale);
2068
- }
2069
- if (0 > filterBounds.xMin + filterBounds.xMax
2070
- || 0 > filterBounds.yMin + filterBounds.yMax) {
2071
- $poolBoundsObject(filterBounds);
2072
- return;
2073
- }
2074
- $poolBoundsObject(filterBounds);
2075
- }
2076
- else {
2077
- return;
2060
+ const canApply = filters !== null
2061
+ && filters.length > 0
2062
+ && this._$canApply(filters);
2063
+ let filterBounds = $getBoundsObject(0, width, 0, height);
2064
+ if (canApply && filters) {
2065
+ for (let idx = 0; idx < filters.length; ++idx) {
2066
+ filterBounds = filters[idx]
2067
+ ._$generateFilterRect(filterBounds, xScale, yScale);
2078
2068
  }
2079
2069
  }
2080
- const blendMode = this._$blendMode || this.blendMode;
2081
- const keys = $getArray(xScale, yScale);
2082
- const instanceId = this._$instanceId;
2083
- const player = $currentPlayer();
2084
- const cacheStore = player.cacheStore;
2085
- const cacheKeys = cacheStore.generateKeys(instanceId, keys);
2086
- let texture = cacheStore.get(cacheKeys);
2070
+ // cache current buffer
2071
+ const manager = context.frameBuffer;
2072
+ const currentAttachment = manager.currentAttachment;
2073
+ if (!currentAttachment
2074
+ || xMin - filterBounds.xMin > currentAttachment.width
2075
+ || yMin - filterBounds.yMin > currentAttachment.height) {
2076
+ $poolBoundsObject(filterBounds);
2077
+ return;
2078
+ }
2079
+ if (0 > xMin + filterBounds.xMax || 0 > yMin + filterBounds.yMax) {
2080
+ $poolBoundsObject(filterBounds);
2081
+ return;
2082
+ }
2083
+ $poolBoundsObject(filterBounds);
2087
2084
  // texture is small or renew
2088
2085
  if (this._$isUpdated()) {
2089
- cacheStore.removeCache(instanceId);
2090
- texture = null;
2086
+ $cacheStore.removeCache(this._$instanceId);
2087
+ context.cachePosition = null;
2088
+ this._$cacheKeys.length = 0;
2089
+ }
2090
+ if (!this._$cacheKeys.length
2091
+ || this._$cacheParams[0] !== xScale
2092
+ || this._$cacheParams[1] !== yScale
2093
+ || this._$cacheParams[2] !== color_transform[7]) {
2094
+ const keys = $getArray(xScale, yScale);
2095
+ this._$cacheKeys = $cacheStore.generateKeys(this._$instanceId, keys);
2096
+ $poolArray(keys);
2097
+ this._$cacheParams[0] = xScale;
2098
+ this._$cacheParams[1] = yScale;
2099
+ this._$cacheParams[2] = color_transform[7];
2091
2100
  }
2092
- if (!texture) {
2101
+ const blendMode = this._$blendMode || this.blendMode;
2102
+ context.cachePosition = $cacheStore.get(this._$cacheKeys);
2103
+ if (!context.cachePosition) {
2093
2104
  // resize
2094
2105
  const lineWidth = $Math.min(1, $Math.max(xScale, yScale));
2095
- const baseWidth = $Math.ceil($Math.abs(baseBounds.xMax - baseBounds.xMin) * xScale);
2096
- const baseHeight = $Math.ceil($Math.abs(baseBounds.yMax - baseBounds.yMin) * yScale);
2097
- // alpha reset
2098
- multiColor[3] = 1;
2106
+ const width = $Math.ceil($Math.abs(baseBounds.xMax - baseBounds.xMin) * xScale);
2107
+ const height = $Math.ceil($Math.abs(baseBounds.yMax - baseBounds.yMin) * yScale);
2099
2108
  // new canvas
2100
- const canvas = cacheStore.getCanvas();
2101
- canvas.width = baseWidth + lineWidth * 2;
2102
- canvas.height = baseHeight + lineWidth * 2;
2109
+ const canvas = $cacheStore.getCanvas();
2110
+ canvas.width = width + lineWidth * 2;
2111
+ canvas.height = height + lineWidth * 2;
2103
2112
  const ctx = canvas.getContext("2d");
2104
2113
  if (!ctx) {
2105
2114
  throw new Error("the context is null.");
@@ -2108,19 +2117,19 @@ export class TextField extends InteractiveObject {
2108
2117
  if (this._$background || this._$border) {
2109
2118
  ctx.beginPath();
2110
2119
  ctx.moveTo(0, 0);
2111
- ctx.lineTo(baseWidth, 0);
2112
- ctx.lineTo(baseWidth, baseHeight);
2113
- ctx.lineTo(0, baseHeight);
2120
+ ctx.lineTo(width, 0);
2121
+ ctx.lineTo(width, height);
2122
+ ctx.lineTo(0, height);
2114
2123
  ctx.lineTo(0, 0);
2115
2124
  if (this._$background) {
2116
2125
  const rgb = $intToRGBA(this._$backgroundColor);
2117
- const alpha = $Math.max(0, $Math.min(rgb.A * 255 * multiColor[3] + multiColor[7], 255)) / 255;
2126
+ const alpha = $Math.max(0, $Math.min(rgb.A * 255 + multiColor[7], 255)) / 255;
2118
2127
  ctx.fillStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
2119
2128
  ctx.fill();
2120
2129
  }
2121
2130
  if (this._$border) {
2122
2131
  const rgb = $intToRGBA(this._$borderColor);
2123
- const alpha = $Math.max(0, $Math.min(rgb.A * 255 * multiColor[3] + multiColor[7], 255)) / 255;
2132
+ const alpha = $Math.max(0, $Math.min(rgb.A * 255 + multiColor[7], 255)) / 255;
2124
2133
  ctx.lineWidth = lineWidth;
2125
2134
  ctx.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
2126
2135
  ctx.stroke();
@@ -2130,20 +2139,25 @@ export class TextField extends InteractiveObject {
2130
2139
  ctx.save();
2131
2140
  ctx.beginPath();
2132
2141
  ctx.moveTo(2, 2);
2133
- ctx.lineTo(baseWidth - 2, 2);
2134
- ctx.lineTo(baseWidth - 2, baseHeight - 2);
2135
- ctx.lineTo(2, baseHeight - 2);
2142
+ ctx.lineTo(width - 2, 2);
2143
+ ctx.lineTo(width - 2, height - 2);
2144
+ ctx.lineTo(2, height - 2);
2136
2145
  ctx.lineTo(2, 2);
2137
2146
  ctx.clip();
2138
2147
  ctx.beginPath();
2139
2148
  ctx.setTransform(xScale, 0, 0, yScale, 0, 0);
2140
- this._$doDraw(ctx, matrix, multiColor, baseWidth / xScale);
2149
+ this._$doDraw(ctx, matrix, multiColor, width / xScale);
2141
2150
  ctx.restore();
2142
- texture = manager.createTextureFromCanvas(ctx.canvas);
2151
+ const position = manager
2152
+ .createCachePosition(width, height);
2153
+ const texture = manager
2154
+ .createTextureFromCanvas(ctx.canvas);
2155
+ context.drawTextureFromRect(texture, position);
2143
2156
  // set cache
2144
- cacheStore.set(cacheKeys, texture);
2157
+ context.cachePosition = position;
2158
+ $cacheStore.set(this._$cacheKeys, position);
2145
2159
  // destroy cache
2146
- cacheStore.destroy(ctx);
2160
+ $cacheStore.destroy(ctx);
2147
2161
  }
2148
2162
  let drawFilter = false;
2149
2163
  let offsetX = 0;
@@ -2151,9 +2165,15 @@ export class TextField extends InteractiveObject {
2151
2165
  if (filters && filters.length
2152
2166
  && this._$canApply(filters)) {
2153
2167
  drawFilter = true;
2154
- texture = this._$drawFilter(context, texture, multiMatrix, filters, width, height);
2155
- offsetX = texture._$offsetX;
2156
- offsetY = texture._$offsetY;
2168
+ const position = this._$drawFilter(context, multiMatrix, filters, width, height);
2169
+ if (position.offsetX) {
2170
+ offsetX = position.offsetX;
2171
+ }
2172
+ if (position.offsetY) {
2173
+ offsetY = position.offsetY;
2174
+ }
2175
+ // update
2176
+ context.cachePosition = position;
2157
2177
  }
2158
2178
  const radianX = $Math.atan2(multiMatrix[1], multiMatrix[0]);
2159
2179
  const radianY = $Math.atan2(-multiMatrix[2], multiMatrix[3]);
@@ -2170,13 +2190,15 @@ export class TextField extends InteractiveObject {
2170
2190
  context.setTransform(1, 0, 0, 1, xMin - offsetX, yMin - offsetY);
2171
2191
  }
2172
2192
  // draw
2173
- context.reset();
2174
- context.globalAlpha = alpha;
2175
- context.imageSmoothingEnabled = true;
2176
- context.globalCompositeOperation = blendMode;
2177
- context.drawImage(texture, 0, 0, texture.width, texture.height, multiColor);
2193
+ if (context.cachePosition) {
2194
+ context.globalAlpha = alpha;
2195
+ context.imageSmoothingEnabled = true;
2196
+ context.globalCompositeOperation = blendMode;
2197
+ context.drawInstance(xMin - offsetX, yMin - offsetY, xMax, yMax, color_transform);
2198
+ // cache position clear
2199
+ context.cachePosition = null;
2200
+ }
2178
2201
  // get cache
2179
- $poolArray(cacheKeys);
2180
2202
  $poolBoundsObject(baseBounds);
2181
2203
  // pool
2182
2204
  if (multiMatrix !== matrix) {
@@ -2230,11 +2252,11 @@ export class TextField extends InteractiveObject {
2230
2252
  const tf = obj.textFormat;
2231
2253
  // color
2232
2254
  const rgb = $intToRGBA(tf.color || 0);
2233
- const alpha = $Math.max(0, $Math.min(rgb.A * 255 * color_transform[3] + color_transform[7], 255)) / 255;
2255
+ const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
2234
2256
  context.fillStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
2235
2257
  if (this._$thickness) {
2236
2258
  const rgb = $intToRGBA(this._$thicknessColor);
2237
- const alpha = $Math.max(0, $Math.min(rgb.A * 255 * color_transform[3] + color_transform[7], 255)) / 255;
2259
+ const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
2238
2260
  context.lineWidth = this._$thickness;
2239
2261
  context.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
2240
2262
  }
@@ -2251,7 +2273,7 @@ export class TextField extends InteractiveObject {
2251
2273
  if (tf.underline) {
2252
2274
  const offset = tf.size ? tf.size / 12 : 0;
2253
2275
  const rgb = $intToRGBA(tf.color || 0);
2254
- const alpha = $Math.max(0, $Math.min(rgb.A * 255 * color_transform[3] + color_transform[7], 255)) / 255;
2276
+ const alpha = $Math.max(0, $Math.min(rgb.A * 255 + color_transform[7], 255)) / 255;
2255
2277
  context.lineWidth = $Math.max(1, 1 / $Math.min(matrix[0], matrix[3]));
2256
2278
  context.strokeStyle = `rgba(${rgb.R},${rgb.G},${rgb.B},${alpha})`;
2257
2279
  context.beginPath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/text",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Next2D Text Packages",
5
5
  "author": "Toshiyuki Ienaga<ienaga@tvon.jp> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -32,12 +32,12 @@
32
32
  "url": "git+https://github.com/Next2D/Player.git"
33
33
  },
34
34
  "peerDependencies": {
35
- "@next2d/display": "1.15.0",
36
- "@next2d/events": "1.15.0",
37
- "@next2d/ui": "1.15.0",
38
- "@next2d/geom": "1.15.0",
39
- "@next2d/interface": "1.15.0",
40
- "@next2d/core": "1.15.0",
41
- "@next2d/webgl": "1.15.0"
35
+ "@next2d/display": "1.16.0",
36
+ "@next2d/events": "1.16.0",
37
+ "@next2d/ui": "1.16.0",
38
+ "@next2d/geom": "1.16.0",
39
+ "@next2d/interface": "1.16.0",
40
+ "@next2d/core": "1.16.0",
41
+ "@next2d/webgl": "1.16.0"
42
42
  }
43
43
  }