View Code? Open in Web Editor
NEW
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 渲染的数据格式)
Home Page: https://haixin-fang.github.io/tojson.js/playground/
JavaScript 84.72%
Shell 0.12%
HTML 2.42%
Vue 11.75%
CSS 0.98%
tojson.js's Issues
定位到错误:
/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' ] )
. ...
...
}