Preserve QPowerPoint strikethrough in PPTX
This commit is contained in:
@@ -614,9 +614,11 @@ describe("powerPointOffice helpers", () => {
|
||||
titleBold: true,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
titleStrike: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
subtitleUnderline: true,
|
||||
subtitleStrike: true
|
||||
});
|
||||
|
||||
const exportedBlob = await exportPptxBlob({
|
||||
@@ -631,9 +633,11 @@ describe("powerPointOffice helpers", () => {
|
||||
titleBold: false,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
titleStrike: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
subtitleUnderline: true,
|
||||
subtitleStrike: true
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -642,6 +646,7 @@ describe("powerPointOffice helpers", () => {
|
||||
|
||||
expect(exportedSlideXml).toContain('i="1"');
|
||||
expect(exportedSlideXml).toContain('u="sng"');
|
||||
expect(exportedSlideXml).toContain('strike="sngStrike"');
|
||||
expect(exportedSlideXml).toContain('b="1"');
|
||||
|
||||
const reimported = await importPptxFile(new File([exportedBlob], "Начертание.pptx", { type: exportedBlob.type }));
|
||||
@@ -649,9 +654,11 @@ describe("powerPointOffice helpers", () => {
|
||||
titleBold: false,
|
||||
titleItalics: true,
|
||||
titleUnderline: true,
|
||||
titleStrike: true,
|
||||
subtitleBold: true,
|
||||
subtitleItalics: true,
|
||||
subtitleUnderline: true
|
||||
subtitleUnderline: true,
|
||||
subtitleStrike: true
|
||||
});
|
||||
});
|
||||
|
||||
@@ -743,7 +750,7 @@ function slideXmlWithTextStyles(title: string, subtitle: string) {
|
||||
}
|
||||
|
||||
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>`;
|
||||
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" strike="sngStrike"/><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" strike="sngStrike"/><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) {
|
||||
|
||||
@@ -18,6 +18,7 @@ interface SlideTextBlock {
|
||||
bold?: boolean;
|
||||
italics?: boolean;
|
||||
underline?: boolean;
|
||||
strike?: boolean;
|
||||
color?: string;
|
||||
fontSize?: number;
|
||||
fontFamily?: string;
|
||||
@@ -105,12 +106,14 @@ export async function importPptxFile(file: File): Promise<ImportedPowerPointDeck
|
||||
titleBold: slideTextBlocks[0]?.bold ?? false,
|
||||
...(slideTextBlocks[0]?.italics ? { titleItalics: true } : {}),
|
||||
...(slideTextBlocks[0]?.underline ? { titleUnderline: true } : {}),
|
||||
...(slideTextBlocks[0]?.strike ? { titleStrike: true } : {}),
|
||||
...(slideTextBlocks[0]?.color ? { titleColor: slideTextBlocks[0].color } : {}),
|
||||
...(slideTextBlocks[0]?.fontSize ? { titleFontSize: slideTextBlocks[0].fontSize } : {}),
|
||||
...(slideTextBlocks[0]?.fontFamily ? { titleFontFamily: slideTextBlocks[0].fontFamily } : {}),
|
||||
...(slideTextBlocks[1]?.bold ? { subtitleBold: true } : {}),
|
||||
...(slideTextBlocks[1]?.italics ? { subtitleItalics: true } : {}),
|
||||
...(slideTextBlocks[1]?.underline ? { subtitleUnderline: true } : {}),
|
||||
...(slideTextBlocks[1]?.strike ? { subtitleStrike: true } : {}),
|
||||
...(slideTextBlocks[1]?.color ? { subtitleColor: slideTextBlocks[1].color } : {}),
|
||||
...(slideTextBlocks[1]?.fontSize ? { subtitleFontSize: slideTextBlocks[1].fontSize } : {}),
|
||||
...(slideTextBlocks[1]?.fontFamily ? { subtitleFontFamily: slideTextBlocks[1].fontFamily } : {}),
|
||||
@@ -159,9 +162,11 @@ export async function exportPptxBlob(deck: ExportablePowerPointDeck): Promise<Bl
|
||||
const titleBold = sourceSlide.titleBold ?? true;
|
||||
const titleItalics = Boolean(sourceSlide.titleItalics);
|
||||
const titleUnderline = Boolean(sourceSlide.titleUnderline);
|
||||
const titleStrike = Boolean(sourceSlide.titleStrike);
|
||||
const subtitleBold = Boolean(sourceSlide.subtitleBold);
|
||||
const subtitleItalics = Boolean(sourceSlide.subtitleItalics);
|
||||
const subtitleUnderline = Boolean(sourceSlide.subtitleUnderline);
|
||||
const subtitleStrike = Boolean(sourceSlide.subtitleStrike);
|
||||
const titleHyperlink = normalizedExternalHyperlinkTarget(sourceSlide.titleHyperlink);
|
||||
const subtitleHyperlink = normalizedExternalHyperlinkTarget(sourceSlide.subtitleHyperlink);
|
||||
const slide = pptx.addSlide();
|
||||
@@ -193,6 +198,7 @@ export async function exportPptxBlob(deck: ExportablePowerPointDeck): Promise<Bl
|
||||
bold: titleBold,
|
||||
italic: titleItalics,
|
||||
...(titleUnderline ? { underline: { style: "sng" } } : {}),
|
||||
...(titleStrike ? { strike: "sngStrike" } : {}),
|
||||
color: titleColor,
|
||||
margin: 0.04,
|
||||
breakLine: false,
|
||||
@@ -208,6 +214,7 @@ export async function exportPptxBlob(deck: ExportablePowerPointDeck): Promise<Bl
|
||||
bold: subtitleBold,
|
||||
italic: subtitleItalics,
|
||||
...(subtitleUnderline ? { underline: { style: "sng" } } : {}),
|
||||
...(subtitleStrike ? { strike: "sngStrike" } : {}),
|
||||
color: subtitleColor,
|
||||
valign: "top",
|
||||
fit: "shrink",
|
||||
@@ -248,6 +255,7 @@ function extractSlideTextBlocks(slideXml: unknown, hyperlinkTargets: Record<stri
|
||||
const bold = runTextBold(runProperties);
|
||||
const italics = runTextItalics(runProperties);
|
||||
const underline = runTextUnderline(runProperties);
|
||||
const strike = runTextStrike(runProperties);
|
||||
const color = runTextColor(runProperties);
|
||||
const fontSize = runTextFontSize(runProperties);
|
||||
const fontFamily = runTextFontFamily(runProperties);
|
||||
@@ -258,6 +266,7 @@ function extractSlideTextBlocks(slideXml: unknown, hyperlinkTargets: Record<stri
|
||||
bold,
|
||||
italics,
|
||||
underline,
|
||||
strike,
|
||||
...(color ? { color } : {}),
|
||||
...(fontSize ? { fontSize } : {}),
|
||||
...(fontFamily ? { fontFamily } : {})
|
||||
@@ -706,6 +715,11 @@ function runTextUnderline(runProperties: Record<string, unknown>) {
|
||||
return Boolean(value && value !== "none");
|
||||
}
|
||||
|
||||
function runTextStrike(runProperties: Record<string, unknown>) {
|
||||
const value = stringValue(runProperties.strike ?? runProperties["@_strike"]).trim().toLowerCase();
|
||||
return Boolean(value && value !== "nostrike");
|
||||
}
|
||||
|
||||
function runTextFontSize(runProperties: Record<string, unknown>) {
|
||||
const rawSize = numberAttribute(runProperties, "sz");
|
||||
return rawSize ? normalizeFontSize(rawSize / 100) : undefined;
|
||||
|
||||
Reference in New Issue
Block a user