@hailin-zheng/editor-core 2.0.14 → 2.0.15

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.js CHANGED
@@ -4780,45 +4780,23 @@ class TextGroupRenderObject extends LeafRenderObject {
4780
4780
  if (this.element.props.background) {
4781
4781
  const bgX = event.relativePagePos.x;
4782
4782
  const bgY = event.relativePagePos.y;
4783
- event.highlights.push({
4784
- sel: 'path',
4785
- data: {
4786
- ns: "http://www.w3.org/2000/svg",
4787
- attrs: {
4788
- d: `M${bgX} ${bgY} h${width} v${this.rect.height} h-${width}z`,
4789
- fill: this.element.props.background,
4790
- }
4791
- }
4792
- });
4783
+ event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, this.rect.width, this.rect.height, this.element.props.background));
4793
4784
  }
4794
4785
  if (this.element.props.underline) {
4795
4786
  const underHeight = this.element.props.fontSize * 1.2;
4796
- event.highlights.push({
4797
- sel: 'path',
4798
- data: {
4799
- ns: "http://www.w3.org/2000/svg",
4800
- attrs: {
4801
- d: `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + underHeight}`,
4802
- stroke: '#000',
4803
- 'stroke-width': 1,
4804
- fill: 'none'
4805
- }
4806
- }
4807
- });
4787
+ const path = `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + underHeight}`;
4788
+ event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4808
4789
  }
4809
4790
  if (this.element.props.linethrough) {
4810
- event.highlights.push({
4811
- sel: 'path',
4812
- data: {
4813
- ns: "http://www.w3.org/2000/svg",
4814
- attrs: {
4815
- d: `M${event.relativePagePos.x} ${event.relativePagePos.y + this.rect.height / 2} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + this.rect.height / 2}`,
4816
- stroke: '#000',
4817
- 'stroke-width': 1,
4818
- fill: 'none'
4819
- }
4820
- }
4821
- });
4791
+ const path = `M${event.relativePagePos.x} ${event.relativePagePos.y + this.rect.height / 2} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + this.rect.height / 2}`;
4792
+ event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4793
+ }
4794
+ if (this.element.props.border) {
4795
+ event.highlights.push(ElementUtil.getStrokeSvgPath(ElementUtil.getRectPath(event.relativePagePos.x, event.relativePagePos.y, this.rect.width, this.rect.height), '#000', 1));
4796
+ }
4797
+ if (this.element.props.overline) {
4798
+ const path = `M${event.relativePagePos.x} ${event.relativePagePos.y} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y}`;
4799
+ event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
4822
4800
  }
4823
4801
  return t;
4824
4802
  }
@@ -19799,17 +19777,81 @@ function printNodes(printNodes, options, printEvent = null) {
19799
19777
 
19800
19778
  class DocumentTemplate {
19801
19779
  static createA4Doc() {
19780
+ return DocumentTemplate.createDoc('A4');
19781
+ }
19782
+ static createDoc(name = 'A4') {
19802
19783
  const doc = new DocumentElement();
19803
19784
  doc.props = new DocumentProps();
19804
- doc.props.width = 210;
19805
- doc.props.height = 297;
19806
- doc.props.padding = new PaddingProps(25.4, 25.4, 19.1, 19.1);
19785
+ const paper = DocumentTemplate.getPaper(name);
19786
+ doc.props.width = paper.width;
19787
+ doc.props.height = paper.height;
19788
+ doc.props.padding = new PaddingProps(paper.top, paper.bottom, paper.left, paper.right);
19807
19789
  doc.addChild(new DocumentHeaderElement());
19808
19790
  doc.addChild(new DocumentBodyElement());
19809
19791
  doc.addChild(new DocumentFooterElement());
19810
19792
  return doc;
19811
19793
  }
19812
- }
19794
+ static getPaper(name) {
19795
+ let top = 25.4, bottom = 25.4, left = 19.1, right = 19.1;
19796
+ const paper = PageSize.find(item => item.name.toUpperCase() === name.toUpperCase());
19797
+ if (paper) {
19798
+ if (top + bottom + 30 > paper.height) {
19799
+ top = bottom = 0;
19800
+ }
19801
+ if (left + right + 30 > paper.width) {
19802
+ left = right = 0;
19803
+ }
19804
+ return {
19805
+ width: paper.width,
19806
+ height: paper.height,
19807
+ top, left, right, bottom
19808
+ };
19809
+ }
19810
+ return { width: PageSize[0].width, height: PageSize[0].height, top, left, right, bottom };
19811
+ }
19812
+ }
19813
+ const PageSize = [
19814
+ { name: 'A4', width: 210, height: 297 },
19815
+ { name: 'A5', width: 148, height: 210 },
19816
+ { name: 'A6', width: 105, height: 148 },
19817
+ { name: 'B5', width: 176, height: 250 },
19818
+ { name: 'B6', width: 125, height: 176 },
19819
+ { name: 'Letter', width: 216, height: 279 },
19820
+ { name: 'Legal', width: 216, height: 356 },
19821
+ { name: 'Executive', width: 184, height: 267 },
19822
+ { name: 'Folio', width: 210, height: 330 },
19823
+ { name: 'Quarto', width: 215, height: 275 },
19824
+ { name: '10x15cm', width: 100, height: 150 },
19825
+ { name: '13x18cm', width: 130, height: 180 },
19826
+ { name: '15x20cm', width: 150, height: 200 },
19827
+ { name: '20x25cm', width: 200, height: 250 },
19828
+ { name: '20x30cm', width: 200, height: 300 },
19829
+ { name: '25x35cm', width: 250, height: 350 },
19830
+ { name: '30x40cm', width: 300, height: 400 },
19831
+ { name: 'A0', width: 841, height: 1189 },
19832
+ { name: 'A1', width: 594, height: 841 },
19833
+ { name: 'A2', width: 420, height: 594 },
19834
+ { name: 'A3', width: 297, height: 420 },
19835
+ { name: 'A7', width: 74, height: 105 },
19836
+ { name: 'A8', width: 52, height: 74 },
19837
+ { name: 'A9', width: 37, height: 52 },
19838
+ { name: 'A10', width: 26, height: 37 },
19839
+ { name: 'B0', width: 1000, height: 1414 },
19840
+ { name: 'B1', width: 707, height: 1000 },
19841
+ { name: 'B2', width: 500, height: 707 },
19842
+ { name: 'B3', width: 353, height: 500 },
19843
+ { name: 'B4', width: 250, height: 353 },
19844
+ { name: 'B7', width: 88, height: 125 },
19845
+ { name: 'B8', width: 62, height: 88 },
19846
+ { name: 'B9', width: 44, height: 62 },
19847
+ { name: 'B10', width: 31, height: 44 },
19848
+ { name: 'C5E', width: 163, height: 229 },
19849
+ { name: 'Comm10E', width: 105, height: 241 },
19850
+ { name: 'DLE', width: 110, height: 220 },
19851
+ { name: 'Folio', width: 210, height: 330 },
19852
+ { name: 'Ledger', width: 432, height: 279 },
19853
+ { name: 'Tabloid', width: 279, height: 432 }
19854
+ ];
19813
19855
 
19814
19856
  /**
19815
19857
  * 处理文档批注
@@ -27122,10 +27164,11 @@ class DocEditor {
27122
27164
  /**
27123
27165
  * 新建文档
27124
27166
  * @param doc
27167
+ * @param name
27125
27168
  */
27126
- createNewDoc(doc = null) {
27169
+ createNewDoc(doc = null, name = 'A4') {
27127
27170
  //this.docCtx.clear();
27128
- const newDoc = doc ?? DocumentTemplate.createA4Doc();
27171
+ const newDoc = doc ?? DocumentTemplate.createDoc(name);
27129
27172
  // this.elementReader.setDocument(newDoc);
27130
27173
  // this.refreshDocument('content');
27131
27174
  this.loadDoc(ElementSerialize.serialize(newDoc, this.viewOptions));
@@ -27349,12 +27392,13 @@ class DocEditor {
27349
27392
  this.resetViewer('force');
27350
27393
  this.selectionState.clear();
27351
27394
  }
27352
- /**
27353
- * 设置纸张大小,单位为毫米(mm)
27354
- * @param width
27355
- * @param height
27356
- */
27357
27395
  setPaperSize(width, height) {
27396
+ if (typeof width === 'string') {
27397
+ const paperSize = DocumentTemplate.getPaper(width);
27398
+ width = paperSize.width;
27399
+ height = paperSize.height;
27400
+ }
27401
+ height = height;
27358
27402
  const docProps = this.docCtx.document.props;
27359
27403
  docProps.width = width;
27360
27404
  docProps.height = height;