Skip to content

Commit

Permalink
Content Model: Always return size in pt when getFormatState (#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 8, 2023
1 parent 6c1c78f commit d29815f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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

0 comments on commit d29815f

Please sign in to comment.