From 33f1f41bd45a67475d217d99a257899afd86dd8c Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Mon, 15 Apr 2024 15:45:54 +0530 Subject: [PATCH 1/2] feat: handle absolute size values Signed-off-by: Kushal Kumar --- src/helpers/xml-builder.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/helpers/xml-builder.js b/src/helpers/xml-builder.js index 5aa8b39..4d37e7a 100644 --- a/src/helpers/xml-builder.js +++ b/src/helpers/xml-builder.js @@ -277,6 +277,24 @@ const fixupLineHeight = (lineHeight, fontSize) => { // eslint-disable-next-line consistent-return const fixupFontSize = (fontSizeString, docxDocumentInstance) => { + if (fontSizeString === 'xx-small') { + fontSizeString = '9px'; + } else if (fontSizeString === 'x-small') { + fontSizeString = '10px'; + } else if (fontSizeString === 'small') { + fontSizeString = '13px'; + } else if (fontSizeString === 'medium') { + fontSizeString = '16px'; + } else if (fontSizeString === 'large') { + fontSizeString = '18px'; + } else if (fontSizeString === 'x-large') { + fontSizeString = '24px'; + } else if (fontSizeString === 'xx-large') { + fontSizeString = '32px'; + } else if (fontSizeString === 'xxx-large') { + fontSizeString = '48px'; + } + if (pointRegex.test(fontSizeString)) { const matchedParts = fontSizeString.match(pointRegex); // convert point to half point @@ -298,6 +316,7 @@ const fixupFontSize = (fontSizeString, docxDocumentInstance) => { } }; + // eslint-disable-next-line consistent-return const fixupRowHeight = (rowHeightString, parentHeight = 0) => { if (pointRegex.test(rowHeightString)) { From 5041cfb34df21a9b92e80939a93b984e29a6b071 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Tue, 16 Apr 2024 14:52:07 +0530 Subject: [PATCH 2/2] feat: handle relative size font values Signed-off-by: Kushal Kumar --- src/helpers/xml-builder.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/helpers/xml-builder.js b/src/helpers/xml-builder.js index 4d37e7a..193594d 100644 --- a/src/helpers/xml-builder.js +++ b/src/helpers/xml-builder.js @@ -277,6 +277,8 @@ const fixupLineHeight = (lineHeight, fontSize) => { // eslint-disable-next-line consistent-return const fixupFontSize = (fontSizeString, docxDocumentInstance) => { + // https://developer.mozilla.org/en-US/docs/Web/CSS/font-size + // Checked manually which size generates what px value and found the below if (fontSizeString === 'xx-small') { fontSizeString = '9px'; } else if (fontSizeString === 'x-small') { @@ -295,6 +297,18 @@ const fixupFontSize = (fontSizeString, docxDocumentInstance) => { fontSizeString = '48px'; } + if (fontSizeString === 'smaller') { + // for this case, font-size becomes 5/6 of the parent font size. + // since we dont have access to immediate parent size + // we will use the default font size given to us + return Math.floor((5 * docxDocumentInstance.fontSize) / 6); + } else if (fontSizeString === 'larger') { + // for this case, font-size inceases by 20% of the parent font size. + // since we dont have access to immediate parent size + // we will use the default font size given to us + return Math.floor(docxDocumentInstance.fontSize * 1.2); + } + if (pointRegex.test(fontSizeString)) { const matchedParts = fontSizeString.match(pointRegex); // convert point to half point @@ -316,7 +330,6 @@ const fixupFontSize = (fontSizeString, docxDocumentInstance) => { } }; - // eslint-disable-next-line consistent-return const fixupRowHeight = (rowHeightString, parentHeight = 0) => { if (pointRegex.test(rowHeightString)) {