Recent

Author Topic: TDWEdit  (Read 6876 times)

CharlyTango

  • Full Member
  • ***
  • Posts: 169
Re: TDWEdit
« Reply #15 on: September 05, 2025, 01:18:26 pm »
I don't think it will be particularly well received if you're thinking of passing on ppu files. Lazarus is not Delphi, and even if it were technically possible, I can't imagine that it would be accepted by the community, if only from the point of view of platform independence.
Lazarus stable, Win32/64

hedgehog

  • Jr. Member
  • **
  • Posts: 75
Re: TDWEdit
« Reply #16 on: September 07, 2025, 07:32:59 am »
Hi, Ed78z!

How did you solve the problem described in this post?
https://forum.lazarus.freepascal.org/index.php/topic,64553.0.html

Can you provide an simple example of "Hello World!", or "Hello Word!" :) ?

Thanks

hedgehog

  • Jr. Member
  • **
  • Posts: 75
Re: TDWEdit
« Reply #17 on: September 07, 2025, 10:17:27 am »
Oh, of course, I know about that code word.

P.S. I just saw that you just commented out the lines in DX12.D2D1 that were causing the error

jianwt

  • Full Member
  • ***
  • Posts: 151
Re: TDWEdit
« Reply #18 on: September 10, 2025, 09:13:24 am »
@Ed78z
I ran the compiled program and input Chinese in TDWEdit. It perfectly supports Chinese input. But I don't know if this control can support the automatic line wrap function?

jianwt

  • Full Member
  • ***
  • Posts: 151
Re: TDWEdit
« Reply #19 on: September 19, 2025, 03:17:35 am »
I just added the SAVE and LOAD features...for the RTF format...it supports 80% of full RTF format, more than TRichMemo or KMemo
Still working on my own RTF units.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   DWEdit, QColors, QPapers, QRTFParser, QRTFSaver;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Button1: TButton;
  15.     Button2: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure Button2Click(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure FormShow(Sender: TObject);
  20.     procedure DWEditSelStartChanged(Sender: TObject);
  21.     procedure DWEditZoomChanged(Sender: TObject);
  22.     procedure DWEditSelPageChanged(Sender: TObject);
  23.     procedure DWEditPageCountChanged(Sender: TObject);
  24.   private
  25.     DWEdit1:TDWEdit;
  26.     procedure UpdateCaption;
  27.     procedure SetupInitialText;
  28.     procedure ApplyCharacterFormatting;
  29.     procedure ApplySpecialFormatting;
  30.     procedure EmbedSampleImage;
  31.     procedure ApplyParagraphFormatting;
  32.   public
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.lfm}
  41.  
  42. { TForm1 }
  43.  
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. begin
  46.   DWEdit1:=TDWEdit.Create(Self);
  47.   with DWEdit1 do
  48.   begin
  49.     Parent := Self;
  50.     SetBounds(0,50,700,550);
  51.     Font.Name := 'Segoe UI';
  52.     Font.Size := 12;
  53.     WordWrap := wwNoWrap;
  54.     TextMargin := 10;
  55.     OnSelStartChange := @DWEditSelStartChanged;
  56.     OnZoomChange := @DWEditZoomChanged;
  57.     OnSelPageChange := @DWEditSelPageChanged;
  58.     OnPageCountChange := @DWEditPageCountChanged;
  59.  
  60.     ZoomFactor := 1.00;
  61.  
  62.     ViewMode:=vmWebView;
  63.     ShowPaperBoundaries:=True;//ONLY in WebView: true/false
  64.     PaperSize:=ppsLetter;
  65.     PaperMargin:=mgNormal;
  66.  
  67.     GridVisible := True;
  68.     GridSize := Point(20, 20);
  69.     GridColor := QColors.clBlue;
  70.     GridStyle := gsLines;// gsLines;
  71.     GridOpacity := 0.1;// 0.0 .. 1.0
  72.   end;
  73. end;
  74.  
  75. procedure TForm1.Button1Click(Sender: TObject);
  76. var
  77.   FS: TFileStream;
  78. begin
  79.   FS := TFileStream.Create('sample.rtf', fmCreate);
  80.   try
  81.     DWEdit1.SaveToRTFStream(FS);
  82.   finally
  83.     FS.Free;
  84.   end;
  85. end;
  86.  
  87. procedure TForm1.Button2Click(Sender: TObject);
  88. var
  89.   FS: TFileStream;
  90. begin
  91.   if FileExists('sample.rtf') then
  92.   begin
  93.     FS := TFileStream.Create('sample.rtf', fmOpenRead);
  94.     try
  95.       DWEdit1.LoadFromRTFStream(FS);
  96.     finally
  97.       FS.Free;
  98.     end;
  99.   end;
  100. end;
  101.  
  102. procedure TForm1.SetupInitialText;
  103. var
  104.   AllText: TStringList;
  105. begin
  106.   AllText := TStringList.Create;
  107.   try
  108.     AllText.Add('Welcome to DWEdit! 🚀 Here are some features:');
  109.     AllText.Add('Ligatures & Stylistic Alternates (in Gabriola font).');
  110.     AllText.Add('Mix colors, sizes, and styles like bold & italic.');
  111.     AllText.Add('Highlighting with background colors is easy.');
  112.     AllText.Add('Custom underlines for emphasis or spellcheck.');
  113.     AllText.Add('Formulas: H2O and E=mc2 (Superscript/Subscript).');
  114.     AllText.Add('Spacing can be adjusted per character.');
  115.     AllText.Add('You can even embed  images "flowing" within text!');
  116.     AllText.Add('Paragraph''s alignment: Left, Right, Center & Justified.');
  117.     AllText.Add('Adjustable space between lines: (next three lines:)');
  118.     AllText.Add('🙂😊😃😄😆😍😘😗😉 👨🏻👩🏽👧🏾👦🏿 (different skin tones)');
  119.     AllText.Add('Full copy/paste & undo/redo system....');
  120.     AllText.Add('"Old Persian": 𐎠𐎡𐎢𐎣𐎤𐎥𐎦𐎧𐎨𐎩𐎪𐎫𐎬𐎭 (A "Left-to-Right" script language)');
  121.     AllText.Add('The next line is "New Persian", which is a Right-to-Left language:');
  122.     AllText.Add('این یک جمله نمونه به زبان فارسی است.');
  123.     AllText.Add(LineEnding+LineEnding);
  124.     AllText.TrailingLineBreak := False;
  125.     DWEdit1.Lines.Text := AllText.Text;
  126.   finally
  127.     AllText.Free;
  128.   end;
  129. end;
  130.  
  131. procedure TForm1.ApplyCharacterFormatting;
  132. var
  133.   attrs: TStyleAttributes;
  134. begin
  135.   // Bold and Italicize 'DWEdit!'
  136.   DWEdit1.SelStart := 11; DWEdit1.SelLength := 7;
  137.   DWEdit1.SetSelectionFontStyle([fsBold, fsItalic], smAdd);
  138.  
  139.   // Mix colors, sizes, and styles
  140.   attrs := Default(TStyleAttributes);
  141.  
  142.   attrs.AttributesSet := [saFontColor]; attrs.FontColor := clBlue;
  143.   DWEdit1.SelStart := 105; DWEdit1.SelLength := 6; DWEdit1.SetSelectionAttributes(attrs); // 'colors'
  144.  
  145.   attrs.AttributesSet := [saFontSize]; attrs.FontSize := 25;
  146.   DWEdit1.SelStart := 113; DWEdit1.SelLength := 5; DWEdit1.SetSelectionAttributes(attrs); // 'sizes'
  147.  
  148.   attrs.AttributesSet := [saFontStyle]; attrs.FontStyle := [fsBold];
  149.   DWEdit1.SelStart := 136; DWEdit1.SelLength := 4; DWEdit1.SetSelectionAttributes(attrs); // 'bold'
  150.  
  151.   attrs.FontStyle := [fsItalic];
  152.   DWEdit1.SelStart := 143; DWEdit1.SelLength := 6; DWEdit1.SetSelectionAttributes(attrs); // 'italic'
  153.  
  154.   // Background Color (Highlighting)
  155.   DWEdit1.SelStart := 152; DWEdit1.SelLength := 12;
  156.   attrs := Default(TStyleAttributes);
  157.   attrs.AttributesSet := [saBackgroundColor];
  158.   attrs.BackgroundColor := QColors.clLightGreen;
  159.   DWEdit1.SetSelectionAttributes(attrs);
  160. end;
  161.  
  162. procedure TForm1.ApplySpecialFormatting;
  163. var
  164.   underline: TDecoration;
  165. begin
  166.   // OpenType Features
  167.   DWEdit1.SelStart := 47; DWEdit1.SelLength := 52;
  168.   DWEdit1.SetSelectionFont('Gabriola');
  169.   DWEdit1.SetSelectionFeatures([ffStandardLigatures, ffStylisticSet1]);
  170.  
  171.   // Custom Wavy Red Underline
  172.   DWEdit1.SelStart := 205; DWEdit1.SelLength := 10;
  173.   underline.Enabled := True;
  174.   underline.Style := dsWavy;
  175.   underline.Color := QColors.clRed_Crayola;
  176.   underline.Thickness := 1.0;
  177.   underline.Offset := 3.0;
  178.   DWEdit1.SetSelectionUnderline(underline);
  179.  
  180.   // Subscript and Superscript
  181.   DWEdit1.SetBaselineScriptForRange(256, 1, bsSubscript); // '2' in H2O
  182.   DWEdit1.SetBaselineScriptForRange(267, 1, bsSuperscript); // '2' in E=mc2
  183.  
  184.   // Character Spacing
  185.   DWEdit1.SetCharacterSpacingForRange(295, 7, 5.0); // 'Spacing'
  186. end;
  187.  
  188. procedure TForm1.EmbedSampleImage;
  189. var
  190.   bmp: TBitmap;   pic: TPicture;
  191. begin
  192.   DWEdit1.SelStart := 354;  DWEdit1.SelLength := 0;
  193.   bmp := TBitmap.Create;
  194.   pic := TPicture.Create;
  195.   try
  196.     // --- Insert Bitmap ---
  197.     bmp.SetSize(50, 30);
  198.     bmp.Canvas.Brush.Color := QColors.clRed_Pantone;
  199.     bmp.Canvas.FillRect(Rect(0, 0, 50, 30));
  200.     bmp.Canvas.Brush.Color := QColors.clWhite;
  201.     bmp.Canvas.Font.Size := 14;
  202.     bmp.Canvas.TextOut(4, 2, 'Ed78');
  203.     DWEdit1.InsertImage(bmp);
  204.     // --- Insert any pictures from file ---
  205.     DWEdit1.SelStart := 786;   DWEdit1.SelLength := 1;
  206.     DWEdit1.Alignment := paCenter;
  207.     pic.LoadFromFile('Image.png');
  208.     DWEdit1.InsertImage(pic, 0.65);// scale to 65%
  209.   finally
  210.     bmp.Free;
  211.     pic.Free;
  212.   end;
  213. end;
  214.  
  215. procedure TForm1.ApplyParagraphFormatting;
  216. begin
  217.   // Paragraph Alignment: Left
  218.   DWEdit1.SelStart := 0; DWEdit1.SelLength := 100;
  219.   DWEdit1.Alignment := paLeft;
  220.  
  221.   // Paragraph Alignment: Center
  222.   DWEdit1.SelStart := 160; DWEdit1.SelLength := 100;
  223.   DWEdit1.Alignment := paCenter;
  224.  
  225.   // Paragraph Alignment: Right
  226.   DWEdit1.SelStart := 300; DWEdit1.SelLength := 50;
  227.   DWEdit1.Alignment := paRight;
  228.  
  229.   // Paragraph Alignment: Justified; When: wwNoWrap;
  230.   DWEdit1.SelStart := 400; DWEdit1.SelLength := 1;
  231.   DWEdit1.Alignment := paJustified;
  232.  
  233.   // Set the line spacing
  234.   DWEdit1.SetLineSpacingMultiplier(444, 180, 2.0); //Double space
  235.  
  236.   // Set BiDIMode for the R2L Persian language
  237.   DWEdit1.SelStart := 750;  DWEdit1.SelLength := 1;
  238.   DWEdit1.SetSelectionBiDiMode(bdmRightToLeft);
  239.   DWEdit1.Alignment := paRight;
  240. end;
  241.  
  242. procedure TForm1.FormShow(Sender: TObject);
  243. begin
  244.   DWEdit1.BeginUpdate; // Disable Undo System
  245.   try
  246.     SetupInitialText;
  247.     ApplyCharacterFormatting;
  248.     ApplySpecialFormatting;
  249.     EmbedSampleImage;
  250.     ApplyParagraphFormatting;
  251.     // Important: Reset selection and set focus
  252.     DWEdit1.SelStart := 0;
  253.     DWEdit1.SelLength := 0;
  254.     DWEdit1.SetFocus;
  255.   finally
  256.     DWEdit1.EndUpdate; // Re-enable Undo System
  257.   end;
  258. end;
  259.  
  260. procedure TForm1.UpdateCaption;
  261. var
  262.   Line, Col: Integer;
  263.   P: TPoint;
  264.   CurrentPage, TotalPage: Integer;
  265. begin
  266.   if not Assigned(DWEdit1) then Exit;
  267.  
  268.   // Get all the info
  269.   DWEdit1.GetSelPage(CurrentPage);
  270.   DWEdit1.GetPageCount(TotalPage);
  271.   DWEdit1.GetCaretLocation(Line, Col);
  272.   DWEdit1.GetCaretPos(P);
  273.  
  274.   // Format the caption
  275.   Self.Caption := Format(
  276.     'SelStart: %d (Line: %d, Col: %d) or in Pixels[X: %d, Y: %d] — Zoom: %d%% — Page: %d of %d',
  277.     [DWEdit1.SelStart, Line + 1, Col + 1, P.X, P.Y, Round(DWEdit1.ZoomFactor * 100), CurrentPage, TotalPage]
  278.   );
  279. end;
  280.  
  281. procedure TForm1.DWEditSelStartChanged(Sender: TObject);
  282. begin
  283.   UpdateCaption;
  284. end;
  285.  
  286. procedure TForm1.DWEditZoomChanged(Sender: TObject);
  287. begin
  288.   UpdateCaption;
  289. end;
  290.  
  291. procedure TForm1.DWEditSelPageChanged(Sender: TObject);
  292. begin
  293.   UpdateCaption;
  294. end;
  295.  
  296. procedure TForm1.DWEditPageCountChanged(Sender: TObject);
  297. begin
  298.   UpdateCaption;
  299. end;
  300.  
  301. end.

@Ed78z

Can TDWEdit.pas be made public? When can it be made public?
« Last Edit: September 19, 2025, 03:23:24 am by jianwt »

Ed78z

  • Jr. Member
  • **
  • Posts: 66
Re: TDWEdit
« Reply #20 on: September 21, 2025, 12:33:16 am »
Hi Jianwt,
I'm still working on it, I just fixed some bugs for: copy-paste From/To MS-WORD and Load/Save From/To .RTF file...

My goal to create a new Lazarus component with modern features like MS WORD, was very ambitious! and I need to stop going further! since it needs a team not just me alone!

So, whatever I developed till now, it's enough! (TDWEdit is still far far advanced than TRichMemo)... I will fix couple of tiny bugs as soon as I can.
« Last Edit: October 08, 2025, 12:11:45 pm by Ed78z »

hedgehog

  • Jr. Member
  • **
  • Posts: 75
Re: TDWEdit
« Reply #21 on: October 11, 2025, 09:25:33 am »
Hi

It seems to me that for the dark mode you should choose a more contrasting highlight color, as, for example, is done in VSСode

Ed78z

  • Jr. Member
  • **
  • Posts: 66
Re: TDWEdit
« Reply #22 on: October 22, 2025, 01:38:54 am »
I just improved my own color themes, and added the "Accent Colors"...now, you may choose any accent colors to apply for both Light and Dark themes....
below are screenshots for Blue and Red accent colors ....

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {Sample Application for DWEdit Component}
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7. interface
  8.  
  9. uses
  10.   Windows, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  11.   Clipbrd, ComCtrls, ExtCtrls,
  12.   DWEdit, QColors, QPapers, QRTFParser, QLanguages, QRTFImage,
  13.   QRTFSaver, QStatusBar, QThemeColors, QTheme, DWSharedTypes, QScrollBar;
  14.  
  15. type
  16.   { TForm1 }
  17.   TForm1 = class(TForm)
  18.     Button1, Button2: TButton;
  19.     Button3: TButton;
  20.     Button4: TButton;
  21.     ColorButton1: TColorButton;
  22.     Label1: TLabel;
  23.     Panel1: TPanel;
  24.  
  25.  
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure Button2Click(Sender: TObject);
  28.     procedure Button3Click(Sender: TObject);
  29.     procedure Button4Click(Sender: TObject);
  30.     procedure ColorButton1ColorChanged(Sender: TObject);
  31.     procedure FormCreate(Sender: TObject);
  32.     procedure FormShow(Sender: TObject);
  33.     procedure DWEditSelStartChanged(Sender: TObject);
  34.     procedure DWEditZoomChanged(Sender: TObject);
  35.     procedure DWEditSelPageChanged(Sender: TObject);
  36.     procedure DWEditPageCountChanged(Sender: TObject);
  37.   private
  38.     DWEdit1:TDWEdit;// disable if installed
  39.     QStatusBar1: TQStatusBar;// disable if installed
  40.  
  41.     Procedure InitStatusBar;
  42.     procedure UpdateCaption;
  43.     procedure SetupInitialText;
  44.     procedure ApplyCharacterFormatting;
  45.     procedure ApplySpecialFormatting;
  46.     procedure EmbedSampleImage;
  47.     procedure ApplyParagraphFormatting;
  48.   public
  49.   end;
  50.  
  51. var
  52.   Form1: TForm1;
  53.  
  54. implementation
  55.  
  56. {$R *.lfm}
  57.  
  58. { TForm1 }
  59.  
  60. Procedure TForm1.InitStatusBar;
  61. Begin
  62.   QStatusBar1 := TQStatusBar.Create(Self);
  63.   QStatusBar1.Parent := Self;
  64.   QStatusBar1.Align := alBottom;
  65.   QStatusBar1.SimplePanel := false;
  66.  
  67.   with QStatusBar1.Panels.Add do
  68.   begin
  69.     Style:=psNormal;
  70.     Width := 70; Alignment := taLeftJustify;
  71.     Text := 'Panel[0]';
  72.   end;
  73.   with QStatusBar1.Panels.Add do
  74.   begin
  75.     Style:=psSuccess;
  76.     Width := 70; Alignment := taCenter;
  77.     Text := 'Panel[1]';
  78.   end;
  79.   with QStatusBar1.Panels.Add do
  80.   begin
  81.     Style:=psWarning;
  82.     Width := 70; Alignment := taRightJustify;
  83.     Text := 'Panel[2]';
  84.   end;
  85.   with QStatusBar1.Panels.Add do
  86.   begin
  87.     Style:=psError;
  88.     Width := 70; Alignment := taLeftJustify;
  89.     Text := 'Panel[3]';
  90.   end;
  91. end;
  92.  
  93. procedure TForm1.FormCreate(Sender: TObject);
  94. begin
  95.   DWEdit1:=TDWEdit.Create(Self);
  96.   with DWEdit1 do
  97.   begin
  98.     Parent := Self;
  99.     Align:=alClient;
  100.     Font.Name := 'Segoe UI';
  101.     Font.Size := 12;
  102.     WordWrap:=wwCharacter;
  103.     OnSelStartChange := @DWEditSelStartChanged;
  104.     OnZoomChange := @DWEditZoomChanged;
  105.     OnSelPageChange := @DWEditSelPageChanged;
  106.     OnPageCountChange := @DWEditPageCountChanged;
  107.  
  108.     GridVisible := False;
  109.     GridSize := Point(20, 20);
  110.     GridColor := QColors.clLightBlue;
  111.     GridStyle := gsLines;//gsDots;
  112.     GridOpacity := 0.2;
  113.  
  114.     Theme := CurrentTheme;
  115.   end;
  116.  
  117.   InitStatusBar;
  118.  
  119.   ApplyTheme(CurrentTheme, GetThemeColor(tcAccentDefault));
  120. end;
  121.  
  122. procedure TForm1.Button1Click(Sender: TObject);
  123. var      //SAVE to RTF
  124.   FS: TFileStream;
  125. begin
  126.   FS := TFileStream.Create('sample.rtf', fmCreate);
  127.   try
  128.     DWEdit1.SaveToRTFStream(FS);
  129.   finally
  130.     FS.Free;
  131.   end;
  132.   DWEdit1.SetFocus;
  133. end;
  134.  
  135. procedure TForm1.Button2Click(Sender: TObject);
  136. var        //LOAD from RTF
  137.   FS: TFileStream;
  138. begin
  139.   if FileExists('sample.rtf') then
  140.   begin
  141.     FS := TFileStream.Create('sample.rtf', fmOpenRead);
  142.     try
  143.       DWEdit1.LoadFromRTFStream(FS);
  144.     finally
  145.       FS.Free;
  146.     end;
  147.   end;
  148.   DWEdit1.SetFocus;
  149. end;
  150.  
  151. procedure TForm1.Button3Click(Sender: TObject);
  152. begin
  153.   If DWEdit1.ViewLayout=vmPaperLayout then
  154.   Begin
  155.     With DWEdit1 do
  156.     Begin
  157.      ViewLayout:=vmWebLayout;     WordWrap:=wwNoWrap;
  158.     end;
  159.      Button3.Caption:='Web Layout';
  160.   end else
  161.   If DWEdit1.ViewLayout=vmWebLayout then
  162.   Begin
  163.     With DWEdit1 do
  164.     Begin
  165.      ViewLayout:=vmPaperLayout;   WordWrap:=wwCharacter;
  166.     end;
  167.      Button3.Caption:='Paper layout';
  168.   end;
  169.   DWEdit1.SetFocus;
  170. end;
  171.  
  172.  
  173. procedure TForm1.Button4Click(Sender: TObject);
  174. var
  175.   NewAccentColor: TColor;
  176. begin
  177.   if CurrentTheme = tmDark then
  178.   begin
  179.     Button4.Caption := 'Light Mode';
  180.     CurrentTheme := tmLight;
  181.   end else
  182.   begin
  183.     Button4.Caption := 'Dark Mode';
  184.     CurrentTheme := tmDark;
  185.   end;
  186.   NewAccentColor := ColorButton1.ButtonColor;
  187.   ApplyTheme(CurrentTheme, NewAccentColor);
  188.   if Assigned(DWEdit1) then DWEdit1.Theme := CurrentTheme;
  189.   DWEdit1.SetFocus;
  190. end;
  191.  
  192. procedure TForm1.ColorButton1ColorChanged(Sender: TObject);
  193. var
  194.   NewAccentColor: TColor;
  195. begin
  196.   NewAccentColor := ColorButton1.ButtonColor;
  197.   ApplyTheme(CurrentTheme, NewAccentColor);
  198.   if Assigned(DWEdit1) then DWEdit1.Theme := CurrentTheme;
  199.   Label1.Font.Color:=NewAccentColor;
  200.   DWEdit1.SetFocus;
  201. end;
  202.  
  203. procedure TForm1.SetupInitialText;
  204. var
  205.   AllText: TStringList;
  206. begin
  207.   AllText := TStringList.Create;
  208.   try
  209.     AllText.Add('Welcome to DWEdit! 🚀 Here are some features:');
  210.     AllText.Add('Ligatures & Stylistic Alternates (in Gabriola font).');
  211.     AllText.Add('Mix colors, sizes, and styles like bold & italic.');
  212.     AllText.Add('Highlighting with background colors is easy.');
  213.     AllText.Add('Custom underlines for emphasis or spellcheck.');
  214.     AllText.Add('Formulas: H2O and E=mc2 (Superscript/Subscript).');
  215.     AllText.Add('Spacing can be adjusted per character.');
  216.     AllText.Add('You can even embed  images "flowing" within text!');
  217.     AllText.Add('Paragraph''s alignment: Left, Right, Center & Justified.');
  218.     AllText.Add('Adjustable space between lines: (next three lines:)');
  219.     AllText.Add('🙂😊😃😄😆😍😘😗😉👨🏻👩🏽👧🏾👦🏿 (different skin tones)');
  220.     AllText.Add('Full copy/paste & undo/redo system....');
  221.     AllText.Add('"Old Persian": 𐎠𐎡𐎢𐎣𐎤𐎥𐎦𐎧𐎨𐎩𐎪𐎫𐎬𐎭 (A "Left-to-Right" script language)');
  222.     AllText.Add('The next line is "New Persian", which is a Right-to-Left language:');
  223.     AllText.Add('این یک جمله نمونه به زبان فارسی است.');
  224.     AllText.Add(LineEnding+LineEnding+LineEnding+LineEnding+LineEnding);
  225.     AllText.TrailingLineBreak := False;
  226.     DWEdit1.Lines.Text := AllText.Text;
  227.   finally
  228.     AllText.Free;
  229.   end;
  230. end;
  231.  
  232. procedure TForm1.ApplyCharacterFormatting;
  233. var
  234.   attrs: TStyleAttributes;
  235. begin
  236.   DWEdit1.SelStart := 11; DWEdit1.SelLength := 7;
  237.   DWEdit1.SetSelectionFontStyle([fsBold, fsItalic], smAdd);
  238.  
  239.   attrs := Default(TStyleAttributes);
  240.  
  241.   attrs.AttributesSet := [saFontColor]; attrs.FontColor := clBlue;
  242.   DWEdit1.SelStart := 105; DWEdit1.SelLength := 6; DWEdit1.SetSelectionAttributes(attrs);
  243.  
  244.   attrs.AttributesSet := [saFontSize]; attrs.FontSize := 25;
  245.   DWEdit1.SelStart := 113; DWEdit1.SelLength := 5; DWEdit1.SetSelectionAttributes(attrs);
  246.  
  247.   attrs.AttributesSet := [saFontStyle]; attrs.FontStyle := [fsBold];
  248.   DWEdit1.SelStart := 136; DWEdit1.SelLength := 4; DWEdit1.SetSelectionAttributes(attrs);
  249.  
  250.   attrs.FontStyle := [fsItalic];
  251.   DWEdit1.SelStart := 143; DWEdit1.SelLength := 6; DWEdit1.SetSelectionAttributes(attrs);
  252.  
  253.   // Background Color (Highlighting)
  254.   DWEdit1.SelStart := 152; DWEdit1.SelLength := 12;
  255.   attrs := Default(TStyleAttributes);
  256.   attrs.AttributesSet := [saBackgroundColor, saFontColor];
  257.   attrs.BackgroundColor := GetThemeColor(tcAccentDefault);
  258.   attrs.FontColor := GetThemeColor(tcTextOnAccentPrimary);
  259.   DWEdit1.SetSelectionAttributes(attrs);
  260. end;
  261.  
  262. procedure TForm1.ApplySpecialFormatting;
  263. var
  264.   underline: TDecoration;
  265. begin
  266.   // OpenType Features
  267.   DWEdit1.SelStart := 47; DWEdit1.SelLength := 52;
  268.   DWEdit1.SetSelectionFont('Gabriola');
  269.   DWEdit1.SetSelectionFeatures([ffStandardLigatures, ffStylisticSet1]);
  270.  
  271.   // Custom Underline
  272.   DWEdit1.SelStart := 205; DWEdit1.SelLength := 10;
  273.   underline.Enabled := True;
  274.   underline.Style := dsDoubleWave;
  275.   underline.Color := QColors.clRed;
  276.   DWEdit1.SetSelectionUnderline(underline);
  277.  
  278.   // Subscript and Superscript
  279.   DWEdit1.SetBaselineScriptForRange(256, 1, bsSubscript); // '2' in H2O
  280.   DWEdit1.SetBaselineScriptForRange(267, 1, bsSuperscript); // '2' in E=mc2
  281.  
  282.   // Character Spacing
  283.   DWEdit1.SetCharacterSpacingForRange(295, 7, 5.0); // 'Spacing'
  284. end;
  285.  
  286. procedure TForm1.EmbedSampleImage;
  287. var
  288.   bmp: TBitmap;   pic: TPicture;
  289. begin
  290.   DWEdit1.SelStart := 354;  DWEdit1.SelLength := 0;
  291.   bmp := TBitmap.Create;
  292.   pic := TPicture.Create;
  293.   try
  294.     // --- Insert Bitmap ---
  295.     bmp.SetSize(50, 30);
  296.     bmp.Canvas.Brush.Color := QColors.clRed_Pantone;
  297.     bmp.Canvas.FillRect(Rect(0, 0, 50, 30));
  298.     bmp.Canvas.Brush.Color := QColors.clWhite;
  299.     bmp.Canvas.Font.Size := 14;
  300.     bmp.Canvas.TextOut(4, 2, 'Ed78');
  301.     DWEdit1.InsertImage(bmp);
  302.     // --- Insert any pictures from file ---
  303.     DWEdit1.SelStart := 787;   DWEdit1.SelLength := 1;
  304.     DWEdit1.Alignment := paCenter;
  305.     pic.LoadFromFile('Image.png');
  306.     DWEdit1.InsertImage(pic, 0.65);// scale to 65%
  307.   finally
  308.     bmp.Free;
  309.     pic.Free;
  310.   end;
  311. end;
  312.  
  313. procedure TForm1.ApplyParagraphFormatting;
  314. begin
  315.   DWEdit1.SelStart := 0; DWEdit1.SelLength := 100;
  316.   DWEdit1.Alignment := paLeft;
  317.  
  318.   DWEdit1.SelStart := 160; DWEdit1.SelLength := 100;
  319.   DWEdit1.Alignment := paCenter;
  320.  
  321.   DWEdit1.SelStart := 300; DWEdit1.SelLength := 50;
  322.   DWEdit1.Alignment := paRight;
  323.  
  324.   DWEdit1.SelStart := 400; DWEdit1.SelLength := 1;
  325.   DWEdit1.Alignment := paJustified;
  326.  
  327.   //lsSingle, lsOneHalf, lsDouble, lsMultiple, lsAtLeast, lsExactly
  328.   //DWEdit1.SetLineSpacing(444, 180, lsAtLeast, 15.0);
  329.   DWEdit1.SetLineSpacing(444, 180, lsDouble);
  330.  
  331.   // Set BiDIMode for the R2L Persian language
  332.   DWEdit1.SelStart := 750;  DWEdit1.SelLength := 1;
  333.   DWEdit1.SetSelectionBiDiMode(bdmRightToLeft);
  334.   DWEdit1.Alignment := paRight;
  335. end;
  336.  
  337. procedure TForm1.FormShow(Sender: TObject);
  338. begin
  339.   DWEdit1.BeginUpdate; // Disable Undo System
  340.   try
  341.     SetupInitialText;
  342.     ApplyCharacterFormatting;
  343.     ApplySpecialFormatting;
  344.     EmbedSampleImage;
  345.     ApplyParagraphFormatting;
  346.  
  347.     DWEdit1.SelStart := 0;  DWEdit1.SelLength := 0;
  348.     DWEdit1.SetFocus;
  349.   finally
  350.     DWEdit1.EndUpdate; // Re-enable Undo System
  351.   end;
  352.   // This will erase any actions created during LFM loading.
  353.   DWEdit1.ClearUndoHistory;
  354. end;
  355.  
  356. procedure TForm1.UpdateCaption;
  357. var
  358.   Line, Col: Integer;
  359.   P: TPoint;
  360.   CurrentPage, TotalPage: Integer;
  361. begin
  362.   if not Assigned(DWEdit1) then Exit;
  363.  
  364.   // Get all the info
  365.   DWEdit1.GetSelPage(CurrentPage);
  366.   DWEdit1.GetPageCount(TotalPage);
  367.   DWEdit1.GetCaretLocation(Line, Col);
  368.   DWEdit1.GetCaretPos(P);
  369.  
  370.   // Format the caption
  371.   Self.Caption := Format(
  372.     'SelStart: %d (Line: %d, Col: %d) or in Pixels[X: %d, Y: %d] — Zoom: %d%% — Page: %d of %d',
  373.     [DWEdit1.SelStart, Line + 1, Col + 1, P.X, P.Y, Round(DWEdit1.ZoomFactor * 100), CurrentPage, TotalPage]
  374.   );
  375. end;
  376.  
  377. procedure TForm1.DWEditSelStartChanged(Sender: TObject);
  378. begin
  379.   UpdateCaption;
  380. end;
  381.  
  382. procedure TForm1.DWEditZoomChanged(Sender: TObject);
  383. begin
  384.   UpdateCaption;
  385. end;
  386.  
  387. procedure TForm1.DWEditSelPageChanged(Sender: TObject);
  388. begin
  389.   UpdateCaption;
  390. end;
  391.  
  392. procedure TForm1.DWEditPageCountChanged(Sender: TObject);
  393. begin
  394.   UpdateCaption;
  395. end;
  396.  
  397.  
  398. end.
« Last Edit: October 24, 2025, 04:22:04 am by Ed78z »

 

TinyPortal © 2005-2018