@next2d/display 3.0.5 → 3.1.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.
@@ -5,7 +5,8 @@ import { execute as displayObjectBlendToNumberService } from "../../DisplayObjec
5
5
  import { execute as displayObjectGenerateHashService } from "../../DisplayObject/service/DisplayObjectGenerateHashService";
6
6
  import { $cacheStore } from "@next2d/cache";
7
7
  import { renderQueue } from "@next2d/render-queue";
8
- import { $clamp, $RENDERER_TEXT_TYPE, $getArray, $poolArray, $poolBoundsArray, $getBoundsArray } from "../../DisplayObjectUtil";
8
+ import { stage } from "../../Stage";
9
+ import { $clamp, $RENDERER_TEXT_TYPE, $getArray, $poolArray, $poolBoundsArray, $getBoundsArray, $getFloat32Array6, $poolFloat32Array6 } from "../../DisplayObjectUtil";
9
10
  import { ColorTransform, Matrix } from "@next2d/geom";
10
11
  /**
11
12
  * @type {TextEncoder}
@@ -56,10 +57,10 @@ export const execute = (text_field, matrix, color_transform, renderer_width, ren
56
57
  ? Matrix.multiply(matrix, rawMatrix)
57
58
  : matrix;
58
59
  const bounds = displayObjectCalcBoundsMatrixService(text_field.xMin, text_field.yMin, text_field.xMax, text_field.yMax, tMatrix);
59
- const xMin = bounds[0];
60
- const yMin = bounds[1];
61
- const xMax = bounds[2];
62
- const yMax = bounds[3];
60
+ let xMin = bounds[0];
61
+ let yMin = bounds[1];
62
+ let xMax = bounds[2];
63
+ let yMax = bounds[3];
63
64
  $poolBoundsArray(bounds);
64
65
  const width = Math.ceil(Math.abs(xMax - xMin));
65
66
  const height = Math.ceil(Math.abs(yMax - yMin));
@@ -104,13 +105,51 @@ export const execute = (text_field, matrix, color_transform, renderer_width, ren
104
105
  text_field.uniqueKey = `${text_field.instanceId}`;
105
106
  }
106
107
  }
107
- const xScale = Math.sqrt(tMatrix[0] * tMatrix[0]
108
- + tMatrix[1] * tMatrix[1]);
109
- const yScale = Math.sqrt(tMatrix[2] * tMatrix[2]
110
- + tMatrix[3] * tMatrix[3]);
111
- const xScaleRounded = Math.round(xScale * 100) / 100;
112
- const yScaleRounded = Math.round(yScale * 100) / 100;
113
- if (text_field.changed
108
+ // cacheAsBitmap: 指定Matrix × 自身のスケール × stageのrendererScaleでキャッシュ品質を決定
109
+ // 1.0基準: Matrix(1,0,0,1)はdisplayObjectの等倍スケールを意味する
110
+ const cacheMatrix = text_field.cacheAsBitmap;
111
+ let renderXScale;
112
+ let renderYScale;
113
+ let cacheScaleX = 1;
114
+ let cacheScaleY = 1;
115
+ if (cacheMatrix) {
116
+ const m = cacheMatrix.rawData;
117
+ cacheScaleX = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
118
+ cacheScaleY = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
119
+ const ownScaleX = rawMatrix
120
+ ? Math.sqrt(rawMatrix[0] * rawMatrix[0] + rawMatrix[1] * rawMatrix[1])
121
+ : 1;
122
+ const ownScaleY = rawMatrix
123
+ ? Math.sqrt(rawMatrix[2] * rawMatrix[2] + rawMatrix[3] * rawMatrix[3])
124
+ : 1;
125
+ renderXScale = cacheScaleX * ownScaleX * stage.rendererScale;
126
+ renderYScale = cacheScaleY * ownScaleY * stage.rendererScale;
127
+ // cacheMatrix倍率をスクリーン座標のboundsにも反映
128
+ if (cacheScaleX !== 1 || cacheScaleY !== 1) {
129
+ const modMatrix = $getFloat32Array6(tMatrix[0] * cacheScaleX, tMatrix[1] * cacheScaleX, tMatrix[2] * cacheScaleY, tMatrix[3] * cacheScaleY, tMatrix[4], tMatrix[5]);
130
+ const modBounds = displayObjectCalcBoundsMatrixService(text_field.xMin, text_field.yMin, text_field.xMax, text_field.yMax, modMatrix);
131
+ xMin = modBounds[0];
132
+ yMin = modBounds[1];
133
+ xMax = modBounds[2];
134
+ yMax = modBounds[3];
135
+ $poolBoundsArray(modBounds);
136
+ $poolFloat32Array6(modMatrix);
137
+ }
138
+ }
139
+ else {
140
+ renderXScale = Math.sqrt(tMatrix[0] * tMatrix[0]
141
+ + tMatrix[1] * tMatrix[1]);
142
+ renderYScale = Math.sqrt(tMatrix[2] * tMatrix[2]
143
+ + tMatrix[3] * tMatrix[3]);
144
+ }
145
+ const xScaleRounded = Math.round(renderXScale * 100) / 100;
146
+ const yScaleRounded = Math.round(renderYScale * 100) / 100;
147
+ if (cacheMatrix && text_field.cacheKey
148
+ && text_field.cacheParams[0] === xScaleRounded
149
+ && text_field.cacheParams[1] === yScaleRounded) {
150
+ // cacheAsBitmap: スケール未変更のためキャッシュキーを維持
151
+ }
152
+ else if (text_field.changed
114
153
  && !text_field.cacheKey
115
154
  || text_field.cacheParams[0] !== xScaleRounded
116
155
  || text_field.cacheParams[1] !== yScaleRounded
@@ -122,7 +161,7 @@ export const execute = (text_field, matrix, color_transform, renderer_width, ren
122
161
  }
123
162
  const cacheKey = text_field.cacheKey;
124
163
  // rennder on
125
- renderQueue.pushTextFieldBuffer(1, $RENDERER_TEXT_TYPE, tMatrix[0], tMatrix[1], tMatrix[2], tMatrix[3], tMatrix[4], tMatrix[5], tColorTransform[0], tColorTransform[1], tColorTransform[2], tColorTransform[3], tColorTransform[4], tColorTransform[5], tColorTransform[6], tColorTransform[7], xMin, yMin, xMax, yMax, text_field.xMin, text_field.yMin, text_field.xMax, text_field.yMax, +text_field.uniqueKey, cacheKey, +text_field.changed, xScale, yScale, text_field.instanceId // フィルターキャッシュ用のユニークキー
164
+ renderQueue.pushTextFieldBuffer(1, $RENDERER_TEXT_TYPE, tMatrix[0] * cacheScaleX, tMatrix[1] * cacheScaleX, tMatrix[2] * cacheScaleY, tMatrix[3] * cacheScaleY, tMatrix[4], tMatrix[5], tColorTransform[0], tColorTransform[1], tColorTransform[2], tColorTransform[3], tColorTransform[4], tColorTransform[5], tColorTransform[6], tColorTransform[7], xMin, yMin, xMax, yMax, text_field.xMin, text_field.yMin, text_field.xMax, text_field.yMax, +text_field.uniqueKey, cacheKey, +text_field.changed | (cacheMatrix ? 2 : 0), renderXScale, renderYScale, text_field.instanceId // フィルターキャッシュ用のユニークキー
126
165
  );
127
166
  if (text_field.$cache && !text_field.$cache.has(text_field.uniqueKey)) {
128
167
  text_field.$cache = null;
@@ -1,5 +1,6 @@
1
1
  import { Matrix } from "@next2d/geom";
2
2
  import { execute as displayObjectGetRawMatrixUseCase } from "../../DisplayObject/usecase/DisplayObjectGetRawMatrixUseCase";
3
+ import { $getFloat32Array6, $poolFloat32Array6 } from "../../DisplayObjectUtil";
3
4
  /**
4
5
  * @description TextField のヒット判定
5
6
  * Hit judgment of TextField
@@ -18,10 +19,28 @@ export const execute = (text_field, hit_context, matrix, hit_object) => {
18
19
  if (width <= 0 || height <= 0) {
19
20
  return false;
20
21
  }
21
- const rawMatrix = displayObjectGetRawMatrixUseCase(text_field);
22
+ let rawMatrix = displayObjectGetRawMatrixUseCase(text_field);
23
+ // cacheAsBitmap倍率をrawMatrixに適用
24
+ const cacheMatrix = text_field.cacheAsBitmap;
25
+ let scaledMatrix = null;
26
+ if (cacheMatrix) {
27
+ const m = cacheMatrix.rawData;
28
+ const csx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
29
+ const csy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
30
+ if (rawMatrix) {
31
+ scaledMatrix = $getFloat32Array6(rawMatrix[0] * csx, rawMatrix[1] * csx, rawMatrix[2] * csy, rawMatrix[3] * csy, rawMatrix[4], rawMatrix[5]);
32
+ }
33
+ else {
34
+ scaledMatrix = $getFloat32Array6(csx, 0, 0, csy, 0, 0);
35
+ }
36
+ rawMatrix = scaledMatrix;
37
+ }
22
38
  const tMatrix = rawMatrix
23
39
  ? Matrix.multiply(matrix, rawMatrix)
24
40
  : matrix;
41
+ if (scaledMatrix) {
42
+ $poolFloat32Array6(scaledMatrix);
43
+ }
25
44
  hit_context.setTransform(tMatrix[0], tMatrix[1], tMatrix[2], tMatrix[3], tMatrix[4], tMatrix[5]);
26
45
  hit_context.beginPath();
27
46
  hit_context.moveTo(0, 0);