From 27e7aec1930c228a5bcf79e769a2c6a036c158e8 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Sun, 9 Feb 2025 01:38:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84(frontend)=20improve=20styles=20exp?= =?UTF-8?q?ort=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When exporting a document to PDF, the headings spacings were too small, the break lines were not displayed. This commit fixes these issues by replacing the needed blocks. --- CHANGELOG.md | 5 +- .../doc-header/components/ModalExport.tsx | 56 ++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e07df1f..ceab904f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,14 @@ and this project adheres to - 📝(doc) Add security.md and codeofconduct.md #604 - ✨(frontend) add home page #553 - +- ✨(frontend) cursor display on activity #609 ## Fixed 🌐(CI) Fix email partially translated #616 +- 🐛(frontend) fix cursor breakline #609 +- 🐛(frontend) fix style pdf export #609 + ## [2.1.0] - 2025-01-29 diff --git a/src/frontend/apps/impress/src/features/docs/doc-header/components/ModalExport.tsx b/src/frontend/apps/impress/src/features/docs/doc-header/components/ModalExport.tsx index 7d7f1657..b828b5b9 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-header/components/ModalExport.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-header/components/ModalExport.tsx @@ -98,7 +98,61 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => { const exporter = new PDFExporter( editor.schema, - pdfDefaultSchemaMappings, + { + ...pdfDefaultSchemaMappings, + blockMapping: { + ...pdfDefaultSchemaMappings.blockMapping, + heading: (block, exporter) => { + const PIXELS_PER_POINT = 0.75; + const MERGE_RATIO = 7.5; + const FONT_SIZE = 16; + const fontSizeEM = + block.props.level === 1 + ? 2 + : block.props.level === 2 + ? 1.5 + : 1.17; + return ( + + {exporter.transformInlineContent(block.content)} + + ); + }, + paragraph: (block, exporter) => { + /** + * Breakline in the editor are not rendered in the PDF + * By adding a space if the block is empty we ensure that the block is rendered + */ + if (Array.isArray(block.content)) { + block.content.forEach((content) => { + if (content.type === 'text' && !content.text) { + content.text = ' '; + } + }); + + if (!block.content.length) { + block.content.push({ + styles: {}, + text: ' ', + type: 'text', + }); + } + } + return ( + + {exporter.transformInlineContent(block.content)} + + ); + }, + }, + }, { resolveFileUrl: async (url) => exportResolveFileUrl(url, defaultExporter.options.resolveFileUrl),