Jump to content
at3s

Character spacing in RichEdit control

Recommended Posts

I tried in Delphi to make working a C++ sample (Character spacing in RichEdit control) but spacing does not change (doc.Selection.Font.Spacing).

I guess, Font.Spacing is deprecated but not sure.

Did someone something similar or can confirm it's not possible? 

Edited by at3s

Share this post


Link to post

Would be nice if you publish the code you have already tried so that we can review it and even try to make it work without having to invent a full test program.

Share this post


Link to post
43 minutes ago, FPiette said:

Would be nice if you publish the code you have already tried so that we can review it and even try to make it work without having to invent a full test program.

Sure. Here is a unit:

unit uRichEdit;

interface

uses
  System.SysUtils
  , Winapi.Windows
  , Vcl.ComCtrls
  , Winapi.RichEdit
  , tom_TLB
  ;

type
  TRichEditHelper = class helper for TRichEdit
  private
    class function reGetTextDocument(RichEdit: TRichEdit): ITextDocument;
  public
    class function reSpacing(ARichEdit: TRichEdit; ASpaces: Integer): Boolean;
  end;

implementation

{ TRichEditHelper }

class function TRichEditHelper.reGetTextDocument(
  RichEdit: TRichEdit): ITextDocument;
var
  re: IUnknown;
begin
  if RichEdit.Perform(EM_GETOLEINTERFACE, 0, LParam(@re)) = 0 then
  begin
    Result := nil;
    Exit;
  end;

  re._AddRef;

  if not Supports(re, ITextDocument, Result) then
    Result := nil;
end;

class function TRichEditHelper.reSpacing(ARichEdit: TRichEdit;
  ASpaces: Integer): Boolean;
var
  doc: ITextDocument;
  spacing: Single;
begin
  doc := reGetTextDocument(ARichEdit);

  doc.Selection.Start := 0;
  doc.Selection.End_ := Length(doc.Selection.Text);
  doc.Selection.Font.Spacing := ASpaces;
end;

end.

and its using:

TRichEdit.RichEditSpacing(reSample, 10);

You have to import 'tom' type library.

Edited by at3s

Share this post


Link to post

You need RichEdit50W, but TRichEdit utilize Riched32.dll / Riched20.dll, not MsftEdit.dll.

 

In my program I used JvRichEdit from JVCL library, modified to utilize MsftEdit.dll instead of Riched32.dll. Updating the component version also significantly speeds up a loading of large RTF files.

Edited by Kryvich
  • Thanks 1

Share this post


Link to post
58 minutes ago, Kryvich said:

You need RichEdit50W, but TRichEdit utilize Riched32.dll, not MsftEdit.dll.

 

In my program I used JvRichEdit from JVCL library, modified to utilize MsftEdit.dll instead of Riched32.dll. Updating the component version also significantly speeds up a loading of large RTF files.

It works in Delphi, thanks a lot. 

Share this post


Link to post

Hi again,

 

For some reason, spacing doesn't work on 32-bit Windows 7 and Windows XP, even it works fine on Windows 10 x64.
I guess it's because their msftedit.dll file version.
Does someone know if it's correct and how to fix this?

Share this post


Link to post
6 minutes ago, FPiette said:

Maybe a new Win8 or Win10 feature not supported by Win7.

 

It seems so.

 

On 10/18/2020 at 7:32 PM, Kryvich said:

You need RichEdit50W, but TRichEdit utilize Riched32.dll / Riched20.dll, not MsftEdit.dll.

 

In my program I used JvRichEdit from JVCL library, modified to utilize MsftEdit.dll instead of Riched32.dll. Updating the component version also significantly speeds up a loading of large RTF files.

Does JvRichEdit's Spacing work fine in all Windows versions (Win7 x32, Win XP f.e.)?

Share this post


Link to post

Yes, I see the same. It's strange, because when I generate tom_TLB.pas, even in Windows XP there is Spacing property in ITextFont interface. After doc.Selection.Font.Spacing := ASpaces, the Spacing property is actually returns the new value, but the edit control is not displaying as expected.

Edited by Kryvich

Share this post


Link to post
20 hours ago, Kryvich said:

Yes, I see the same. It's strange, because when I generate tom_TLB.pas, even in Windows XP there is Spacing property in ITextFont interface. After doc.Selection.Font.Spacing := ASpaces, the Spacing property is actually returns the new value, but the edit control is not displaying as expected.

Exactly. I even tried to copy and load different MsftEdit.dll versions in Windows 7, but without success.

Share this post


Link to post

The fun part is that WordPad, which uses the same Rich Edit control, can display text correctly in Windows 7 (but not in XP).

Win7-RICHEDIT50W.thumb.jpg.b06d248d10c69de1620b8de1733e47fd.jpg

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×