11import React from 'react' ;
22
33import { DocsExporterODT } from '../types' ;
4- import { convertSvgToPng } from '../utils' ;
4+ import { convertSvgToPng , odtRegisterParagraphStyleForBlock } from '../utils' ;
55
66const 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 ] ;
0 commit comments