Preserve QPowerPoint slide backgrounds

This commit is contained in:
Курнат Андрей
2026-06-01 06:43:17 +03:00
parent 24206eb8bb
commit 4377e5279e
8 changed files with 119 additions and 5 deletions
+43
View File
@@ -201,6 +201,45 @@ describe("powerPointOffice helpers", () => {
expect(mediaFiles.length).toBeGreaterThan(0);
});
it("импортирует и экспортирует пользовательский цвет фона слайда", async () => {
const zip = new JSZip();
zip.file(
"ppt/presentation.xml",
`<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`
);
zip.file(
"ppt/_rels/presentation.xml.rels",
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/></Relationships>`
);
zip.file("ppt/slides/slide1.xml", slideXmlWithBackground("Фон слайда", "FCE4D6"));
const importedBlob = await zip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const imported = await importPptxFile(new File([importedBlob], "Фон.pptx", { type: importedBlob.type }));
expect(imported.slides[0].backgroundColor).toBe("FCE4D6");
const exportedBlob = await exportPptxBlob({
title: "Фон.pptx",
slides: [
{
id: "slide-1",
title: "Фон слайда",
subtitle: "",
notes: "",
theme: "classic",
backgroundColor: "FCE4D6"
}
]
});
const exportedZip = await JSZip.loadAsync(await exportedBlob.arrayBuffer());
const exportedSlideXml = await exportedZip.file("ppt/slides/slide1.xml")?.async("string");
expect(exportedSlideXml).toContain("FCE4D6");
});
it("нормализует пробелы в импортированном тексте", () => {
expect(normalizeWhitespace(" Строка\tс \n пробелами ")).toBe("Строка с пробелами");
});
@@ -212,6 +251,10 @@ function slideXml(...texts: string[]) {
.join("")}</p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithBackground(title: string, color: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:bg><p:bgPr><a:solidFill><a:srgbClr val="${color}"/></a:solidFill></p:bgPr></p:bg><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithPicture(title: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:pic><p:nvPicPr><p:cNvPr id="4" name="Picture 1" descr="Логотип"/></p:nvPicPr><p:blipFill><a:blip r:embed="rIdImage"/></p:blipFill><p:spPr><a:xfrm><a:off x="914400" y="1828800"/><a:ext cx="2743200" cy="1371600"/></a:xfrm></p:spPr></p:pic></p:spTree></p:cSld></p:sld>`;
}