MCPcopy
hub / github.com/veasion/AiPPT / toPaint

Function toPaint

static/ppt2svg.js:918–1081  ·  view source on GitHub ↗
(paint, anchor, params)

Source from the content-addressed store, hash-verified

916 }
917
918 function toPaint(paint, anchor, params) {
919 if (!paint) {
920 return 'transparent'
921 } else if (paint.type == 'noFill') {
922 // 无填充
923 return 'transparent'
924 } else if (paint.type == 'color') {
925 // 颜色
926 return toColor(paint.color)
927 } else if (paint.type == 'bgFill') {
928 // 背景填充
929 if (ctx.bgFillStyle) {
930 return toPaint(ctx.bgFillStyle, ctx.bgAnchor || anchor, params)
931 } else {
932 return 'transparent'
933 }
934 } else if (paint.type == 'groupFill') {
935 // 组合背景
936 let groupFillStyle = paint.parentGroupFillStyle || ctx.groupFillStyle
937 if (groupFillStyle) {
938 return toPaint(groupFillStyle, scaleAnchor(groupFillStyle.groupAnchor) || anchor, params)
939 } else {
940 return 'transparent'
941 }
942 } else if (paint.type == 'gradient') {
943 // 渐变
944 let gradient = paint.gradient
945 let x = 0, y = 0
946 let width = anchor[2], height = anchor[3]
947 let centerX = x + width / 2
948 let centerY = y + height / 2
949 let gradientNode
950 // linear,circular,rectangular,shape
951 if (gradient.gradientType == 'circular') {
952 // 射线
953 let cx = centerX + width * (gradient.insets[1] - gradient.insets[3]) / 2
954 let cy = centerY + height * (gradient.insets[0] - gradient.insets[2]) / 2
955 // let radius = Math.sqrt(width * width + height * height) * (gradient.insets[1] == 0.5 ? 0.5 : 1)
956 let _cx = ((cx / width) * 100).toFixed(0) + '%'
957 let _cy = ((cy / height) * 100).toFixed(0) + '%'
958 let _r = (gradient.insets[1] * 100).toFixed(0) + '%'
959 gradientNode = defs.append('radialGradient').attr('cx', _cx).attr('cy', _cy).attr('r', _r).attr('fx', _cx).attr('fy', _cy)
960 } else {
961 // 线性
962 let startX = x
963 let startY = centerY
964 let endX = x + width
965 let endY = centerY
966 if (gradient.angle) {
967 let radians = gradient.angle * Math.PI / 180
968 let midX = (startX + endX) / 2
969 let midY = (startY + endY) / 2
970 let newStartX = midX + (startX - midX) * Math.cos(radians) - (startY - midY) * Math.sin(radians)
971 let newStartY = midY + (startX - midX) * Math.sin(radians) + (startY - midY) * Math.cos(radians)
972 let newEndX = midX + (endX - midX) * Math.cos(radians) - (endY - midY) * Math.sin(radians)
973 let newEndY = midY + (endX - midX) * Math.sin(radians) + (endY - midY) * Math.cos(radians)
974 startX = newStartX
975 startY = newStartY

Callers 5

drawBackgroundFunction · 0.70
createRNodeFunction · 0.70
drawTableColumnFunction · 0.70
drawGraphicFrameFunction · 0.70
drawGeometryFunction · 0.70

Calls 4

scaleAnchorFunction · 0.85
texturePatternFunction · 0.85
toColorFunction · 0.70
loadImageFunction · 0.70

Tested by

no test coverage detected