Recent

Author Topic: TDWEdit  (Read 6873 times)

Ed78z

  • Jr. Member
  • **
  • Posts: 66
TDWEdit
« on: August 04, 2025, 12:53:08 am »
I'm wondering can anyone help me to write a new component to use it instead of TMemo or even TRichMemo?
A new component based on DirectWrite to render any text styles, formats, layouts,... in addition to support unicode beyond BMP (plane-0)

Please see the attached file as an idea.
« Last Edit: August 07, 2025, 09:55:37 am by Ed78z »

dbannon

  • Hero Member
  • *****
  • Posts: 3568
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TDWEdit
« Reply #1 on: August 04, 2025, 07:20:51 am »
Maybe you should look at using KMemo ?  (Might have same problem but don't know).

Failing that, I suggest 'fixing' either TRichMemo or KMemo would be a lot easier than starting from scratch.

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

Ed78z

  • Jr. Member
  • **
  • Posts: 66
Re: TDWEdit
« Reply #2 on: August 04, 2025, 08:20:15 am »
Maybe you should look at using KMemo ?  (Might have same problem but don't know).

Failing that, I suggest 'fixing' either TRichMemo or KMemo would be a lot easier than starting from scratch.

Davo

Thank you for your response, basically TMemo, TRichMemo, KMemo,... all based on GDI not the DirectWrite. The GDI is not reliable for the unicode beyond plane 0 ($0000-$FFFF),  it means for all the characters beyond $10000 has issue and may acts strangely. (you may see this issue in MS WordPad that uses RichEdit v8.0)
Also, advance text style, text layout, scripts, advanced OpenType fonts ... must be done via DirectWire (Windows) [or CoreText (macOS), HarfBuzz (cross-platform)]

https://forum.lazarus.freepascal.org/index.php/topic,71899.msg562024.html#msg562024

Thanks!

dbannon

  • Hero Member
  • *****
  • Posts: 3568
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TDWEdit
« Reply #3 on: August 04, 2025, 01:15:50 pm »
OK, Ed, I have to agree. In my current setup, I cannot display any 4 byte utf8 characters in my app that uses KMemo. However, I used to be able to display, eg, the EGYPTIAN HIEROGLYPH starting at f0 93 80 80 (in a previous install of Linux). I assume I cannot now because the font I am using does not include that range. If that is the case then your problem is not KMemo but the default font.

In other words, before you abandon KMemo (or TRichMemo) I think you need to establish that the selected font can display the range you are needing. The full 5 byte range is a very large set of characters and the vast majority of users don't want to see many more than the 3 byte ones. So, I'd expect most font designers cut some corners to save space. Perhaps ...

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

gues1

  • Guest
Re: TDWEdit
« Reply #4 on: August 04, 2025, 03:48:27 pm »
Maybe you should look at using KMemo ?  (Might have same problem but don't know).

Failing that, I suggest 'fixing' either TRichMemo or KMemo would be a lot easier than starting from scratch.

Davo

Thank you for your response, basically TMemo, TRichMemo, KMemo,... all based on GDI not the DirectWrite. The GDI is not reliable for the unicode beyond plane 0 ($0000-$FFFF),  it means for all the characters beyond $10000 has issue and may acts strangely. (you may see this issue in MS WordPad that uses RichEdit v8.0)
Also, advance text style, text layout, scripts, advanced OpenType fonts ... must be done via DirectWire (Windows) [or CoreText (macOS), HarfBuzz (cross-platform)]

https://forum.lazarus.freepascal.org/index.php/topic,71899.msg562024.html#msg562024

Thanks!
Wordpad is not distribuited nor present in any actual editions of Windows 11, so you cannot relay on this.

Richedit is based now on version 8.5.

Untill now all characters (or better, all chars I used 'till now) in all defined Planes are working in normal mode for me (I use Delphi, but Lazarus use exactly the same component).
There were some issue in some particular chars (but I have nomore those issues) trasformed with properties (like UpperCase, LowerCase).

I nevere had problems with bolds (I used arabian, chinese and japan chars and cyrillic some times with their various "model"), but I never try to write something about text layout (like oriented chars i.e.).

Also the fonts used are the normal one used commonly.

Your project seems to be very ambitious.

Note: Richedit can work with DirectWrite too .... I'm going to do some tests ..

Ed78z

  • Jr. Member
  • **
  • Posts: 66
Re: TDWEdit
« Reply #5 on: August 04, 2025, 04:56:38 pm »
Thank you for your response,
So, I'm using Windows 11 X64
WordPad.exe located at C:\Program Files\Windows NT\Accessories, its version is 10.0.22621.3810
Modern WordPad uses msftedit.dll which is located at C:\Windows\System32, if you right click on it and get properties, you will see: Rich Text Edit Control, v8.5

So, as I said, even RichEdit v8.5, has same issue with 4-bytes characters UTF-8 (or two unit UTF-16)
Windows' RichEdit module, designed and works on U+0000 to U+FFFF perfectly, however, beyond BMP, it doesn't behaves/works correctly. also, Lazarus uses GDI which can't render advance text styles and layouts, so, basically we can't update its TRichEdit component. (internal core limitations)

That's why we need a new component in Lazarus to handle advance text styles, layout, OpenType shaping (GSUB), ....
I called it TDWEdit!

gues1

  • Guest
Re: TDWEdit
« Reply #6 on: August 04, 2025, 05:42:31 pm »
WordPad.exe located at C:\Program Files\Windows NT\Accessories, its version is 10.0.22621.3810
Modern WordPad uses msftedit.dll which is located at C:\Windows\System32, if you right click on it and get properties, you will see: Rich Text Edit Control, v8.5
Current version of Windows 11 is: "10.0.26100.4770" and there is no WordPad.

I used the new RichEdit control that can works with D2D (DirectWrite), simply activate it by a MESSAGE COMMAND  :D :

Attach are the results and this is the article Microsoft: https://devblogs.microsoft.com/math-in-office/richeditd2d-window-controls/

I have not enabled the GRAPHY or do other tries ... it was only to test it.

You can see the differences between the two drawings (copy / paste the same characters).

The code to do this is:

Code: Pascal  [Select][+][-]
  1. const
  2.   EM_SWITCHTOD2D = (WM_USER + 389); // with wparam = lparam = 0 that switches the current window control to D2D.
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var i: integer;
  6. begin
  7.   Label1.Caption:= 'DIRECTWRITE';
  8.   i := sendmessage(RichMemo1.Handle, EM_SWITCHTOD2D, 0, 0);
  9.   ShowMessage(i.ToString);
  10. end;
  11.  

To use that the control MUST BE EMPTY and you must click the button before any other action on the control.
After you use the button the control atcs with D2D.

The result from SendMessage should be '1'.
Another thing is that the source of Lazarus must be changed, other way is that like I do: edit the DLL and modify some things inside ...

This is only a TRY.
« Last Edit: August 04, 2025, 05:45:03 pm by gues1 »

Ed78z

  • Jr. Member
  • **
  • Posts: 66
Re: TDWEdit
« Reply #7 on: August 04, 2025, 06:17:07 pm »
Thank you,
but as I said, TRichMemo, behaves/works strangely beyond BMP, for example, your pasted emoji is black and white!, it should be colorful!
Try to paste these:😀😃😄😁😆😅

Basically, TRichMemo has some core limitations (Architectural):
- Rendering : Relies on GDI (on Windows), So, No advanced shaping or color fonts
- Unicode : Surrogate pairs (4-byte characters) are not glyph-aware, causing styling, caret, and selection issues
- Text Shaping : No OpenType shaping, fails with ligatures, complex scripts (Arabic, Hindi, etc.)
- Grapheme Clusters: Treats characters as 1 code unit, so, doesn't respect combining marks, ZWJ sequences, emoji clusters
- Line Wrapping : Uses basic width calculation, no kerning, justification, or proper script fallback
.......
.......

and thanks for the link:

It seems we need riched20.dll to enable D2D/emoji features.
C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\riched20.dll

The message (WM_USER + 389) only applies to controls of class: RichEdit20WPT
Since EM_SWITCHTOD2D is part of Microsoft 365's enhanced RichEdit engine, basically you need MS Office installed on your system to enable D2D fully.
« Last Edit: August 04, 2025, 06:36:14 pm by Ed78z »

gues1

  • Guest
Re: TDWEdit
« Reply #8 on: August 04, 2025, 07:34:45 pm »
It seems we need riched20.dll to enable D2D/emoji features.
C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\riched20.dll

The message (WM_USER + 389) only applies to controls of class: RichEdit20WPT
Since EM_SWITCHTOD2D is part of Microsoft 365's enhanced RichEdit engine, basically you need MS Office installed on your system to enable D2D fully.
If you read carefully my post, is exactly what I do.

But I used the DLL in budle with Notepad (not Office). I had to change it (the DLL with an HEX Editor) 'cause the link from Lazarus and the inside struct of DLL should be paired (alternative one should change Lazarus sources).

And it was enabled like you saw.

The "color glyph" is another argument ... to use it you must integrate the new "Text Services" of Windows, that should be implemented in Lazarus.

I'm looking to implement it in Delphi (but not now, I'm too busy).

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
Re: TDWEdit
« Reply #9 on: August 26, 2025, 10:57:45 pm »
Hi, @Ed78z

Can you please, share your final component TDWEdit to give a try?

Thanks in advance.

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
Re: TDWEdit
« Reply #10 on: August 28, 2025, 07:19:22 am »
@Ed78z

You are doing a great work! Looks amazing.

I will calmly wait for the final result. Keep it up!  :)

CharlyTango

  • Full Member
  • ***
  • Posts: 169
Re: TDWEdit
« Reply #11 on: September 03, 2025, 12:57:43 pm »
@Ed78z -> impressive work

Since you're working so hard right now, may I draw your attention to WPTools?
Lazarus is missing something like this.  8)

Working with it under Delphi was nice. Gluing a menu area and an editing area to a form and you have a full-featured Office Style Edititor.

Lazarus stable, Win32/64

jianwt

  • Full Member
  • ***
  • Posts: 151
Re: TDWEdit
« Reply #12 on: September 04, 2025, 02:44:06 am »
@ Ed78z
Where is the DWEdit control?

jianwt

  • Full Member
  • ***
  • Posts: 151
Re: TDWEdit
« Reply #13 on: September 04, 2025, 05:55:46 am »
@ Ed78z
Looking forward to your DWEdit control and hoping it can support Chinese input.

jianwt

  • Full Member
  • ***
  • Posts: 151
Re: TDWEdit
« Reply #14 on: September 05, 2025, 03:11:42 am »
@Ed78z
Sorry, I tried to load the dwedit.ppu file you compiled, but unfortunately, I couldn't run it. I deliberately installed Lazarus version 4.2_64  fpc3.2.2. My system is win10_64, but it still won't run.

When you come up with a version that I can use, I'll test it for you.
« Last Edit: September 05, 2025, 05:24:26 am by jianwt »

 

TinyPortal © 2005-2018