mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 04:26:13 +02:00
* Patch from Jesús Reyes:
-Avoid premature end of parsing stylesheet group by fixing: --No more break if rtfstylenum,rtfbasedon or rtfnext tokens are seen --Silently ignore unknown control words and -The style name was not correctly initialized git-svn-id: trunk@6507 -
This commit is contained in:
parent
581cd410fe
commit
032a3891e8
@ -25,6 +25,8 @@ Uses classes,sysutils;
|
|||||||
|
|
||||||
type Trtferrorhandler = Procedure (s : string) of object;
|
type Trtferrorhandler = Procedure (s : string) of object;
|
||||||
|
|
||||||
|
{ TRTFParser }
|
||||||
|
|
||||||
TRTFParser = class(TObject)
|
TRTFParser = class(TObject)
|
||||||
private
|
private
|
||||||
FOnRTFError : TRTFerrorHandler;
|
FOnRTFError : TRTFerrorHandler;
|
||||||
@ -47,6 +49,7 @@ TRTFParser = class(TObject)
|
|||||||
ccb : array [0..rtfMaxClass] of TRTFFuncPtr; { class callbacks }
|
ccb : array [0..rtfMaxClass] of TRTFFuncPtr; { class callbacks }
|
||||||
dcb : array [0..rtfMaxDestination] of TRTFFuncPtr; { destination callbacks }
|
dcb : array [0..rtfMaxDestination] of TRTFFuncPtr; { destination callbacks }
|
||||||
readHook : TRTFFUNCPTR;
|
readHook : TRTFFUNCPTR;
|
||||||
|
FTokenClass: Integer;
|
||||||
Procedure Error (msg : String);
|
Procedure Error (msg : String);
|
||||||
Procedure LookupInit ;
|
Procedure LookupInit ;
|
||||||
Procedure ReadFontTbl ;
|
Procedure ReadFontTbl ;
|
||||||
@ -465,6 +468,7 @@ FrtfClass := rtfUnknown;
|
|||||||
FrtfParam := rtfNoParam;
|
FrtfParam := rtfNoParam;
|
||||||
rtfTextBuf := '';
|
rtfTextBuf := '';
|
||||||
rtfTextLen := 0;
|
rtfTextLen := 0;
|
||||||
|
FTokenClass := rtfUnknown;
|
||||||
|
|
||||||
{ get first character, which may be a pushback from previous token }
|
{ get first character, which may be a pushback from previous token }
|
||||||
|
|
||||||
@ -549,6 +553,7 @@ if ( not isalpha (c)) then
|
|||||||
End;
|
End;
|
||||||
{ control symbol }
|
{ control symbol }
|
||||||
Lookup (rtfTextBuf); { sets class, major, minor }
|
Lookup (rtfTextBuf); { sets class, major, minor }
|
||||||
|
FTokenClass:=rtfControl;
|
||||||
exit;
|
exit;
|
||||||
End;
|
End;
|
||||||
{ control word }
|
{ control word }
|
||||||
@ -566,6 +571,7 @@ while (isalpha (c)) do
|
|||||||
if (c<>EOF) then
|
if (c<>EOF) then
|
||||||
delete(rtfTextBuf,length(rtfTextbuf),1);
|
delete(rtfTextBuf,length(rtfTextbuf),1);
|
||||||
Lookup (rtfTextBuf); { sets class, major, minor }
|
Lookup (rtfTextBuf); { sets class, major, minor }
|
||||||
|
FTokenClass:=rtfControl;
|
||||||
if (c <>EOF) then
|
if (c <>EOF) then
|
||||||
rtfTextBuf:=rtfTextBuf+chr(c);
|
rtfTextBuf:=rtfTextBuf+chr(c);
|
||||||
{ Should be looking at first digit of parameter if there
|
{ Should be looking at first digit of parameter if there
|
||||||
@ -809,22 +815,24 @@ While true do
|
|||||||
FstyleList := sp;
|
FstyleList := sp;
|
||||||
if not CheckCM (rtfGroup, rtfBeginGroup) then
|
if not CheckCM (rtfGroup, rtfBeginGroup) then
|
||||||
Error ('SSErr - missing {');
|
Error ('SSErr - missing {');
|
||||||
while GetToken=rtfControl do
|
while (GetToken=rtfControl) or (FTokenClass=rtfControl) do
|
||||||
Begin
|
Begin
|
||||||
|
if rtfClass=rtfUnknown then
|
||||||
|
continue;
|
||||||
if (CheckMM (rtfParAttr, rtfStyleNum)) then
|
if (CheckMM (rtfParAttr, rtfStyleNum)) then
|
||||||
Begin
|
Begin
|
||||||
sp^.rtfSNum:=rtfParam;
|
sp^.rtfSNum:=rtfParam;
|
||||||
break;
|
continue;
|
||||||
End;
|
End;
|
||||||
if (CheckMM (rtfStyleAttr, rtfBasedOn)) then
|
if (CheckMM (rtfStyleAttr, rtfBasedOn)) then
|
||||||
Begin
|
Begin
|
||||||
sp^.rtfSBasedOn:=rtfParam;
|
sp^.rtfSBasedOn:=rtfParam;
|
||||||
break;
|
continue;
|
||||||
End;
|
End;
|
||||||
if (CheckMM (rtfStyleAttr, rtfNext)) then
|
if (CheckMM (rtfStyleAttr, rtfNext)) then
|
||||||
Begin
|
Begin
|
||||||
sp^.rtfSNextPar:=rtfParam;
|
sp^.rtfSNextPar:=rtfParam;
|
||||||
break;
|
Continue;
|
||||||
End;
|
End;
|
||||||
new(sep);
|
new(sep);
|
||||||
if sep=nil then
|
if sep=nil then
|
||||||
@ -840,11 +848,12 @@ While true do
|
|||||||
sepLast^.rtfNextSE:=sep;
|
sepLast^.rtfNextSE:=sep;
|
||||||
sep^.rtfNextSE:=nil;
|
sep^.rtfNextSE:=nil;
|
||||||
sepLast:=sep;
|
sepLast:=sep;
|
||||||
End;
|
End;
|
||||||
if sp^.rtfSNextPar=-1 then { \snext not given }
|
if sp^.rtfSNextPar=-1 then { \snext not given }
|
||||||
sp^.rtfSNextPar:=sp^.rtfSNum; { next is itself }
|
sp^.rtfSNextPar:=sp^.rtfSNum; { next is itself }
|
||||||
if rtfClass<>rtfText then
|
if rtfClass<>rtfText then
|
||||||
Error ('SSErr - missing style name');
|
Error ('SSErr - missing style name');
|
||||||
|
Bp:='';
|
||||||
while rtfClass=rtfText do
|
while rtfClass=rtfText do
|
||||||
Begin
|
Begin
|
||||||
if rtfMajor=ord(';') then
|
if rtfMajor=ord(';') then
|
||||||
@ -1040,7 +1049,6 @@ Procedure TRTFParser.Error (msg : String);
|
|||||||
begin
|
begin
|
||||||
if assigned(onrtferror) then onrtferror(msg);
|
if assigned(onrtferror) then onrtferror(msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ ---------------------------------------------------------------------
|
{ ---------------------------------------------------------------------
|
||||||
Token comparison routines
|
Token comparison routines
|
||||||
---------------------------------------------------------------------}
|
---------------------------------------------------------------------}
|
||||||
|
Loading…
Reference in New Issue
Block a user