* Fix UseParentFont (Bug ID 33336) and dulicate naming (Bug ID 33354)

git-svn-id: trunk@38450 -
This commit is contained in:
michael 2018-03-08 08:48:28 +00:00
parent 31be7eeba9
commit 6189e06708

View File

@ -288,7 +288,11 @@ type
end; end;
{ TFPReportFont }
TFPReportFont = class(TPersistent) TFPReportFont = class(TPersistent)
private
FOnChanged: TNotifyEvent;
private private
FFontName: string; FFontName: string;
FFontSize: integer; FFontSize: integer;
@ -296,6 +300,8 @@ type
procedure SetFontName(const avalue: string); procedure SetFontName(const avalue: string);
procedure SetFontSize(const avalue: integer); procedure SetFontSize(const avalue: integer);
procedure SetFontColor(const avalue: TFPReportColor); procedure SetFontColor(const avalue: TFPReportColor);
Procedure Changed;
Property OnChanged : TNotifyEvent Read FOnChanged Write FOnChanged;
public public
constructor Create; virtual; constructor Create; virtual;
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
@ -888,11 +894,12 @@ type
FKeepTogetherWithChildren: Boolean; FKeepTogetherWithChildren: Boolean;
FUseParentFont: boolean; FUseParentFont: boolean;
FVisibleOnPage: TFPReportVisibleOnPage; FVisibleOnPage: TFPReportVisibleOnPage;
FFont: TFPReportFont; FMyFont: TFPReportFont;
FIsOverflowed: Boolean; FIsOverflowed: Boolean;
FIsColumnType: Boolean; FIsColumnType: Boolean;
FBandPosition: TFPReportBandPosition; FBandPosition: TFPReportBandPosition;
function GetFont: TFPReportFont; function GetParentFont: TFPReportFont;
procedure HandleFontChange(Sender: TObject);
procedure SetBandPosition(pBandPosition: TFPReportBandPosition); virtual; procedure SetBandPosition(pBandPosition: TFPReportBandPosition); virtual;
procedure SetChildBand(AValue: TFPReportCustomChildBand); procedure SetChildBand(AValue: TFPReportCustomChildBand);
procedure ApplyStretchMode; procedure ApplyStretchMode;
@ -920,7 +927,7 @@ type
procedure BeforePrintWithChilds; virtual; procedure BeforePrintWithChilds; virtual;
procedure MovedToNextPageWithChilds; virtual; procedure MovedToNextPageWithChilds; virtual;
procedure AfterPrintWithChilds; virtual; procedure AfterPrintWithChilds; virtual;
property Font: TFPReportFont read GetFont write SetFont; property Font: TFPReportFont read FMyFont write SetFont;
property UseParentFont: boolean read FUseParentFont write SetUseParentFont; property UseParentFont: boolean read FUseParentFont write SetUseParentFont;
{ when set to True then band and child bands are keept on the same page (no page break between them) } { when set to True then band and child bands are keept on the same page (no page break between them) }
property KeepTogetherWithChildren: Boolean read FKeepTogetherWithChildren write SetKeepTogetherWithChildren default True; property KeepTogetherWithChildren: Boolean read FKeepTogetherWithChildren write SetKeepTogetherWithChildren default True;
@ -1777,7 +1784,8 @@ type
ExpressionNodes: array of TExprNodeInfoRec; ExpressionNodes: array of TExprNodeInfoRec;
FFont: TFPReportFont; FFont: TFPReportFont;
FUseParentFont: Boolean; FUseParentFont: Boolean;
function GetFont: TFPReportFont; function GetParentFont: TFPReportFont;
procedure HandleFontChange(Sender: TObject);
procedure SetText(AValue: TFPReportString); procedure SetText(AValue: TFPReportString);
procedure SetUseParentFont(AValue: Boolean); procedure SetUseParentFont(AValue: Boolean);
procedure WrapText(const AText: String; var ALines: TStrings; const ALineWidth: TFPReportUnits; out AHeight: TFPReportUnits); procedure WrapText(const AText: String; var ALines: TStrings; const ALineWidth: TFPReportUnits; out AHeight: TFPReportUnits);
@ -1812,7 +1820,7 @@ type
procedure UpdateAggregates; procedure UpdateAggregates;
function PrepareObject(aRTParent: TFPReportElement): TFPReportElement; override; function PrepareObject(aRTParent: TFPReportElement): TFPReportElement; override;
property Text: TFPReportString read FText write SetText; property Text: TFPReportString read FText write SetText;
property Font: TFPReportFont read GetFont write SetFont; property Font: TFPReportFont read FFont write SetFont;
property TextAlignment: TFPReportTextAlignment read FTextAlignment write SetTextAlignment; property TextAlignment: TFPReportTextAlignment read FTextAlignment write SetTextAlignment;
property LineSpacing: TFPReportUnits read FLineSpacing write SetLineSpacing default 1; property LineSpacing: TFPReportUnits read FLineSpacing write SetLineSpacing default 1;
property LinkColor: TFPReportColor read FLinkColor write SetLinkColor default clBlue; property LinkColor: TFPReportColor read FLinkColor write SetLinkColor default clBlue;
@ -2086,6 +2094,7 @@ type
Property BandClasses [aIndex : TFPReportBandType] : TFPReportCustomBandClass read getBandClass; Property BandClasses [aIndex : TFPReportBandType] : TFPReportCustomBandClass read getBandClass;
Property PageClass : TFPReportCustomPageClass Read FPageClass; Property PageClass : TFPReportCustomPageClass Read FPageClass;
end; end;
{ keeps track of interested bands. eg: a list of page header like bands etc. } { keeps track of interested bands. eg: a list of page header like bands etc. }
TBandList = class(TObject) TBandList = class(TObject)
private private
@ -3518,40 +3527,36 @@ begin
Changed; Changed;
end; end;
function TFPReportCustomMemo.GetFont: TFPReportFont; procedure TFPReportCustomMemo.HandleFontChange(Sender: TObject);
begin begin
if UseParentFont then FUseParentFont:=False;
begin Changed;
if Assigned(Owner) then end;
Result := TFPReportCustomBand(Owner).Font
else function TFPReportCustomMemo.GetParentFont: TFPReportFont;
begin
if not Assigned(FFont) then begin
FFont := TFPReportFont.Create; if Assigned(Band) then
Result := FFont; Result := Band.Font
end;
end
else else
begin Result:=Nil;
if not Assigned(FFont) then
FFont := TFPReportFont.Create;
Result := FFont;
end;
end; end;
procedure TFPReportCustomMemo.SetUseParentFont(AValue: Boolean); procedure TFPReportCustomMemo.SetUseParentFont(AValue: Boolean);
Var
R : TFPReportFont;
begin begin
if FUseParentFont = AValue then if FUseParentFont = AValue then
Exit; Exit;
if aValue then
begin
R:=GetParentFont;
if (R<>Nil) then
FFont.Assign(R); // Careful, will set FUseParentFont to false through OnChange handler
end;
FUseParentFont := AValue; FUseParentFont := AValue;
if FUseParentFont then
FreeAndNil(FFont)
else
begin
FFont := TFPReportFont.Create;
if Assigned(Owner) then
FFont.Assign(TFPReportCustomBand(Owner).Font);
end;
Changed; Changed;
end; end;
@ -3638,7 +3643,6 @@ begin
if ALineWidth = 0 then if ALineWidth = 0 then
Exit; Exit;
{ We are doing a PostScript Name lookup (it contains Bold, Italic info) } { We are doing a PostScript Name lookup (it contains Bold, Italic info) }
lFC := gTTFontCache.Find(Font.Name); lFC := gTTFontCache.Find(Font.Name);
if not Assigned(lFC) then if not Assigned(lFC) then
@ -4133,6 +4137,7 @@ var
lHeight: single; lHeight: single;
lDescenderHeight: single; lDescenderHeight: single;
lFC: TFPFontCacheItem; lFC: TFPFontCacheItem;
begin begin
// TODO: FontName might need to change to TextBlock.FontName. // TODO: FontName might need to change to TextBlock.FontName.
lFC := gTTFontCache.Find(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info) lFC := gTTFontCache.Find(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
@ -4386,8 +4391,7 @@ end;
procedure TFPReportCustomMemo.SetFont(const AValue: TFPReportFont); procedure TFPReportCustomMemo.SetFont(const AValue: TFPReportFont);
begin begin
if UseParentFont then UseParentFont := False;
UseParentFont := False;
FFont.Assign(AValue); FFont.Assign(AValue);
Changed; Changed;
end; end;
@ -4616,7 +4620,8 @@ begin
FOptions := []; FOptions := [];
FOriginal := nil; FOriginal := nil;
FUseParentFont := True; FUseParentFont := True;
FFont := nil FFont := TFPReportFont.Create;
FFont.OnChanged:=@HandleFontChange;
end; end;
destructor TFPReportCustomMemo.Destroy; destructor TFPReportCustomMemo.Destroy;
@ -4650,8 +4655,11 @@ begin
end; end;
procedure TFPReportCustomMemo.ReadElement(AReader: TFPReportStreamer); procedure TFPReportCustomMemo.ReadElement(AReader: TFPReportStreamer);
var var
E: TObject; E: TObject;
F : TFPReportFont;
begin begin
inherited ReadElement(AReader); inherited ReadElement(AReader);
E := AReader.FindChild('TextAlignment'); E := AReader.FindChild('TextAlignment');
@ -4665,13 +4673,19 @@ begin
end; end;
end; end;
FText := AReader.ReadString('Text', ''); FText := AReader.ReadString('Text', '');
FUseParentFont := AReader.ReadBoolean('UseParentFont', UseParentFont); UseParentFont := AReader.ReadBoolean('UseParentFont', UseParentFont);
if not FUseParentFont then if not UseParentFont then
begin begin
Font.Name := AReader.ReadString('FontName', Font.Name); Font.Name := AReader.ReadString('FontName', Font.Name);
Font.Size := AReader.ReadInteger('FontSize', Font.Size); Font.Size := AReader.ReadInteger('FontSize', Font.Size);
Font.Color := QWordToReportColor(AReader.ReadQWord('FontColor', Font.Color)); Font.Color := QWordToReportColor(AReader.ReadQWord('FontColor', Font.Color));
end; end
else
begin
F:=GetParentFont;
If Assigned(F) then
Font.Assign(F);
end;
FLineSpacing := AReader.ReadFloat('LineSpacing', LineSpacing); FLineSpacing := AReader.ReadFloat('LineSpacing', LineSpacing);
FLinkColor := QWordToReportColor(AReader.ReadQWord('LinkColor', LinkColor)); FLinkColor := QWordToReportColor(AReader.ReadQWord('LinkColor', LinkColor));
Options := StringToMemoOptions(AReader.ReadString('Options', '')); Options := StringToMemoOptions(AReader.ReadString('Options', ''));
@ -5784,7 +5798,12 @@ end;
procedure TFPReportComponent.ReadElement(AReader: TFPReportStreamer); procedure TFPReportComponent.ReadElement(AReader: TFPReportStreamer);
begin begin
Name := AReader.ReadString('Name', 'UnknownName'); try
Name := AReader.ReadString('Name', 'UnknownName');
except
On E : EComponentError do
Name:=AllocateName;
end;
end; end;
{ TFPReportRect } { TFPReportRect }
@ -6810,7 +6829,8 @@ begin
AReader.PushElement(E); // child index is the identifier AReader.PushElement(E); // child index is the identifier
try try
lName := AReader.CurrentElementName; lName := AReader.CurrentElementName;
c := gElementFactory.CreateInstance(lName, self); c := gElementFactory.CreateInstance(lName, Report);
c.Parent:=Self;
c.ReadElement(AReader); c.ReadElement(AReader);
finally finally
AReader.PopElement; AReader.PopElement;
@ -7074,17 +7094,6 @@ procedure TFPReportCustomPage.ReadElement(AReader: TFPReportStreamer);
var var
E: TObject; E: TObject;
begin begin
inherited ReadElement(AReader);
E := AReader.FindChild('Margins');
if Assigned(E) then
begin
AReader.PushElement(E);
try
FMargins.ReadElement(AReader);
finally
AReader.PopElement;
end;
end;
Orientation := StringToPaperOrientation(AReader.ReadString('Orientation', 'poPortrait')); Orientation := StringToPaperOrientation(AReader.ReadString('Orientation', 'poPortrait'));
Pagesize.PaperName := AReader.ReadString('PageSize.PaperName', 'A4'); Pagesize.PaperName := AReader.ReadString('PageSize.PaperName', 'A4');
Pagesize.Width := AReader.ReadFloat('PageSize.Width', 210); Pagesize.Width := AReader.ReadFloat('PageSize.Width', 210);
@ -7095,6 +7104,17 @@ begin
FDataName:=AReader.ReadString('Data',''); FDataName:=AReader.ReadString('Data','');
if FDataName<>'' then if FDataName<>'' then
RestoreDataFromNames; RestoreDataFromNames;
E := AReader.FindChild('Margins');
if Assigned(E) then
begin
AReader.PushElement(E);
try
FMargins.ReadElement(AReader);
finally
AReader.PopElement;
end;
end;
inherited ReadElement(AReader);
end; end;
function TFPReportCustomPage.FindBand(ABand: TFPReportBandClass): TFPReportCustomBand; function TFPReportCustomPage.FindBand(ABand: TFPReportBandClass): TFPReportCustomBand;
@ -8197,20 +8217,17 @@ begin
Result := Parent as TFPReportCustomPage; Result := Parent as TFPReportCustomPage;
end; end;
function TFPReportCustomBand.GetFont: TFPReportFont; function TFPReportCustomBand.GetParentFont: TFPReportFont;
begin begin
if UseParentFont then If Assigned(Page) then
begin Result:=Page.Font
if Assigned(Owner) then
Result := TFPReportCustomPage(Owner).Font
else
begin
FFont := TFPReportFont.Create;
Result := FFont;
end;
end
else else
Result := FFont; Result:=Nil;
end;
procedure TFPReportCustomBand.HandleFontChange(Sender: TObject);
begin
FUseParentFont:=False;
end; end;
Class function TFPCustomReport.IsStringValueZero(const AValue: string): boolean; Class function TFPCustomReport.IsStringValueZero(const AValue: string): boolean;
@ -8281,9 +8298,8 @@ end;
procedure TFPReportCustomBand.SetFont(AValue: TFPReportFont); procedure TFPReportCustomBand.SetFont(AValue: TFPReportFont);
begin begin
if UseParentFont then UseParentFont:=False;
UseParentFont := False; FMyFont.Assign(AValue);
FFont.Assign(AValue);
Changed; Changed;
end; end;
@ -8295,18 +8311,20 @@ begin
end; end;
procedure TFPReportCustomBand.SetUseParentFont(AValue: boolean); procedure TFPReportCustomBand.SetUseParentFont(AValue: boolean);
Var
F : TFPReportFont;
begin begin
if FUseParentFont = AValue then if FUseParentFont = AValue then
Exit; Exit;
if AValue then
begin
F:=GetParentFont;
if Assigned(F) then
FMyFont.Assign(F); // Will set SetUseParentFont to false in onChange
end;
FUseParentFont := AValue; FUseParentFont := AValue;
if FUseParentFont then
FreeAndNil(FFont)
else
begin
FFont := TFPReportFont.Create;
if Assigned(Owner) then
FFont.Assign(TFPReportCustomPage(Owner).Font);
end;
Changed; Changed;
end; end;
@ -8484,14 +8502,15 @@ begin
inherited Create(AOwner); inherited Create(AOwner);
FVisibleOnPage := vpAll; FVisibleOnPage := vpAll;
FUseParentFont := True; FUseParentFont := True;
FFont := nil;
FKeepTogetherWithChildren := True; FKeepTogetherWithChildren := True;
FBandPosition := bpNormal; FBandPosition := bpNormal;
FMyFont:=TFPReportFont.Create;
FMyFont.OnChanged:=@HandleFontChange;
end; end;
destructor TFPReportCustomBand.Destroy; destructor TFPReportCustomBand.Destroy;
begin begin
FreeAndNil(FFont); FreeAndNil(FMyFont);
inherited Destroy; inherited Destroy;
end; end;
@ -8520,31 +8539,39 @@ procedure TFPReportCustomBand.ReadElement(AReader: TFPReportStreamer);
var var
E: TObject; E: TObject;
s: string; s: string;
F : TFPReportFont;
begin begin
E := AReader.FindChild(GetReportBandName); E := AReader.FindChild(GetReportBandName);
if Assigned(E) then if Assigned(E) then
begin begin
AReader.PushElement(E); AReader.PushElement(E);
try try
inherited ReadElement(AReader);
s := AReader.ReadString('ChildBand', ''); s := AReader.ReadString('ChildBand', '');
if (s<>'') then if (s<>'') then
Page.Report.AddReference(Self, 'ChildBand', s); Page.Report.AddReference(Self, 'ChildBand', s);
FVisibleOnPage := StringToVisibleOnPage(AReader.ReadString('VisibleOnPage', 'vpAll')); FVisibleOnPage := StringToVisibleOnPage(AReader.ReadString('VisibleOnPage', 'vpAll'));
FKeepTogetherWithChildren := AReader.ReadBoolean('KeepTogetherWithChildren', FKeepTogetherWithChildren); FKeepTogetherWithChildren := AReader.ReadBoolean('KeepTogetherWithChildren', FKeepTogetherWithChildren);
FBandPosition := StringToBandPosition(AReader.ReadString('BandPosition', 'bpNormal')); FBandPosition := StringToBandPosition(AReader.ReadString('BandPosition', 'bpNormal'));
FUseParentFont := AReader.ReadBoolean('UseParentFont', UseParentFont); UseParentFont := AReader.ReadBoolean('UseParentFont', UseParentFont);
if not FUseParentFont then if not UseParentFont then
begin begin
Font.Name := AReader.ReadString('FontName', Font.Name); Font.Name := AReader.ReadString('FontName', Font.Name);
Font.Size := AReader.ReadInteger('FontSize', Font.Size); Font.Size := AReader.ReadInteger('FontSize', Font.Size);
Font.Color := QWordToReportColor(AReader.ReadQWord('FontColor', Font.Color)); Font.Color := QWordToReportColor(AReader.ReadQWord('FontColor', Font.Color));
end; end
else
begin
F:=GetParentFont;
if Assigned(F) then
Font.Assign(F);
end;
// TODO: Read Data information // TODO: Read Data information
S:=AReader.ReadString('Data',''); S:=AReader.ReadString('Data','');
if (S<>'') then if (S<>'') then
SetDataFromName(S); SetDataFromName(S);
// This must come last: e.g. the UseParentFont assumes the font is properly set up
inherited ReadElement(AReader);
finally finally
AReader.PopElement; AReader.PopElement;
end; end;
@ -9342,18 +9369,27 @@ end;
procedure TFPReportFont.SetFontName(const avalue: string); procedure TFPReportFont.SetFontName(const avalue: string);
begin begin
FFontName := AValue; FFontName := AValue;
Changed;
end; end;
procedure TFPReportFont.SetFontSize(const avalue: integer); procedure TFPReportFont.SetFontSize(const avalue: integer);
begin begin
Changed;
FFontSize := AValue; FFontSize := AValue;
end; end;
procedure TFPReportFont.SetFontColor(const avalue: TFPReportColor); procedure TFPReportFont.SetFontColor(const avalue: TFPReportColor);
begin begin
Changed;
FFontColor := AValue; FFontColor := AValue;
end; end;
procedure TFPReportFont.Changed;
begin
If Assigned(FOnChanged) then
FOnChanged(Self);
end;
constructor TFPReportFont.Create; constructor TFPReportFont.Create;
begin begin
inherited Create; inherited Create;
@ -9372,6 +9408,7 @@ begin
FFontName := o.Name; FFontName := o.Name;
FFontSize := o.Size; FFontSize := o.Size;
FFontColor := o.Color; FFontColor := o.Color;
Changed;
end end
else else
Inherited Assign(Source); Inherited Assign(Source);