From d9816048801933ea613a471d2125b5a2cc1fc510 Mon Sep 17 00:00:00 2001 From: Novout Date: Thu, 7 Oct 2021 13:10:34 -0300 Subject: [PATCH] feat(pdf): image entity insert --- FEATURES.md | 2 +- src/use/pdf.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index 78d25d44e..cc3a6a6d9 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -47,7 +47,7 @@ Here will contain all the features that Better Write offers. - ✅ - Paragraph Italic - ✅ - Paragraph Links - ✅ - Heading's -- ❌ - Image's +- ➖ - Image's - ❌ - Emoji's - ✅ - Break Page - ✅ - Line Page diff --git a/src/use/pdf.ts b/src/use/pdf.ts index 80d73e933..a1be9bff8 100644 --- a/src/use/pdf.ts +++ b/src/use/pdf.ts @@ -125,6 +125,24 @@ export const usePDF: Callback = () => { } } + const image = (raw: string, store: Store) => { + return { + image: raw, + width: + useDefines().pdf().base().pageSizeFixes()[ + store.state.pdf.styles.base.pageSize + ][0] - + generate().base(store).pageMargins[0] - + generate().base(store).pageMargins[2], + margin: [ + generate().base(store).pageMargins[0], + 10, + generate().base(store).pageMargins[2], + 10, + ], + } + } + const frontCover = (store: Store, arr: Array) => { if (store.state.pdf.styles.switcher.cover) { if (!store.state.pdf.styles.base.background.data) return @@ -222,6 +240,8 @@ export const usePDF: Callback = () => { _raw = pageBreak() } else if ((entity as any).type === 'line-break') { _raw = lineBreak() + } else if ((entity as any).type === 'image') { + _raw = image((entity as any).raw, store) } arr.push(_raw)