embroidery-qc-image 1.0.33 → 1.0.35
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.
- package/dist/components/EmbroideryQCImage.d.ts.map +1 -1
- package/dist/index.esm.js +34 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +34 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -143,18 +143,30 @@ const loadFont = (fontName) => {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
return new Promise((resolve) => {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
const fontFormats = ['woff2', 'ttf', 'otf'];
|
|
147
|
+
let currentFormatIndex = 0;
|
|
148
|
+
const tryLoadFont = () => {
|
|
149
|
+
if (currentFormatIndex >= fontFormats.length) {
|
|
150
|
+
console.warn(`Could not load font ${fontName} from CDN (tried all formats)`);
|
|
151
|
+
resolve();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const format = fontFormats[currentFormatIndex];
|
|
155
|
+
const fontUrl = `${BASE_URLS.FONT}/${encodeURIComponent(fontName)}.${format}`;
|
|
156
|
+
const fontFace = new FontFace(fontName, `url(${fontUrl})`);
|
|
157
|
+
fontFace
|
|
158
|
+
.load()
|
|
159
|
+
.then((loadedFont) => {
|
|
160
|
+
document.fonts.add(loadedFont);
|
|
161
|
+
resolve();
|
|
162
|
+
})
|
|
163
|
+
.catch(() => {
|
|
164
|
+
// Try next format
|
|
165
|
+
currentFormatIndex++;
|
|
166
|
+
tryLoadFont();
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
tryLoadFont();
|
|
158
170
|
});
|
|
159
171
|
};
|
|
160
172
|
const getImageUrl = (type, value) => {
|
|
@@ -669,7 +681,7 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
669
681
|
// Calculate text size to fit top section
|
|
670
682
|
let previewFontSize = LAYOUT.HEADER_FONT_SIZE * 3; // Start with large size
|
|
671
683
|
const fontToUse = isFontMissing ? LAYOUT.FONT_FAMILY : position.font;
|
|
672
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
684
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
673
685
|
const text = position.text || "";
|
|
674
686
|
const maxTextWidth = usableWidth * 0.9; // Use 75% of width for better padding
|
|
675
687
|
const maxTextHeight = actualTopSectionHeight; // Use 60% of height
|
|
@@ -677,13 +689,13 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
677
689
|
let textWidth = ctx.measureText(text).width;
|
|
678
690
|
while (textWidth > maxTextWidth && previewFontSize > 50) {
|
|
679
691
|
previewFontSize *= 0.95;
|
|
680
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
692
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
681
693
|
textWidth = ctx.measureText(text).width;
|
|
682
694
|
}
|
|
683
695
|
// Ensure text height also fits
|
|
684
696
|
while (previewFontSize > maxTextHeight && previewFontSize > 50) {
|
|
685
697
|
previewFontSize *= 0.95;
|
|
686
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
698
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
687
699
|
}
|
|
688
700
|
// Update textWidth after final scaling
|
|
689
701
|
textWidth = ctx.measureText(text).width;
|
|
@@ -763,7 +775,7 @@ const renderStrokePatchesCanvas = (ctx, canvas, config, imageRefs) => {
|
|
|
763
775
|
// Render font name với chính font đó
|
|
764
776
|
const prefixWidth = ctx.measureText(fontPrefix).width;
|
|
765
777
|
const fontName = position.font || LAYOUT.FONT_FAMILY;
|
|
766
|
-
ctx.font = `${infoFontSize}px ${fontName}`;
|
|
778
|
+
ctx.font = `${infoFontSize}px "${fontName}"`;
|
|
767
779
|
ctx.fillText(fontName, startX + prefixWidth, infoY);
|
|
768
780
|
}
|
|
769
781
|
infoY += infoLineHeight;
|
|
@@ -1053,7 +1065,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1053
1065
|
let high = previewFontSize;
|
|
1054
1066
|
while (high - low > 1) {
|
|
1055
1067
|
const mid = (low + high) / 2;
|
|
1056
|
-
ctx.font = `${mid}px ${fontToUse}`;
|
|
1068
|
+
ctx.font = `${mid}px "${fontToUse}"`;
|
|
1057
1069
|
// Kiểm tra width của tất cả các dòng
|
|
1058
1070
|
const maxLineWidth = Math.max(...textLines.map(line => ctx.measureText(line).width));
|
|
1059
1071
|
// Kiểm tra height với line height = 1.1 (giảm từ 1.2 để text to hơn)
|
|
@@ -1070,7 +1082,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1070
1082
|
}
|
|
1071
1083
|
}
|
|
1072
1084
|
previewFontSize = bestFontSize;
|
|
1073
|
-
ctx.font = `${previewFontSize}px ${fontToUse}`;
|
|
1085
|
+
ctx.font = `${previewFontSize}px "${fontToUse}"`;
|
|
1074
1086
|
// Center the text inside rectangle
|
|
1075
1087
|
const finalLineHeight = previewFontSize * 1.1;
|
|
1076
1088
|
const totalTextHeightFinal = textLines.length * finalLineHeight;
|
|
@@ -1128,7 +1140,7 @@ const renderTemplateCustomTextPatchesCanvas = (ctx, canvas, config, imageRefs) =
|
|
|
1128
1140
|
// Render font name với chính font đó
|
|
1129
1141
|
const prefixWidth = ctx.measureText(fontPrefix).width;
|
|
1130
1142
|
const fontName = position.font || LAYOUT.FONT_FAMILY;
|
|
1131
|
-
ctx.font = `${infoFontSize}px ${fontName}`;
|
|
1143
|
+
ctx.font = `${infoFontSize}px "${fontName}"`;
|
|
1132
1144
|
ctx.fillText(fontName, startX + prefixWidth, infoY);
|
|
1133
1145
|
}
|
|
1134
1146
|
infoY += infoLineHeight;
|
|
@@ -1738,7 +1750,7 @@ const renderUniformLabels = (ctx, uniformProps, x, y, maxWidth, scaleFactor, ima
|
|
|
1738
1750
|
let currentX = x + prefixWidth;
|
|
1739
1751
|
ctx.fillText(prefix, x, cursorY);
|
|
1740
1752
|
// Render tên font với font từ config
|
|
1741
|
-
ctx.font = `${fontSize}px ${values.font}`;
|
|
1753
|
+
ctx.font = `${fontSize}px "${values.font}"`;
|
|
1742
1754
|
const fontNameWidth = ctx.measureText(values.font).width;
|
|
1743
1755
|
ctx.fillText(values.font, currentX, cursorY);
|
|
1744
1756
|
currentX += fontNameWidth;
|
|
@@ -1963,7 +1975,7 @@ displayIndex, showLabels, scaleFactor, imageRefs, mockupBounds = null) => {
|
|
|
1963
1975
|
const measureFontTextWidth = (fontSize) => {
|
|
1964
1976
|
ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
|
|
1965
1977
|
const prefixWidth = ctx.measureText(prefix).width;
|
|
1966
|
-
ctx.font = `${fontSize}px ${position.font}`;
|
|
1978
|
+
ctx.font = `${fontSize}px "${position.font}"`;
|
|
1967
1979
|
const fontNameWidth = ctx.measureText(fontName).width;
|
|
1968
1980
|
ctx.font = `${fontSize}px ${LAYOUT.FONT_FAMILY}`;
|
|
1969
1981
|
const suffixWidth = ctx.measureText(suffix).width;
|
|
@@ -2039,7 +2051,7 @@ displayIndex, showLabels, scaleFactor, imageRefs, mockupBounds = null) => {
|
|
|
2039
2051
|
const prefixWidth = ctx.measureText(prefix).width;
|
|
2040
2052
|
let currentX = x + prefixWidth;
|
|
2041
2053
|
ctx.fillText(prefix, x, currentY);
|
|
2042
|
-
ctx.font = `${effectiveFontSize}px ${position.font}`;
|
|
2054
|
+
ctx.font = `${effectiveFontSize}px "${position.font}"`;
|
|
2043
2055
|
const fontNameWidth = ctx.measureText(fontName).width;
|
|
2044
2056
|
const totalWidth = prefixWidth + fontNameWidth;
|
|
2045
2057
|
if (totalWidth > shrunkEffectiveMaxWidth) {
|