customized-fabric 2.0.1 → 2.0.3
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.
@@ -29,7 +29,7 @@ export declare const toCurvedTextObject: (object: CurvedText) => {
|
|
29
29
|
prefix: any;
|
30
30
|
infix: any;
|
31
31
|
suffix: any;
|
32
|
-
|
32
|
+
curvedLengthRatio: any;
|
33
33
|
pathSide: any;
|
34
34
|
pathStartOffset: any;
|
35
35
|
isAllCapital: any;
|
@@ -52,8 +52,7 @@ export default class CurvedText extends fabric.Group {
|
|
52
52
|
setSuffix?: (text: string) => void;
|
53
53
|
setMaxFontSize?: (fontSize: string) => void;
|
54
54
|
setFontFamily?: (fontName: string, fontUrl?: string) => void;
|
55
|
-
setTextAttributes?: (options:
|
56
|
-
setTextWidth?: (width: number) => void;
|
55
|
+
setTextAttributes?: (options: any) => void;
|
57
56
|
getTextAttribute?: (attribute: string) => any;
|
58
57
|
getSettings?: (attribute: string) => any;
|
59
58
|
setSizes?: (options: {
|
@@ -18,7 +18,8 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
18
18
|
objectCaching: false,
|
19
19
|
...constants_1.CURVED_TEXT_OBJECT_ATTRIBUTES.stroke,
|
20
20
|
});
|
21
|
-
const { prefix = "", infix = "", suffix = "" } = text ?? {};
|
21
|
+
const { prefix = "", infix = "", suffix = "", isAllCapital } = text ?? {};
|
22
|
+
const fullText = prefix + infix + suffix;
|
22
23
|
this.textObject = new fabric_1.fabric.IText("", {
|
23
24
|
originX: "center",
|
24
25
|
originY: "center",
|
@@ -26,8 +27,9 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
26
27
|
objectCaching: false,
|
27
28
|
fontFamily: "",
|
28
29
|
paintFirst: "stroke",
|
30
|
+
curvedLengthRatio: 0.3,
|
29
31
|
...text,
|
30
|
-
text:
|
32
|
+
text: isAllCapital ? fullText.toUpperCase() : fullText,
|
31
33
|
});
|
32
34
|
const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
|
33
35
|
this.set({
|
@@ -66,11 +68,13 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
66
68
|
}
|
67
69
|
this.fire("scaling");
|
68
70
|
},
|
69
|
-
autoChangeFontSize: function (changeSpeed) {
|
70
|
-
let {
|
71
|
+
autoChangeFontSize: function (changeSpeed = 0.1) {
|
72
|
+
let { curvedLengthRatio, fontSize = 0, maxFontSize } = this.textObject;
|
73
|
+
const circumference = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2);
|
74
|
+
const curvedLength = circumference * curvedLengthRatio;
|
71
75
|
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
72
76
|
fontSize = Number(fontSize);
|
73
|
-
while (
|
77
|
+
while (curvedLength <= maxLineWidth) {
|
74
78
|
fontSize -= changeSpeed;
|
75
79
|
this.textObject.set({
|
76
80
|
fontSize,
|
@@ -78,7 +82,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
78
82
|
this.canvas?.renderAll?.();
|
79
83
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
80
84
|
}
|
81
|
-
while (maxFontSize > fontSize.toFixed(1) &&
|
85
|
+
while (maxFontSize > fontSize.toFixed(1) && curvedLength > maxLineWidth) {
|
82
86
|
fontSize += changeSpeed;
|
83
87
|
this.textObject.set({
|
84
88
|
fontSize,
|
@@ -144,10 +148,6 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
144
148
|
this.textObject.set(options);
|
145
149
|
this.fire("scaling");
|
146
150
|
},
|
147
|
-
setTextWidth: function (width) {
|
148
|
-
this.textObject.set({ curvedWidth: width });
|
149
|
-
this.fire("scaling");
|
150
|
-
},
|
151
151
|
getTextAttribute: function (attribute) {
|
152
152
|
return this.textObject.get(attribute);
|
153
153
|
},
|
@@ -211,7 +211,7 @@ const toCurvedTextObject = (object) => {
|
|
211
211
|
prefix: textObject?.prefix,
|
212
212
|
infix: textObject?.infix,
|
213
213
|
suffix: textObject?.suffix,
|
214
|
-
|
214
|
+
curvedLengthRatio: textObject?.curvedLengthRatio,
|
215
215
|
pathSide: textObject?.pathSide,
|
216
216
|
pathStartOffset: textObject?.pathStartOffset,
|
217
217
|
isAllCapital: textObject?.isAllCapital,
|
package/lib/utils/svg.util.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
import { fabric } from "fabric";
|
2
2
|
export declare const getEllipsePath: (rx: number, ry: number, side?: "left" | "right") => string;
|
3
3
|
export declare const getPathLength: (path: fabric.Path) => any;
|
4
|
+
export declare const getEllipseCircumference: (a: number, b: number) => number;
|
package/lib/utils/svg.util.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getPathLength = exports.getEllipsePath = void 0;
|
3
|
+
exports.getEllipseCircumference = exports.getPathLength = exports.getEllipsePath = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
5
|
const getEllipsePath = (rx, ry, side = "left") => {
|
6
6
|
const sideFactor = side == "left" ? -1 : 1;
|
@@ -17,3 +17,7 @@ const getPathLength = (path) => {
|
|
17
17
|
return pathLength;
|
18
18
|
};
|
19
19
|
exports.getPathLength = getPathLength;
|
20
|
+
const getEllipseCircumference = (a, b) => {
|
21
|
+
return Math.PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (a + 3 * b)));
|
22
|
+
};
|
23
|
+
exports.getEllipseCircumference = getEllipseCircumference;
|