@hailin-zheng/editor-core 2.1.21 → 2.1.22

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/index-cjs.js CHANGED
@@ -660,7 +660,6 @@ class CommonUtil {
660
660
  static cloneValue(val) {
661
661
  return CommonUtil.cloneDeep(val);
662
662
  }
663
- // @ts-ignore
664
663
  static cloneDeep(source, visited = new WeakMap()) {
665
664
  if (source === null || typeof source !== 'object') {
666
665
  // 如果是基本类型或 null,则直接返回
@@ -4883,6 +4882,8 @@ class TextGroupRenderObject extends LeafRenderObject {
4883
4882
  return;
4884
4883
  }
4885
4884
  const props = this.element.props;
4885
+ //基线位置到top的距离
4886
+ const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(props.getFont());
4886
4887
  let { width, height } = this.rect;
4887
4888
  let vertHeight = 0; //baseLine;
4888
4889
  if (props.vertAlign === 'subscript') {
@@ -4901,10 +4902,11 @@ class TextGroupRenderObject extends LeafRenderObject {
4901
4902
  return curr.actualSize + prev;
4902
4903
  }, this.rect.x);
4903
4904
  const x = arr.join(' ');
4904
- const y = this.rect.y + vertHeight; //this.textMeasures.map(item => this.rect.y + vertHeight).join(' ');
4905
- // const text = this.textMeasures.map(item => {
4906
- // return item.char
4907
- // }).join('');
4905
+ let y = this.rect.y + vertHeight;
4906
+ //基线处理
4907
+ y += actualFontBoundingBoxAscent ?? 0;
4908
+ //行高处理
4909
+ y += (height - props.fontSize) / 2;
4908
4910
  const t = {
4909
4911
  sel: 'text',
4910
4912
  text: text,
@@ -4912,8 +4914,6 @@ class TextGroupRenderObject extends LeafRenderObject {
4912
4914
  ns: "http://www.w3.org/2000/svg",
4913
4915
  attrs: {
4914
4916
  //"transform": `translate(0,${(height - props.fontSize) / 2})`,
4915
- "translate": { x: 0, y: (height - props.fontSize) / 2 },
4916
- 'dominant-baseline': 'hanging',
4917
4917
  'font-family': this.element.props.fontName,
4918
4918
  'font-size': fontSize,
4919
4919
  x,
@@ -4921,6 +4921,9 @@ class TextGroupRenderObject extends LeafRenderObject {
4921
4921
  }
4922
4922
  },
4923
4923
  };
4924
+ if (actualFontBoundingBoxAscent === undefined) {
4925
+ t.data.attrs['dominant-baseline'] = 'hanging';
4926
+ }
4924
4927
  if (this.element.props.fontWeight !== 'normal') {
4925
4928
  t.data.attrs['font-weight'] = this.element.props.fontWeight;
4926
4929
  }
@@ -12868,7 +12871,18 @@ class PaintContent {
12868
12871
  this.init();
12869
12872
  }
12870
12873
  init() {
12871
- this.ctx.textBaseline = 'top';
12874
+ //this.ctx.textBaseline = 'top';
12875
+ }
12876
+ cacheFontBoundingBoxAscentMap = new Map();
12877
+ getActualFontBoundingBoxAscent(font) {
12878
+ if (this.cacheFontBoundingBoxAscentMap.has(font)) {
12879
+ return this.cacheFontBoundingBoxAscentMap.get(font);
12880
+ }
12881
+ this.ctx.font = font;
12882
+ const textMetrics = this.ctx.measureText('正');
12883
+ const value = textMetrics.actualBoundingBoxAscent;
12884
+ this.cacheFontBoundingBoxAscentMap.set(font, value);
12885
+ return value;
12872
12886
  }
12873
12887
  setGlobalAlpha(alpha) {
12874
12888
  this.ctx.globalAlpha = alpha;
@@ -27835,7 +27849,7 @@ class DocEditor {
27835
27849
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
27836
27850
  }
27837
27851
  version() {
27838
- return "2.1.21";
27852
+ return "2.1.22";
27839
27853
  }
27840
27854
  switchPageHeaderEditor() {
27841
27855
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);