Recent

Author Topic: Cross-platform rich text  (Read 1672 times)

lelanthran

  • Newbie
  • Posts: 6
Cross-platform rich text
« on: November 16, 2025, 07:07:08 pm »
For a project I have in mind I need a text editor for the user to enter some prose, save it (possibly converting it to a text-based representation), and then load it later when they reopen the application.

I tried using various RTF components (Memos, usually) but they aren't really all that featureful and they aren't very cross-platform (One works only on Windows, for example).

I also tried a few  components that promised to accept a subset of HTML, and render it as a proper memo, but none of them were very successful; either the subset of HTML was too small to be useful or they just didn't work (one worked on Wayland but not on Xorg (or the other way around, not sure now), with the brokeness being a failure to update/repaint when the window changed).

Instead of looking at third-party components, are there any plans to include, at some point, a component that offers rich text (not RTF, which has very few capabilities).

In 2025, users editing a note want to select some text within their content, switch the font of it, change the color and size, set it to bold, underline and italic, give it  a background color, etc. They want to embed images and diagrams into this content. They want the ability to put red/blue/green squiggly lines in it to indicate spelling/grammar/etc errors. They want proper ordered lists, and proper unordered lists (with infinite nesting of both). They want to insert tables. They want to specify left/right/center/full justification, superscript/subscripts.

They may want to insert code blocks (i.e. blocks of code which are monospaced, with line counts, with syntax highlighting, etc), they may want actual blocks for quoted content (i.e. the quote has a 1px frame around it). They want to insert hyperlinks that work (and open the browser). They may want exact positioning, (via struts, for example), linebreaks represented during editing.

Even if the various RTF components worked flawlessly and across platforms, in 2025 RTF does not meet the expectations of users, regarding how the content should look. When you're making a TODO list, or calendar application, or shared-notes, etc ... user's want everything I specified above.

Are there any plans amongst the Lazarus community to move towards creating an editing component like this?

jamie

  • Hero Member
  • *****
  • Posts: 7379
Re: Cross-platform rich text
« Reply #1 on: November 16, 2025, 11:46:30 pm »
Have you looked at TSyncEdit ?

It is the component used for the source editing however, it's also intended to be used for apps because it's loaded with things that let you control the outcome of what is being displayed. You can create your own markup beautifiers.

 What you described may require separate editors.

 Currently I am in the middle of doing something similar for a pacific program.

 jamie.
The only true wisdom is knowing you know nothing

lelanthran

  • Newbie
  • Posts: 6
Re: Cross-platform rich text
« Reply #2 on: November 17, 2025, 01:59:37 am »
Have you looked at TSyncEdit ?

Haven't heard of that one; I'm familiar with TSynEdit though.

Quote
It is the component used for the source editing however, it's also intended to be used for apps because it's loaded with things that let you control the outcome of what is being displayed. You can create your own markup beautifiers.

It's fine for source code markup, but the expectation of users in 2025 are to format their text, with a minimum of inline font size changes, font family changes, font color changes, background color changes, super/subscript, inline/embedded images, working hypertext links, bullet point lists, numbered lists, left/center/right/full justification, etc.

Their expectations are set by using SaaS apps, like Jira, or similar systems, where they can make notes and it supports almost all of the above. A rich text editor (not RTF) is what the users expect when they type their content into an application.

Quote
What you described may require separate editors.

Currently, sure, but this sort of component is needed for many types of applications; many products using an Electron base are doing so out of necessity - they can provide a rich text editing experience to their users.

I feel that, in 2025,  a component that provides all of that should be included in any GUI development system. Even for trivial applications, the lack of such a component is a deal-breaker.

It would be nice to know if the Lazarus team has something on their roadmap.

jamie

  • Hero Member
  • *****
  • Posts: 7379
Re: Cross-platform rich text
« Reply #3 on: November 17, 2025, 02:51:31 am »
That was a clerical error on my part.

TSynEDit

The only true wisdom is knowing you know nothing

LV

  • Sr. Member
  • ****
  • Posts: 377
Re: Cross-platform rich text
« Reply #4 on: November 17, 2025, 06:08:38 am »
Are there any plans amongst the Lazarus community to move towards creating an editing component like this?

I'm not a developer. Just to keep the conversation going. As far as I know, Lazarus doesn't have a ready-made component that meets your requirements. These are partial solutions. There are components like RichMemo and KMemo (part of KControls), but they have their limitations and don't cover everything you've listed. TRichView is a commercial component, but it supports Lazarus. One of the forum members is actively developing an advanced component, TDWEdit. Lazarus supports PDF creation and display. Real-world scenarios that are currently recommended for developers include Lazarus WebView + a JS editor (CEF4Delphi / WebView2 / QtWebEngine). I hope more knowledgeable forum members will chime in and answer your questions.

Thaddy

  • Hero Member
  • *****
  • Posts: 18475
  • Here stood a man who saw the Elbe and jumped it.
Re: Cross-platform rich text
« Reply #5 on: November 17, 2025, 05:20:48 pm »
@lelanthran

Note that the rtf format persé is not limited: even microsoft's own rtf controls do not implement the full specification.

Try TKMemo from kcontrols. Install from OPM.
https://wiki.freepascal.org/KControls
I have used it in past and find it sufficiently mature for most rtf based things.

Small demo code, kmemo+button + Opendialog. 5 seconds work. laz 4.99/fpctrunk from today tested, but it also works with much older versions.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   with OpenDialog1 do
  4.   begin
  5.     filter :='rich text files|*.rtf';
  6.     if execute then  Kmemo1.loadfromFile(Filename);
  7.   end;
  8. end;

And it is cross-platform.

It is not very difficult - or not more difficult - to write an editor with it, in fact, much simpler than with the Windows richedit control or Richview.
It is also much better than SynEdit for daily prose use, because SynEdit is a syntaxhighlighter and has other purposes: programming languages centric.It is not a wordprocessor.
KMemo is.... and has a built-in engine for wordprocessing, not coding.

Note: I need to retest on some machines/architectures, but win/lin/mac Intel is safe.
« Last Edit: November 17, 2025, 06:24:02 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

lelanthran

  • Newbie
  • Posts: 6
Re: Cross-platform rich text
« Reply #6 on: November 17, 2025, 08:08:00 pm »
@lelanthran

Note that the rtf format persé is not limited: even microsoft's own rtf controls do not implement the full specification.

Try TKMemo from kcontrols. Install from OPM.
https://wiki.freepascal.org/KControls
I have used it in past and find it sufficiently mature for most rtf based things.


This is very helpful, thank you. It seems almost perfect (not too sure about the bullet point handling, but not a deal-breaker).

How does one get something like this into the main Lazarus project? Are the Lazarus devs open to rolling this into the project?

wp

  • Hero Member
  • *****
  • Posts: 13264
Re: Cross-platform rich text
« Reply #7 on: November 17, 2025, 08:29:30 pm »
Try TKMemo from kcontrols. Install from OPM.
How does one get something like this into the main Lazarus project? Are the Lazarus devs open to rolling this into the project?
No. KMemo is in a third-party package (KControls) out of reach for the Lazarus developers. But for such cases we have OPM - it is just one click away. OPM was made exactly for this case: Go to "Package" > "Online package manager" > scroll down to "KControls" > check it > Click "Install" > Confirm to rebuild the IDE > When the IDE restarte - that's all.

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: Cross-platform rich text
« Reply #8 on: November 18, 2025, 02:02:14 am »
@lelanthran

Note that the rtf format persé is not limited: even microsoft's own rtf controls do not implement the full specification.

Try TKMemo from kcontrols. Install from OPM.
https://wiki.freepascal.org/KControls
I have used it in past and find it sufficiently mature for most rtf based things.

Small demo code, kmemo+button + Opendialog. 5 seconds work. laz 4.99/fpctrunk from today tested, but it also works with much older versions.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   with OpenDialog1 do
  4.   begin
  5.     filter :='rich text files|*.rtf';
  6.     if execute then  Kmemo1.loadfromFile(Filename);
  7.   end;
  8. end;

And it is cross-platform.

It is not very difficult - or not more difficult - to write an editor with it, in fact, much simpler than with the Windows richedit control or Richview.
It is also much better than SynEdit for daily prose use, because SynEdit is a syntaxhighlighter and has other purposes: programming languages centric.It is not a wordprocessor.
KMemo is.... and has a built-in engine for wordprocessing, not coding.

Note: I need to retest on some machines/architectures, but win/lin/mac Intel is safe.

@Thaddy
"I've been trying to find a memo control that allows me to input any text string, but with the specific requirement that the entered text should have continuous horizontal underlines, exactly like the style shown in the uploaded image. Can KMEMO implement this underline feature? If so, how can I achieve these underlines? Thank you for your assistance!"

dbannon

  • Hero Member
  • *****
  • Posts: 3606
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross-platform rich text
« Reply #9 on: November 18, 2025, 02:58:36 am »
... Can KMEMO implement this underline feature? If so, how can I achieve these underlines? Thank you for your assistance!"

Yes, KMemo can do the underline. Not the bold red boxes but I suspect you added them to highlight what you mean ?

I use KMemo in tomboy-ng (see sig below). It works between Linux (gtk2, Qt5, Qt6), Windows and MacOS. On 32bit, 64bit intel and Arm, even PowerEL. Its an "all pascal solution".

I suggest you get it from the github website, the one in OPM is outdated. The problem there is  that KMemo is just part of a much larger package, KControls. I regularly use and test the KMemo sub-package but have no use for all the other sub-packages so cannot recommend updating KControls in OPM.  (incidentally, when I make Debian source packages, I bundle KMemo source without all the other sub-packages, its easy to separate).

https://github.com/kryslt/KControls/

You will see it used, quite extensively, in my project, specifically in https://github.com/tomboy-notes/tomboy-ng/blob/master/source/editbox.pas and a much simpler example https://github.com/tomboy-notes/tomboy-ng/blob/master/source/colours.pas

It really is a great package, its stable, pretty near bug free and easy to use.

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: Cross-platform rich text
« Reply #10 on: November 18, 2025, 03:06:24 am »
... Can KMEMO implement this underline feature? If so, how can I achieve these underlines? Thank you for your assistance!"

Yes, KMemo can do the underline. Not the bold red boxes but I suspect you added them to highlight what you mean ?

I use KMemo in tomboy-ng (see sig below). It works between Linux (gtk2, Qt5, Qt6), Windows and MacOS. On 32bit, 64bit intel and Arm, even PowerEL. Its an "all pascal solution".

I suggest you get it from the github website, the one in OPM is outdated. The problem there is  that KMemo is just part of a much larger package, KControls. I regularly use and test the KMemo sub-package but have no use for all the other sub-packages so cannot recommend updating KControls in OPM.  (incidentally, when I make Debian source packages, I bundle KMemo source without all the other sub-packages, its easy to separate).

https://github.com/kryslt/KControls/

You will see it used, quite extensively, in my project, specifically in https://github.com/tomboy-notes/tomboy-ng/blob/master/source/editbox.pas and a much simpler example https://github.com/tomboy-notes/tomboy-ng/blob/master/source/colours.pas

It really is a great package, its stable, pretty near bug free and easy to use.

Davo
@ dbannon
Yes, not the bold red boxes in the picture, but the horizontal lines that run from left to right under the input string. How to draw these lines, I need help. Can you do it? How can I draw these horizontal lines in the code based on the font size of the input string?Thank you.
« Last Edit: November 18, 2025, 03:16:20 am by jianwt »

dbannon

  • Hero Member
  • *****
  • Posts: 3606
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross-platform rich text
« Reply #11 on: November 18, 2025, 03:38:31 am »

@ dbannon
...How to draw these lines, I need help. Can you do it? How can I draw these horizontal lines in the code based on the font size of the input string?Thank you.
Do you mean using KMemo ?  Assuming yes.

In KMemo, all text is in blocks, the largest possible block is a paragraph (because a new-line is in a block of its own).  You can set attributes, such as underline, for any block. Its usual to want to apply an attribute to less than a whole paragraph so KMemo has means to break into a block inserting smaller blocks. All characters in a block have the same attributes.

So, you need to determine what you want underlined, identify the first and last character, make that a block. Apply underline to that block.

Specific code will depend on your application but take a look at https://github.com/tomboy-notes/tomboy-ng/blob/master/source/editbox.pas line number 1542, you will see how I have done it.

It only gets messy if you use bullets ....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Sieben

  • Sr. Member
  • ****
  • Posts: 383
Re: Cross-platform rich text
« Reply #12 on: November 18, 2025, 06:29:34 am »
I don't think that 'underline' is the right term here - to me it looks more like lined paper. I'd expect there to be a line even if there was no text. Just sayin'...
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

Thausand

  • Sr. Member
  • ****
  • Posts: 437
Re: Cross-platform rich text
« Reply #13 on: November 18, 2025, 07:04:19 am »
I have make search forum and see jianwt have ask before this question :)

https://forum.lazarus.freepascal.org/index.php/topic,65987.0.html (have answer no can do gtk)

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: Cross-platform rich text
« Reply #14 on: November 18, 2025, 07:14:08 am »
I have make search forum and see jianwt have ask before this question :)

https://forum.lazarus.freepascal.org/index.php/topic,65987.0.html (have answer no can do gtk)
@Thausand

Yes, I have asked this question several times and tried a few controls, but none of them could meet my requirements. However, I think KMEMO might be able to do it, but I don't know how to operate it. So I'm asking for everyone's advice here.

 

TinyPortal © 2005-2018