Skip to content
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

Content Model: Always return size in pt when getFormatState #2052

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export function retrieveModelFormatState(
includeListFormatHolder: 'never',
}
);

if (formatState.fontSize) {
formatState.fontSize = px2Pt(formatState.fontSize);
}
}

function retrieveSegmentFormat(
Expand Down Expand Up @@ -231,3 +235,12 @@ function mergeValue<K extends keyof ContentModelFormatState>(
delete format[key];
}
}

function px2Pt(px: string) {
if (px && px.indexOf('px') == px.length - 2) {
// Edge may not handle the floating computing well which causes the calculated value is a little less than actual value
// So add 0.05 to fix it
return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';
}
return px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('retrieveModelFormatState', () => {
const baseFormatResult: ContentModelFormatState = {
backgroundColor: 'red',
fontName: 'Arial',
fontSize: '10px',
fontSize: '7.5pt',
isBold: true,
isItalic: true,
isStrikeThrough: true,
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('retrieveModelFormatState', () => {
isStrikeThrough: true,
fontName: 'Arial',
isSuperscript: true,
fontSize: '10px',
fontSize: '7.5pt',
backgroundColor: 'red',
textColor: 'green',
});
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('retrieveModelFormatState', () => {
isItalic: true,
isUnderline: true,
isStrikeThrough: true,
fontSize: '10px',
fontSize: '7.5pt',
});
});

Expand Down Expand Up @@ -701,7 +701,7 @@ describe('retrieveModelFormatState', () => {
isSuperscript: false,
isSubscript: false,
fontName: 'Arial',
fontSize: '12px',
fontSize: '9pt',
isCodeInline: false,
canUnlink: false,
canAddImageAltText: false,
Expand Down Expand Up @@ -734,7 +734,7 @@ describe('retrieveModelFormatState', () => {
isBold: false,
isSuperscript: false,
isSubscript: false,
fontSize: '12px',
fontSize: '9pt',
isCodeInline: false,
canUnlink: false,
canAddImageAltText: false,
Expand Down
Loading