TextDiff
- Rickard Johansson
- Site Admin
- Posts: 6731
- Joined: 19 Jul 2006 14:29
TextDiff
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()
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
Thanks for this code! If you won't put it on Github, can I do it? my GH account is Alexey-T.
- Rickard Johansson
- Site Admin
- Posts: 6731
- Joined: 19 Jul 2006 14:29
Re: TextDiff
Yes, you can put it on Github
Re: TextDiff
Ok, thanks, it is here:
https://github.com/Alexey-T/TextDiff
https://github.com/Alexey-T/TextDiff
Re: TextDiff
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.
- 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
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).
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;
- Rickard Johansson
- Site Admin
- Posts: 6731
- Joined: 19 Jul 2006 14:29
Re: TextDiff
Version 5.01 is available:
Rewrote demo 1 and fixed issues in demo 2.
Rewrote demo 1 and fixed issues in demo 2.
Re: TextDiff
Pls remove "uses Windows" in HashUnit becase of Unix in FPC.
In both demos, too...
In both demos, too...
Re: TextDiff
a)
h := PaintBox1.Canvas.TextHeight('W');
w := PaintBox1.Canvas.TextWidth('W');
better to calc in FormShow 1 time
b)
better to make var C: TCanvas for it.
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;
- Rickard Johansson
- Site Admin
- Posts: 6731
- Joined: 19 Jul 2006 14:29
Re: TextDiff
Updated to v5.02. Minor fixes in both source files and demos.
Re: TextDiff
updated in GH. thanks. I am not sure it is ok to put Textdiff.exe in GH. they allow open src only.
- Rickard Johansson
- Site Admin
- Posts: 6731
- Joined: 19 Jul 2006 14:29
Re: TextDiff
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...
So it's probably okey to remove the "TextDiff" folder and remove the textdiff utility notice in the readme file...