返回 oh-my-ppt
ooxml-text.test.ts
根目录 / tests / unit / html-pptx / ooxml-text.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { buildSlideXml } from '@arcsin1/html2pptx/ooxml'
3 import type { HtmlToPptxSlide } from '@arcsin1/html2pptx'
4
5 describe('buildSlideXml text export', () => {
6 it('writes text box padding as PPTX body insets', () => {
7 const slide: HtmlToPptxSlide = {
8 texts: [
9 {
10 text: '写给业务人员',
11 x: 9,
12 y: 0.6,
13 w: 2,
14 h: 0.56,
15 fontSize: 15,
16 paddingLeft: 0.25,
17 paddingRight: 0.25,
18 paddingTop: 0.15,
19 paddingBottom: 0.15
20 }
21 ],
22 shapes: [],
23 images: [],
24 tables: []
25 }
26
27 const xml = buildSlideXml(slide, new Map(), 1)
28
29 expect(xml).toContain('lIns="228600"')
30 expect(xml).toContain('rIns="228600"')
31 expect(xml).toContain('tIns="137160"')
32 expect(xml).toContain('bIns="137160"')
33 expect(xml).toContain('<a:t>写给业务人员</a:t>')
34 })
35
36 it('writes rich text runs with their own color and bold style', () => {
37 const slide: HtmlToPptxSlide = {
38 texts: [
39 {
40 text: '本页文字梳理:原始内容',
41 x: 1,
42 y: 1,
43 w: 4,
44 h: 0.5,
45 fontSize: 18,
46 fontFace: 'Noto Sans SC',
47 color: '3E3A39',
48 runs: [
49 {
50 text: '本页文字梳理:',
51 fontSize: 18,
52 fontFace: 'Noto Sans SC',
53 color: 'C00000',
54 bold: true
55 },
56 {
57 text: '原始内容',
58 fontSize: 18,
59 fontFace: 'Noto Sans SC',
60 color: '3E3A39'
61 }
62 ]
63 }
64 ],
65 shapes: [],
66 images: [],
67 tables: []
68 }
69
70 const xml = buildSlideXml(slide, new Map(), 1)
71
72 expect(xml).toContain('<a:srgbClr val="C00000"/>')
73 expect(xml).toContain('<a:t>本页文字梳理:</a:t>')
74 expect(xml).toContain('b="1"')
75 expect(xml).toContain('<a:srgbClr val="3E3A39"/>')
76 expect(xml).toContain('<a:t>原始内容</a:t>')
77 })
78
79 it('writes single-side exported borders as PPT line shapes', () => {
80 const slide: HtmlToPptxSlide = {
81 texts: [],
82 shapes: [
83 {
84 x: 1,
85 y: 1.5,
86 w: 3,
87 h: 0.001,
88 shapeType: 'line',
89 border: {
90 color: 'BFDDE8',
91 widthPt: 1.5,
92 dash: 'dash'
93 }
94 }
95 ],
96 images: [],
97 tables: []
98 }
99
100 const xml = buildSlideXml(slide, new Map(), 1)
101
102 expect(xml).toContain('<a:prstGeom prst="line"><a:avLst/></a:prstGeom>')
103 expect(xml).toContain('<a:prstDash val="dash"/>')
104 expect(xml).not.toContain('prst="rect"><a:avLst/></a:prstGeom>')
105 })
106
107 it('writes flipped line shapes for CSS chevron arrowheads', () => {
108 const slide: HtmlToPptxSlide = {
109 texts: [],
110 shapes: [
111 {
112 x: 1,
113 y: 1.5,
114 w: 0.2,
115 h: 0.12,
116 shapeType: 'line',
117 flipV: true,
118 border: {
119 color: 'AF2125',
120 widthPt: 1.5
121 }
122 }
123 ],
124 images: [],
125 tables: []
126 }
127
128 const xml = buildSlideXml(slide, new Map(), 1)
129
130 expect(xml).toContain('<a:xfrm flipV="1">')
131 expect(xml).toContain('<a:prstGeom prst="line"><a:avLst/></a:prstGeom>')
132 })
133 })
134
134 lines TYPESCRIPT