Forum > RichMemo
[solved]Paragraph Indents only work correctly in TRichMemo when font size is 10
indydev:
Seeing strange results with RichMemo and paragraph indentation, I decided to examine the RTF output. Long story short, RichMemo only makes the correct indents (HeadIndent -- \li , FirstLine indent -- \fi) when the font size of the TRichMemo control is set to 10. At least that is the case in Linux. I made a button toggle to switch between font size 10 and 12 to watch the correct and incorrect display. The RTF code for font size is `\fs20` for 10 and `\fs24` for 12. Setting up a TMemo and directing the RTF output from TRichMemo on a form you can see the RTF code display the `\fsxx` values correctly.
Here's some code I used to test this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var pm: TParaMetric;begin RichMemo1.Clear; RichMemo1.Lines.Add('1.' + #9 + 'To create a hanging indent for list items in RTF, you need to set the `\li` (left indent) to the desired indentation level for the list item, and the `\fi` (first line indent) to a negative value that pulls the first line back to the left, creating the hanging effect for the list sym'); RichMemo1.Lines.Add('2.' + #9 + 'If you want to set a specific line spacing, you would include `\sl` followed by the value and `\slmult1` in your RTF control words. If you want to use the default line spacing, you can simply omit these control words.'); RichMemo1.Lines.Add('3.' + #9 + 'In RTF, the `\fi` value is the indentation for the first line of a paragraph relative to the left margin, and the `\li` value is negative.'); pm.HeadIndent:=18; pm.FirstLine:=-18; RichMemo1.SetParaMetric(0, Length(RichMemo1.Text), pm);end;
Here's the RTF output with font set to size 10:
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{\rtf1\ansi\ansicp1252\deff0\deflan1033{\fonttbl{\f0\fcharset0 Ubuntu;}}{\colortbl;\red211\green211\blue211;}\f0\fs20\cf1 \pard\li360\fi-360\sl200\slmult1 1. To create a hanging indent for list items in RTF, you need to set the `\\li` (left indent) to the desired indentation level for the list item, and the `\\fi` (first line indent) to a negative value that pulls the first line back to the left, creating the hanging effect for the list sym\par \pard\li360\fi-360\sl200\slmult1 2. If you want to set a specific line spacing, you would include `\\sl` followed by the value and `\\slmult1` in your RTF control words. If you want to use the default line spacing, you can simply omit these control words.\par \pard\li360\fi-360\sl200\slmult1 3. In RTF, the `\\fi` value is the indentation for the first line of a paragraph relative to the left margin, and the `\\li` value is negative.\par }
And the RTF output with font set to size 12:
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{\rtf1\ansi\ansicp1252\deff0\deflan1033{\fonttbl{\f0\fcharset0 Ubuntu;}}{\colortbl;\red211\green211\blue211;}\f0\fs24\cf1 \pard\li360\fi-360\sl200\slmult1 1. To create a hanging indent for list items in RTF, you need to set the `\\li` (left indent) to the desired indentation level for the list item, and the `\\fi` (first line indent) to a negative value that pulls the first line back to the left, creating the hanging effect for the list sym\par \pard\li360\fi-360\sl200\slmult1 2. If you want to set a specific line spacing, you would include `\\sl` followed by the value and `\\slmult1` in your RTF control words. If you want to use the default line spacing, you can simply omit these control words.\par \pard\li360\fi-360\sl200\slmult1 3. In RTF, the `\\fi` value is the indentation for the first line of a paragraph relative to the left margin, and the `\\li` value is negative.\par }
I decided to try and fool the TRichMemo control by changing the `\li360\fi-360`values to `\li432\fi-432` to see if that would fix the issue when the font size was set to 12 (12*2*18=432). It looked close but was slightly off. When I checked the RTF output from the TRichMemo control it had changed `\li432\fi-432` to `\li435\fi-435` which seems totally bizarre.
I only use Linux so I don't know if this happens in Windows or not.
indydev:
Found a way around for font size 12 if you are willing to have a little more space, and set the `lixxx\fi-xxx` numbers manually. Since 480 is a multiple of both 24 and 20 (20*24) AND a multiple of 5, just change `\li360\fi-360` to `\li480\fi-480`. This at least lines up the indents correctly. The RTF Encoder in Linux seems to only allow for `\li ` and `\fi ` values in multiples of 5 (although `\li0` is ok).
rvk:
--- Quote from: indydev on December 15, 2023, 02:34:12 am --- pm.HeadIndent:=18;
pm.FirstLine:=-18;
--- End quote ---
I'm not sure what the problem is (I'm not on Linux but I see nothing strange in Windows).
(Or if the display is "off" you should have included screenshots instead of rtf-code)
The HeadIndent and Firstline are in points. In the RTF it's 1/20th point (twip) so that's why you get 360 (18*20).
Changing the font wouldn't effect this.
(Or are your seeing that it does have effect the indent size when you switch fontsize?)
indydev:
That is how it should work, but in Linux it doesn't. I have tried to track down why this happens but cannot find it.
indydev:
Here you can see the two results. The first is with the font at size 10. The second is with the font at size 12.
If you are examining the forms, ignore the checked bullet radio button, it's disconnected for the moment.
Navigation
[0] Message Index
[#] Next page