Page 1 of 1
TextDiff
Posted: 19 May 2020 13:20
by Rickard Johansson
The zip file contain source code for the freeware component - TDiff - written and tested in Delphi 10.x and Lazarus.
The TDiff component is used in RJ Texted to compare documents. Two simple demos are included to help you include the component in your own applications.
TDiff was written by Angus Johnson in 2001 - 2008. I simply made some changes to handle Unicode strings, make some simple updates and add Lazarus support.
View code and Download (from Github)
https://github.com/rickard67/TextDiff
or you can use the repository provided by Alexey-T
https://github.com/Alexey-T/TextDiff
Added in this version compared to the original
* Added TList<Cardinal> to store hash values
* Made some minor code formatting and code changes
* Fixed Unicode string issues
* Added Lazarus support
* Replaced almost all code in demo 1. It should be much easier to understand now.
* Fixed a few issues in demo 2.
* Fixed an issue in diff.AddChangeChr()
Re: TextDiff
Posted: 19 May 2020 15:46
by Alextp
Thanks for this code! If you won't put it on Github, can I do it? my GH account is Alexey-T.
Re: TextDiff
Posted: 19 May 2020 16:24
by Rickard Johansson
Yes, you can put it on Github
Re: TextDiff
Posted: 21 May 2020 06:38
by Alextp
Re: TextDiff
Posted: 23 May 2020 06:27
by Alextp
RJ, small report:
- made small fixes to demo1 and demo2 to compile them on Linux in Lazarus (in Github)
- I run demo2, choose 2 files:
https://github.com/Alexey-T/TRegExpr/bl ... egExpr.pas
https://github.com/Alexey-T/ATSynEdit/b ... egexpr.pas
I compare them.
now command "Next diff" (Ctrl+N or Ctrl+P) goes to next diff. only 2-3 times. after n times, command dont jump more.
but more changes exist.
Re: TextDiff
Posted: 23 May 2020 07:05
by Alextp
Wish for demo1 code: it has function which heavily uses paitning via DC. better to rewrite it to use TCanvas methods.
e.g. TextOut(canvas1.handle, .....) -> canvas1.TextOut(....).
This is more compatible for all WSes in Lazarus.
Current code may work or may not (if LCL Widgetset is not complete).
Code: Select all
procedure MarkupTextOut(canvas: TCanvas; x,y: integer; text: string);
var
i,len, clr: integer;
savedTextAlign, SavedBkColor, savedTextColor: cardinal;
savedPt: TPoint;
begin
i := pos('<',text);
if i = 0 then
begin
canvas.TextOut(x,y,text);
exit;
end;
savedTextColor := GetTextColor(canvas.Handle);
SavedBkColor := GetBkColor(canvas.handle);
{$ifdef windows}
savedTextAlign := GetTextAlign(canvas.Handle);
SetTextAlign(canvas.Handle, savedTextAlign or TA_UPDATECP);
{$endif}
MoveToEx(canvas.Handle, x, y, @savedPt);
repeat
if i > 1 then
TextOut(canvas.handle,0,0,pchar(text),i-1);
delete(text,1,i);
len := length(text);
if len < 3 then
break
else if (text[1] = 'F') and (text[2] ='C') and (text[3] = ':') and
(len > 9) and (text[10] = '>') then
begin
clr := strtointdef('$'+copy(text,4,6),$0);
SetTextColor(canvas.handle, clr);
delete(text,1,10);
dec(len,10);
end
else if (text[1] = 'B') and (text[2] ='C') and (text[3] = ':') and
(len > 9) and (text[10] = '>') then
begin
clr := strtointdef('$'+copy(text,4,6),$1FFFFFF);
if clr > $FFFFFF then
SetBkColor(canvas.handle, SavedBkColor) else
SetBkColor(canvas.handle, clr);
delete(text,1,10);
dec(len,10);
end
else
break;
i := pos('<',text);
until (i = 0);
TextOut(canvas.handle,0,0,pchar(text),len);
SetTextColor(canvas.handle,savedTextColor);
SetBkColor(canvas.handle, SavedBkColor);
{$ifdef windows}
SetTextAlign(canvas.Handle, savedTextAlign);
{$endif}
with savedPt do
MoveToEx(canvas.Handle, X,Y, nil);
end;
Re: TextDiff
Posted: 23 May 2020 17:35
by Rickard Johansson
Version 5.01 is available:
Rewrote demo 1 and fixed issues in demo 2.
Re: TextDiff
Posted: 23 May 2020 18:13
by Alextp
Pls remove "uses Windows" in HashUnit becase of Unix in FPC.
In both demos, too...
Re: TextDiff
Posted: 23 May 2020 18:15
by Alextp
a)
h := PaintBox1.Canvas.TextHeight('W');
w := PaintBox1.Canvas.TextWidth('W');
better to calc in FormShow 1 time
b)
Code: Select all
y := y+h+5;
PaintBox1.Canvas.Brush.Color := clBtnFace;
PaintBox1.Canvas.TextOut(0,y,' Matches : '+inttostr(matches));
y := y+h+2;
PaintBox1.Canvas.Brush.Color := $AAFFAA;
PaintBox1.Canvas.TextOut(0,y,' Modifies: '+inttostr(modifies));
y := y+h+2;
PaintBox1.Canvas.Brush.Color := $FFAAAA;
PaintBox1.Canvas.TextOut(0,y,' Adds : '+inttostr(adds));
y := y+h+2;
PaintBox1.Canvas.Brush.Color := $AAAAFF;
PaintBox1.Canvas.TextOut(0,y,' Deletes : '+inttostr(deletes));
end;
better to make var C: TCanvas for it.
Re: TextDiff
Posted: 23 May 2020 22:00
by Rickard Johansson
Updated to v5.02. Minor fixes in both source files and demos.
Re: TextDiff
Posted: 24 May 2020 16:30
by Alextp
updated in GH. thanks. I am not sure it is ok to put Textdiff.exe in GH. they allow open src only.
Re: TextDiff
Posted: 24 May 2020 21:23
by Rickard Johansson
The license text doesn't say anything about the TextDiff utility. Only the source code.
So it's probably okey to remove the "TextDiff" folder and remove the textdiff utility notice in the readme file...