@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.
@@ -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');
@@ -45,6 +45,8 @@ export declare class TextStateElement {
45
45
  private clearFlickerInterval;
46
46
  /**
47
47
  * 获取指定状态在当前语种下的字体样式
48
+ * fontStyleCultures 中保存的对象含 fontStyle 字符串但无 isBold/isItalic/fontFamily,
49
+ * 此处从 fontStyle 解析这三个字段后返回
48
50
  */
49
51
  private getFontForState;
50
52
  /**
@@ -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', (this.width / 2).toString());
81
+ tspan.setAttribute('x', anchorX.toString());
69
82
  tspan.setAttribute('y', startY + i * lineHeight + 'px');
70
- tspan.textContent = lines[i].replace(/ /g, '\u00A0');
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', 'middle');
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
- return this.fontStyleCultures[stateKey][targetLanguage];
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: style.isBold,
239
- isItalic: style.isItalic,
244
+ isBold,
245
+ isItalic,
240
246
  fontSize: style.fontSize,
241
- fontFamily: style.fontFamily || 'msyh',
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' });
@@ -5,6 +5,6 @@ export interface Font {
5
5
  readonly fontSize: string;
6
6
  fontFamily?: string;
7
7
  readonly color: string;
8
- readonly textAlign: string;
8
+ readonly textAlign?: string;
9
9
  readonly fontStyle?: string;
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "main": "bundles/fc-gui.umd.js",
3
- "version": "3.0.0-alpha.163",
3
+ "version": "3.0.0-alpha.164",
4
4
  "module": "public_api.js",
5
5
  "typings": "public_api.d.ts",
6
6
  "license": "UNLICENSED",