Sync snapshot (2026-08-19) (#110)
- Improve Docs pagination, anchored-object fidelity, password protection, recovery safety, and multilingual font fallback - Scale Sheets editing and saves for large workbooks with safer AI bulk operations, aggregation, undo, recovery, and richer visual fidelity - Expand Slides fidelity with 3D rendering, SmartArt and WordArt improvements, pattern and texture fills, and resource cleanup - Add AI PDF creation, text insertion, reading-position restore, safer atomic saves, and improved comments and page workflows - Add Markdown math rendering and protect linked assets across save, conversion, and document lifecycle operations - Read legacy DOC and PPT attachments locally and strengthen document package resource cleanup - Document default-on usage analytics with a persistent Settings opt-out and a dedicated, tested privacy page Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
04a994b9e9
commit
fe2e17403c
File diff suppressed because it is too large
Load Diff
@@ -49,6 +49,13 @@ import {
|
||||
presetPolygon,
|
||||
presetPath,
|
||||
} from './preset-geometry'
|
||||
import {
|
||||
buildExtrusion,
|
||||
inPlaneRotationDeg,
|
||||
flattenSvgPath,
|
||||
ellipseRing,
|
||||
roundRectRing,
|
||||
} from './scene3d'
|
||||
|
||||
export interface BuildOptions {
|
||||
/** Target canvas width (px); height follows the slide aspect ratio. */
|
||||
@@ -98,6 +105,18 @@ const CHIP_LABEL: Record<string, string> = {
|
||||
unknown: 'Unsupported element',
|
||||
}
|
||||
|
||||
/** White-DC backing for a metafile picture, after any clrChange keyed to that white. */
|
||||
function metafileDcColor(
|
||||
isMetafile: boolean,
|
||||
cc: { from: string; to: string } | undefined,
|
||||
): { bgColor: string } | undefined {
|
||||
if (!isMetafile) return undefined
|
||||
if (!cc || !cc.from.toUpperCase().startsWith('#FFFFFF')) return { bgColor: '#FFFFFF' }
|
||||
const alpha = cc.to.length >= 9 ? parseInt(cc.to.slice(7, 9), 16) : 255
|
||||
// Keep the target's alpha: a semi-transparent recolor backs with a translucent panel
|
||||
return alpha > 0 ? { bgColor: cc.to } : undefined
|
||||
}
|
||||
|
||||
export function buildRenderSlide(
|
||||
slide: Slide,
|
||||
size: SlideDeck['size'],
|
||||
@@ -381,6 +400,7 @@ function buildShape(
|
||||
if (shadow) node.shadow = shadow
|
||||
const glow = resolveGlow(el.glow, vp)
|
||||
if (glow) node.glow = glow
|
||||
if (el.scene3d) applyScene3D(el, node, vp)
|
||||
if (el.text && el.text.paragraphs.length) {
|
||||
node.text = layoutText({
|
||||
body: el.text,
|
||||
@@ -393,6 +413,54 @@ function buildShape(
|
||||
return node
|
||||
}
|
||||
|
||||
/**
|
||||
* scene3d/sp3d: a camera with only an in-plane revolution spins the flat shape;
|
||||
* anything with a real 3D rotation or extrusion depth gets meshed, projected and
|
||||
* shaded (see scene3d.ts) — depth 0 projects just the tilted front cap.
|
||||
*/
|
||||
function applyScene3D(el: TextElement, node: ShapeRenderNode, vp: Viewport): void {
|
||||
if (node.line) return // connectors keep their polyline rendering
|
||||
const scene = el.scene3d!
|
||||
const spin = inPlaneRotationDeg(scene)
|
||||
if (spin != null) {
|
||||
if (spin !== 0) node.box = { ...node.box, rotationDeg: node.box.rotationDeg + spin }
|
||||
return
|
||||
}
|
||||
const depthPx = emuToPx(scene.extrusionEmu ?? 0, vp.scale)
|
||||
const box = node.box
|
||||
let rings: number[][] | undefined
|
||||
if (node.pathData ?? node.fillPathData)
|
||||
rings = flattenSvgPath((node.pathData ?? node.fillPathData)!)
|
||||
else if (node.polygonPoints) rings = [node.polygonPoints]
|
||||
else if (node.presetGeometry === 'ellipse' || node.presetGeometry === 'circle')
|
||||
rings = [ellipseRing(box.w, box.h)]
|
||||
else if (node.cornerRadiusPx != null) rings = [roundRectRing(box.w, box.h, node.cornerRadiusPx)]
|
||||
else rings = [[0, 0, box.w, 0, box.w, box.h, 0, box.h]]
|
||||
if (!rings.length) return
|
||||
const fill = node.fill
|
||||
const frontSolid = fill.kind === 'solid' ? fill.color : undefined
|
||||
const gradientMid =
|
||||
fill.kind === 'gradient' && fill.stops.length
|
||||
? fill.stops[Math.floor(fill.stops.length / 2)]!.color
|
||||
: undefined
|
||||
const frontColor = frontSolid ?? gradientMid ?? '#FFFFFF'
|
||||
// PowerPoint colors the extruded walls with the outline color when one exists, else the fill.
|
||||
const sideColor = scene.extrusionColor ?? node.stroke?.color ?? frontColor
|
||||
const ext = buildExtrusion({
|
||||
rings,
|
||||
w: box.w,
|
||||
h: box.h,
|
||||
depthPx,
|
||||
zPx: emuToPx(scene.zEmu ?? 0, vp.scale),
|
||||
scene,
|
||||
frontColor,
|
||||
sideColor,
|
||||
...(node.stroke ? { strokeColor: node.stroke.color, strokeWidthPx: node.stroke.widthPx } : {}),
|
||||
...(fill.kind !== 'solid' ? { frontUsesFill: true } : {}),
|
||||
})
|
||||
if (ext) node.extrusion = ext
|
||||
}
|
||||
|
||||
/** Picture shape geometry -> three clip channels (same preset implementation as shape geometry). */
|
||||
function pictureClip(
|
||||
preset: string | undefined,
|
||||
@@ -446,7 +514,10 @@ function buildPicture(
|
||||
...(el.name ? { name: el.name } : {}),
|
||||
...(el.descr ? { descr: el.descr } : {}),
|
||||
...(el.fill && el.fill.type !== 'none' ? { fill: resolveFill(el.fill, vp, media) } : {}),
|
||||
...(isMetafile ? { bgColor: '#FFFFFF' } : {}),
|
||||
// clrChange applies to the metafile playback result including that white DC:
|
||||
// a clrChange keyed to white recolors the backing (an alpha-0 target drops it —
|
||||
// tdf113163's black master bg shows through); other keys leave the DC white
|
||||
...(metafileDcColor(isMetafile, el.clrChange) ?? {}),
|
||||
...(el.duotone ? { duotone: el.duotone } : {}),
|
||||
...(el.clrChange ? { clrChange: el.clrChange } : {}),
|
||||
}
|
||||
@@ -510,9 +581,9 @@ function buildGroup(
|
||||
|
||||
/**
|
||||
* Table → TableRenderNode. Cell coordinates are relative to the table's top-left (px).
|
||||
* Column widths/row heights are distributed by EMU ratio over the frame's actual px size.
|
||||
* Row height is a minimum in PPT: rows whose wrapped cell text needs more space grow to
|
||||
* fit it, and the node box grows with the total so nothing is clipped.
|
||||
* Columns and rows render at their EMU sizes (the grid is authoritative; the frame ext
|
||||
* is often stale). Row height is a minimum in PPT: rows whose wrapped cell text needs
|
||||
* more space grow to fit it, and the node box grows with the total so nothing is clipped.
|
||||
*/
|
||||
function buildTable(
|
||||
el: TableElement,
|
||||
@@ -521,14 +592,24 @@ function buildTable(
|
||||
metrics: FontMetricsProvider,
|
||||
media: MediaResolver | undefined,
|
||||
): TableRenderNode {
|
||||
const sumW = el.colWidths.reduce((a, b) => a + b, 0) || 1
|
||||
const colPx = el.colWidths.map((w) => (w / sumW) * box.w)
|
||||
// a:gridCol w is authoritative in PowerPoint: a stale frame cx (generator tools write
|
||||
// placeholder exts) never squeezes the columns — the table renders at its grid width,
|
||||
// just like rows ignore a stale cy below. Group placement bakes ext/chExt scaling into
|
||||
// the box, so recover that factor from box vs the element's own ext (1 outside groups,
|
||||
// where box comes from the same ext — a stale ext still cancels out).
|
||||
const extWpx = emuToPx(el.transform?.offset.cx ?? 0, vp.scale)
|
||||
const extHpx = emuToPx(el.transform?.offset.cy ?? 0, vp.scale)
|
||||
const groupScaleX = extWpx > 0 ? box.w / extWpx : 1
|
||||
const groupScaleY = extHpx > 0 ? box.h / extHpx : 1
|
||||
const colPx = el.colWidths.map((w) => emuToPx(w, vp.scale) * groupScaleX)
|
||||
// a:tr h is an absolute minimum height (h=0 → size to content); PowerPoint ignores a
|
||||
// stale frame cy and recomputes the table height from the rows
|
||||
const rowPx = el.rowHeights.map((h) => emuToPx(h, vp.scale))
|
||||
const rowPx = el.rowHeights.map((h) => emuToPx(h, vp.scale) * groupScaleY)
|
||||
// Prefix sums → start of each column
|
||||
const colX: number[] = [0]
|
||||
for (const w of colPx) colX.push(colX[colX.length - 1]! + w)
|
||||
const totalW = colX[colX.length - 1]!
|
||||
if (Math.abs(totalW - box.w) > 0.5) box = { ...box, w: totalW }
|
||||
|
||||
// Measure pass: grow any row whose cell content wraps taller than the stored height
|
||||
// (rowSpan cells are skipped — their height is ambiguous to attribute to one row).
|
||||
|
||||
@@ -26,7 +26,7 @@ export function resolveFill(
|
||||
kind: 'gradient',
|
||||
stops: fill.stops.map((s) => ({ pos: s.pos, color: s.color })),
|
||||
angleDeg: fill.angle != null ? fill.angle / 60000 : 0,
|
||||
...(fill.path ? { radial: true } : {}),
|
||||
...(fill.path ? { radial: true, path: fill.path } : {}),
|
||||
...(fill.path && fill.fillTo
|
||||
? {
|
||||
center: {
|
||||
@@ -37,8 +37,9 @@ export function resolveFill(
|
||||
: {}),
|
||||
}
|
||||
case 'image': {
|
||||
// Tile natural size: image pixels are 96dpi units; vp.scale is the 96dpi-px multiplier
|
||||
const pxPerImagePx = vp.scale
|
||||
// Tile natural size: PowerPoint lays dpi-less bitmaps out at 144dpi (measured on
|
||||
// page_transparent_bitmap: 94px tile = 0.653in), i.e. 2/3 of a 96dpi unit
|
||||
const pxPerImagePx = vp.scale * (96 / 144)
|
||||
return {
|
||||
kind: 'image',
|
||||
dataUrl: media?.(fill.mediaRef),
|
||||
@@ -61,8 +62,14 @@ export function resolveFill(
|
||||
}
|
||||
}
|
||||
case 'pattern':
|
||||
// Pattern fills are approximated with the foreground color for now (Phase 2 skips 8x8 tile replication)
|
||||
return { kind: 'solid', color: fill.fg }
|
||||
// 8x8 preset mask, one mask pixel per 96dpi pixel (PowerPoint measured on n820786)
|
||||
return {
|
||||
kind: 'pattern',
|
||||
preset: fill.preset,
|
||||
fg: fill.fg,
|
||||
bg: fill.bg,
|
||||
cellPx: 8 * vp.scale,
|
||||
}
|
||||
default:
|
||||
return { kind: 'none' }
|
||||
}
|
||||
|
||||
@@ -18,3 +18,5 @@ export * from './text-layout'
|
||||
export * from './build-slide'
|
||||
export * from './build-chart'
|
||||
export * from './preset-geometry'
|
||||
export * from './scene3d'
|
||||
export { patternGrid } from './pattern-fills'
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* a:pattFill preset patterns: 8×8 GDI-style masks (bit 7 = leftmost pixel, fg where set).
|
||||
* Percent presets dither through an 8×8 Bayer matrix at their exact density, the
|
||||
* structural presets use the classic GDI hatch bitmaps. PowerPoint draws the cell at
|
||||
* 8px per 96dpi inch/12 — i.e. one mask pixel per 96dpi pixel (n820786 measured).
|
||||
*/
|
||||
|
||||
const BAYER8 = [
|
||||
[0, 32, 8, 40, 2, 34, 10, 42],
|
||||
[48, 16, 56, 24, 50, 18, 58, 26],
|
||||
[12, 44, 4, 36, 14, 46, 6, 38],
|
||||
[60, 28, 52, 20, 62, 30, 54, 22],
|
||||
[3, 35, 11, 43, 1, 33, 9, 41],
|
||||
[51, 19, 59, 27, 49, 17, 57, 25],
|
||||
[15, 47, 7, 39, 13, 45, 5, 37],
|
||||
[63, 31, 55, 23, 61, 29, 53, 21],
|
||||
]
|
||||
|
||||
const PCT: Record<string, number> = {
|
||||
pct5: 5,
|
||||
pct10: 10,
|
||||
pct20: 20,
|
||||
pct25: 25,
|
||||
pct30: 30,
|
||||
pct40: 40,
|
||||
pct50: 50,
|
||||
pct60: 60,
|
||||
pct70: 70,
|
||||
pct75: 75,
|
||||
pct80: 80,
|
||||
pct90: 90,
|
||||
}
|
||||
|
||||
/** Structural presets: 8 rows, one byte per row. */
|
||||
const MASKS: Record<string, number[]> = {
|
||||
horz: [0xff, 0, 0, 0, 0xff, 0, 0, 0],
|
||||
vert: [0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88],
|
||||
ltHorz: [0xff, 0, 0, 0, 0, 0, 0, 0],
|
||||
ltVert: [0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80],
|
||||
dkHorz: [0xff, 0xff, 0, 0, 0xff, 0xff, 0, 0],
|
||||
dkVert: [0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc],
|
||||
narHorz: [0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0],
|
||||
narVert: [0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||
dashHorz: [0xf0, 0, 0, 0, 0x0f, 0, 0, 0],
|
||||
dashVert: [0x80, 0x80, 0x80, 0x80, 0x08, 0x08, 0x08, 0x08],
|
||||
// GDI+ HatchStyleCross aliases LargeGrid: single hatch every 8, not the small grid
|
||||
cross: [0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80],
|
||||
dnDiag: [0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11],
|
||||
upDiag: [0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88],
|
||||
ltDnDiag: [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01],
|
||||
ltUpDiag: [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80],
|
||||
dkDnDiag: [0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99],
|
||||
dkUpDiag: [0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc, 0x99],
|
||||
wdDnDiag: [0xe1, 0xf0, 0x78, 0x3c, 0x1e, 0x0f, 0x87, 0xc3],
|
||||
wdUpDiag: [0x87, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, 0xe1, 0xc3],
|
||||
dashDnDiag: [0x80, 0x40, 0x20, 0x10, 0, 0, 0, 0],
|
||||
dashUpDiag: [0x01, 0x02, 0x04, 0x08, 0, 0, 0, 0],
|
||||
diagCross: [0x99, 0x66, 0x66, 0x99, 0x99, 0x66, 0x66, 0x99],
|
||||
smCheck: [0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33],
|
||||
lgCheck: [0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f],
|
||||
smGrid: [0xff, 0x88, 0x88, 0x88, 0xff, 0x88, 0x88, 0x88],
|
||||
lgGrid: [0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80],
|
||||
dotGrid: [0xaa, 0, 0x80, 0, 0x80, 0, 0x80, 0],
|
||||
smConfetti: [0x01, 0x10, 0x02, 0x40, 0x08, 0x80, 0x04, 0x20],
|
||||
lgConfetti: [0x8c, 0x31, 0x03, 0xc6, 0x18, 0x63, 0x30, 0xc4],
|
||||
horzBrick: [0xff, 0x80, 0x80, 0x80, 0xff, 0x08, 0x08, 0x08],
|
||||
diagBrick: [0x80, 0x40, 0x20, 0x10, 0x08, 0x14, 0x22, 0x41],
|
||||
solidDmnd: [0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0],
|
||||
openDmnd: [0x10, 0x28, 0x44, 0x82, 0x44, 0x28, 0x10, 0],
|
||||
dotDmnd: [0x10, 0, 0x44, 0, 0x10, 0, 0, 0],
|
||||
plaid: [0xaa, 0x55, 0xaa, 0x55, 0xf0, 0xf0, 0xf0, 0xf0],
|
||||
sphere: [0x38, 0x44, 0x92, 0xaa, 0x92, 0x44, 0x38, 0],
|
||||
weave: [0x88, 0x54, 0x22, 0x45, 0x88, 0x15, 0x22, 0x51],
|
||||
divot: [0x08, 0x14, 0, 0, 0x80, 0x41, 0, 0],
|
||||
shingle: [0x80, 0x40, 0x20, 0xe0, 0x02, 0x04, 0x08, 0x07],
|
||||
wave: [0, 0x60, 0x99, 0x06, 0, 0x60, 0x99, 0x06],
|
||||
trellis: [0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55],
|
||||
zigZag: [0x11, 0x22, 0x44, 0x88, 0x88, 0x44, 0x22, 0x11],
|
||||
}
|
||||
|
||||
/** 8×8 boolean grid for a preset (true = foreground pixel); pct50 fallback. */
|
||||
export function patternGrid(preset: string): boolean[][] {
|
||||
const pct = PCT[preset]
|
||||
if (pct != null) {
|
||||
const th = (pct / 100) * 64
|
||||
return BAYER8.map((row) => row.map((v) => v < th))
|
||||
}
|
||||
const mask = MASKS[preset] ?? MASKS['cross']!
|
||||
return mask.map((row) => Array.from({ length: 8 }, (_, u) => !!(row & (1 << (7 - u)))))
|
||||
}
|
||||
@@ -304,6 +304,54 @@ export function presetPolygon(
|
||||
const yh = h - head
|
||||
return [x1, 0, x1, yh, 0, yh, w / 2, h, w, yh, x2, yh, x2, 0]
|
||||
}
|
||||
// Arrow callouts: a callout box on one side with an arrow (shaft + head) growing
|
||||
// out of the opposite side (ECMA guide formulas; adj4 = box extent)
|
||||
case 'upArrowCallout':
|
||||
case 'downArrowCallout': {
|
||||
// Adjusts may exceed 100000 up to the ECMA maxAdj bounds (h/ss etc. on
|
||||
// non-square boxes), so clamp against those instead of frac's 0..1
|
||||
const fracU = (name: string, dflt: number) => Math.max((adjust?.[name] ?? dflt) / 100000, 0)
|
||||
const a2 = Math.min(fracU('adj2', 25000), (0.5 * w) / ss)
|
||||
const a1 = Math.min(fracU('adj1', 25000), a2 * 2)
|
||||
const a3 = Math.min(fracU('adj3', 25000), h / ss)
|
||||
const a4 = Math.min(fracU('adj4', 64977), 1 - (a3 * ss) / h)
|
||||
const headHalf = ss * a2
|
||||
const shaftHalf = (ss * a1) / 2
|
||||
const x1 = w / 2 - headHalf
|
||||
const x2 = w / 2 - shaftHalf
|
||||
const x3 = w / 2 + shaftHalf
|
||||
const x4 = w / 2 + headHalf
|
||||
if (preset === 'upArrowCallout') {
|
||||
const y1 = ss * a3 // arrowhead base
|
||||
const y2 = h - h * a4 // callout-box top
|
||||
return [0, y2, x2, y2, x2, y1, x1, y1, w / 2, 0, x4, y1, x3, y1, x3, y2, w, y2, w, h, 0, h]
|
||||
}
|
||||
const y1 = h - ss * a3
|
||||
const y2 = h * a4 // callout-box bottom
|
||||
return [0, y2, x2, y2, x2, y1, x1, y1, w / 2, h, x4, y1, x3, y1, x3, y2, w, y2, w, 0, 0, 0]
|
||||
}
|
||||
case 'leftArrowCallout':
|
||||
case 'rightArrowCallout': {
|
||||
const fracU = (name: string, dflt: number) => Math.max((adjust?.[name] ?? dflt) / 100000, 0)
|
||||
const a2 = Math.min(fracU('adj2', 25000), (0.5 * h) / ss)
|
||||
const a1 = Math.min(fracU('adj1', 25000), a2 * 2)
|
||||
const a3 = Math.min(fracU('adj3', 25000), w / ss)
|
||||
const a4 = Math.min(fracU('adj4', 64977), 1 - (a3 * ss) / w)
|
||||
const headHalf = ss * a2
|
||||
const shaftHalf = (ss * a1) / 2
|
||||
const y1 = h / 2 - headHalf
|
||||
const y2 = h / 2 - shaftHalf
|
||||
const y3 = h / 2 + shaftHalf
|
||||
const y4 = h / 2 + headHalf
|
||||
if (preset === 'leftArrowCallout') {
|
||||
const x1 = ss * a3
|
||||
const x2 = w - w * a4
|
||||
return [x2, 0, x2, y2, x1, y2, x1, y1, 0, h / 2, x1, y4, x1, y3, x2, y3, x2, h, w, h, w, 0]
|
||||
}
|
||||
const x1 = w - ss * a3
|
||||
const x2 = w * a4
|
||||
return [x2, 0, x2, y2, x1, y2, x1, y1, w, h / 2, x1, y4, x1, y3, x2, y3, x2, h, 0, h, 0, 0]
|
||||
}
|
||||
case 'leftRightArrow': {
|
||||
const thick = h * frac('adj1', 50000)
|
||||
const head = Math.min(w / 2, ss * frac('adj2', 50000))
|
||||
@@ -425,6 +473,10 @@ export function presetPolygon(
|
||||
const depth = Math.min(frac('adj1', 15000) * 2, 0.6)
|
||||
return gearPoints(6, w, h, 1 - depth)
|
||||
}
|
||||
case 'gear9': {
|
||||
const depth = Math.min(frac('adj1', 10000) * 2, 0.6)
|
||||
return gearPoints(9, w, h, 1 - depth)
|
||||
}
|
||||
case 'quadArrow': {
|
||||
const sw2 = (ss * frac('adj1', 22500)) / 2
|
||||
const hw = ss * frac('adj2', 22500)
|
||||
@@ -514,9 +566,9 @@ export function presetPolygon(
|
||||
return wedgeCalloutPolygon(w, h, tipX, tipY)
|
||||
}
|
||||
case 'irregularSeal1':
|
||||
return starPoints(11, w, h, 0.3)
|
||||
return sealPoints(IRREGULAR_SEAL_1, w, h)
|
||||
case 'irregularSeal2':
|
||||
return starPoints(13, w, h, 0.25)
|
||||
return sealPoints(IRREGULAR_SEAL_2, w, h)
|
||||
case 'star4':
|
||||
return starPoints(4, w, h, frac('adj', 12500))
|
||||
case 'star5':
|
||||
@@ -588,6 +640,32 @@ function gearPoints(teeth: number, w: number, h: number, innerR: number): number
|
||||
}
|
||||
|
||||
/** n-point star: outer vertices on the bounding ellipse, inner-vertex radius fraction = innerFrac. */
|
||||
// ECMA-376 presetShapeDefinitions vertex lists (21600-unit space) — the seals are
|
||||
// hand-drawn explosions, not regular stars
|
||||
// prettier-ignore
|
||||
const IRREGULAR_SEAL_1 = [
|
||||
10800, 5800, 14522, 0, 14155, 5325, 18380, 4457, 16702, 7315, 21097, 8137,
|
||||
17607, 10475, 21600, 13290, 16837, 12942, 18145, 18095, 14020, 14457, 13247, 19737,
|
||||
10532, 14935, 8485, 21600, 7715, 15627, 4762, 17617, 5667, 13937, 135, 14587,
|
||||
3722, 11775, 0, 8837, 4627, 7992, 2777, 4912, 7772, 6142, 8485, 1017,
|
||||
]
|
||||
// prettier-ignore
|
||||
const IRREGULAR_SEAL_2 = [
|
||||
11462, 4342, 14790, 0, 14525, 5777, 18007, 3172, 16380, 6532, 21600, 6645,
|
||||
16985, 9402, 18270, 11290, 16380, 12310, 18877, 15632, 14640, 14350, 14942, 17370,
|
||||
12180, 15935, 11612, 18842, 9872, 17370, 8700, 19712, 7527, 18125, 4917, 21600,
|
||||
4805, 18240, 1285, 17825, 3330, 15370, 0, 12877, 3935, 11592, 1172, 8270,
|
||||
5372, 7817, 4502, 3625, 8550, 6382, 9722, 1887,
|
||||
]
|
||||
|
||||
function sealPoints(coords21600: readonly number[], w: number, h: number): number[] {
|
||||
const pts: number[] = []
|
||||
for (let i = 0; i < coords21600.length; i += 2) {
|
||||
pts.push((coords21600[i]! / 21600) * w, (coords21600[i + 1]! / 21600) * h)
|
||||
}
|
||||
return pts
|
||||
}
|
||||
|
||||
function starPoints(n: number, w: number, h: number, innerFrac: number): number[] {
|
||||
const cx = w / 2
|
||||
const cy = h / 2
|
||||
@@ -830,29 +908,33 @@ export function presetPath(
|
||||
}
|
||||
case 'circularArrow':
|
||||
case 'leftCircularArrow': {
|
||||
// Approximation of the ECMA geometry: an annular band plus a triangular arrowhead
|
||||
// at the sweep end; the left variant mirrors the winding direction
|
||||
// Approximation of the ECMA geometry: an annular band from adj3 to adj4 plus a
|
||||
// triangular head spanning the last adj2 degrees; the left variant winds CCW
|
||||
const left = preset === 'leftCircularArrow'
|
||||
const t = ss * frac('adj1', 12500)
|
||||
const headR = t * 0.9
|
||||
const headSpan = Math.min(ang('adj2', 1142319), 90)
|
||||
// adj4 = start angle, adj3 = head-tip angle (ECMA circularArrow)
|
||||
const end = ang('adj3', left ? 1142319 : 20457681)
|
||||
const start = ang('adj4', 10800000)
|
||||
const headR = Math.max(ss * frac('adj5', 12500), t * 0.75)
|
||||
const rxO = Math.max(cx - headR, 0)
|
||||
const ryO = Math.max(cy - headR, 0)
|
||||
const rxI = Math.max(rxO - t, 0)
|
||||
const ryI = Math.max(ryO - t, 0)
|
||||
const rxM = (rxO + rxI) / 2
|
||||
const ryM = (ryO + ryI) / 2
|
||||
const start = left ? 115 : 65
|
||||
const sweep = left ? -250 : 250
|
||||
const end = start + sweep
|
||||
const headAng = left ? -32 : 32
|
||||
const total = left ? -(sweepCW(end, start) || 250) : sweepCW(start, end) || 250
|
||||
const headAng = left ? -headSpan : headSpan
|
||||
const sweep = total - headAng
|
||||
const bodyEnd = start + sweep
|
||||
const pt = (deg: number, rx: number, ry: number) =>
|
||||
[cx + rx * Math.cos(deg * D2R), cy + ry * Math.sin(deg * D2R)] as const
|
||||
const b = new PathB().arc(cx, cy, rxO, ryO, start, sweep, 'M')
|
||||
const [hx1, hy1] = pt(end, rxO + headR, ryO + headR)
|
||||
const [tx, ty] = pt(end + headAng, rxM, ryM)
|
||||
const [hx2, hy2] = pt(end, Math.max(rxI - headR, 0), Math.max(ryI - headR, 0))
|
||||
const [hx1, hy1] = pt(bodyEnd, rxM + headR, ryM + headR)
|
||||
const [tx, ty] = pt(bodyEnd + headAng, rxM, ryM)
|
||||
const [hx2, hy2] = pt(bodyEnd, Math.max(rxM - headR, 0), Math.max(ryM - headR, 0))
|
||||
b.L(hx1, hy1).L(tx, ty).L(hx2, hy2)
|
||||
b.arc(cx, cy, rxI, ryI, end, -sweep, 'L').Z()
|
||||
b.arc(cx, cy, rxI, ryI, bodyEnd, -sweep, 'L').Z()
|
||||
return { path: b.d() }
|
||||
}
|
||||
case 'donut': {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
import type { Fill, Stroke } from '@genoffice/pptx-engine'
|
||||
import type { PlacedBox } from './coords'
|
||||
import type { ExtrusionFaceRender } from './scene3d'
|
||||
|
||||
export type RenderNodeType =
|
||||
| 'shape' // vector shape (may contain text)
|
||||
@@ -47,6 +48,8 @@ export type RenderFill =
|
||||
stops: Array<{ pos: number; color: string }>
|
||||
angleDeg: number
|
||||
radial?: boolean
|
||||
/** Actual <a:path path> kind (circle/rect/shape); rendering approximates all as radial */
|
||||
path?: 'circle' | 'rect' | 'shape'
|
||||
/** Radial focus center as width/height fractions (from <a:fillToRect>; default 0.5/0.5) */
|
||||
center?: { x: number; y: number }
|
||||
}
|
||||
@@ -65,6 +68,15 @@ export type RenderFill =
|
||||
/** Tile grid: scale in px-per-image-px, anchor offsets in px, and the algn anchor */
|
||||
tile?: { scaleX: number; scaleY: number; txPx: number; tyPx: number; algn: string }
|
||||
}
|
||||
| {
|
||||
kind: 'pattern'
|
||||
/** ST_PresetPatternVal (pct50, ltDnDiag, ...) */
|
||||
preset: string
|
||||
fg: string
|
||||
bg: string
|
||||
/** Pattern cell edge in canvas px (8 mask pixels at 96dpi, viewport-scaled) */
|
||||
cellPx: number
|
||||
}
|
||||
|
||||
export interface RenderStroke {
|
||||
color: string
|
||||
@@ -123,6 +135,12 @@ export interface GlyphRun {
|
||||
outline?: { color: string; widthPx: number }
|
||||
/** Run outer shadow (px), drawn via canvas shadow props */
|
||||
shadow?: { color: string; blurPx: number; offsetX: number; offsetY: number }
|
||||
/** WordArt gradient text fill (resolved stops; angleDeg 0 = left→right, 90 = top→bottom) */
|
||||
gradient?: { stops: Array<{ pos: number; color: string }>; angleDeg: number }
|
||||
/** Run glow (zero-offset canvas shadow) */
|
||||
glow?: { color: string; blurPx: number }
|
||||
/** Run reflection: the renderer draws a faded mirrored copy below the baseline */
|
||||
reflection?: boolean
|
||||
/** Extra per-char spacing spread in by justify alignment (px); draw-only, the editor ignores it and doesn't store it */
|
||||
justifyExtraPx?: number
|
||||
/** Super/subscript baseline shift (px, positive = up; <a:rPr baseline>), already baked into baselineY */
|
||||
@@ -187,6 +205,8 @@ export interface RenderTextLayout {
|
||||
wrap: boolean
|
||||
/** bodyPr vert: vertical column layout (lines = columns, right→left); vert/vert270/wordArtVert degrade to eaVert */
|
||||
vert?: 'eaVert' | 'vert' | 'vert270' | 'wordArtVert'
|
||||
/** WordArt text extrusion: glyphs get offset copies in this color behind them (px) */
|
||||
extrusion?: { color: string; dx: number; dy: number }
|
||||
}
|
||||
|
||||
/** Connector/line endpoint arrow description (for rendering, sizes converted to px). */
|
||||
@@ -228,6 +248,8 @@ export interface ShapeRenderNode extends RenderNodeBase {
|
||||
stroke?: RenderStroke
|
||||
shadow?: RenderShadow
|
||||
glow?: RenderGlow
|
||||
/** scene3d+sp3d extrusion: pre-projected shaded faces (painter order) replacing the flat geometry */
|
||||
extrusion?: { faces: ExtrusionFaceRender[]; wireframe?: boolean }
|
||||
text?: RenderTextLayout
|
||||
}
|
||||
|
||||
@@ -320,6 +342,7 @@ export interface ChartLabel {
|
||||
fontSizePx: number
|
||||
color: string
|
||||
bold?: boolean
|
||||
italic?: boolean
|
||||
/** Rotation angle (e.g. -90 for a value-axis title) */
|
||||
rotationDeg?: number
|
||||
}
|
||||
|
||||
@@ -0,0 +1,910 @@
|
||||
/**
|
||||
* Shape extrusion for <a:scene3d> + <a:sp3d>: builds the projected, shaded face polygons
|
||||
* PowerPoint draws for a 3D shape (front cap, back cap, side walls).
|
||||
*
|
||||
* Camera preset angles and light-rig definitions are the MS-OI29500 values (measured
|
||||
* against MS Office; same data set LibreOffice uses, see LO tdf#70039).
|
||||
* Angles rx/ry/rz are degrees; MS Office rotates first around y (lon), then x (lat),
|
||||
* then z (rev), in a left-handed frame with x right, y down, z toward the viewer.
|
||||
*/
|
||||
|
||||
export interface Scene3DProps {
|
||||
cameraPreset: string
|
||||
cameraRot?: { lat: number; lon: number; rev: number }
|
||||
lightRig?: string
|
||||
lightDir?: string
|
||||
lightRot?: { lat: number; lon: number; rev: number }
|
||||
extrusionEmu?: number
|
||||
zEmu?: number
|
||||
extrusionColor?: string
|
||||
material?: string
|
||||
}
|
||||
|
||||
export interface ExtrusionFaceRender {
|
||||
/** Projected face as an SVG path (local px relative to the shape box top-left; caps carry hole subpaths) */
|
||||
path: string
|
||||
/** Pre-shaded solid color ('#RRGGBB'), 'transparent' for wireframe edges */
|
||||
color: string
|
||||
/** Front cap: the adapter may substitute the shape's own (gradient/image) fill */
|
||||
front?: boolean
|
||||
stroke?: string
|
||||
strokeWidthPx?: number
|
||||
}
|
||||
|
||||
export interface ExtrusionRender {
|
||||
/** Painter order: farthest first */
|
||||
faces: ExtrusionFaceRender[]
|
||||
/** legacyWireframe material: faces carry no fill, only edges */
|
||||
wireframe?: boolean
|
||||
}
|
||||
|
||||
interface CameraPreset {
|
||||
parallel: boolean
|
||||
rx: number // deg, rotation around x (latitude)
|
||||
ry: number // deg, rotation around y (longitude)
|
||||
rz: number // deg, rotation around z (revolution)
|
||||
ox: number // projection origin, fraction of width from center
|
||||
oy: number
|
||||
skewAmount: number // % of depth, parallel cameras only
|
||||
skewAngle: number // deg
|
||||
vx: number // eye offset, 1/100 mm, perspective only
|
||||
vy: number
|
||||
vz: number // eye distance, 1/100 mm, perspective only
|
||||
}
|
||||
|
||||
const D = 1 / 60000
|
||||
const cam = (
|
||||
parallel: boolean,
|
||||
rx: number,
|
||||
ry: number,
|
||||
rz: number,
|
||||
ox = 0,
|
||||
oy = 0,
|
||||
skewAmount = 0,
|
||||
skewAngle = 0,
|
||||
vx = 0,
|
||||
vy = 0,
|
||||
vz = 0,
|
||||
): CameraPreset => ({
|
||||
parallel,
|
||||
rx: rx * D,
|
||||
ry: ry * D,
|
||||
rz: rz * D,
|
||||
ox,
|
||||
oy,
|
||||
skewAmount,
|
||||
skewAngle,
|
||||
vx,
|
||||
vy,
|
||||
vz,
|
||||
})
|
||||
|
||||
/** ST_PresetCameraType → rotation/projection values ([MS-OI29500], angles in 1/60000°). */
|
||||
const CAMERA_PRESETS: Record<string, CameraPreset> = {
|
||||
isometricBottomDown: cam(true, 2124000, 18882000, 17988000),
|
||||
isometricBottomUp: cam(true, 2124000, 2718000, 3612000),
|
||||
isometricLeftDown: cam(true, 2100000, 2700000, 0),
|
||||
isometricLeftUp: cam(true, 19500000, 2700000, 0),
|
||||
isometricOffAxis1Left: cam(true, 1080000, 3840000, 0),
|
||||
isometricOffAxis1Right: cam(true, 1080000, 20040000, 0),
|
||||
isometricOffAxis1Top: cam(true, 18078000, 18390000, 3456000),
|
||||
isometricOffAxis2Left: cam(true, 1080000, 1560000, 0),
|
||||
isometricOffAxis2Right: cam(true, 1080000, 17760000, 0),
|
||||
isometricOffAxis2Top: cam(true, 18078000, 3210000, 18144000),
|
||||
isometricOffAxis3Bottom: cam(true, 3522000, 18390000, 18144000),
|
||||
isometricOffAxis3Left: cam(true, 20520000, 3840000, 0),
|
||||
isometricOffAxis3Right: cam(true, 20520000, 20040000, 0),
|
||||
isometricOffAxis4Bottom: cam(true, 3522000, 3210000, 3456000),
|
||||
isometricOffAxis4Left: cam(true, 20520000, 1560000, 0),
|
||||
isometricOffAxis4Right: cam(true, 20520000, 17760000, 0),
|
||||
isometricRightDown: cam(true, 19500000, 18900000, 0),
|
||||
isometricRightUp: cam(true, 2100000, 18900000, 0),
|
||||
isometricTopDown: cam(true, 19476000, 2718000, 17988000),
|
||||
isometricTopUp: cam(true, 19476000, 18882000, 3612000),
|
||||
legacyObliqueBottom: cam(true, 0, 0, 0, 0, 0.5, 50, 90),
|
||||
legacyObliqueBottomLeft: cam(true, 0, 0, 0, -0.5, 0.5, 50, 45),
|
||||
legacyObliqueBottomRight: cam(true, 0, 0, 0, 0.5, 0.5, 50, 135),
|
||||
legacyObliqueFront: cam(true, 0, 0, 0),
|
||||
legacyObliqueLeft: cam(true, 0, 0, 0, -0.5, 0, 50, -360),
|
||||
legacyObliqueRight: cam(true, 0, 0, 0, 0.5, 0, 50, 180),
|
||||
legacyObliqueTop: cam(true, 0, 0, 0, 0, -0.5, 50, -90),
|
||||
legacyObliqueTopLeft: cam(true, 0, 0, 0, -0.5, -0.5, 50, -45),
|
||||
legacyObliqueTopRight: cam(true, 0, 0, 0, 0.5, -0.5, 50, -135),
|
||||
legacyPerspectiveBottom: cam(false, 0, 0, 0, 0, 0.5, 50, 90, 0, 3472, 25000),
|
||||
legacyPerspectiveBottomLeft: cam(false, 0, 0, 0, -0.5, 0.5, 50, 45, -3472, 3472, 25000),
|
||||
legacyPerspectiveBottomRight: cam(false, 0, 0, 0, 0.5, 0.5, 50, 135, 3472, 3472, 25000),
|
||||
legacyPerspectiveFront: cam(false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25000),
|
||||
legacyPerspectiveLeft: cam(false, 0, 0, 0, -0.5, 0, 50, -360, -3472, 0, 25000),
|
||||
legacyPerspectiveRight: cam(false, 0, 0, 0, 0.5, 0, 50, 180, 3472, 0, 25000),
|
||||
legacyPerspectiveTop: cam(false, 0, 0, 0, 0, -0.5, 50, -90, 0, -3472, 25000),
|
||||
legacyPerspectiveTopLeft: cam(false, 0, 0, 0, -0.5, -0.5, 50, -45, -3472, -3472, 25000),
|
||||
legacyPerspectiveTopRight: cam(false, 0, 0, 0, 0.5, -0.5, 50, -135, 3472, -3472, 25000),
|
||||
obliqueBottom: cam(true, 0, 0, 0, 0, 0.5, 30, 90),
|
||||
obliqueBottomLeft: cam(true, 0, 0, 0, -0.5, 0.5, 30, 45),
|
||||
obliqueBottomRight: cam(true, 0, 0, 0, 0.5, 0.5, 30, 135),
|
||||
obliqueLeft: cam(true, 0, 0, 0, -0.5, 0, 30, -360),
|
||||
obliqueRight: cam(true, 0, 0, 0, 0.5, 0, 30, 180),
|
||||
obliqueTop: cam(true, 0, 0, 0, 0, -0.5, 30, -90),
|
||||
obliqueTopLeft: cam(true, 0, 0, 0, -0.5, -0.5, 30, -45),
|
||||
obliqueTopRight: cam(true, 0, 0, 0, 0.5, -0.5, 30, -135),
|
||||
orthographicFront: cam(true, 0, 0, 0),
|
||||
perspectiveAbove: cam(false, 20400000, 0, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveAboveLeftFacing: cam(false, 2358000, 858000, 20466000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveAboveRightFacing: cam(false, 2358000, 20742000, 1134000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveBelow: cam(false, 1200000, 0, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveContrastingLeftFacing: cam(false, 624000, 2634000, 21384000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveContrastingRightFacing: cam(false, 624000, 18966000, 216000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveFront: cam(false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveHeroicExtremeLeftFacing: cam(
|
||||
false,
|
||||
486000,
|
||||
2070000,
|
||||
21426000,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
18981,
|
||||
),
|
||||
perspectiveHeroicExtremeRightFacing: cam(
|
||||
false,
|
||||
486000,
|
||||
19530000,
|
||||
174000,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
18981,
|
||||
),
|
||||
perspectiveHeroicLeftFacing: cam(false, 20940000, 858000, 156000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveHeroicRightFacing: cam(false, 20940000, 20742000, 21444000, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveLeft: cam(false, 0, 1200000, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveRelaxed: cam(false, 18576000, 0, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveRelaxedModerately: cam(false, 19488000, 0, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
perspectiveRight: cam(false, 0, 20400000, 0, 0, 0, 0, 0, 0, 0, 38451),
|
||||
}
|
||||
|
||||
interface RigLight {
|
||||
r: number
|
||||
g: number
|
||||
b: number
|
||||
x: number
|
||||
y: number
|
||||
z: number
|
||||
diffuse: boolean
|
||||
}
|
||||
|
||||
interface LightRig {
|
||||
ambient: number
|
||||
lights: RigLight[]
|
||||
}
|
||||
|
||||
const L = (
|
||||
r: number,
|
||||
g: number,
|
||||
b: number,
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
diffuse = true,
|
||||
): RigLight => ({ r, g, b, x, y, z, diffuse })
|
||||
|
||||
/** ST_LightRigType → ambient + individual lights ([MS-OI29500]; direction = travel direction of the light). */
|
||||
const LIGHT_RIGS: Record<string, LightRig> = {
|
||||
balanced: {
|
||||
ambient: 0.13,
|
||||
lights: [
|
||||
L(1.05, 1.05, 1.05, 0.5263, -0.4092, -0.7453),
|
||||
L(1, 1, 1, -0.9386, 0.3426, -0.041),
|
||||
L(0.5, 0.5, 0.5, 0.0934, 0.763, 0.6396),
|
||||
],
|
||||
},
|
||||
brightRoom: {
|
||||
ambient: 1.5,
|
||||
lights: [
|
||||
L(1, 1, 1, 0, -1, 0),
|
||||
L(1, 1, 1, 0.8227, -0.1882, -0.5364, false),
|
||||
L(-0.5, -0.5, -0.5, 0, 0, -1),
|
||||
L(0.5, 0.5, 0.5, 0, 1, 0),
|
||||
],
|
||||
},
|
||||
chilly: {
|
||||
ambient: 0.11,
|
||||
lights: [
|
||||
L(0.31, 0.32, 0.32, 0.6574, -0.7316, -0.1806),
|
||||
L(0.45, 0.45, 0.45, -0.3539, -0.1505, -0.9231),
|
||||
L(1.03, 1.02, 1.15, 0.672, -0.6185, -0.4073),
|
||||
L(0.41, 0.45, 0.48, -0.5781, 0.7976, 0.1722),
|
||||
],
|
||||
},
|
||||
contrasting: { ambient: 1, lights: [L(1, 1, 1, 0, -1, 0, false), L(1, 1, 1, 0, 1, 0, false)] },
|
||||
flat: {
|
||||
ambient: 1,
|
||||
lights: [
|
||||
L(0.821, 0.821, 0.821, -0.9546, -0.1619, -0.2502, false),
|
||||
L(2.072, 2.54, 2.91, 0.0009, 0.8605, 0.5095, false),
|
||||
L(3.843, 3.843, 3.843, 0.6574, -0.7316, -0.1806, false),
|
||||
],
|
||||
},
|
||||
flood: {
|
||||
ambient: 0.13,
|
||||
lights: [
|
||||
L(1.1, 1.1, 1.1, 0.5685, -0.7651, -0.3022),
|
||||
L(1.1, 1.1, 1.1, -0.2366, -0.9595, -0.1531),
|
||||
L(0.55, 0.55, 0.55, -0.8982, 0.1386, -0.4171),
|
||||
],
|
||||
},
|
||||
freezing: {
|
||||
ambient: 0,
|
||||
lights: [
|
||||
L(0.53, 0.567, 0.661, 0.6574, -0.7316, -0.1806),
|
||||
L(0.37, 0.461, 0.461, -0.2781, -0.4509, -0.8482),
|
||||
L(0.649, 0.638, 0.904, 0.672, -0.6185, -0.4073),
|
||||
L(0.971, 1.19, 1.363, -0.1825, 0.968, 0.1722),
|
||||
],
|
||||
},
|
||||
glow: { ambient: 1, lights: [L(1, 1, 1, 0, -1, 0), L(0.7, 0.7, 0.7, 0, 1, 0)] },
|
||||
harsh: {
|
||||
ambient: 0.28,
|
||||
lights: [
|
||||
L(0.88, 0.88, 0.88, 0.6689, -0.6755, -0.3104),
|
||||
L(0.88, 0.88, 0.88, -0.592, -0.7371, -0.326),
|
||||
],
|
||||
},
|
||||
legacyFlat1: {
|
||||
ambient: 0.305,
|
||||
lights: [L(0.58, 0.58, 0.58, 0, 0, -0.2), L(0.29, 0.29, 0.29, 0, 0, -0.2)],
|
||||
},
|
||||
legacyFlat2: {
|
||||
ambient: 0.305,
|
||||
lights: [L(0.58, 0.58, 0.58, -1, -1, -0.2), L(0.29, 0.29, 0.29, 0, 1, -0.2)],
|
||||
},
|
||||
legacyFlat3: {
|
||||
ambient: 0.305,
|
||||
lights: [L(0.58, 0.58, 0.58, 0, -1, -0.2), L(0.29, 0.29, 0.29, 0, 1, -0.2)],
|
||||
},
|
||||
legacyFlat4: {
|
||||
ambient: 0.305,
|
||||
lights: [L(0.58, 0.58, 0.58, 1, -1, -0.2), L(0.29, 0.29, 0.29, 0, 1, -0.2)],
|
||||
},
|
||||
legacyHarsh1: {
|
||||
ambient: 0.061,
|
||||
lights: [L(0.793, 0.793, 0.793, 0, 0, -0.2), L(0.214, 0.214, 0.214, 0, 0, -0.2)],
|
||||
},
|
||||
legacyHarsh2: {
|
||||
ambient: 0.061,
|
||||
lights: [L(0.793, 0.793, 0.793, -1, -1, -0.2), L(0.214, 0.214, 0.214, 0, 1, -0.2)],
|
||||
},
|
||||
legacyHarsh3: {
|
||||
ambient: 0.061,
|
||||
lights: [L(0.793, 0.793, 0.793, 0, -1, -0.2), L(0.214, 0.214, 0.214, 0, 1, -0.2)],
|
||||
},
|
||||
legacyHarsh4: {
|
||||
ambient: 0.061,
|
||||
lights: [L(0.793, 0.793, 0.793, 1, -1, -0.2), L(0.214, 0.214, 0.214, 0, 1, -0.2)],
|
||||
},
|
||||
legacyNormal1: {
|
||||
ambient: 0.153,
|
||||
lights: [L(0.671, 0.671, 0.671, 0, 0, -0.2), L(0.183, 0.183, 0.183, 0, 0, -0.2)],
|
||||
},
|
||||
legacyNormal2: {
|
||||
ambient: 0.153,
|
||||
lights: [L(0.671, 0.671, 0.671, -1, -1, -0.2), L(0.183, 0.183, 0.183, 0, 1, -0.2)],
|
||||
},
|
||||
legacyNormal3: {
|
||||
ambient: 0.153,
|
||||
lights: [L(0.671, 0.671, 0.671, 0, -1, -0.2), L(0.183, 0.183, 0.183, 0, 1, -0.2)],
|
||||
},
|
||||
legacyNormal4: {
|
||||
ambient: 0.153,
|
||||
lights: [L(0.671, 0.671, 0.671, 1, -1, -0.2), L(0.183, 0.183, 0.183, 0, 1, -0.2)],
|
||||
},
|
||||
morning: {
|
||||
ambient: 0,
|
||||
lights: [
|
||||
L(0.669, 0.648, 0.596, 0.6574, -0.7316, -0.1806),
|
||||
L(0.459, 0.454, 0.385, -0.2781, -0.4509, -0.8482),
|
||||
L(0.9, 0.86, 0.83, 0.672, -0.6185, -0.4073),
|
||||
L(0.911, 0.846, 0.728, -0.1825, 0.968, 0.1722),
|
||||
],
|
||||
},
|
||||
soft: { ambient: 0.3, lights: [L(0.8, 0.8, 0.8, -0.6897, 0.2484, -0.6802)] },
|
||||
sunrise: {
|
||||
ambient: 0,
|
||||
lights: [
|
||||
L(0.667, 0.63, 0.527, 0.6574, -0.7316, -0.1806),
|
||||
L(0.459, 0.459, 0.371, -0.2781, -0.4509, -0.8482),
|
||||
L(0.826, 0.712, 0.638, 0.672, -0.6185, -0.4073),
|
||||
L(1.511, 1.319, 0.994, -0.1825, 0.968, 0.1722),
|
||||
],
|
||||
},
|
||||
sunset: {
|
||||
ambient: 0,
|
||||
lights: [
|
||||
L(0.672, 0.169, 0.169, 0.6574, -0.7316, -0.1806),
|
||||
L(0.459, 0.448, 0.327, 0.0922, -0.3551, -0.9303),
|
||||
L(0.775, 0.612, 0.502, 0.672, -0.6185, -0.4073),
|
||||
L(0.761, 0.69, 0.397, -0.424, 0.8891, 0.1722),
|
||||
],
|
||||
},
|
||||
threePt: {
|
||||
ambient: 0,
|
||||
lights: [
|
||||
L(1.141, 1.141, 1.141, -0.6515, -0.2693, -0.7093),
|
||||
L(0.5, 0.5, 0.5, 0.8482, 0.2469, -0.4686),
|
||||
L(1, 1, 1, 0.5634, -0.2812, 0.7769),
|
||||
],
|
||||
},
|
||||
twoPt: {
|
||||
ambient: 0.25,
|
||||
lights: [
|
||||
L(0.84, 0.84, 0.84, 0.5266, -0.4089, -0.7454),
|
||||
L(0.3, 0.3, 0.3, -0.8983, 0.2365, -0.3704),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
/** lightRig dir attribute → clockwise rig rotation around z (degrees); 't' is the preset's own orientation. */
|
||||
const RIG_DIR_DEG: Record<string, number> = {
|
||||
t: 0,
|
||||
tr: 45,
|
||||
r: 90,
|
||||
br: 135,
|
||||
b: 180,
|
||||
bl: 225,
|
||||
l: 270,
|
||||
tl: 315,
|
||||
}
|
||||
|
||||
type Vec3 = [number, number, number]
|
||||
type Mat3 = [number, number, number, number, number, number, number, number, number]
|
||||
|
||||
const IDENT: Mat3 = [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
||||
|
||||
function matMul(a: Mat3, b: Mat3): Mat3 {
|
||||
const o = new Array(9).fill(0) as unknown as Mat3
|
||||
for (let r = 0; r < 3; r++)
|
||||
for (let c = 0; c < 3; c++)
|
||||
o[r * 3 + c] = a[r * 3]! * b[c]! + a[r * 3 + 1]! * b[3 + c]! + a[r * 3 + 2]! * b[6 + c]!
|
||||
return o
|
||||
}
|
||||
|
||||
function apply(m: Mat3, v: Vec3): Vec3 {
|
||||
return [
|
||||
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
||||
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
||||
m[6] * v[0] + m[7] * v[1] + m[8] * v[2],
|
||||
]
|
||||
}
|
||||
|
||||
const rad = (deg: number) => (deg * Math.PI) / 180
|
||||
|
||||
// Left-handed frame: x right, y down, z toward the viewer (matches the MS-OI29500 tables).
|
||||
const rotX = (a: number): Mat3 => [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
Math.cos(a),
|
||||
Math.sin(a),
|
||||
0,
|
||||
-Math.sin(a),
|
||||
Math.cos(a),
|
||||
]
|
||||
const rotY = (a: number): Mat3 => [
|
||||
Math.cos(a),
|
||||
0,
|
||||
-Math.sin(a),
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
Math.sin(a),
|
||||
0,
|
||||
Math.cos(a),
|
||||
]
|
||||
const rotZ = (a: number): Mat3 => [
|
||||
Math.cos(a),
|
||||
Math.sin(a),
|
||||
0,
|
||||
-Math.sin(a),
|
||||
Math.cos(a),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
]
|
||||
|
||||
/** MS Office camera rotation: first lon (y), then lat (x), then rev (z). */
|
||||
function cameraMatrix(latDeg: number, lonDeg: number, revDeg: number): Mat3 {
|
||||
return matMul(rotZ(rad(revDeg)), matMul(rotX(rad(latDeg)), rotY(rad(lonDeg))))
|
||||
}
|
||||
|
||||
// EMU→px at the render viewport's 96dpi logical scale is handled by the caller; the
|
||||
// perspective eye distance is defined in 1/100 mm and converted here (96 px / 25.4 mm).
|
||||
const PX_PER_MM100 = 96 / 2540
|
||||
|
||||
function parseRgb(color: string): [number, number, number] {
|
||||
const h = color.replace(/^#/, '')
|
||||
if (/^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(h)) {
|
||||
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)]
|
||||
}
|
||||
const m = /rgba?\((\d+)[,\s]+(\d+)[,\s]+(\d+)/.exec(color)
|
||||
if (m) return [Number(m[1]), Number(m[2]), Number(m[3])]
|
||||
return [128, 128, 128]
|
||||
}
|
||||
|
||||
const toHex = (n: number) =>
|
||||
Math.max(0, Math.min(255, Math.round(n)))
|
||||
.toString(16)
|
||||
.padStart(2, '0')
|
||||
|
||||
/** prstMaterial shading params: Blinn-Phong specular strength/exponent, diffuse/ambient scale,
|
||||
* rim darkening (dkEdge). Calibrated against Scene3d_material_highlight PowerPoint renders. */
|
||||
interface MaterialParams {
|
||||
spec: number
|
||||
shin: number
|
||||
diffuse: number
|
||||
ambient: number
|
||||
rim?: number
|
||||
}
|
||||
const MATERIALS: Record<string, MaterialParams> = {
|
||||
warmMatte: { spec: 0.5, shin: 3, diffuse: 1, ambient: 1 },
|
||||
matte: { spec: 0, shin: 1, diffuse: 1, ambient: 1 },
|
||||
flat: { spec: 0, shin: 1, diffuse: 1, ambient: 1 },
|
||||
legacyMatte: { spec: 0, shin: 1, diffuse: 1, ambient: 1 },
|
||||
plastic: { spec: 0.6, shin: 6, diffuse: 1, ambient: 1 },
|
||||
legacyPlastic: { spec: 0.8, shin: 4, diffuse: 1, ambient: 1 },
|
||||
metal: { spec: 0.9, shin: 4, diffuse: 1.05, ambient: 1 },
|
||||
legacyMetal: { spec: 0.9, shin: 5, diffuse: 0.55, ambient: 0.6 },
|
||||
softmetal: { spec: 0.6, shin: 4, diffuse: 1, ambient: 1 },
|
||||
dkEdge: { spec: 0.8, shin: 5, diffuse: 1, ambient: 1, rim: 0.45 },
|
||||
softEdge: { spec: 0.4, shin: 4, diffuse: 1, ambient: 1 },
|
||||
clear: { spec: 0.8, shin: 5, diffuse: 1, ambient: 1 },
|
||||
powder: { spec: 0.3, shin: 3, diffuse: 1, ambient: 1 },
|
||||
translucentPowder: { spec: 0.3, shin: 3, diffuse: 1, ambient: 1 },
|
||||
}
|
||||
const DEFAULT_MATERIAL = MATERIALS.warmMatte!
|
||||
const LAMBERT: MaterialParams = { spec: 0, shin: 1, diffuse: 1, ambient: 1 }
|
||||
|
||||
/** Blinn-Phong shading of a base color by the rig's ambient + diffuse lights plus a
|
||||
* material specular term (view direction = +z toward the viewer). */
|
||||
function shade(
|
||||
base: [number, number, number],
|
||||
normal: Vec3,
|
||||
rig: LightRig,
|
||||
lightXf: Mat3,
|
||||
mat: MaterialParams = LAMBERT,
|
||||
// Specular highlights depend on the eye, so they always use the view-space normal
|
||||
// even when diffuse shading is camera-invariant (shape-space normal)
|
||||
viewNormal: Vec3 = normal,
|
||||
): string {
|
||||
let fr = rig.ambient * mat.ambient
|
||||
let fg = fr
|
||||
let fb = fr
|
||||
let spec = 0
|
||||
for (const l of rig.lights) {
|
||||
// MS-OI29500 light directions are in MSO's rig frame; map into the screen frame
|
||||
// (x right, y down, z toward viewer): (x,y,z) → (-y, x, z). Verified against the
|
||||
// harsh rig's lit/dark walls in PowerPoint renders.
|
||||
const dir = apply(lightXf, [-l.y, l.x, l.z])
|
||||
const len = Math.hypot(dir[0], dir[1], dir[2]) || 1
|
||||
// The table stores the light's travel direction; illumination uses the vector toward the light.
|
||||
const lx = -dir[0] / len
|
||||
const ly = -dir[1] / len
|
||||
const lz = -dir[2] / len
|
||||
const d = Math.max(0, normal[0] * lx + normal[1] * ly + normal[2] * lz)
|
||||
if (l.diffuse) {
|
||||
fr += d * l.r * mat.diffuse
|
||||
fg += d * l.g * mat.diffuse
|
||||
fb += d * l.b * mat.diffuse
|
||||
}
|
||||
if (mat.spec > 0) {
|
||||
// Blinn-Phong half vector against the straight-on viewer
|
||||
const hl = Math.hypot(lx, ly, lz + 1) || 1
|
||||
const nh = Math.max(
|
||||
0,
|
||||
(viewNormal[0] * lx + viewNormal[1] * ly + viewNormal[2] * (lz + 1)) / hl,
|
||||
)
|
||||
spec += Math.pow(nh, mat.shin) * mat.spec * Math.max(l.r, l.g, l.b)
|
||||
}
|
||||
}
|
||||
if (mat.rim) {
|
||||
// dkEdge: faces turning away from the viewer darken toward the silhouette
|
||||
const facing = Math.min(1, Math.abs(viewNormal[2]))
|
||||
const k = mat.rim + (1 - mat.rim) * facing
|
||||
fr *= k
|
||||
fg *= k
|
||||
fb *= k
|
||||
}
|
||||
const s = spec * 255
|
||||
return `#${toHex(base[0] * fr + s)}${toHex(base[1] * fg + s)}${toHex(base[2] * fb + s)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an absolute M/L/C/Q/Z SVG path (the only commands preset/custGeom paths emit)
|
||||
* into closed polygon rings; curves are sampled uniformly.
|
||||
*/
|
||||
export function flattenSvgPath(d: string, curveSegs = 10): number[][] {
|
||||
const toks = d.trim().split(/[\s,]+/)
|
||||
const rings: number[][] = []
|
||||
let ring: number[] = []
|
||||
let x = 0
|
||||
let y = 0
|
||||
let i = 0
|
||||
const num = () => Number(toks[i++])
|
||||
const closeRing = () => {
|
||||
if (ring.length >= 6) rings.push(ring)
|
||||
ring = []
|
||||
}
|
||||
while (i < toks.length) {
|
||||
const t = toks[i++]
|
||||
switch (t) {
|
||||
case 'M':
|
||||
closeRing()
|
||||
x = num()
|
||||
y = num()
|
||||
ring.push(x, y)
|
||||
break
|
||||
case 'L':
|
||||
x = num()
|
||||
y = num()
|
||||
ring.push(x, y)
|
||||
break
|
||||
case 'C': {
|
||||
const c1x = num()
|
||||
const c1y = num()
|
||||
const c2x = num()
|
||||
const c2y = num()
|
||||
const ex = num()
|
||||
const ey = num()
|
||||
for (let k = 1; k <= curveSegs; k++) {
|
||||
const u = k / curveSegs
|
||||
const v = 1 - u
|
||||
ring.push(
|
||||
v * v * v * x + 3 * v * v * u * c1x + 3 * v * u * u * c2x + u * u * u * ex,
|
||||
v * v * v * y + 3 * v * v * u * c1y + 3 * v * u * u * c2y + u * u * u * ey,
|
||||
)
|
||||
}
|
||||
x = ex
|
||||
y = ey
|
||||
break
|
||||
}
|
||||
case 'Q': {
|
||||
const cx1 = num()
|
||||
const cy1 = num()
|
||||
const ex = num()
|
||||
const ey = num()
|
||||
for (let k = 1; k <= curveSegs; k++) {
|
||||
const u = k / curveSegs
|
||||
const v = 1 - u
|
||||
ring.push(
|
||||
v * v * x + 2 * v * u * cx1 + u * u * ex,
|
||||
v * v * y + 2 * v * u * cy1 + u * u * ey,
|
||||
)
|
||||
}
|
||||
x = ex
|
||||
y = ey
|
||||
break
|
||||
}
|
||||
case 'Z':
|
||||
case 'z':
|
||||
closeRing()
|
||||
break
|
||||
default:
|
||||
// Bare coordinate pair after M/L (SVG shorthand) — treat as L.
|
||||
if (t !== undefined && Number.isFinite(Number(t))) {
|
||||
x = Number(t)
|
||||
y = num()
|
||||
ring.push(x, y)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
closeRing()
|
||||
// Drop consecutive duplicate points (flattened curve endpoints repeat corners).
|
||||
return rings.map((r) => {
|
||||
const o: number[] = []
|
||||
for (let k = 0; k < r.length; k += 2) {
|
||||
const n = o.length
|
||||
if (n >= 2 && Math.abs(o[n - 2]! - r[k]!) < 0.01 && Math.abs(o[n - 1]! - r[k + 1]!) < 0.01)
|
||||
continue
|
||||
o.push(r[k]!, r[k + 1]!)
|
||||
}
|
||||
while (
|
||||
o.length >= 4 &&
|
||||
Math.abs(o[0]! - o[o.length - 2]!) < 0.01 &&
|
||||
Math.abs(o[1]! - o[o.length - 1]!) < 0.01
|
||||
)
|
||||
o.splice(o.length - 2, 2)
|
||||
return o
|
||||
})
|
||||
}
|
||||
|
||||
/** Sampled ellipse ring (local px). */
|
||||
export function ellipseRing(w: number, h: number, segs = 48): number[] {
|
||||
const out: number[] = []
|
||||
for (let k = 0; k < segs; k++) {
|
||||
const a = (k / segs) * 2 * Math.PI
|
||||
out.push((w / 2) * (1 + Math.cos(a)), (h / 2) * (1 + Math.sin(a)))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Rounded-rect ring (local px), r clamped to half the short side. */
|
||||
export function roundRectRing(w: number, h: number, r: number, segsPerCorner = 6): number[] {
|
||||
const rr = Math.max(0, Math.min(r, w / 2, h / 2))
|
||||
if (rr < 0.5) return [0, 0, w, 0, w, h, 0, h]
|
||||
const out: number[] = []
|
||||
const corner = (cx: number, cy: number, a0: number) => {
|
||||
for (let k = 0; k <= segsPerCorner; k++) {
|
||||
const a = a0 + (k / segsPerCorner) * (Math.PI / 2)
|
||||
out.push(cx + rr * Math.cos(a), cy + rr * Math.sin(a))
|
||||
}
|
||||
}
|
||||
corner(rr, rr, Math.PI) // top-left, sweeping to top edge
|
||||
corner(w - rr, rr, -Math.PI / 2)
|
||||
corner(w - rr, h - rr, 0)
|
||||
corner(rr, h - rr, Math.PI / 2)
|
||||
return out
|
||||
}
|
||||
|
||||
/** Even-odd point-in-rings test (local px). */
|
||||
function insideRings(rings: number[][], x: number, y: number): boolean {
|
||||
let inside = false
|
||||
for (const r of rings) {
|
||||
for (let i = 0, j = r.length - 2; i < r.length; j = i, i += 2) {
|
||||
const xi = r[i]!
|
||||
const yi = r[i + 1]!
|
||||
const xj = r[j]!
|
||||
const yj = r[j + 1]!
|
||||
if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside
|
||||
}
|
||||
}
|
||||
return inside
|
||||
}
|
||||
|
||||
interface Face3 {
|
||||
verts: Vec3[]
|
||||
normal: Vec3
|
||||
kind: 'front' | 'back' | 'side'
|
||||
}
|
||||
|
||||
export interface BuildExtrusionInput {
|
||||
/** Flattened closed outline rings (local px; holes as additional rings, even-odd) */
|
||||
rings: number[][]
|
||||
w: number
|
||||
h: number
|
||||
depthPx: number
|
||||
/** sp3d z: whole-shape shift toward the viewer (px) */
|
||||
zPx: number
|
||||
scene: Scene3DProps
|
||||
/** Resolved solid front color (callers reduce gradients to a mid color) */
|
||||
frontColor: string
|
||||
sideColor: string
|
||||
strokeColor?: string
|
||||
strokeWidthPx?: number
|
||||
/** Front cap keeps the shape's own non-solid fill (adapter substitutes it) */
|
||||
frontUsesFill?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera with no extrusion and only an in-plane rotation (rev around z): the shape is
|
||||
* simply rotated in 2D — callers should add this to the node rotation instead of meshing.
|
||||
*/
|
||||
export function inPlaneRotationDeg(scene: Scene3DProps): number | null {
|
||||
const preset = CAMERA_PRESETS[scene.cameraPreset]
|
||||
if (!preset) return null
|
||||
if ((scene.extrusionEmu ?? 0) > 0) return null
|
||||
// A z shift changes the projection (perspective scale, oblique skew offset) — mesh it.
|
||||
if ((scene.zEmu ?? 0) !== 0) return null
|
||||
const lat = scene.cameraRot ? scene.cameraRot.lat * D : preset.rx
|
||||
const lon = scene.cameraRot ? scene.cameraRot.lon * D : preset.ry
|
||||
const rev = scene.cameraRot ? scene.cameraRot.rev * D : preset.rz
|
||||
const near = (a: number) =>
|
||||
Math.abs(((a % 360) + 360) % 360) < 0.5 || Math.abs((((a % 360) + 360) % 360) - 360) < 0.5
|
||||
if (!near(lat) || !near(lon)) return null
|
||||
// MS Office camera revolution turns the scene clockwise-positive in screen terms.
|
||||
return rev === 0 ? 0 : -rev
|
||||
}
|
||||
|
||||
export function buildExtrusion(input: BuildExtrusionInput): ExtrusionRender | null {
|
||||
const { rings, w, h, depthPx, scene } = input
|
||||
const preset = CAMERA_PRESETS[scene.cameraPreset]
|
||||
// depth 0 is legal: a flat shape tilted by the camera projects to just its front cap
|
||||
if (!preset || !rings.length || depthPx < 0) return null
|
||||
|
||||
const lat = scene.cameraRot ? scene.cameraRot.lat * D : preset.rx
|
||||
const lon = scene.cameraRot ? scene.cameraRot.lon * D : preset.ry
|
||||
const rev = scene.cameraRot ? scene.cameraRot.rev * D : preset.rz
|
||||
const m = cameraMatrix(lat, lon, rev)
|
||||
|
||||
const cx = w / 2
|
||||
const cy = h / 2
|
||||
const zOff = input.zPx
|
||||
|
||||
// 3D mesh: front cap at z=zOff, back cap at z=zOff-depth, one wall per outline edge.
|
||||
const faces: Face3[] = []
|
||||
const frontRings: Vec3[][] = []
|
||||
const backRings: Vec3[][] = []
|
||||
for (const ring of rings) {
|
||||
const fr: Vec3[] = []
|
||||
const br: Vec3[] = []
|
||||
for (let i = 0; i < ring.length; i += 2) {
|
||||
fr.push([ring[i]! - cx, ring[i + 1]! - cy, zOff])
|
||||
br.push([ring[i]! - cx, ring[i + 1]! - cy, zOff - depthPx])
|
||||
}
|
||||
frontRings.push(fr)
|
||||
backRings.push(br)
|
||||
if (depthPx <= 0) continue
|
||||
for (let i = 0; i < fr.length; i++) {
|
||||
const j = (i + 1) % fr.length
|
||||
const ex = fr[j]![0] - fr[i]![0]
|
||||
const ey = fr[j]![1] - fr[i]![1]
|
||||
const elen = Math.hypot(ex, ey)
|
||||
if (elen < 1e-6) continue
|
||||
// Outward 2D wall normal: probe both perpendiculars against the even-odd interior.
|
||||
let nx = ey / elen
|
||||
let ny = -ex / elen
|
||||
const mx = (fr[i]![0] + fr[j]![0]) / 2 + cx
|
||||
const my = (fr[i]![1] + fr[j]![1]) / 2 + cy
|
||||
if (insideRings(rings, mx + nx * 0.75, my + ny * 0.75)) {
|
||||
nx = -nx
|
||||
ny = -ny
|
||||
}
|
||||
faces.push({ verts: [fr[i]!, fr[j]!, br[j]!, br[i]!], normal: [nx, ny, 0], kind: 'side' })
|
||||
}
|
||||
}
|
||||
|
||||
// Rotate the mesh (normals rotate with it; the camera matrix is orthonormal). The
|
||||
// pre-rotation normal is kept for shading: with modern cameras the light rig follows
|
||||
// the camera, so illumination is camera-invariant (evaluated in shape space).
|
||||
const shapeNormals = faces.map((f) => f.normal)
|
||||
for (const f of faces) {
|
||||
f.verts = f.verts.map((v) => apply(m, v))
|
||||
f.normal = apply(m, f.normal)
|
||||
}
|
||||
const frontR = frontRings.map((r) => r.map((v) => apply(m, v)))
|
||||
const backR = backRings.map((r) => r.map((v) => apply(m, v)))
|
||||
const frontNormal = apply(m, [0, 0, 1])
|
||||
const backNormal = apply(m, [0, 0, -1])
|
||||
|
||||
// Projection to screen px (still centered at the shape center).
|
||||
const eyeDist = preset.vz * PX_PER_MM100
|
||||
const eyeX = preset.vx * PX_PER_MM100
|
||||
const eyeY = preset.vy * PX_PER_MM100
|
||||
const skew = preset.skewAmount / 100
|
||||
const skewA = rad(preset.skewAngle)
|
||||
const origX = preset.ox * w
|
||||
const origY = preset.oy * h
|
||||
const project = (v: Vec3): [number, number] => {
|
||||
if (preset.parallel) {
|
||||
// Oblique parallel projection: depth leaks into xy along the skew angle.
|
||||
return [v[0] - v[2] * skew * Math.cos(skewA) + cx, v[1] - v[2] * skew * Math.sin(skewA) + cy]
|
||||
}
|
||||
const s = eyeDist / Math.max(eyeDist - (v[2] - 0), 1)
|
||||
return [
|
||||
origX + eyeX + (v[0] - origX - eyeX) * s + cx,
|
||||
origY + eyeY + (v[1] - origY - eyeY) * s + cy,
|
||||
]
|
||||
}
|
||||
|
||||
const rig = LIGHT_RIGS[scene.lightRig ?? ''] ?? LIGHT_RIGS.threePt!
|
||||
let lightXf: Mat3 = IDENT
|
||||
if (scene.lightRot) {
|
||||
// Measured on Scene3d_material_highlight (twoPt rev=90°): PowerPoint keeps the rig's
|
||||
// table directions — a rev spin does not move the lights. lat/lon still reposition
|
||||
// the rig (inverse, like the dir attribute's z-steps).
|
||||
const c = cameraMatrix(scene.lightRot.lat * D, scene.lightRot.lon * D, 0)
|
||||
lightXf = [c[0], c[3], c[6], c[1], c[4], c[7], c[2], c[5], c[8]]
|
||||
} else {
|
||||
const dirDeg = RIG_DIR_DEG[scene.lightDir ?? 't'] ?? 0
|
||||
if (dirDeg) lightXf = rotZ(rad(dirDeg))
|
||||
}
|
||||
|
||||
const frontBase = parseRgb(input.frontColor)
|
||||
const sideBase = parseRgb(scene.extrusionColor ?? input.sideColor)
|
||||
const wireframe = scene.material === 'legacyWireframe'
|
||||
// Material shading only for an explicit prstMaterial: the default (absent) keeps the
|
||||
// plain Lambert look every calibrated deck was measured with
|
||||
const mat = scene.material ? (MATERIALS[scene.material] ?? DEFAULT_MATERIAL) : LAMBERT
|
||||
// Caps keep the authored look — PowerPoint puts the material highlight on the walls only
|
||||
const capMat = { ...mat, spec: 0 }
|
||||
|
||||
const out: ExtrusionFaceRender[] = []
|
||||
const rnd = (n: number) => Math.round(n * 100) / 100
|
||||
const ringPath = (verts: Vec3[]): string => {
|
||||
const pts = verts.map(project)
|
||||
return `M ${pts.map((p) => `${rnd(p[0])} ${rnd(p[1])}`).join(' L ')} Z`
|
||||
}
|
||||
const capPath = (ringsOf: Vec3[][]): string => ringsOf.map(ringPath).join(' ')
|
||||
const meanZ = (verts: Vec3[]) => verts.reduce((s, v) => s + v[2], 0) / verts.length
|
||||
|
||||
if (wireframe) {
|
||||
const sw = Math.max(input.strokeWidthPx ?? 1, 0.75)
|
||||
const stroke = input.strokeColor ?? '#000000'
|
||||
out.push({ path: capPath(backR), color: 'transparent', stroke, strokeWidthPx: sw })
|
||||
// Connecting edges only at real corners (flattened curves would spray lines everywhere).
|
||||
for (let ri = 0; ri < frontR.length; ri++) {
|
||||
const fr = frontR[ri]!
|
||||
const br = backR[ri]!
|
||||
for (let i = 0; i < fr.length; i++) {
|
||||
const prev = fr[(i - 1 + fr.length) % fr.length]!
|
||||
const next = fr[(i + 1) % fr.length]!
|
||||
const a1 = Math.atan2(fr[i]![1] - prev[1], fr[i]![0] - prev[0])
|
||||
const a2 = Math.atan2(next[1] - fr[i]![1], next[0] - fr[i]![0])
|
||||
let da = Math.abs(a1 - a2)
|
||||
if (da > Math.PI) da = 2 * Math.PI - da
|
||||
if (da < rad(20)) continue
|
||||
const p1 = project(fr[i]!)
|
||||
const p2 = project(br[i]!)
|
||||
out.push({
|
||||
path: `M ${rnd(p1[0])} ${rnd(p1[1])} L ${rnd(p2[0])} ${rnd(p2[1])}`,
|
||||
color: 'transparent',
|
||||
stroke,
|
||||
strokeWidthPx: sw,
|
||||
})
|
||||
}
|
||||
}
|
||||
out.push({ path: capPath(frontR), color: 'transparent', stroke, strokeWidthPx: sw })
|
||||
return { faces: out, wireframe: true }
|
||||
}
|
||||
|
||||
// Painter order: back cap, walls far→near, front cap. Walls facing away from the
|
||||
// viewer are culled (interior walls seen through holes survive: they face the viewer).
|
||||
const viewDirAt = (verts: Vec3[]): Vec3 => {
|
||||
// Skewed parallel projection: the projector direction leans along the skew, so
|
||||
// side walls of an unrotated oblique box stay visible.
|
||||
if (preset.parallel) return [skew * Math.cos(skewA), skew * Math.sin(skewA), 1]
|
||||
const cxv = verts.reduce((s, v) => s + v[0], 0) / verts.length
|
||||
const cyv = verts.reduce((s, v) => s + v[1], 0) / verts.length
|
||||
const czv = verts.reduce((s, v) => s + v[2], 0) / verts.length
|
||||
return [eyeX + origX - cxv, eyeY + origY - cyv, eyeDist - czv]
|
||||
}
|
||||
const facing = (normal: Vec3, verts: Vec3[]) => {
|
||||
const vd = viewDirAt(verts)
|
||||
return normal[0] * vd[0] + normal[1] * vd[1] + normal[2] * vd[2] > 0
|
||||
}
|
||||
|
||||
// Skewed parallel cameras (oblique/legacy) rotate the shape under fixed lights (shade
|
||||
// with view-space normals); rotating cameras (isometric/perspective/orthographic) move
|
||||
// the camera with the rig attached (shade with shape-space normals, so the authored
|
||||
// appearance survives every preset and the back cap goes dark).
|
||||
const legacy = preset.skewAmount > 0 || scene.cameraPreset.startsWith('legacy')
|
||||
if (backR[0] && facing(backNormal, backR[0])) {
|
||||
out.push({
|
||||
path: capPath(backR),
|
||||
color: legacy
|
||||
? shade(sideBase, backNormal, rig, lightXf, capMat)
|
||||
: shade(frontBase, [0, 0, -1], rig, lightXf, capMat, backNormal),
|
||||
})
|
||||
}
|
||||
const wallIdx = faces
|
||||
.map((f, i) => i)
|
||||
.filter((i) => facing(faces[i]!.normal, faces[i]!.verts))
|
||||
.sort((a, b) => meanZ(faces[a]!.verts) - meanZ(faces[b]!.verts))
|
||||
for (const i of wallIdx) {
|
||||
const f = faces[i]!
|
||||
out.push({
|
||||
path: ringPath(f.verts),
|
||||
color: shade(sideBase, legacy ? f.normal : shapeNormals[i]!, rig, lightXf, mat, f.normal),
|
||||
})
|
||||
}
|
||||
if (frontR[0] && facing(frontNormal, frontR[0])) {
|
||||
out.push({
|
||||
path: capPath(frontR),
|
||||
color: input.frontUsesFill
|
||||
? input.frontColor
|
||||
: shade(frontBase, legacy ? frontNormal : [0, 0, 1], rig, lightXf, capMat, frontNormal),
|
||||
...(input.frontUsesFill ? { front: true } : {}),
|
||||
...(input.strokeColor
|
||||
? { stroke: input.strokeColor, strokeWidthPx: input.strokeWidthPx ?? 1 }
|
||||
: {}),
|
||||
})
|
||||
}
|
||||
return { faces: out }
|
||||
}
|
||||
@@ -60,6 +60,12 @@ interface Token {
|
||||
outline?: { color: string; widthPx: number }
|
||||
/** Run outer shadow (px, offset resolved from dist/dir) */
|
||||
shadow?: { color: string; blurPx: number; offsetX: number; offsetY: number }
|
||||
/** WordArt gradient text fill (resolved stops + screen angle) */
|
||||
gradient?: { stops: Array<{ pos: number; color: string }>; angleDeg: number }
|
||||
/** Run glow (px radius) */
|
||||
glow?: { color: string; blurPx: number }
|
||||
/** Run reflection (faded mirror below the baseline) */
|
||||
reflection?: boolean
|
||||
/** Run hyperlink (TextRun.hyperlink encoding) */
|
||||
link?: string
|
||||
}
|
||||
@@ -288,6 +294,24 @@ function tokenizeParagraph(p: Paragraph, scale: number, fontScale: number): Toke
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(run.gradient
|
||||
? {
|
||||
gradient: {
|
||||
stops: run.gradient.stops.map((s) => ({ pos: s.pos, color: s.color })),
|
||||
// OOXML gradient angle is 1/60000° clockwise from the +x axis
|
||||
angleDeg: (run.gradient.angle ?? 5400000) / 60000,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(run.glow
|
||||
? {
|
||||
glow: {
|
||||
color: run.glow.color,
|
||||
blurPx: emuToPx(run.glow.radius, scale) * fontScale,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(run.reflection ? { reflection: true } : {}),
|
||||
...(run.shadow
|
||||
? {
|
||||
shadow: {
|
||||
@@ -631,6 +655,9 @@ function buildLine(
|
||||
widthPx: w,
|
||||
...(tok.ls ? { letterSpacingPx: tok.ls } : {}),
|
||||
...(tok.outline ? { outline: tok.outline } : {}),
|
||||
...(tok.gradient ? { gradient: tok.gradient } : {}),
|
||||
...(tok.glow ? { glow: tok.glow } : {}),
|
||||
...(tok.reflection ? { reflection: true } : {}),
|
||||
...(tok.shadow ? { shadow: tok.shadow } : {}),
|
||||
...(tok.blShift ? { baselineShiftPx: tok.blShift } : {}),
|
||||
...(tok.blPct ? { baselinePct: tok.blPct } : {}),
|
||||
@@ -823,6 +850,21 @@ export function layoutText(input: TextLayoutInput): RenderTextLayout {
|
||||
}))
|
||||
: result.lines
|
||||
|
||||
// WordArt text extrusion: depth projected by the body camera tilt (same screen basis
|
||||
// as the scene3d shape pipeline: depth leans (sin lon, -sin lat·cos lon) per unit)
|
||||
let extrusion: RenderTextLayout['extrusion']
|
||||
if (body.extrusion3d) {
|
||||
const e = body.extrusion3d
|
||||
const d = emuToPx(e.depthEmu, vp.scale)
|
||||
const la = (e.latDeg * Math.PI) / 180
|
||||
const lo = (e.lonDeg * Math.PI) / 180
|
||||
extrusion = {
|
||||
color: e.color,
|
||||
dx: -d * Math.sin(lo),
|
||||
dy: d * Math.sin(la) * Math.cos(lo),
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
lines,
|
||||
insets,
|
||||
@@ -832,6 +874,7 @@ export function layoutText(input: TextLayoutInput): RenderTextLayout {
|
||||
contentHeight: result.contentHeight,
|
||||
...(result.inkBottom ? { inkBottom: result.inkBottom } : {}),
|
||||
wrap,
|
||||
...(extrusion ? { extrusion } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -946,6 +989,9 @@ function layoutTextVertical(
|
||||
...(tok.strike ? { strike: true } : {}),
|
||||
...(tok.highlight ? { highlight: tok.highlight } : {}),
|
||||
...(tok.outline ? { outline: tok.outline } : {}),
|
||||
...(tok.gradient ? { gradient: tok.gradient } : {}),
|
||||
...(tok.glow ? { glow: tok.glow } : {}),
|
||||
...(tok.reflection ? { reflection: true } : {}),
|
||||
...(tok.shadow ? { shadow: tok.shadow } : {}),
|
||||
widthPx: metrics.measure(g, tok.style),
|
||||
...(tok.blPct ? { baselinePct: tok.blPct } : {}),
|
||||
@@ -980,6 +1026,9 @@ function layoutTextVertical(
|
||||
...(tok.strike ? { strike: true } : {}),
|
||||
...(tok.highlight ? { highlight: tok.highlight } : {}),
|
||||
...(tok.outline ? { outline: tok.outline } : {}),
|
||||
...(tok.gradient ? { gradient: tok.gradient } : {}),
|
||||
...(tok.glow ? { glow: tok.glow } : {}),
|
||||
...(tok.reflection ? { reflection: true } : {}),
|
||||
...(tok.shadow ? { shadow: tok.shadow } : {}),
|
||||
widthPx: adv,
|
||||
rotate90: true,
|
||||
|
||||
@@ -74,6 +74,28 @@ describe('buildChartNode', () => {
|
||||
expect(s1[1]!.y).toBeLessThan(s1[0]!.y)
|
||||
})
|
||||
|
||||
it('negative overlap spreads clustered bars apart; positive overlap tucks them together', () => {
|
||||
const base: ChartModel = {
|
||||
kind: 'bar',
|
||||
barDir: 'col',
|
||||
grouping: 'clustered',
|
||||
gapWidthPct: 76,
|
||||
categories: ['a'],
|
||||
series: [
|
||||
{ name: 's1', color: '#111111', values: [-0.7] },
|
||||
{ name: 's2', color: '#222222', values: [-1.0] },
|
||||
],
|
||||
}
|
||||
const flat = buildChartNode('r_o0', 'el', base, box, vp, metrics)!
|
||||
const spread = buildChartNode('r_o1', 'el', { ...base, overlapPct: -95 }, box, vp, metrics)!
|
||||
// overlap -95: adjacent series sit 1.95 bar-widths apart, so bars must shrink
|
||||
expect(spread.bars[0]!.w).toBeLessThan(flat.bars[0]!.w * 0.75)
|
||||
const gapPx = spread.bars[1]!.x - (spread.bars[0]!.x + spread.bars[0]!.w)
|
||||
expect(gapPx).toBeCloseTo(spread.bars[0]!.w * 0.95, 0)
|
||||
// all-negative data with autoZero: bars hang from the zero line (same top edge)
|
||||
expect(spread.bars[0]!.y).toBeCloseTo(spread.bars[1]!.y, 1)
|
||||
})
|
||||
|
||||
it('builds bar+line combo: bar series as bars, line series as overlaid polyline', () => {
|
||||
const model: ChartModel = {
|
||||
kind: 'bar',
|
||||
@@ -599,3 +621,246 @@ describe('legend swatch metrics (PowerPoint ~0.5em squares)', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildBar3DNode (c:bar3DChart true 3D stage)', () => {
|
||||
const bar3DModel: ChartModel = {
|
||||
kind: 'bar',
|
||||
grouping: 'standard',
|
||||
categories: ['C1', 'C2', 'C3', 'C4'],
|
||||
series: [
|
||||
{ name: 'S1', values: [4.3, 2.5, 3.5, 4.5] },
|
||||
{ name: 'S2', values: [2.4, 4.4, 1.8, 2.8] },
|
||||
{ name: 'S3', values: [2, 2, 3, 5] },
|
||||
],
|
||||
legendPos: 'r',
|
||||
bar3D: { rotX: 15, rotY: 20, depthPct: 100, rAngAx: true, gapDepthPct: 150, serAxLabels: true },
|
||||
}
|
||||
|
||||
it('draws three faces per bar in painter order (back series first)', () => {
|
||||
const node = buildChartNode('r3d', 'e3d', bar3DModel, box, vp, metrics)!
|
||||
// 12 bars × 3 faces (top/right/front)
|
||||
expect(node.paths!.length).toBe(36)
|
||||
// front face of the first-emitted (back row, series 3) bar is the series-3 palette color
|
||||
expect(node.paths![2]!.fill).toBe('#A5A5A5')
|
||||
})
|
||||
|
||||
it('3D value axis snaps to the data ceiling without headroom (max 5, not 6)', () => {
|
||||
const node = buildChartNode('r3d2', 'e3d2', bar3DModel, box, vp, metrics)!
|
||||
const tickTexts = node.labels.filter((l) => /^\d+$/.test(l.text)).map((l) => l.text)
|
||||
expect(tickTexts).toContain('5')
|
||||
expect(tickTexts).not.toContain('6')
|
||||
})
|
||||
|
||||
it('labels series names along the depth axis and categories along the leaning front edge', () => {
|
||||
const node = buildChartNode('r3d3', 'e3d3', bar3DModel, box, vp, metrics)!
|
||||
// series names appear twice: legend + depth axis
|
||||
expect(node.labels.filter((l) => l.text === 'S2').length).toBe(2)
|
||||
const c1 = node.labels.find((l) => l.text === 'C1')!
|
||||
const c4 = node.labels.find((l) => l.text === 'C4')!
|
||||
expect(c4.y).toBeGreaterThan(c1.y) // category axis leans down to the right
|
||||
})
|
||||
|
||||
it('stacked 3D bars stay on the pseudo-3D path (no depth stage)', () => {
|
||||
const stacked = { ...bar3DModel, grouping: 'stacked' as const }
|
||||
const node = buildChartNode('r3d4', 'e3d4', stacked, box, vp, metrics)!
|
||||
expect(node.bars.length).toBeGreaterThan(0) // classic bars, not projected paths
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildArea3DNode (c:area3DChart true 3D stage)', () => {
|
||||
const area3DModel: ChartModel = {
|
||||
kind: 'area',
|
||||
grouping: 'standard',
|
||||
categories: ['', '', '', '', ''],
|
||||
series: [
|
||||
{ name: 'Series 1', values: [32, 28, 12, 15, 28] },
|
||||
{ name: 'Series 2', values: [12, 12, 18, 24, 28] },
|
||||
],
|
||||
area3D: { rotX: 15, rotY: 20, gapDepthPct: 150, serAxLabels: false },
|
||||
}
|
||||
|
||||
it('standard grouping extrudes one ribbon per series, back row first', () => {
|
||||
const node = buildChartNode('a3d', 'ea3d', area3DModel, box, vp, metrics)!
|
||||
// per series: 4 roof segments + 1 end cap + 1 front silhouette
|
||||
expect(node.paths!.length).toBe(12)
|
||||
// back row (series 2) emits first; its front silhouette is the series-2 palette color
|
||||
expect(node.paths![5]!.fill).toBe('#ED7D31')
|
||||
expect(node.paths![11]!.fill).toBe('#4472C4')
|
||||
})
|
||||
|
||||
it('stacked grouping piles all series into a single ribbon with one exposed roof', () => {
|
||||
const stacked = { ...area3DModel, grouping: 'stacked' as const }
|
||||
const node = buildChartNode('a3d2', 'ea3d2', stacked, box, vp, metrics)!
|
||||
// 2 front bands + 2 end caps + 4 roof segments (topmost series only)
|
||||
expect(node.paths!.length).toBe(8)
|
||||
})
|
||||
|
||||
it('3D value axis snaps to the data ceiling without headroom and thins ticks to the stage height', () => {
|
||||
const node = buildChartNode('a3d3', 'ea3d3', area3DModel, box, vp, metrics)!
|
||||
const tickTexts = node.labels.map((l) => l.text)
|
||||
expect(tickTexts).toContain('40')
|
||||
expect(tickTexts).not.toContain('50')
|
||||
})
|
||||
|
||||
it('percentStacked pins the axis to 0-100%', () => {
|
||||
const pct = { ...area3DModel, grouping: 'percentStacked' as const }
|
||||
const node = buildChartNode('a3d4', 'ea3d4', pct, box, vp, metrics)!
|
||||
expect(node.labels.some((l) => l.text === '100%')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// ── Plot-area geometry & axis calibration (PPT-measured, python-pptx/aspose corpus) ──
|
||||
|
||||
describe('axis calibration', () => {
|
||||
const negModel: ChartModel = {
|
||||
kind: 'bar',
|
||||
barDir: 'col',
|
||||
grouping: 'clustered',
|
||||
categories: ['C1', 'C2'],
|
||||
series: [{ name: 'A', values: [-4, 5] }],
|
||||
valAxis: { gridColor: '#E6E6E6' },
|
||||
}
|
||||
|
||||
it('reversed value axis flips the mapping (maxMin: min renders at the top)', () => {
|
||||
const normal = buildChartNode('n', 'e', negModel, box, vp, metrics)!
|
||||
const reversed = buildChartNode(
|
||||
'r',
|
||||
'e',
|
||||
{ ...negModel, valAxis: { reversed: true } },
|
||||
box,
|
||||
vp,
|
||||
metrics,
|
||||
)!
|
||||
const yNormal = normal.bars.map((b) => b.y)
|
||||
const yReversed = reversed.bars.map((b) => b.y)
|
||||
// The negative bar hangs below the zero line normally, above it when reversed
|
||||
expect(yNormal[0]!).toBeGreaterThan(yNormal[1]!)
|
||||
expect(yReversed[0]!).toBeLessThan(yReversed[1]!)
|
||||
// Bar rects keep their real extent under the flipped mapping (Bugbot: h collapsed to 0.5)
|
||||
for (const b of [...normal.bars, ...reversed.bars]) expect(b.h).toBeGreaterThan(20)
|
||||
})
|
||||
|
||||
it('a range spanning zero puts the category axis and its labels at the zero line', () => {
|
||||
const node = buildChartNode('z', 'e', negModel, box, vp, metrics)!
|
||||
const xAxis = node.axisLines[0]!
|
||||
// zero sits strictly inside the plot, not at its bottom
|
||||
const plotBottom = Math.max(...node.gridLines.map((g) => g.y1))
|
||||
expect(xAxis.y1).toBeLessThan(plotBottom - 10)
|
||||
// category labels hug the axis line, not the frame bottom
|
||||
const cat = node.labels.find((l) => l.text === 'C1')!
|
||||
expect(Math.abs(cat.y - xAxis.y1)).toBeLessThan(30)
|
||||
})
|
||||
|
||||
it('explicit majorUnit/minorUnit drive tick spacing and minor subdivision', () => {
|
||||
const model: ChartModel = {
|
||||
kind: 'line',
|
||||
categories: ['a', 'b'],
|
||||
series: [{ name: 'A', values: [1, 14] }],
|
||||
valAxis: {
|
||||
min: -2,
|
||||
max: 15,
|
||||
majorUnit: 2,
|
||||
minorUnit: 0.5,
|
||||
gridColor: '#0000FF',
|
||||
minorGridColor: '#FF0000',
|
||||
},
|
||||
}
|
||||
const node = buildChartNode('u', 'e', model, box, vp, metrics)!
|
||||
const majors = node.gridLines.filter((g) => g.color === '#0000FF')
|
||||
const minors = node.gridLines.filter((g) => g.color === '#FF0000')
|
||||
// ticks -2..14 step 2 → 9 majors; minor slots k=1..33 minus the 8 major-coincident ones
|
||||
expect(majors).toHaveLength(9)
|
||||
expect(minors.length).toBe(25)
|
||||
})
|
||||
|
||||
it('no-style-part charts default to the dark PPT gridline grays', () => {
|
||||
const model: ChartModel = {
|
||||
kind: 'line',
|
||||
categories: ['a', 'b'],
|
||||
series: [{ name: 'A', values: [1, 4] }],
|
||||
valAxis: { gridColor: '#E6E6E6', gridColorAuto: true, minorGridAuto: true },
|
||||
}
|
||||
const node = buildChartNode('g', 'e', model, box, vp, metrics)!
|
||||
expect(node.gridLines.some((g) => g.color === '#868686')).toBe(true)
|
||||
expect(node.gridLines.some((g) => g.color === '#B7B7B7')).toBe(true)
|
||||
// with a style part, the explicit-ish default stays light and minors stay hidden
|
||||
const styled = buildChartNode('g2', 'e', { ...model, hasStylePart: true }, box, vp, metrics)!
|
||||
expect(styled.gridLines.every((g) => g.color === '#E6E6E6')).toBe(true)
|
||||
})
|
||||
|
||||
it('overlay axis titles reserve no plot space', () => {
|
||||
const base: ChartModel = {
|
||||
kind: 'line',
|
||||
categories: ['a', 'b'],
|
||||
series: [{ name: 'A', values: [1, 4] }],
|
||||
valAxis: { title: 'Primary', gridColor: '#E6E6E6' },
|
||||
}
|
||||
const reserved = buildChartNode('t1', 'e', base, box, vp, metrics)!
|
||||
const overlay = buildChartNode(
|
||||
't2',
|
||||
'e',
|
||||
{ ...base, valAxis: { title: 'Primary', titleOverlay: true, gridColor: '#E6E6E6' } },
|
||||
box,
|
||||
vp,
|
||||
metrics,
|
||||
)!
|
||||
const left = (n: typeof reserved) => Math.min(...n.gridLines.map((g) => g.x1))
|
||||
expect(left(overlay)).toBeLessThan(left(reserved) - 10)
|
||||
})
|
||||
|
||||
it('garbage-baseline tick labels reserve a formatted-zero slot, not the full label width', () => {
|
||||
// Aspose INT_MIN baseline (ChartEntities measured): nothing draws, but PowerPoint
|
||||
// keeps a slot ≈ the formatted zero plus the top half-label headroom
|
||||
const base: ChartModel = {
|
||||
kind: 'line',
|
||||
categories: ['a', 'b'],
|
||||
series: [{ name: 'A', values: [1, 14] }],
|
||||
valAxis: { min: -2, max: 15, majorUnit: 2, numFmt: '0.0%', gridColor: '#E6E6E6' },
|
||||
}
|
||||
const normal = buildChartNode('n', 'e', base, box, vp, metrics)!
|
||||
const garbage = buildChartNode(
|
||||
'g',
|
||||
'e',
|
||||
{ ...base, valAxis: { ...base.valAxis, tickLblGarbage: true } },
|
||||
box,
|
||||
vp,
|
||||
metrics,
|
||||
)!
|
||||
const left = (n: typeof normal) => Math.min(...n.gridLines.map((g) => g.x1))
|
||||
const top = (n: typeof normal) => Math.min(...n.gridLines.map((g) => Math.min(g.y1, g.y2)))
|
||||
// narrower than the real labels ("1400.0%") but wider than no reserve at all
|
||||
expect(left(garbage)).toBeLessThan(left(normal) - 5)
|
||||
expect(left(garbage)).toBeGreaterThan(40)
|
||||
// headroom kept: same plot top as with drawn labels
|
||||
expect(Math.abs(top(garbage) - top(normal))).toBeLessThan(1)
|
||||
expect(garbage.labels.every((l) => !/%$/.test(l.text))).toBe(true)
|
||||
})
|
||||
|
||||
it('value tick labels honor the axis numFmt', () => {
|
||||
const model: ChartModel = {
|
||||
kind: 'line',
|
||||
categories: ['a', 'b'],
|
||||
series: [{ name: 'A', values: [0.2, 0.8] }],
|
||||
valAxis: { numFmt: '0%' },
|
||||
}
|
||||
const node = buildChartNode('f', 'e', model, box, vp, metrics)!
|
||||
expect(node.labels.some((l) => /%$/.test(l.text))).toBe(true)
|
||||
})
|
||||
|
||||
it('pure line charts stack in stacked/percentStacked grouping', () => {
|
||||
const model: ChartModel = {
|
||||
kind: 'line',
|
||||
grouping: 'stacked',
|
||||
categories: ['a', 'b'],
|
||||
series: [
|
||||
{ name: 'A', values: [2, 3] },
|
||||
{ name: 'B', values: [4, 5] },
|
||||
],
|
||||
}
|
||||
const node = buildChartNode('ls', 'e', model, box, vp, metrics)!
|
||||
// series B draws at the cumulative value (6/8), so its axis shows ticks up to 8
|
||||
expect(node.labels.some((l) => l.text === '8')).toBe(true)
|
||||
const [a, b] = node.polylines
|
||||
expect(b!.points[1]!).toBeLessThan(a!.points[1]!)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -287,6 +287,80 @@ describe('buildRenderSlide (end-to-end on real fixture)', () => {
|
||||
expect(node.cells[1].w).toBeCloseTo(node.box.w / 2, 1)
|
||||
})
|
||||
|
||||
it('table renders at its grid width when the frame ext is a stale placeholder', async () => {
|
||||
const { deck } = await openPptx(enginePptx('01_standard_business.pptx'))
|
||||
const slide = deck.slides[0]!
|
||||
const el: any = {
|
||||
id: 'tbl_1',
|
||||
type: 'table',
|
||||
anchor: { spIndex: -1, originalXml: '', range: [0, 0] },
|
||||
// ext cx=3000000 is stale: the grid below sums to 6593050 EMU (real prod deck shape)
|
||||
transform: {
|
||||
offset: { x: 0, y: 0, cx: 3000000, cy: 3000000 },
|
||||
rot: 0,
|
||||
flipH: false,
|
||||
flipV: false,
|
||||
},
|
||||
colWidths: [1449850, 5143200],
|
||||
rowHeights: [645100, 645100],
|
||||
rows: [
|
||||
[{}, {}],
|
||||
[{}, {}],
|
||||
],
|
||||
}
|
||||
const rs = buildRenderSlide({ ...slide, elements: [el], decorations: [] }, deck.size, {
|
||||
fitWidthPx: 1280,
|
||||
})
|
||||
const node = rs.nodes[0] as any
|
||||
const emuPerPx = deck.size.cx / 1280
|
||||
expect(node.box.w).toBeCloseTo(6593050 / emuPerPx, 0)
|
||||
expect(node.cells[1].w / node.cells[0].w).toBeCloseTo(5143200 / 1449850, 1)
|
||||
})
|
||||
|
||||
it('a table inside a scaled group keeps the group scale on its grid sizes', async () => {
|
||||
const { deck } = await openPptx(enginePptx('01_standard_business.pptx'))
|
||||
const slide = deck.slides[0]!
|
||||
const tbl: any = {
|
||||
id: 'tbl_g',
|
||||
type: 'table',
|
||||
anchor: { spIndex: -1, originalXml: '', range: [0, 0] },
|
||||
transform: {
|
||||
offset: { x: 0, y: 0, cx: 3810000, cy: 1905000 },
|
||||
rot: 0,
|
||||
flipH: false,
|
||||
flipV: false,
|
||||
},
|
||||
colWidths: [1905000, 1905000],
|
||||
rowHeights: [952500, 952500],
|
||||
rows: [
|
||||
[{}, {}],
|
||||
[{}, {}],
|
||||
],
|
||||
}
|
||||
const grp: any = {
|
||||
id: 'grp_1',
|
||||
type: 'group',
|
||||
anchor: { spIndex: -1, originalXml: '', range: [0, 0] },
|
||||
// group is half the size of its child coordinate space -> children scale by 0.5
|
||||
transform: {
|
||||
offset: { x: 0, y: 0, cx: 1905000, cy: 952500 },
|
||||
rot: 0,
|
||||
flipH: false,
|
||||
flipV: false,
|
||||
},
|
||||
childOffset: { x: 0, y: 0, cx: 3810000, cy: 1905000 },
|
||||
children: [tbl],
|
||||
}
|
||||
const rs = buildRenderSlide({ ...slide, elements: [grp], decorations: [] }, deck.size, {
|
||||
fitWidthPx: 1280,
|
||||
})
|
||||
const node = rs.nodes[0] as any
|
||||
const table = node.children[0]
|
||||
const emuPerPx = deck.size.cx / 1280
|
||||
expect(table.box.w).toBeCloseTo(1905000 / emuPerPx, 0)
|
||||
expect(table.cells[0].w).toBeCloseTo(952500 / emuPerPx, 0)
|
||||
})
|
||||
|
||||
it('cells after a mid-row merge keep their grid position (continuation tc is not double-counted)', async () => {
|
||||
const { deck } = await openPptx(enginePptx('01_standard_business.pptx'))
|
||||
const slide = deck.slides[0]!
|
||||
@@ -780,4 +854,39 @@ describe('metafile pictures get an opaque white backdrop (PlanS academy banner)'
|
||||
expect(emf.bgColor).toBe('#FFFFFF')
|
||||
expect(png.bgColor).toBeUndefined()
|
||||
})
|
||||
|
||||
it('a clrChange metafile drops the white DC backing (the recolor sees through it)', async () => {
|
||||
const { deck } = await openPptx(enginePptx('01_standard_business.pptx'))
|
||||
const slide = deck.slides[0]!
|
||||
const el: any = {
|
||||
id: 'pic_cc',
|
||||
type: 'picture',
|
||||
anchor: { spIndex: -1, originalXml: '', range: [0, 0] },
|
||||
transform: {
|
||||
offset: { x: 0, y: 0, cx: 1000000, cy: 1000000 },
|
||||
rot: 0,
|
||||
flipH: false,
|
||||
flipV: false,
|
||||
},
|
||||
mediaRef: '',
|
||||
dataUrl: 'data:image/x-emf;base64,AAAA',
|
||||
clrChange: { from: '#FFFFFF', to: '#FFFFFF00' },
|
||||
}
|
||||
const rs = buildRenderSlide({ ...slide, elements: [el], decorations: [] }, deck.size, {
|
||||
fitWidthPx: 1280,
|
||||
})
|
||||
const node = rs.nodes[0] as any
|
||||
expect(node.bgColor).toBeUndefined()
|
||||
expect(node.clrChange).toEqual({ from: '#FFFFFF', to: '#FFFFFF00' })
|
||||
|
||||
// non-white keys never touch the DC; an opaque white key recolors it
|
||||
const build = (clrChange: any) =>
|
||||
buildRenderSlide({ ...slide, elements: [{ ...el, clrChange }], decorations: [] }, deck.size, {
|
||||
fitWidthPx: 1280,
|
||||
}).nodes[0] as any
|
||||
expect(build({ from: '#FF0000', to: '#00FF0000' }).bgColor).toBe('#FFFFFF')
|
||||
expect(build({ from: '#FFFFFF', to: '#00FF00' }).bgColor).toBe('#00FF00')
|
||||
// partial alpha stays on the backing (canvas accepts #RRGGBBAA)
|
||||
expect(build({ from: '#FFFFFF', to: '#00FF0080' }).bgColor).toBe('#00FF0080')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -33,6 +33,22 @@ describe('2.2 fill/stroke resolution', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('tile scale maps image pixels at 144dpi (PowerPoint measured), x sx/sy', () => {
|
||||
const f: Fill = {
|
||||
type: 'image',
|
||||
mediaRef: 'ppt/media/t.png',
|
||||
mode: 'tile',
|
||||
tile: { tx: 0, ty: 0, sx: 0.5, sy: 1, algn: 'tl' },
|
||||
}
|
||||
const r = resolveFill(f, vp, () => 'data:img')
|
||||
expect(r.kind).toBe('image')
|
||||
if (r.kind === 'image') {
|
||||
// vp.scale = 1 → one image px = 96/144 = 2/3 of a canvas px, halved again by sx
|
||||
expect(r.tile?.scaleX).toBeCloseTo((96 / 144) * 0.5)
|
||||
expect(r.tile?.scaleY).toBeCloseTo(96 / 144)
|
||||
}
|
||||
})
|
||||
|
||||
it('image fill resolves dataUrl via media resolver', () => {
|
||||
const f: Fill = { type: 'image', mediaRef: 'ppt/media/image1.png', mode: 'stretch' }
|
||||
const r = resolveFill(f, vp, (ref) => (ref.includes('image1') ? 'data:img' : undefined))
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { patternGrid } from '../src/pattern-fills'
|
||||
|
||||
const density = (g: boolean[][]) => g.flat().filter(Boolean).length / 64
|
||||
|
||||
describe('patternGrid', () => {
|
||||
it('percent presets dither at their stated density', () => {
|
||||
for (const [name, pct] of [
|
||||
['pct5', 5],
|
||||
['pct25', 25],
|
||||
['pct50', 50],
|
||||
['pct90', 90],
|
||||
] as const) {
|
||||
expect(Math.abs(density(patternGrid(name)) - pct / 100)).toBeLessThan(0.05)
|
||||
}
|
||||
// monotone in density
|
||||
expect(density(patternGrid('pct10'))).toBeLessThan(density(patternGrid('pct40')))
|
||||
})
|
||||
|
||||
it('structural presets have the right orientation', () => {
|
||||
const horz = patternGrid('ltHorz')
|
||||
expect(horz[0]!.every(Boolean)).toBe(true)
|
||||
expect(horz[1]!.every((v) => !v)).toBe(true)
|
||||
const vert = patternGrid('ltVert')
|
||||
expect(vert.every((row) => row[0])).toBe(true)
|
||||
expect(vert.every((row) => !row[1])).toBe(true)
|
||||
// ltDnDiag: one fg pixel per row marching right
|
||||
const dn = patternGrid('ltDnDiag')
|
||||
for (let v = 0; v < 8; v++) expect(dn[v]![v]).toBe(true)
|
||||
})
|
||||
|
||||
it('unknown presets fall back to a visible pattern', () => {
|
||||
const g = patternGrid('nonsense42')
|
||||
expect(density(g)).toBeGreaterThan(0.05)
|
||||
expect(density(g)).toBeLessThan(0.95)
|
||||
})
|
||||
})
|
||||
@@ -323,8 +323,44 @@ describe('circularArrow presets', () => {
|
||||
for (const preset of ['circularArrow', 'leftCircularArrow']) {
|
||||
const r = presetPath(preset, 100, 100)
|
||||
expect(r?.path).toBeTruthy()
|
||||
// annular: the path contains two arc sweeps (many cubic segments), not a 4-corner box
|
||||
expect((r!.path!.match(/C /g) ?? []).length).toBeGreaterThan(4)
|
||||
// annular: two arc sweeps of cubic segments (≥2 each at the default 161° sweep),
|
||||
// not a 4-corner box (which would have none)
|
||||
expect((r!.path!.match(/C /g) ?? []).length).toBeGreaterThanOrEqual(4)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('gear9', () => {
|
||||
it('returns a 36-point toothed polygon, not a rect fallback', () => {
|
||||
const pts = presetPolygon('gear9', 100, 100)
|
||||
expect(pts).toBeTruthy()
|
||||
expect(pts!.length).toBe(9 * 4 * 2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('arrow callouts (tdf150789 SmartArt section arrows)', () => {
|
||||
it('upArrowCallout outlines a bottom box with a centered up arrow', () => {
|
||||
const pts = presetPolygon('upArrowCallout', 200, 100)!
|
||||
expect(pts).toHaveLength(22)
|
||||
// Arrow tip at top center
|
||||
expect(pts[8]).toBe(100)
|
||||
expect(pts[9]).toBe(0)
|
||||
// Callout box top at h - h*0.64977 (default adj4)
|
||||
expect(pts[1]).toBeCloseTo(100 - 64.977, 1)
|
||||
// Box spans the full width at the bottom
|
||||
expect(pts.slice(-4)).toEqual([200, 100, 0, 100])
|
||||
})
|
||||
|
||||
it('downArrowCallout mirrors vertically (box on top, arrow tip at bottom center)', () => {
|
||||
const pts = presetPolygon('downArrowCallout', 200, 100)!
|
||||
expect(pts[8]).toBe(100)
|
||||
expect(pts[9]).toBe(100)
|
||||
expect(pts[1]).toBeCloseTo(64.977, 1)
|
||||
})
|
||||
|
||||
it('rightArrowCallout points right with the box on the left', () => {
|
||||
const pts = presetPolygon('rightArrowCallout', 100, 200)!
|
||||
expect(pts[8]).toBe(100)
|
||||
expect(pts[9]).toBe(100)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
buildExtrusion,
|
||||
inPlaneRotationDeg,
|
||||
flattenSvgPath,
|
||||
ellipseRing,
|
||||
roundRectRing,
|
||||
type Scene3DProps,
|
||||
} from '../src/scene3d'
|
||||
|
||||
const RECT = [0, 0, 200, 0, 200, 100, 0, 100]
|
||||
|
||||
function scene(over: Partial<Scene3DProps> = {}): Scene3DProps {
|
||||
return { cameraPreset: 'isometricRightUp', lightRig: 'threePt', lightDir: 't', ...over }
|
||||
}
|
||||
|
||||
function build(over: Partial<Scene3DProps> = {}, extra: Record<string, unknown> = {}) {
|
||||
return buildExtrusion({
|
||||
rings: [RECT],
|
||||
w: 200,
|
||||
h: 100,
|
||||
depthPx: 40,
|
||||
zPx: 0,
|
||||
scene: scene(over),
|
||||
frontColor: '#C5E0B4',
|
||||
sideColor: '#ED7D31',
|
||||
...extra,
|
||||
})
|
||||
}
|
||||
|
||||
/** Parse "M x y L …" into [x,y,…] (absolute path emitted by the extrusion builder). */
|
||||
function pathPoints(d: string): number[] {
|
||||
return d
|
||||
.split(/[\s,]+/)
|
||||
.filter((t) => /^-?[\d.]+$/.test(t))
|
||||
.map(Number)
|
||||
}
|
||||
|
||||
function centroid(pts: number[]): { x: number; y: number } {
|
||||
let x = 0
|
||||
let y = 0
|
||||
for (let i = 0; i < pts.length; i += 2) {
|
||||
x += pts[i]!
|
||||
y += pts[i + 1]!
|
||||
}
|
||||
return { x: (x * 2) / pts.length, y: (y * 2) / pts.length }
|
||||
}
|
||||
|
||||
describe('flattenSvgPath', () => {
|
||||
it('polylines close into rings, curves get sampled', () => {
|
||||
const rings = flattenSvgPath('M 0 0 L 10 0 L 10 10 L 0 10 Z')
|
||||
expect(rings).toHaveLength(1)
|
||||
expect(rings[0]).toEqual([0, 0, 10, 0, 10, 10, 0, 10])
|
||||
const curved = flattenSvgPath('M 0 0 C 0 10 10 10 10 0 Z')
|
||||
expect(curved[0]!.length).toBeGreaterThan(8)
|
||||
})
|
||||
|
||||
it('multiple subpaths become separate rings (donut hole)', () => {
|
||||
const rings = flattenSvgPath('M 0 0 L 20 0 L 20 20 L 0 20 Z M 5 5 L 15 5 L 15 15 L 5 15 Z')
|
||||
expect(rings).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ring helpers', () => {
|
||||
it('ellipseRing stays on the ellipse', () => {
|
||||
const r = ellipseRing(200, 100, 16)
|
||||
for (let i = 0; i < r.length; i += 2) {
|
||||
const dx = (r[i]! - 100) / 100
|
||||
const dy = (r[i + 1]! - 50) / 50
|
||||
expect(dx * dx + dy * dy).toBeCloseTo(1, 6)
|
||||
}
|
||||
})
|
||||
|
||||
it('roundRectRing clamps the radius and keeps corners inside the box', () => {
|
||||
const r = roundRectRing(100, 40, 500)
|
||||
for (let i = 0; i < r.length; i += 2) {
|
||||
expect(r[i]!).toBeGreaterThanOrEqual(-0.001)
|
||||
expect(r[i]!).toBeLessThanOrEqual(100.001)
|
||||
expect(r[i + 1]!).toBeGreaterThanOrEqual(-0.001)
|
||||
expect(r[i + 1]!).toBeLessThanOrEqual(40.001)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('inPlaneRotationDeg', () => {
|
||||
it('orthographicFront + rev-only rot spins the flat shape (opposite orientation)', () => {
|
||||
expect(
|
||||
inPlaneRotationDeg(
|
||||
scene({ cameraPreset: 'orthographicFront', cameraRot: { lat: 0, lon: 0, rev: 5400000 } }),
|
||||
),
|
||||
).toBe(-90)
|
||||
})
|
||||
|
||||
it('extrusion, tilted cameras and unknown presets need the mesh path', () => {
|
||||
expect(
|
||||
inPlaneRotationDeg(
|
||||
scene({
|
||||
cameraPreset: 'orthographicFront',
|
||||
cameraRot: { lat: 0, lon: 0, rev: 5400000 },
|
||||
extrusionEmu: 1,
|
||||
}),
|
||||
),
|
||||
).toBeNull()
|
||||
expect(inPlaneRotationDeg(scene())).toBeNull()
|
||||
expect(inPlaneRotationDeg(scene({ cameraPreset: 'nope' }))).toBeNull()
|
||||
// a z shift changes perspective scale / oblique offset even without depth
|
||||
expect(inPlaneRotationDeg(scene({ cameraPreset: 'perspectiveFront', zEmu: 914400 }))).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildExtrusion', () => {
|
||||
it('depth 0 projects just the tilted front cap; unknown cameras bail out', () => {
|
||||
const flat = build({}, { depthPx: 0 })!
|
||||
expect(flat.faces).toHaveLength(1)
|
||||
expect(flat.faces[0]!.color).not.toBe('transparent')
|
||||
expect(build({ cameraPreset: 'bogus' })).toBeNull()
|
||||
})
|
||||
|
||||
it('isometric rect: back cap, visible walls, then front cap on top (painter order)', () => {
|
||||
const ext = build()!
|
||||
expect(ext.wireframe).toBeUndefined()
|
||||
const front = ext.faces[ext.faces.length - 1]!
|
||||
expect(front.color).not.toBe('transparent')
|
||||
// threePt front-face illumination ≈ 1.04 → the cap keeps roughly its base color
|
||||
expect(front.color.toUpperCase()).toBe('#CEEABC')
|
||||
// rect → 2 walls survive culling (left + top), plus the front cap; back cap is hidden
|
||||
expect(ext.faces.length).toBeGreaterThanOrEqual(3)
|
||||
})
|
||||
|
||||
it('modern cameras keep the authored cap appearance under every preset', () => {
|
||||
const a = build({ cameraPreset: 'isometricRightUp' })!
|
||||
const b = build({ cameraPreset: 'perspectiveContrastingLeftFacing' })!
|
||||
expect(a.faces[a.faces.length - 1]!.color).toBe(b.faces[b.faces.length - 1]!.color)
|
||||
})
|
||||
|
||||
it('legacy oblique: side walls stay visible and the extrusion offsets along the skew', () => {
|
||||
const ext = build({ cameraPreset: 'legacyObliqueTopLeft' })!
|
||||
expect(ext.faces.length).toBeGreaterThanOrEqual(3) // ≥2 walls + front cap
|
||||
// Wireframe emits both caps: 50% skew at -45° puts the back cap 40·0.5·cos45 ≈ 14.1px
|
||||
// right/up of the front cap.
|
||||
const wf = build({ cameraPreset: 'legacyObliqueTopLeft', material: 'legacyWireframe' })!
|
||||
const back = centroid(pathPoints(wf.faces[0]!.path))
|
||||
const front = centroid(pathPoints(wf.faces[wf.faces.length - 1]!.path))
|
||||
expect(back.x - front.x).toBeCloseTo(14.14, 1)
|
||||
expect(back.y - front.y).toBeCloseTo(-14.14, 1)
|
||||
})
|
||||
|
||||
it('perspective projection shrinks the far cap', () => {
|
||||
const wf = build({ cameraPreset: 'perspectiveFront', material: 'legacyWireframe' })!
|
||||
const width = (pts: number[]) =>
|
||||
Math.max(...pts.filter((_, i) => i % 2 === 0)) -
|
||||
Math.min(...pts.filter((_, i) => i % 2 === 0))
|
||||
const backW = width(pathPoints(wf.faces[0]!.path))
|
||||
const frontW = width(pathPoints(wf.faces[wf.faces.length - 1]!.path))
|
||||
expect(frontW).toBeCloseTo(200, 1)
|
||||
expect(backW).toBeLessThan(frontW)
|
||||
})
|
||||
|
||||
it('extrusionClr overrides the wall color source', () => {
|
||||
const plain = build()!
|
||||
const tinted = build({ extrusionColor: '#00FFFF' })!
|
||||
const wallOf = (ext: typeof plain) => ext.faces[1]!.color
|
||||
expect(wallOf(tinted)).not.toBe(wallOf(plain))
|
||||
})
|
||||
|
||||
it('legacyWireframe renders edge strokes only', () => {
|
||||
const ext = build(
|
||||
{ material: 'legacyWireframe' },
|
||||
{ strokeColor: '#000000', strokeWidthPx: 1 },
|
||||
)!
|
||||
expect(ext.wireframe).toBe(true)
|
||||
for (const f of ext.faces) {
|
||||
expect(f.color).toBe('transparent')
|
||||
expect(f.stroke).toBe('#000000')
|
||||
}
|
||||
})
|
||||
|
||||
it('harsh rig shades the visible walls unevenly (left saturated, top dimmer)', () => {
|
||||
const ext = build({ cameraPreset: 'isometricOffAxis1Right', lightRig: 'harsh' })!
|
||||
const walls = ext.faces.slice(0, -1)
|
||||
const lum = (c: string) => parseInt(c.slice(1, 3), 16)
|
||||
const lums = walls.map((f) => lum(f.color))
|
||||
expect(Math.max(...lums)).toBeGreaterThan(Math.min(...lums) + 20)
|
||||
})
|
||||
|
||||
it('holes survive into both caps as subpaths', () => {
|
||||
const ext = buildExtrusion({
|
||||
rings: [
|
||||
[0, 0, 200, 0, 200, 100, 0, 100],
|
||||
[50, 25, 150, 25, 150, 75, 50, 75],
|
||||
],
|
||||
w: 200,
|
||||
h: 100,
|
||||
depthPx: 40,
|
||||
zPx: 0,
|
||||
scene: scene(),
|
||||
frontColor: '#C5E0B4',
|
||||
sideColor: '#ED7D31',
|
||||
})!
|
||||
const front = ext.faces[ext.faces.length - 1]!
|
||||
expect(front.path.match(/M /g)!.length).toBe(2)
|
||||
// 8 wall candidates (4 outer + 4 inner); roughly half survive culling
|
||||
expect(ext.faces.length).toBeGreaterThanOrEqual(5)
|
||||
})
|
||||
})
|
||||
@@ -976,3 +976,54 @@ describe('bodyPr numCol columns', () => {
|
||||
expect(layout.lines.length).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('WordArt effect passthrough', () => {
|
||||
const m = new HeuristicMetrics()
|
||||
const run = {
|
||||
text: 'Word',
|
||||
fontSize: 20,
|
||||
color: '#111111',
|
||||
gradient: {
|
||||
stops: [
|
||||
{ pos: 0, color: '#FF0000' },
|
||||
{ pos: 1, color: '#0000FF' },
|
||||
],
|
||||
angle: 5400000,
|
||||
},
|
||||
glow: { color: '#ED7D31', radius: 53100 },
|
||||
reflection: true,
|
||||
}
|
||||
|
||||
it('gradient/glow/reflection reach the glyph runs (angle in degrees, glow in px)', () => {
|
||||
const layout = layoutText({
|
||||
body: body({ paragraphs: [{ runs: [run] }] }),
|
||||
boxWidthPx: 400,
|
||||
boxHeightPx: 100,
|
||||
metrics: m,
|
||||
vp,
|
||||
})
|
||||
const g = layout.lines[0]!.runs[0]!
|
||||
expect(g.gradient?.angleDeg).toBe(90)
|
||||
expect(g.gradient?.stops).toHaveLength(2)
|
||||
expect(g.glow?.color).toBe('#ED7D31')
|
||||
expect(g.glow?.blurPx).toBeGreaterThan(0)
|
||||
expect(g.reflection).toBe(true)
|
||||
})
|
||||
|
||||
it('bodyPr extrusion projects to a screen offset (lat 30° → downward)', () => {
|
||||
const layout = layoutText({
|
||||
body: body({
|
||||
paragraphs: [{ runs: [{ text: 'W', fontSize: 20, color: '#111111' }] }],
|
||||
extrusion3d: { color: '#C0504D', depthEmu: 127000, latDeg: 30, lonDeg: 0 },
|
||||
}),
|
||||
boxWidthPx: 400,
|
||||
boxHeightPx: 100,
|
||||
metrics: m,
|
||||
vp,
|
||||
})
|
||||
expect(layout.extrusion?.color).toBe('#C0504D')
|
||||
expect(layout.extrusion?.dx).toBeCloseTo(0, 5)
|
||||
// PowerPoint renders the depth below the glyphs for a positive camera latitude
|
||||
expect(layout.extrusion!.dy).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user