Skip to content

Commit

Permalink
Fix an RTF formatting bug brought up in #72
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMBarr committed Sep 9, 2024
1 parent fdf80b7 commit 0566d48
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Souls to another`);
describe('formatRtf', () => {
it('should use the defaults', () => {
expect(Utils.formatRtf(`test\ninput\nstring with some words`)).toEqual(
`{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320',{\\fonttbl\\f0\\fswiss\\fcharset0 Arial;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\qc\\pardirnatural\\f0\\fs120 \\cf1 test\\\rinput\\\rstring with some words}`
`{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320{\\fonttbl\\f0\\fswiss\\fcharset0 Arial;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\qc\\pardirnatural\\f0\\fs120 \\cf1 test\\\rinput\\\rstring with some words}`
);
});

Expand All @@ -49,7 +49,7 @@ Souls to another`);
b: 150,
})
).toEqual(
`{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320',{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}{\\colortbl;\\red50\\green100\\blue150;}\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\qc\\pardirnatural\\f0\\fs60 \\cf1 test\\\rinput\\\rstring with some words}`
`{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}{\\colortbl;\\red50\\green100\\blue150;}\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\qc\\pardirnatural\\f0\\fs60 \\cf1 test\\\rinput\\\rstring with some words}`
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const stripRtf = (str: string): string => {
export const formatRtf = (text: string, font = 'Arial', size = 60, color: IRgbColor = { r: 255, g: 255, b: 255 }): string => {
//Text will be centered.
//RTF font size is in half-points. Multiply input size by 2 to get size in half points
return `{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320',{\\fonttbl\\f0\\fswiss\\fcharset0 ${font};}{\\colortbl;\\red${
return `{\\rtf1\\ansi\\ansicpg1252\\cocoartf1038\\cocoasubrtf320{\\fonttbl\\f0\\fswiss\\fcharset0 ${font};}{\\colortbl;\\red${
color.r
}\\green${color.g}\\blue${
color.b
Expand Down
Loading

0 comments on commit 0566d48

Please sign in to comment.