Skip to content

Handle variations of Font size attribute values #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/helpers/xml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,38 @@ 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') {
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 (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
Expand Down