Skip to content

Commit 8bf8bfa

Browse files
committed
fixup! ✨(frontend) enable ODT export for documents
1 parent ab97db7 commit 8bf8bfa

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/imageODT.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import { DocsExporterODT } from '../types';
4-
import { convertSvgToPng } from '../utils';
4+
import { convertSvgToPng, odtRegisterParagraphStyleForBlock } from '../utils';
55

66
const MAX_WIDTH = 600;
77

@@ -64,6 +64,17 @@ export const blockMappingImageODT: DocsExporterODT['mappings']['blockMapping']['
6464
const finalWidth = previewWidth || width;
6565
const finalHeight = ((previewWidth || width) / width) * height;
6666

67+
const baseParagraphProps = {
68+
backgroundColor: block.props.backgroundColor,
69+
textAlignment: block.props.textAlignment,
70+
};
71+
72+
const paragraphStyleName = odtRegisterParagraphStyleForBlock(
73+
exporter,
74+
baseParagraphProps,
75+
{ paddingCm: 0 },
76+
);
77+
6778
// Convert pixels to cm (ODT uses cm for dimensions)
6879
const widthCm = finalWidth / 37.795275591;
6980
const heightCm = finalHeight / 37.795275591;
@@ -72,18 +83,13 @@ export const blockMappingImageODT: DocsExporterODT['mappings']['blockMapping']['
7283
const frame = React.createElement(
7384
'text:p',
7485
{
75-
'text:style-name':
76-
block.props.textAlignment === 'center'
77-
? 'center'
78-
: block.props.textAlignment === 'right'
79-
? 'right'
80-
: 'left',
86+
'text:style-name': paragraphStyleName,
8187
},
8288
React.createElement(
8389
'draw:frame',
8490
{
8591
'draw:name': `Image${Date.now()}`,
86-
'text:anchor-type': 'paragraph',
92+
'text:anchor-type': 'as-char',
8793
'svg:width': `${widthCm}cm`,
8894
'svg:height': `${heightCm}cm`,
8995
},
@@ -101,11 +107,17 @@ export const blockMappingImageODT: DocsExporterODT['mappings']['blockMapping']['
101107

102108
// Add caption if present
103109
if (block.props.caption) {
110+
const captionStyleName = odtRegisterParagraphStyleForBlock(
111+
exporter,
112+
baseParagraphProps,
113+
{ paddingCm: 0, parentStyleName: 'Caption' },
114+
);
115+
104116
return [
105117
frame,
106118
React.createElement(
107119
'text:p',
108-
{ 'text:style-name': 'Caption' },
120+
{ 'text:style-name': captionStyleName },
109121
block.props.caption,
110122
),
111123
];

src/frontend/apps/impress/src/features/docs/doc-export/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function isOdtExporterLike(value: unknown): value is OdtExporterLike {
116116
export function odtRegisterParagraphStyleForBlock(
117117
exporter: unknown,
118118
props: Partial<DefaultProps>,
119-
options?: { paddingCm?: number },
119+
options?: { paddingCm?: number; parentStyleName?: string },
120120
) {
121121
if (!isOdtExporterLike(exporter)) {
122122
throw new Error('Invalid ODT exporter: missing registerStyle');
@@ -144,12 +144,19 @@ export function odtRegisterParagraphStyleForBlock(
144144
: 'justify';
145145

146146
const paddingCm = options?.paddingCm ?? 0.42; // ~1rem (16px)
147+
const parentStyleName = options?.parentStyleName;
147148

148149
// registerStyle is available on ODT exporter; call through with React elements
149150
const styleName = exporter.registerStyle((name: string) =>
150151
React.createElement(
151152
'style:style',
152-
{ 'style:name': name, 'style:family': 'paragraph' },
153+
{
154+
'style:name': name,
155+
'style:family': 'paragraph',
156+
...(parentStyleName
157+
? { 'style:parent-style-name': parentStyleName }
158+
: {}),
159+
},
153160
React.createElement('style:paragraph-properties', {
154161
'fo:text-align': foTextAlign,
155162
'fo:padding': `${paddingCm}cm`,

0 commit comments

Comments
 (0)