fix: a frame keeps its place whatever kind of frame it is

Text boxes and shapes had no offsets at all, and for images the wrap side
overrode the x: a file that names the side its text flows on lost the
coordinate, our own export included. Side and place are read separately now,
and one helper turns both into the float's margins for every frame kind.
This commit is contained in:
Steffen Becker committed 2026-08-08 10:17:21 +00:00
1 parent f8c818c203
commit 5968b6a04b
7 files changed
+99 -54

No files matched your search

+10 -2
View File
@@ -390,6 +390,8 @@ type TextBoxDocx = {
heightPx: number;
rotationDeg: number;
wrap: 'inline' | 'left' | 'right' | 'topBottom';
offsetCm: number | null;
offsetYCm: number | null;
shapeKind: 'textbox' | 'roundRect' | 'ellipse';
fill: string | null;
stroke: string | null;
@@ -406,6 +408,8 @@ function textBoxDocxDescriptor(node: TiptapNode): TextBoxDocx {
heightPx: typeof a.height === 'number' && a.height > 0 ? Math.round(a.height) : 96,
rotationDeg: typeof a.rotation === 'number' ? a.rotation : 0,
wrap: wrapAttr === 'left' || wrapAttr === 'right' || wrapAttr === 'topBottom' ? wrapAttr : 'inline',
offsetCm: typeof a.wrapOffset === 'number' ? a.wrapOffset : null,
offsetYCm: typeof a.wrapOffsetY === 'number' ? a.wrapOffsetY : null,
shapeKind: kind === 'roundRect' || kind === 'ellipse' ? kind : 'textbox',
fill: typeof a.fillColor === 'string' && a.fillColor ? a.fillColor : null,
stroke: typeof a.strokeColor === 'string' && a.strokeColor ? a.strokeColor : null,
@@ -582,12 +586,16 @@ function textBoxDrawingXml(box: TextBoxDocx, index: number): string {
? '<wp:wrapTopAndBottom/>'
: `<wp:wrapSquare wrapText="${box.wrap === 'right' ? 'left' : 'right'}"/>`;
const align = box.wrap === 'right' ? 'right' : 'left';
const emu = (cm: number) => Math.round(cm * 360000);
const posH = box.offsetCm != null && box.wrap !== 'topBottom'
? `<wp:posOffset>${emu(box.offsetCm)}</wp:posOffset>`
: `<wp:align>${align}</wp:align>`;
return (
`<w:drawing><wp:anchor ${wpNs} distT="0" distB="0" distL="114300" distR="114300"` +
` simplePos="0" relativeHeight="${251658240 + index}" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="0">` +
`<wp:simplePos x="0" y="0"/>` +
`<wp:positionH relativeFrom="margin"><wp:align>${align}</wp:align></wp:positionH>` +
`<wp:positionV relativeFrom="paragraph"><wp:posOffset>0</wp:posOffset></wp:positionV>` +
`<wp:positionH relativeFrom="margin">${posH}</wp:positionH>` +
`<wp:positionV relativeFrom="paragraph"><wp:posOffset>${emu(box.offsetYCm ?? 0)}</wp:posOffset></wp:positionV>` +
`${extent}${wrapEl}${docPr}${graphic}</wp:anchor></w:drawing>`
);
}
+11 -3
View File
@@ -451,6 +451,8 @@ type TextBoxExport = {
heightCm: number;
rotationDeg: number;
wrap: WrapMode;
wrapOffsetCm: number | null;
wrapOffsetYCm: number | null;
shapeKind: ShapeKind;
fill: string | null;
stroke: string | null;
@@ -468,6 +470,8 @@ function textBoxDescriptor(node: TiptapNode): TextBoxExport {
heightCm: pxToCm(typeof a.height === 'number' && a.height > 0 ? a.height : 96),
rotationDeg: typeof a.rotation === 'number' ? a.rotation : 0,
wrap: wrapAttr === 'left' || wrapAttr === 'right' || wrapAttr === 'topBottom' ? wrapAttr : 'inline',
wrapOffsetCm: typeof a.wrapOffset === 'number' ? round3(a.wrapOffset) : null,
wrapOffsetYCm: typeof a.wrapOffsetY === 'number' ? round3(a.wrapOffsetY) : null,
shapeKind: kind === 'roundRect' || kind === 'ellipse' ? kind : 'textbox',
fill: typeof a.fillColor === 'string' && a.fillColor ? a.fillColor : null,
stroke: typeof a.strokeColor === 'string' && a.strokeColor ? a.strokeColor : null,
@@ -2756,8 +2760,9 @@ function textBoxGraphicStyle(box: TextBoxExport, index: number): string {
: 'draw:stroke="none"';
const wrap = box.wrap === 'inline'
? ''
: ` ${imageWrapProps(box.wrap, null)} style:number-wrapped-paragraphs="no-limit"` +
` style:horizontal-rel="paragraph-content" style:vertical-pos="top" style:vertical-rel="paragraph"`;
: ` ${imageWrapProps(box.wrap, box.wrapOffsetCm)} style:number-wrapped-paragraphs="no-limit"` +
` style:horizontal-rel="paragraph-content"` +
` style:vertical-pos="${box.wrapOffsetYCm != null ? 'from-top' : 'top'}" style:vertical-rel="paragraph"`;
// auto-grow only for plain text boxes; a custom-shape needs both explicitly
// false, or LibreOffice's shape autofit shrinks it to its text.
const grow = box.shapeKind === 'textbox'
@@ -2778,9 +2783,12 @@ function textBoxXml(box: TextBoxExport, inner: string, index: number): string {
const n = index + 1;
const anchor = box.wrap === 'inline' ? 'as-char' : 'paragraph';
const transform = frameTransform(box.rotationDeg, box.widthCm, box.heightCm);
const at = box.wrap === 'inline' ? ''
: (box.wrapOffsetCm != null && box.wrap !== 'topBottom' ? ` svg:x="${box.wrapOffsetCm}cm"` : '') +
(box.wrapOffsetYCm != null ? ` svg:y="${box.wrapOffsetYCm}cm"` : '');
const common =
` draw:style-name="TbxFr${n}" text:anchor-type="${anchor}" draw:z-index="${index}"` +
` svg:width="${box.widthCm}cm"`;
` svg:width="${box.widthCm}cm"${at}`;
if (box.shapeKind === 'textbox') {
// svg:height for consumers without auto-grow; fo:min-height is the real semantic
// (height = minimum, content grows the box) and wins on our own re-import.