@hailin-zheng/editor-core 2.1.21 → 2.1.23

Sign up to get free protection for your applications and to get access to all the features.
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,则直接返回
@@ -4679,7 +4678,9 @@ class TableRowElement extends BlockContainerElement {
4679
4678
  }
4680
4679
  }
4681
4680
  createRenderObject() {
4682
- return new TableRowRenderObject(this);
4681
+ const rowRender = new TableRowRenderObject(this);
4682
+ rowRender.minHeight = this.props.minHeight;
4683
+ return rowRender;
4683
4684
  }
4684
4685
  serialize(viewOptions) {
4685
4686
  return {
@@ -4712,10 +4713,13 @@ class TableRowRenderObject extends MuiltBlockLineRenderObject {
4712
4713
  remeasureState = true;
4713
4714
  //当前行是否存在合并单元格
4714
4715
  hasMergeCells = undefined;
4716
+ //行最小高度,用于标记当前行临时的最小高度状态
4717
+ minHeight = -1;
4715
4718
  clone() {
4716
4719
  const cloneRender = new TableRowRenderObject(this.element);
4717
4720
  cloneRender.remeasureState = this.remeasureState;
4718
4721
  cloneRender.hasMergeCells = this.hasMergeCells;
4722
+ cloneRender.minHeight = this.minHeight;
4719
4723
  cloneRender.rect = ElementUtil.cloneRect(this.rect);
4720
4724
  for (let i = 0; i < this.length; i++) {
4721
4725
  cloneRender.addChild(this.getChild(i).clone());
@@ -4883,6 +4887,8 @@ class TextGroupRenderObject extends LeafRenderObject {
4883
4887
  return;
4884
4888
  }
4885
4889
  const props = this.element.props;
4890
+ //基线位置到top的距离
4891
+ const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(props.getFont());
4886
4892
  let { width, height } = this.rect;
4887
4893
  let vertHeight = 0; //baseLine;
4888
4894
  if (props.vertAlign === 'subscript') {
@@ -4901,10 +4907,11 @@ class TextGroupRenderObject extends LeafRenderObject {
4901
4907
  return curr.actualSize + prev;
4902
4908
  }, this.rect.x);
4903
4909
  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('');
4910
+ let y = this.rect.y + vertHeight;
4911
+ //基线处理
4912
+ y += actualFontBoundingBoxAscent ?? 0;
4913
+ //行高处理
4914
+ y += (height - props.fontSize) / 2;
4908
4915
  const t = {
4909
4916
  sel: 'text',
4910
4917
  text: text,
@@ -4912,8 +4919,6 @@ class TextGroupRenderObject extends LeafRenderObject {
4912
4919
  ns: "http://www.w3.org/2000/svg",
4913
4920
  attrs: {
4914
4921
  //"transform": `translate(0,${(height - props.fontSize) / 2})`,
4915
- "translate": { x: 0, y: (height - props.fontSize) / 2 },
4916
- 'dominant-baseline': 'hanging',
4917
4922
  'font-family': this.element.props.fontName,
4918
4923
  'font-size': fontSize,
4919
4924
  x,
@@ -4921,6 +4926,9 @@ class TextGroupRenderObject extends LeafRenderObject {
4921
4926
  }
4922
4927
  },
4923
4928
  };
4929
+ if (actualFontBoundingBoxAscent === undefined) {
4930
+ t.data.attrs['dominant-baseline'] = 'hanging';
4931
+ }
4924
4932
  if (this.element.props.fontWeight !== 'normal') {
4925
4933
  t.data.attrs['font-weight'] = this.element.props.fontWeight;
4926
4934
  }
@@ -11097,7 +11105,7 @@ class ElementUtil {
11097
11105
  canvas.style.height = scaleHeight + 'px';
11098
11106
  canvas.width = scaleWidth * dpr;
11099
11107
  canvas.height = scaleHeight * dpr;
11100
- ctx.textBaseline = 'top';
11108
+ //ctx.textBaseline = 'top';
11101
11109
  ctx.scale(dpr, dpr);
11102
11110
  }
11103
11111
  // static setOffscreenCanvas(canvas: OffscreenCanvas, ctx: OffscreenCanvasRenderingContext2D, viewOptions: { width: number, height: number }, scale: number = 1): void {
@@ -11247,8 +11255,7 @@ class ElementUtil {
11247
11255
  return innerRect.height;
11248
11256
  }
11249
11257
  static remeasureTableRow(rowRender, forceColIndex = -1) {
11250
- const rowEle = rowRender.element;
11251
- let maxCellHeight = rowEle.props.minHeight > 20 ? rowEle.props.minHeight : 20;
11258
+ let maxCellHeight = rowRender.minHeight > 20 ? rowRender.minHeight : 20;
11252
11259
  //限制行最小高度
11253
11260
  maxCellHeight = maxCellHeight < 20 ? 20 : maxCellHeight;
11254
11261
  //获取行内非纵向合并单元格的最高单元格高度
@@ -12796,6 +12803,13 @@ class ElementUtil {
12796
12803
  }
12797
12804
  }
12798
12805
 
12806
+ exports.TextUnitsHolder = void 0;
12807
+ (function (TextUnitsHolder) {
12808
+ TextUnitsHolder[TextUnitsHolder["char"] = 0] = "char";
12809
+ TextUnitsHolder[TextUnitsHolder["sourceSize"] = 1] = "sourceSize";
12810
+ TextUnitsHolder[TextUnitsHolder["actualSize"] = 2] = "actualSize";
12811
+ TextUnitsHolder[TextUnitsHolder["actualBoundingBoxAscent"] = 3] = "actualBoundingBoxAscent";
12812
+ })(exports.TextUnitsHolder || (exports.TextUnitsHolder = {}));
12799
12813
  class RenderContext {
12800
12814
  mainContext;
12801
12815
  contentContext;
@@ -12868,7 +12882,18 @@ class PaintContent {
12868
12882
  this.init();
12869
12883
  }
12870
12884
  init() {
12871
- this.ctx.textBaseline = 'top';
12885
+ //this.ctx.textBaseline = 'top';
12886
+ }
12887
+ cacheFontBoundingBoxAscentMap = new Map();
12888
+ getActualFontBoundingBoxAscent(font) {
12889
+ if (this.cacheFontBoundingBoxAscentMap.has(font)) {
12890
+ return this.cacheFontBoundingBoxAscentMap.get(font);
12891
+ }
12892
+ this.ctx.font = font;
12893
+ const textMetrics = this.ctx.measureText('正');
12894
+ const value = textMetrics.actualBoundingBoxAscent;
12895
+ this.cacheFontBoundingBoxAscentMap.set(font, value);
12896
+ return value;
12872
12897
  }
12873
12898
  setGlobalAlpha(alpha) {
12874
12899
  this.ctx.globalAlpha = alpha;
@@ -15000,13 +15025,15 @@ class DocumentArrange {
15000
15025
  let currRow = rows[j];
15001
15026
  const cutRows = [];
15002
15027
  while (currRow) {
15003
- const minHeight = currRow.element.props.minHeight;
15028
+ const minHeight = currRow.minHeight;
15004
15029
  const rowContentHeight = this.getBlockLineHeight(currRow);
15005
15030
  if (rowContentHeight + sumHeight > limitHeight) {
15006
15031
  //行存在最小高度,且当前行内容的高度小于最小高度,且当前行跨页的情况下,不截断该行
15007
15032
  if (minHeight > 0 && minHeight > rowContentHeight) {
15008
15033
  break;
15009
15034
  }
15035
+ //设定最小高度不生效
15036
+ currRow.minHeight = -1;
15010
15037
  //限制的外框尺寸
15011
15038
  const availHeight = limitHeight - sumHeight;
15012
15039
  const limitRenderInnerHeight = ElementUtil.innerRectMaxHeight(tbRender, availHeight);
@@ -15057,6 +15084,9 @@ class DocumentArrange {
15057
15084
  // }
15058
15085
  render.remeasureState = true;
15059
15086
  const cloneRowRender = render.element.createRenderObject();
15087
+ if (cloneRowRender.minHeight > 0 && render.minHeight <= 0) {
15088
+ cloneRowRender.minHeight = render.minHeight;
15089
+ }
15060
15090
  cloneRowRender.rect.width = render.rect.width;
15061
15091
  //cloneRowRender.rect.maxWidth = render.rect.height;
15062
15092
  const cellRenders = [...render.getItems()];
@@ -27835,7 +27865,7 @@ class DocEditor {
27835
27865
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
27836
27866
  }
27837
27867
  version() {
27838
- return "2.1.21";
27868
+ return "2.1.23";
27839
27869
  }
27840
27870
  switchPageHeaderEditor() {
27841
27871
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);