customized-fabric 2.0.22 → 2.0.24
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.
@@ -33,8 +33,7 @@ export declare const toCurvedTextObject: (object: CurvedText) => {
|
|
33
33
|
pathSide: any;
|
34
34
|
positionAngle: any;
|
35
35
|
isAllCapital: any;
|
36
|
-
|
37
|
-
endAngle: any;
|
36
|
+
globalCompositeOperation: string | undefined;
|
38
37
|
};
|
39
38
|
};
|
40
39
|
export default class CurvedText extends fabric.Group {
|
@@ -5,8 +5,8 @@ const fabric_1 = require("fabric");
|
|
5
5
|
const constants_1 = require("./constants");
|
6
6
|
const utils_1 = require("../utils");
|
7
7
|
const objectId_1 = require("../utils/objectId");
|
8
|
+
const svg_util_1 = require("../utils/svg.util");
|
8
9
|
const common_util_1 = require("../utils/common.util");
|
9
|
-
const utils_2 = require("./utils");
|
10
10
|
const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
11
11
|
initialize: function (options) {
|
12
12
|
let { text, ...rest } = options ?? {};
|
@@ -33,21 +33,10 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
33
33
|
positionAngle: 0,
|
34
34
|
maxFontSize: 200,
|
35
35
|
strokeLineJoin: "round",
|
36
|
-
startAngle: 45,
|
37
|
-
endAngle: 135,
|
38
36
|
...text,
|
39
37
|
text: isAllCapital ? fullText.toUpperCase() : fullText,
|
40
38
|
});
|
41
|
-
|
42
|
-
stroke: "black",
|
43
|
-
strokeDashArray: [10, 10],
|
44
|
-
fill: "transparent",
|
45
|
-
});
|
46
|
-
const group = new fabric_1.fabric.Group([
|
47
|
-
this.rectObject,
|
48
|
-
this.ellipseObject,
|
49
|
-
this.textObject,
|
50
|
-
]);
|
39
|
+
const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
|
51
40
|
this.set({
|
52
41
|
...group,
|
53
42
|
_id: new objectId_1.ObjectId().toString(),
|
@@ -82,47 +71,44 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
82
71
|
}
|
83
72
|
this.set(attributes);
|
84
73
|
this.rectObject.set(attributes);
|
85
|
-
this.calculateTextPath();
|
74
|
+
this.calculateTextPath(width, height);
|
86
75
|
this.autoChangeFontSize(0.1);
|
87
|
-
this.updateEllipsePath();
|
88
76
|
this.canvas?.renderAll?.();
|
89
77
|
});
|
90
78
|
if (options?.isOriginal) {
|
91
|
-
this.rectObject?.set({
|
92
|
-
this.ellipseObject.set({ visible: false });
|
79
|
+
this.rectObject?.set({ strokeWidth: 0 });
|
93
80
|
}
|
94
81
|
else {
|
95
82
|
if (options?.hideStroke) {
|
96
|
-
this.rectObject?.set({
|
97
|
-
this.ellipseObject.set({ visible: false });
|
83
|
+
this.rectObject?.set({ strokeWidth: 0 });
|
98
84
|
}
|
99
85
|
this.setFontFamily(text?.fontFamily ?? "", options?.fontUrl);
|
100
86
|
}
|
101
87
|
this.fire("scaling");
|
102
88
|
},
|
103
|
-
autoChangeFontSize: function (
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
let
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
89
|
+
autoChangeFontSize: function (changeSpeed = 0.1) {
|
90
|
+
let { fontSize, lengthRatio, maxFontSize } = this.textObject;
|
91
|
+
fontSize = Number(fontSize || 0);
|
92
|
+
lengthRatio = Number(lengthRatio || 0.4);
|
93
|
+
maxFontSize = Number(maxFontSize || 200);
|
94
|
+
const length = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2) * lengthRatio;
|
95
|
+
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
96
|
+
while (length <= maxLineWidth) {
|
97
|
+
fontSize -= changeSpeed;
|
98
|
+
this.textObject.set({
|
99
|
+
fontSize,
|
100
|
+
});
|
101
|
+
this.canvas?.renderAll?.();
|
102
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
103
|
+
}
|
104
|
+
while (maxFontSize > fontSize.toFixed(1) && length > maxLineWidth) {
|
105
|
+
fontSize += changeSpeed;
|
106
|
+
this.textObject.set({
|
107
|
+
fontSize,
|
108
|
+
});
|
109
|
+
this.canvas?.renderAll?.();
|
110
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
123
111
|
}
|
124
|
-
this.textObject.set({ fontSize: bestFit });
|
125
|
-
this.canvas?.renderAll();
|
126
112
|
},
|
127
113
|
setText: function (text) {
|
128
114
|
this.textObject.set({
|
@@ -190,34 +176,30 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
190
176
|
}
|
191
177
|
return this.textObject.get(attribute);
|
192
178
|
},
|
193
|
-
calculateTextPath: function () {
|
194
|
-
|
195
|
-
|
196
|
-
const
|
197
|
-
const
|
198
|
-
const
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
179
|
+
calculateTextPath: function (width, height) {
|
180
|
+
let { pathSide, positionAngle } = this.textObject;
|
181
|
+
positionAngle = Number(positionAngle || 0);
|
182
|
+
const textHeight = 0;
|
183
|
+
const rx = (width - textHeight) / 2;
|
184
|
+
const ry = (height - textHeight) / 2;
|
185
|
+
const path = new fabric_1.fabric.Path((0, svg_util_1.getEllipsePath)(rx, ry, pathSide), {
|
186
|
+
fill: undefined,
|
187
|
+
stroke: "black",
|
188
|
+
objectCaching: false,
|
189
|
+
originX: "center",
|
190
|
+
originY: "center",
|
191
|
+
visible: this.pathVisible,
|
206
192
|
});
|
207
|
-
this.
|
208
|
-
|
209
|
-
|
210
|
-
const
|
211
|
-
const rx = layerWidth / 2;
|
212
|
-
const ry = layerHeight / 2;
|
213
|
-
const { startAngle, endAngle, pathSide } = this.textObject;
|
214
|
-
const { x, y } = (0, utils_2.getEllipseArcCenterPoint)(rx, ry, startAngle, endAngle);
|
193
|
+
this.pathObject = path;
|
194
|
+
const pathInfo = fabric_1.fabric.util?.getPathSegmentsInfo?.(path.path);
|
195
|
+
const pathLength = pathInfo?.[(pathInfo?.length ?? 0) - 1]?.length;
|
196
|
+
const pathStartOffset = ((positionAngle % 360) * pathLength) / 360;
|
215
197
|
this.textObject.set({
|
216
|
-
|
217
|
-
|
198
|
+
path,
|
199
|
+
pathLength,
|
200
|
+
pathStartOffset,
|
218
201
|
});
|
219
|
-
this
|
220
|
-
this.canvas?.requestRenderAll();
|
202
|
+
this?.canvas?.renderAll();
|
221
203
|
},
|
222
204
|
});
|
223
205
|
const toCurvedTextObject = (object) => {
|
@@ -254,8 +236,7 @@ const toCurvedTextObject = (object) => {
|
|
254
236
|
pathSide: textObject?.pathSide,
|
255
237
|
positionAngle: textObject?.positionAngle,
|
256
238
|
isAllCapital: textObject?.isAllCapital,
|
257
|
-
|
258
|
-
endAngle: textObject?.endAngle,
|
239
|
+
globalCompositeOperation: textObject?.globalCompositeOperation,
|
259
240
|
},
|
260
241
|
};
|
261
242
|
};
|
@@ -32,6 +32,7 @@ export declare const toTextInputObject: (object: TextInput) => {
|
|
32
32
|
isAllCapital: any;
|
33
33
|
lineHeight: number | undefined;
|
34
34
|
charSpacing: number | undefined;
|
35
|
+
globalCompositeOperation: string | undefined;
|
35
36
|
};
|
36
37
|
};
|
37
38
|
export default class TextInput extends fabric.Group {
|
@@ -202,6 +202,7 @@ const toTextInputObject = (object) => {
|
|
202
202
|
isAllCapital: textObject?.isAllCapital,
|
203
203
|
lineHeight: textObject?.lineHeight,
|
204
204
|
charSpacing: textObject?.charSpacing,
|
205
|
+
globalCompositeOperation: textObject?.globalCompositeOperation,
|
205
206
|
},
|
206
207
|
};
|
207
208
|
};
|