C# – Rich Text Format Line Spacing

crtf

I try to convert a plain text in RTF-Format. Therefore, I use RichTextBox (WinForms).
The concerned method the RTF-Markup as string.

Now, I want to insert line spacing in the markup. I found that there are 2 parameters:

 - \slX (Space between lines in twips)
 - \slmultX (either 0 or 1)

If I set \slmult0, the line spacing is above the line of text.
When I set \slmult1, the line spacing is below the line of text.

I calculate the spacing in the following way:

(lineSpacing + fontSize)*20

When I switched from \slmult0 to \slmult1, I determined, that the line distance is little smaller than with \slmult0.

Does somebody know the reason for this behavior? Do I have to calculate with another formula?

Best Answer

If I set \slmult0, the line spacing is above the line of text. When I set \slmult1, the line spacing is below the line of text.

That is not what I read in the specs.

The way I understand it, it means that \slmult0 says that the value of \slN is to be used directly as a distance in some unit, whereas \slmult1 says the N in \slN is meant as a factor by which the regular line spacing is multiplied.

See the last post here for (some) more details! (But there is also a note about it taking effect one line too late..)

Also do note the importance of the sign of N in the \slN! (This was the reason of my comment above: The effect of, say \sl234, will depend on the size of the tallest character in the line..!)

Here is a nice discussion of some things RTF; a note about units:

Measurements in RTF are generally in twips. A twip is a twentieth of a point, i.e., a 1440th of an inch. That leads to some large numbers sometimes (like \li2160, to set the left indent to an inch and a half)

and a clear definition of extra spacing before and after paragraphs:

\sbN -- N twips of extra (vertical) space before this paragraph (default: 0)
\saN -- N twips of extra (vertical) space after this paragraph (default: 0)

Here are more direct instructions:

To double-space a paragraph, put the code \sl480\slmult1 right after the \pard. To triple-space it, use \sl720\slmult1. To have just 1.5-spacing, use \sl360\slmult1. A single-spaced paragraph is the default, and doesn’t need any particular code. (The magic numbers 480, 720, and 360 don’t depend on the point size of the text in the paragraph.)

Related Topic