📄 unitpltortf.pas
字号:
slist.Free ;
end;
end;
procedure TPLConversion.writeNext(TokenState: TTokenState;word:string);
var position:integer;
wordlen:integer;
begin
position:=1;
word:=self.FPreFixList[TokenState]+word+self.FPostFixList[TokenState];
wordLen:=length(word);
while position<=wordlen do
begin
Position:=position+1023;
if position >wordLen then
begin
strtochars(word,Fbuffer);
self.Write(Fbuffer,lengthchars(Fbuffer));
end
else
begin
strtochars(copy(word,1,1023),Fbuffer);
self.Write(Fbuffer,1023);
word:=copy(word,1024,length(word)-1023);
end;
end;
end;
procedure TPLConversion.WriteRtfTail;
begin
Fbuffer:='}'+#13+#10;
self.Write(fBuffer,lengthchars(fbuffer));
end;
function TPLConversion.findINSymbols(ch: char): boolean;
begin
if ord(ch)<128 then
begin
result:=Fsymbols[ord(ch)] ;
end
else result:=false;
end;
function TPLConversion.KeyDeal(word: string): boolean;
var s:string;
i:integer;
begin
if not self.FUpLow then
s:=AnsiUpperCase(word)
else s:=word;
if self.KeyList.Find (s,i) then
begin
self.writeNext(tsKeyword,word);
result:=true;
end
else
result:=false;
end;
procedure TPLConversion.loadfromInifile(inifilename, PLname: string);
var Inifile:Tinifile;
begin
if fileexists(inifilename) then
begin
inifile:=Tinifile.Create(inifilename);
try
self.FUpLow := inifile.Readbool(plname,'isuplow',false);
self.KeyIsBold:= inifile.Readbool(plname,'KeyIsBold',true);
self.commentIsItalisc := inifile.Readbool(plname,'commentIsItalisc',true);
self.setDefultFix ;
self.FontSize :=inifile.Readinteger(plname,'FontSize',24);
self.SetKeyList(inifile.ReadString(plname,'keys','') ) ;
self.SetCommentList(inifile.ReadString(plname,'comments',''));
self.Fstring:=inifile.ReadString(plname,'stringsymbol','"')[1];
self.SetSymbolList(inifile.ReadString(plname,'symbols','')) ;
self.FTokenStateColor[tsKeyword]:=inifile.ReadInteger(plname,'keycolor',0);
self.FTokenStateColor[tsComment]:=inifile.ReadInteger(plname,'commentcolor',0);
self.FTokenStateColor[tsstring]:=inifile.ReadInteger(plname,'stringcolor',0);
self.FTokenStateColor[tsnumber]:=inifile.ReadInteger(plname,'numbercolor',0);
self.resetColorString ;
self.PLName :=PLName;
finally
inifile.Free ;
end;
end;
end;
function TPLConversion.ReallyGo: boolean;
begin
result :=true;
if Fstring =#0 then
result:=false
else if FKeyList.Count=0 then
result:=false
else if FcommentList[CommentBegin].Count=0 then
result:=false;
end;
procedure TPLConversion.reset;
var i:integer;
begin
self.isUpLow :=false;
self.PLName :='';
self.FKeyList.Clear ;
self.FcommentList[CommentBegin].Clear ;
self.FcommentList[Commentend].Clear ;
self.PLName :='';
self.Fstring :=#0 ;
for i:=0 to Length(self.FSymbols )-1 do
begin
self.FSymbols[i]:=false;
end;
end;
procedure TPLConversion.resetColorString;
var Ts: TTokenState;
begin
FColorString := '{\colortbl ;';
for Ts:= tsComment to tsString do
begin
FColorString := FColorString+self.ColorToRTF(FTokenStateColor[Ts]);
end;
FColorString := FColorString+'}'+#13+#10;
end;
{ TPLMessage }
procedure TPLMessage.clear;
var Ts:TTokenState;
begin
self.Finifilename :='';
self.FPLname :='';
self.isUpLow :=false;
self.Keys :='';
self.comments :='';
self.stringSymbol :=#0 ;
self.Symbols:='';
for Ts:=Tscomment to Tsstring do
begin
self.FTsColors [ts]:=0;
end;
end;
constructor TPLMessage.Create(Newinifilename,NewPLname:string);
begin
self.clear ;
self.inifilename:=Newinifilename;
self.PLname:=NewPLname;
end;
function TPLMessage.getTokenColor(Ts: TTokenState): Tcolor;
begin
if Ts<>tsUnknown then
begin
result:=Ftscolors[ts];
end
else
result:=0;
end;
function TPLMessage.isok: boolean;
begin
if (self.Keys ='') or (self.comments ='')
or(self.stringSymbol =#0)or(self.Symbols ='') then
result:=false
else
result:=true;
end;
function TPLMessage.loadfromInifile:boolean;
var Inifile:Tinifile;
word,AllLinkTypes,linktype:string;
i,AllLinkTypesLen:integer;
begin
if fileexists(inifilename) and (FPLname<>'') then
begin
inifile:=Tinifile.Create(inifilename);
try
self.isUpLow := inifile.Readbool(plname,'isUpLow',false);
self.Keys :=inifile.ReadString(plname,'Keys','') ;
self.FontSize :=inifile.Readinteger(plname,'FontSize',24);
self.comments :=inifile.ReadString(plname,'comments','');
self.KeyIsBold:= inifile.Readbool(plname,'KeyIsBold',true);
self.commentIsItalisc := inifile.Readbool(plname,'commentIsItalisc',true);
self.stringSymbol:=inifile.ReadString(plname,'stringSymbol','"')[1];
self.Symbols := inifile.ReadString(plname,'Symbols','') ;
self.FTsColors [Tscomment]:=inifile.ReadInteger(plname,'commentcolor',$800000);
self.FTsColors [TsKeyword]:=inifile.ReadInteger(plname,'keycolor',clDefault);
self.FTsColors [Tsnumber]:=inifile.ReadInteger(plname,'numbercolor',clFuchsia);
self.FTsColors [Tsstring]:=inifile.ReadInteger(plname,'stringcolor',clFuchsia);
//获取关联文件类型
AllLinkTypes:=inifile.ReadString('PLName','linkfiles','');
if AllLinkTypes<>'' then
begin
self.Flinktypes :='';
AllLinkTypes:=AllLinkTypes+' ';
AllLinkTypesLen:=length(AllLinkTypes);
linktype:='' ;
for i:=1 to AllLinkTypesLen do
begin
if AllLinkTypes[i]<>' 'then
linktype:= linktype+AllLinkTypes[i]
else
begin
if linktype<>'' then
begin
word:=inifile.ReadString('link',linktype,'');
if word= self.FPLname then
self.Flinktypes :=self.Flinktypes +linktype+' ';
linktype:='';
end;
end;
end;
end;
finally
inifile.Free ;
result:=true;
end;
end
else
result:=false;
end;
function TPLMessage.LoadPLname(PLnamelist: TStrings): boolean;
var Inifile:Tinifile;
var word,PLnames:string;
i,PLNamesLen:integer;
begin
if fileexists(self.Finifilename ) and (PLNamelist<>nil)then
begin
inifile:=Tinifile.Create(self.Finifilename );
try
plnames:=inifile.ReadString('PLName','Name' ,'');
if PLNames<>'' then
begin
PLnamelist.Clear ;
PLNames:=PLnames+' ';
PLNamesLen:=length(PLNames);
word:='' ;
for i:=1 to PLNamesLen do
begin
if PLNames[i]<>' 'then
word:= word+PLnames[i]
else
begin
if word<>'' then
begin
PLnamelist.Add(word);
word:='';
end;
end;
end;
end;
result:=true;
finally
inifile.Free ;
end;
end
else
result:=false;
end;
procedure TPLMessage.savetoInifile;
var Inifile:Tinifile;
PLnames:string;
AllLinkTypes,linktype:string;
i,LinkTypesLen,AllLinkTypesLen:integer;
begin
if (inifilename<>'')and (PLname<>'') then
begin
inifile:=Tinifile.Create(inifilename);
try
inifile.writebool(plname,'isUpLow',isUpLow);
inifile.WriteInteger(PLname,'FontSize',self.FontSize );
inifile.writebool(plname,'KeyIsBold',self.KeyIsBold );
inifile.writebool(plname,'commentIsItalisc',self.commentIsItalisc );
inifile.writeString(plname,'Keys',Keys) ;
inifile.writeString(plname,'comments',comments);
inifile.writeString(plname,'stringSymbol',stringSymbol);
inifile.writeString(plname,'Symbols',Symbols) ;
inifile.writeInteger(plname,'keycolor',FTsColors [TsKeyword]);
inifile.writeInteger(plname,'commentcolor',FTsColors [TsComment]);
inifile.writeInteger(plname,'numbercolor',FTsColors [Tsnumber]);
inifile.writeInteger(plname,'stringcolor',FTsColors [Tsstring]);
///////////////////////////
PLnames:=inifile.ReadString('PLName','Name','');
if Pos(' '+self.PLname+' ' ,' '+PLnames+' ')=0 then
begin //add self.plname
PLnames:=trim(PLnames)+' '+self.PLname ;
inifile.WriteString('PLName','Name',PLnames);
end;
////////////////////////////////////////////
///////////////////////////////////////////
//del old linktype of slef.PLname;
//////////////////////////
AllLinkTypes:=inifile.ReadString('PLName','linkfiles','');
if AllLinkTypes<>'' then
begin
AllLinkTypes:=AllLinkTypes+' ';
AllLinkTypesLen:=length(AllLinkTypes);
linktype:='' ;
for i:=1 to AllLinkTypesLen do
begin
if AllLinkTypes[i]<>' 'then
linktype:= linktype+AllLinkTypes[i]
else
begin
if linktype<>'' then
begin
if self.FPLname=inifile.ReadString('link',linktype,'') then
inifile.DeleteKey('link',linktype);
linktype:='';
end;
end;
end;
end;
///////////////////////////////////////
//add new linktype of slef.PLname;
///////////////////////////////
AllLinkTypes:=inifile.ReadString('PLName','linkfiles','');
if (self.Flinktypes <>'') and (AllLinkTypes<>'') then
begin
Flinktypes:=Flinktypes+' ';
LinkTypesLen:=length(Flinktypes);
linktype:='' ;
for i:=1 to LinkTypesLen do
begin
if Flinktypes[i]<>' 'then
linktype:= linktype+Flinktypes[i]
else
begin
if linktype<>'' then
begin
inifile.writeString('link',linktype,self.PLname );
if pos(' '+linktype+' ',' '+alllinktypes+' ')=0 then
begin
alllinktypes:=trim(alllinktypes)+' '+linktype ;
inifile.WriteString('PLName','linkfiles',alllinktypes);
end;
linkType:='';
end;
end;
end;
end;
finally
inifile.Free ;
end;
end;
end;
procedure TPLMessage.setKeys(newKeys: string);
var i:integer;
begin
self.FKeys:='';
for i:=1 to length(newKeys) do
begin
if not (newKeys[i] in [#10,#13]) then
FKeys:=FKeys+newKeys[i];
end;
end;
procedure TPLMessage.setPLname(newPLname: string);
var i:integer;
begin
self.FPLname:='';
for i:=1 to length(newPLname) do
begin
if not (newPLname[i] in [' ',#10,#13]) then
FPLName:=FPLName+newPLname[i];
end;
end;
function TPLMessage.setTokenColor(Ts: TTokenState;
NewColor: Tcolor): boolean;
begin
if ts<>tsUnknown then
begin
self.FTsColors[ts]:=NewColor;
result:=false;
end
else
result:=false;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -