@flexem/fc-gui 3.0.0-alpha.163 → 3.0.0-alpha.164
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/bundles/@flexem/fc-gui.umd.js +44 -14
- package/bundles/@flexem/fc-gui.umd.js.map +1 -1
- package/bundles/@flexem/fc-gui.umd.min.js +1 -1
- package/bundles/@flexem/fc-gui.umd.min.js.map +1 -1
- package/elements/shared/text/text-element.js +1 -1
- package/elements/shared/text/text-state-element.d.ts +2 -0
- package/elements/shared/text/text-state-element.js +33 -8
- package/elements/view-operation/view-operation.element.js +10 -5
- package/model/shared/text/font.d.ts +1 -1
- package/package.json +1 -1
|
@@ -77,7 +77,7 @@ export class TextElementModal {
|
|
|
77
77
|
lineHeight = parseInt(font.fontSize, 10) + 5;
|
|
78
78
|
fontString += font.fontSize + '/' + lineHeight.toString() + 'px ' + font.fontFamily;
|
|
79
79
|
textDiv.style.cssText = `color: ${font.color};word-break: break-all;font: ${fontString};text-align: ${textAlign};`;
|
|
80
|
-
if (font.isUnderline) {
|
|
80
|
+
if (font.isUnderline && content.length > 0) {
|
|
81
81
|
textDiv.style.textDecoration = 'underline';
|
|
82
82
|
}
|
|
83
83
|
const spanText = document.createElement('span');
|
|
@@ -44,10 +44,23 @@ export class TextStateElement {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const textElement = this.getforeignObjectElement();
|
|
47
|
-
// 设置 text-anchor 和 dominant-baseline
|
|
48
|
-
textElement.setAttribute('text-anchor', 'middle');
|
|
49
|
-
textElement.setAttribute('dominant-baseline', 'middle');
|
|
50
47
|
textElement.setAttribute('pointer-events', 'auto');
|
|
48
|
+
// 根据 textAlign 计算 SVG text-anchor 和 x 坐标
|
|
49
|
+
const textAlign = font.textAlign || 'center';
|
|
50
|
+
let textAnchor;
|
|
51
|
+
let anchorX;
|
|
52
|
+
if (textAlign === 'left') {
|
|
53
|
+
textAnchor = 'start';
|
|
54
|
+
anchorX = 0;
|
|
55
|
+
}
|
|
56
|
+
else if (textAlign === 'right') {
|
|
57
|
+
textAnchor = 'end';
|
|
58
|
+
anchorX = this.width;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
textAnchor = 'middle';
|
|
62
|
+
anchorX = this.width / 2;
|
|
63
|
+
}
|
|
51
64
|
// 拆分换行
|
|
52
65
|
const lines = content.split('\n');
|
|
53
66
|
const fontSize = parseInt(font.fontSize, 10);
|
|
@@ -65,16 +78,16 @@ export class TextStateElement {
|
|
|
65
78
|
textElement.appendChild(tspan);
|
|
66
79
|
}
|
|
67
80
|
tspan.setAttribute('display', 'inline');
|
|
68
|
-
tspan.setAttribute('x',
|
|
81
|
+
tspan.setAttribute('x', anchorX.toString());
|
|
69
82
|
tspan.setAttribute('y', startY + i * lineHeight + 'px');
|
|
70
|
-
tspan.textContent = lines[i].replace(/ /g, '
|
|
83
|
+
tspan.textContent = lines[i].replace(/ /g, ' ');
|
|
71
84
|
tspan.setAttribute('font-size', font.fontSize);
|
|
72
85
|
tspan.setAttribute('fill', font.color);
|
|
73
86
|
tspan.setAttribute('font-family', font.fontFamily);
|
|
74
87
|
tspan.setAttribute('font-weight', font.isBold ? 'bold' : 'normal');
|
|
75
88
|
tspan.setAttribute('font-style', font.isItalic ? 'italic' : 'normal');
|
|
76
89
|
tspan.setAttribute('text-decoration', font.isUnderline ? 'underline' : 'none');
|
|
77
|
-
tspan.setAttribute('text-anchor',
|
|
90
|
+
tspan.setAttribute('text-anchor', textAnchor);
|
|
78
91
|
tspan.setAttribute('dominant-baseline', 'middle');
|
|
79
92
|
}
|
|
80
93
|
// 隐藏多余的 tspan(不删除)
|
|
@@ -132,7 +145,7 @@ export class TextStateElement {
|
|
|
132
145
|
}
|
|
133
146
|
}
|
|
134
147
|
doFaultFlicker(textElement, stateId) {
|
|
135
|
-
if (this.version > 3 && this.faultFlickers) {
|
|
148
|
+
if (this.version != null && this.version > 3 && this.faultFlickers) {
|
|
136
149
|
this.clearFlickerInterval(textElement);
|
|
137
150
|
const faultFlicker = this.faultFlickers.find(t => t.id === stateId);
|
|
138
151
|
if (faultFlicker && faultFlicker.faultFlicker) {
|
|
@@ -161,6 +174,8 @@ export class TextStateElement {
|
|
|
161
174
|
}
|
|
162
175
|
/**
|
|
163
176
|
* 获取指定状态在当前语种下的字体样式
|
|
177
|
+
* fontStyleCultures 中保存的对象含 fontStyle 字符串但无 isBold/isItalic/fontFamily,
|
|
178
|
+
* 此处从 fontStyle 解析这三个字段后返回
|
|
164
179
|
*/
|
|
165
180
|
getFontForState(stateId, defaultFont) {
|
|
166
181
|
if (!this.fontStyleCultures) {
|
|
@@ -181,7 +196,17 @@ export class TextStateElement {
|
|
|
181
196
|
};
|
|
182
197
|
const targetLanguage = getTargetLanguage();
|
|
183
198
|
if (this.fontStyleCultures[stateKey][targetLanguage]) {
|
|
184
|
-
|
|
199
|
+
const culturedFont = this.fontStyleCultures[stateKey][targetLanguage];
|
|
200
|
+
if (culturedFont.fontStyle) {
|
|
201
|
+
const fs = culturedFont.fontStyle;
|
|
202
|
+
const isBold = fs.indexOf('bold') !== -1;
|
|
203
|
+
const isItalic = fs.indexOf('Italic') !== -1;
|
|
204
|
+
const parts = fs.split(' ');
|
|
205
|
+
const familyIndex = (isBold ? 1 : 0) + (isItalic ? 1 : 0) + 1;
|
|
206
|
+
const fontFamily = parts.length > familyIndex ? parts[familyIndex] : null;
|
|
207
|
+
return Object.assign(Object.assign({}, culturedFont), { isBold, isItalic, fontFamily });
|
|
208
|
+
}
|
|
209
|
+
return culturedFont;
|
|
185
210
|
}
|
|
186
211
|
return defaultFont;
|
|
187
212
|
}
|
|
@@ -233,14 +233,19 @@ export class ViewOperationElement extends ConditionalEnableElement {
|
|
|
233
233
|
const targetLanguage = getTargetLanguage();
|
|
234
234
|
if (this.model.fontStyleCultures && this.model.fontStyleCultures[targetLanguage]) {
|
|
235
235
|
const style = this.model.fontStyleCultures[targetLanguage];
|
|
236
|
+
const fs = style.fontStyle || '';
|
|
237
|
+
const isBold = fs.indexOf('bold') !== -1;
|
|
238
|
+
const isItalic = fs.indexOf('Italic') !== -1;
|
|
239
|
+
const parts = fs.split(' ');
|
|
240
|
+
const familyIndex = (isBold ? 1 : 0) + (isItalic ? 1 : 0) + 1;
|
|
241
|
+
const fontFamily = parts.length > familyIndex ? parts[familyIndex] : null;
|
|
236
242
|
return {
|
|
237
243
|
isUnderline: style.isUnderline,
|
|
238
|
-
isBold
|
|
239
|
-
isItalic
|
|
244
|
+
isBold,
|
|
245
|
+
isItalic,
|
|
240
246
|
fontSize: style.fontSize,
|
|
241
|
-
fontFamily:
|
|
242
|
-
color: style.color
|
|
243
|
-
textAlign: style.textAlign
|
|
247
|
+
fontFamily: fontFamily || 'msyh',
|
|
248
|
+
color: style.color
|
|
244
249
|
};
|
|
245
250
|
}
|
|
246
251
|
return Object.assign(Object.assign({}, this.model.label.font), { fontFamily: this.model.label.font.fontFamily || 'msyh' });
|