haixin-fang / tojson.js

tojson.js is a class library that supports parsing Psd, Sketch, and PPT to JSON. This JSON conforms to the data format of fabric.js rendering. (tojson.js 是一个支持解析 Psd、Sketch、PPT转 json 的类库, 该 json 满足 fabric.js 渲染的数据格式)
https://haixin-fang.github.io/tojson.js/playground/
49 stars 5 forks source link

bug: pptx自定义形状解析 #1

Open ouyoungs opened 9 months ago

ouyoungs commented 9 months ago

定位到错误: /pptx-json/src/index.js

不能正确解析常规形状之外的图形:

line 750

  if (custShapType && type !== "diagram") {
    const ext = getTextByPathList(slideXfrmNode, ["a:ext", "attrs"]);
    const cx = parseInt(ext["cx"]) * SLIDE_FACTOR;
    const cy = parseInt(ext["cy"]) * SLIDE_FACTOR;
    const w = parseInt(ext["cx"]) * SLIDE_FACTOR;
    const h = parseInt(ext["cy"]) * SLIDE_FACTOR;
    // TypeError: Cannot read properties of undefined (reading 'w')
    let d = '';
    console.log(custShapType, w, h)
    try {
      d = getCustomShapePath(custShapType, w, h);

    } catch (e) {
      console.log(e, 'Error')
      d = '';
    }
    return {
      ...data,
      type: "shape",
      cx,
      cy,
      shapType: "custom",
      path: d,
    };
  }

shape.js

这里忽略了数组这种情况

export function getCustomShapePath(custShapType, w, h) {
  const pathLstNode = getTextByPathList(custShapType, ['a:pathLst'])
  let pathNodes = getTextByPathList(pathLstNode, ['a:path'])

  if (Array.isArray(pathNodes)) {
    pathNodes = pathNodes.pop()
  }
  const maxX = parseInt(pathNodes['attrs']['w'])
  const maxY = parseInt(pathNodes['attrs']['h'])
  ....
  ...
}
ouyoungs commented 9 months ago

test118.pptx

含有自定义形状的pptx