diff --git a/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts b/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts index 560dc4fe087..ea1df7077df 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts @@ -121,6 +121,10 @@ export function retrieveModelFormatState( includeListFormatHolder: 'never', } ); + + if (formatState.fontSize) { + formatState.fontSize = px2Pt(formatState.fontSize); + } } function retrieveSegmentFormat( @@ -231,3 +235,12 @@ function mergeValue( 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; +} diff --git a/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts b/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts index 9e700715aaa..135e32a41dd 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts @@ -35,7 +35,7 @@ describe('retrieveModelFormatState', () => { const baseFormatResult: ContentModelFormatState = { backgroundColor: 'red', fontName: 'Arial', - fontSize: '10px', + fontSize: '7.5pt', isBold: true, isItalic: true, isStrikeThrough: true, @@ -329,7 +329,7 @@ describe('retrieveModelFormatState', () => { isStrikeThrough: true, fontName: 'Arial', isSuperscript: true, - fontSize: '10px', + fontSize: '7.5pt', backgroundColor: 'red', textColor: 'green', }); @@ -490,7 +490,7 @@ describe('retrieveModelFormatState', () => { isItalic: true, isUnderline: true, isStrikeThrough: true, - fontSize: '10px', + fontSize: '7.5pt', }); }); @@ -701,7 +701,7 @@ describe('retrieveModelFormatState', () => { isSuperscript: false, isSubscript: false, fontName: 'Arial', - fontSize: '12px', + fontSize: '9pt', isCodeInline: false, canUnlink: false, canAddImageAltText: false, @@ -734,7 +734,7 @@ describe('retrieveModelFormatState', () => { isBold: false, isSuperscript: false, isSubscript: false, - fontSize: '12px', + fontSize: '9pt', isCodeInline: false, canUnlink: false, canAddImageAltText: false,