Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.umd.js.map

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion src/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,42 @@ export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
if (color && color.indexOf('#') === -1) color = '#' + color

return color
}
}
export function createGradientText(colors, rot = 90) {
const gradientStops = colors
.map((stop) => {
return `${stop.color} ${stop.pos}`
})
.join(', ')

const gradientStyle = `linear-gradient(${rot}deg, ${gradientStops})`

return `background: ${gradientStyle};
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
color: transparent;`
}
export function getGradFill(solidFill, clrMap, phClr, warpObj) {
const grdFill = solidFill['a:gradFill']
const gsLst = grdFill['a:gsLst']['a:gs']
const color_ary = []

for (let i = 0; i < gsLst.length; i++) {
const lo_color = getSolidFill(gsLst[i], clrMap, phClr, warpObj)
const pos = getTextByPathList(gsLst[i], ['attrs', 'pos'])

color_ary[i] = {
pos: pos ? pos / 1000 + '%' : '',
color: lo_color,
}
}
const lin = grdFill['a:lin']
let rot = 90
if (lin) {
rot = angleToDegrees(lin['attrs']['ang'])
rot = rot + 90
}
const colors = color_ary.sort((a, b) => parseInt(a.pos) - parseInt(b.pos))
return createGradientText(colors, rot)
}
10 changes: 10 additions & 0 deletions src/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getFontSubscript,
getFontShadow,
} from './fontStyle'
import { getFillType, getGradFill } from './fill'

export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpObj) {
if (!textBodyNode) return ''
Expand Down Expand Up @@ -131,6 +132,15 @@ export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayou
if (fontSpace) styleText += `letter-spacing: ${fontSpace};`
if (subscript) styleText += `vertical-align: ${subscript};`
if (shadow) styleText += `text-shadow: ${shadow};`
// 渐变色
const rPrNode = getTextByPathList(node, ['a:rPr'])
if (rPrNode) {
const filTyp = getFillType(rPrNode)
if (filTyp === 'GRADIENT_FILL') {
const fontGradientFillStr = getGradFill(rPrNode, pNode, lstStyle, pFontStyle, lvl, warpObj)
styleText += fontGradientFillStr
}
}

const linkID = getTextByPathList(node, ['a:rPr', 'a:hlinkClick', 'attrs', 'r:id'])
if (linkID) {
Expand Down