PPTX

效果与填充

为形状应用阴影、发光、3D 效果和各种填充类型

通过视觉效果(阴影、发光、3D)和填充(纯色、渐变、图片、透明)增强形状。

纯色填充

import { generatePresentation } from "@office-open/pptx";
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "6.6cm",
            "fill": { "type": "solid", "color": "2E74B5" }
          }
        }
      ]
    }
  ]
}

简写形式 -- 直接传入颜色字符串:

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "6.6cm",
            "fill": "2E74B5"
          }
        }
      ]
    }
  ]
}

渐变填充

线性渐变(带角度)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "0D47A1" },
                { "position": 100, "color": "42A5F5" }
              ],
              "angle": 45
            }
          }
        }
      ]
    }
  ]
}

径向渐变(带路径)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "10.6cm",
            "geometry": "ellipse",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "FFFFFF" },
                { "position": 100, "color": "1565C0" }
              ],
              "path": "circle"
            }
          }
        }
      ]
    }
  ]
}

多色标渐变

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "E53935" },
                { "position": 50, "color": "FF9800" },
                { "position": 100, "color": "FFEB3B" }
              ],
              "angle": 90
            }
          }
        }
      ]
    }
  ]
}

图片填充(Blip Fill)

data 字段接受原始字节(Uint8ArrayArrayBufferBuffer),也支持 base64 data URL(如 data:image/png;base64,...)。

import * as fs from "node:fs";
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "9.3cm",
            "fill": {
              "type": "blip",
              "data": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
              "imageType": "png"
            }
          }
        }
      ]
    }
  ]
}

无填充(透明)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "6.6cm",
            "fill": { "type": "none" },
            "outline": { "color": "2E74B5", "width": 2 }
          }
        }
      ]
    }
  ]
}

轮廓

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "6.6cm",
            "fill": { "type": "solid", "color": "E3F2FD" },
            "outline": {
              "color": "1565C0",
              "width": "0.1cm",
              "dash": "solid"
            }
          }
        }
      ]
    }
  ]
}

效果

使用 effects 属性控制阴影、发光、倒影、柔化边缘和 3D 效果:

外部阴影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "ED7D31",
            "effects": {
              "outerShadow": {
                "blurRadius": 50800,
                "distance": 38100,
                "direction": 90,
                "color": { "value": "000000", "transforms": { "alpha": 50 } }
              }
            }
          }
        }
      ]
    }
  ]
}

内部阴影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "5B9BD5",
            "effects": {
              "innerShadow": {
                "blurRadius": 40000,
                "distance": 30000,
                "direction": 90,
                "color": { "value": "000000", "transforms": { "alpha": 40 } }
              }
            }
          }
        }
      ]
    }
  ]
}

发光

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "70AD47",
            "effects": {
              "glow": {
                "radius": 152400,
                "color": { "value": "92D050", "transforms": { "alpha": 60 } }
              }
            }
          }
        }
      ]
    }
  ]
}

倒影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "FFC000",
            "effects": {
              "reflection": {
                "blurRadius": 6350,
                "distance": 38100,
                "direction": 90,
                "startAlpha": 90,
                "endAlpha": 0
              }
            }
          }
        }
      ]
    }
  ]
}

柔化边缘

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "BF8F00",
            "effects": {
              "softEdge": 50800
            }
          }
        }
      ]
    }
  ]
}

3D 旋转和斜面

3D 拆成两个形状属性 —— 不在 effects 下:

  • scene3da:scene3d)—— 3D 场景:cameralightRig(可选 backdrop)。相机旋转是球坐标 { lat, lon, rev },单位为度;lightRig 携带 rigdirection
  • shape3da:sp3d)—— 3D 形状本体:bevelT/bevelB(顶/底斜面)、 extrusionHcontourWzprstMaterial
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "4.0cm",
            "fill": "FFC000",
            "scene3d": {
              "camera": {
                "preset": "perspectiveFront",
                "fov": 30,
                "rotation": { "lat": 0, "lon": 0, "rev": 10 }
              },
              "lightRig": { "rig": "threePt", "direction": "t" }
            },
            "shape3d": {
              "bevelT": { "w": 76200, "h": 76200, "prst": "circle" },
              "extrusionH": 50000,
              "prstMaterial": "plastic"
            }
          }
        }
      ]
    }
  ]
}

组合效果

可以同时应用多种效果:

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "7030A0",
            "effects": {
              "outerShadow": {
                "blurRadius": 40000,
                "distance": 30000,
                "direction": 45,
                "color": { "value": "000000", "transforms": { "alpha": 40 } }
              },
              "glow": {
                "radius": 101600,
                "color": { "value": "B381E7", "transforms": { "alpha": 35 } }
              }
            }
          }
        }
      ]
    }
  ]
}

Effects 选项

effects 只承载扁平的 2D 效果(EffectListOptions)。3D 直接位于形状上,分属 scene3dshape3d

属性类型说明
effects.blurBlurEffectOptions模糊效果
effects.glowGlowEffectOptions发光效果(radius + color
effects.innerShadowInnerShadowEffectOptions内部阴影(blurRadiusdistancedirection 单位为度、color
effects.outerShadowOuterShadowEffectOptions外部阴影(blurRadiusdistancedirection 单位为度、color
effects.reflectionReflectionEffectOptions | true倒影(blurRadiusdistancedirection 单位为度、startAlphaendAlpha
effects.softEdgenumber | UniversalMeasure柔化边缘半径 —— 标量(EMU 或 UniversalMeasure)
scene3dScene3DOptions3D 场景 —— cameralightRig(角度单位为度)
shape3dShape3DOptions3D 形状本体 —— bevelT/bevelBextrusionHcontourWzprstMaterial

阴影与发光的 colorSolidFillOptions{ value, transforms });不透明度 通过 color.transforms.alpha(整数百分比)传入,而非顶层 alpha

Copyright © 2026