Preserve QPowerPoint text run styles in PPTX
This commit is contained in:
@@ -592,6 +592,69 @@ describe("powerPointOffice helpers", () => {
|
||||
expect(exportedSlideXml).toContain('typeface="Times New Roman"');
|
||||
});
|
||||
|
||||
it("импортирует и экспортирует начертание текста слайда PPTX", 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", slideXmlWithTextRunStyles("Заголовок", "Подзаголовок"));
|
||||
|
||||
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]).toMatchObject({
|
||||
titleBold: true,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
});
|
||||
|
||||
const exportedBlob = await exportPptxBlob({
|
||||
title: "Начертание.pptx",
|
||||
slides: [
|
||||
{
|
||||
id: "slide-1",
|
||||
title: "Заголовок",
|
||||
subtitle: "Подзаголовок",
|
||||
notes: "",
|
||||
theme: "classic",
|
||||
titleBold: false,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
}
|
||||
]
|
||||
});
|
||||
const exportedZip = await JSZip.loadAsync(await exportedBlob.arrayBuffer());
|
||||
const exportedSlideXml = (await exportedZip.file("ppt/slides/slide1.xml")?.async("string")) ?? "";
|
||||
|
||||
expect(exportedSlideXml).toContain('i="1"');
|
||||
expect(exportedSlideXml).toContain('u="sng"');
|
||||
expect(exportedSlideXml).toContain('b="1"');
|
||||
|
||||
const reimported = await importPptxFile(new File([exportedBlob], "Начертание.pptx", { type: exportedBlob.type }));
|
||||
expect(reimported.slides[0]).toMatchObject({
|
||||
titleBold: false,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
});
|
||||
});
|
||||
|
||||
it("импортирует внешние ссылки текста PPTX через hlinkClick relationships", async () => {
|
||||
const zip = new JSZip();
|
||||
zip.file(
|
||||
@@ -679,6 +742,10 @@ function slideXmlWithTextStyles(title: string, subtitle: 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:spTree><p:sp><p:txBody><a:p><a:r><a:rPr sz="3400"><a:solidFill><a:srgbClr val="C2410C"/></a:solidFill><a:latin typeface="Courier New"/></a:rPr><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p><a:r><a:rPr sz="2200"><a:solidFill><a:srgbClr val="0F766E"/></a:solidFill><a:latin typeface="Times New Roman"/></a:rPr><a:t>${subtitle}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
|
||||
}
|
||||
|
||||
function slideXmlWithTextRunStyles(title: string, subtitle: 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:spTree><p:sp><p:txBody><a:p><a:r><a:rPr b="1" i="1" u="sng"/><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p><a:r><a:rPr b="1" i="1" u="sng"/><a:t>${subtitle}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
|
||||
}
|
||||
|
||||
function slideXmlWithTextHyperlinks(title: string, subtitle: 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:rPr><a:hlinkClick r:id="rIdTitleLink"/></a:rPr><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p><a:r><a:rPr><a:hlinkClick r:id="rIdSubtitleLink"/></a:rPr><a:t>${subtitle}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user