Rich Text Format Line Spacing
Asked Answered
A

1

6

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?

Across answered 22/7, 2015 at 11:35 Comment(3)
It might be simpler to go through something like docx as intermediate representation here as the tooling is better.Alkalize
_I determined, that the line distance is little smaller _ How did you do that?Crustaceous
You can see it for example in wordpad: Create a new RTF-File change spacing to '2'. Then, save + close the file -> copy it -> change in the copy \slmult0 to 1 and compare both files in wordpad.Across
C
5

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.)

Crustaceous answered 22/7, 2015 at 11:57 Comment(3)
Hi TaW, thank you for the prompt anser. I think, I have to clarify my question. I need the behavior from \slmult0 (distance), but the space should be below the line of text. Furthermore a question to the post in the link. What is the single line spacing in pt/twips ("\slN means that line spacing is N/240*(single line spacing)")Across
I have added a few more links and quotes to study. I would always expect the spacing to affect only the one paragraph you set it for, meaning the spacing between all its lines. Did you set it before or (as recommended right after the \pard or (if you don't reset the paragraph after the \par))?Crustaceous
I've been experimenting with RTF line spacing, and I think the explanation on the Safari Books page is very bad. 480, 720, and 360 aren't magic numbers -- they're multiples of 240, which is the height in twips of the default RTF font size of 12pt. \slmult1 says that the \sl value is a multiple of single height spacing. I would have expected to use \sl2, for example, to get double spacing, but what you have to use is 2 x 240. In combination with \slmult1, the rich edit control then understands that you want double spacing, regardless of the actual font size in effect.Bergeron

© 2022 - 2024 — McMap. All rights reserved.