Improvement of DoCopyProps routines in fcl-image package
by 'lagprogramming'.
I think DoCopyProps routines in the the fcl-image package have bugs. I added comments to routines, the first routine is the original and the second is the modified one.
procedure TFPCustomFont.DoCopyProps (From:TFPCanvasHelper);
ignores Orientation.
procedure TFPCustomFont.DoCopyProps (From:TFPCanvasHelper);
begin
with from as TFPCustomFont do
begin
self.FName := FName;
self.FSize := FSize;
self.FFPColor := FFPColor;//Replaced by using inherited
self.FFlags := FFlags;//Replaced by using inherited
end;
end;
->
procedure TFPCustomFont.DoCopyProps (From:TFPCanvasHelper);
begin
with from as TFPCustomFont do
begin
self.FName := FName;
self.FOrientation := FOrientation;//Added Orientation
self.FSize := FSize;
end;
inherited DoCopyProps(From);//Added inherited
end;
procedure TFPCustomPen.DoCopyProps (From:TFPCanvasHelper);
ignores EndCap and JoinStyle.
procedure TFPCustomPen.DoCopyProps (From:TFPCanvasHelper);
begin
with From as TFPCustomPen do
begin
self.Style := Style;
self.Width := Width;
self.Mode := Mode;
self.pattern := pattern;
end;
inherited;
end;
->
procedure TFPCustomPen.DoCopyProps (From:TFPCanvasHelper);
begin
with From as TFPCustomPen do
begin
self.Style := Style;
self.Width := Width;
self.Mode := Mode;
self.Pattern := Pattern;
self.EndCap := EndCap;//Added EndCap
self.JoinStyle := JoinStyle;//Added JoinStyle
end;
inherited DoCopyProps(From);
end;
procedure TFPCustomBrush.DoCopyProps (From:TFPCanvasHelper);
ignores Pattern.
procedure TFPCustomBrush.DoCopyProps (From:TFPCanvasHelper);
begin
with From as TFPCustomBrush do
begin
self.Style := Style;
self.Image := Image;
end;
inherited DoCopyProps(From);
end;
->
procedure TFPCustomBrush.DoCopyProps (From:TFPCanvasHelper);
begin
with From as TFPCustomBrush do
begin
self.Style := Style;
self.Image := Image;
self.Pattern := Copy(Pattern, low(Pattern) ,Length(Pattern));//Added Pattern. Copy, not just assign it, in order to make sure it has a single reference.
end;
inherited DoCopyProps(From);
end;
1/2 TFPCustomFont.DoCopyProps uses variable names while TFPCustomPen.DoCopyProps and TFPCustomBrush.DoCopyProps use property names. They should look alike. Either all of them use property names, either all of them use private variables names.
2/2 In procedure TFPCustomFont.DoCopyProps lines self.FFPColor := FFPColor; and self.FFlags := FFlags; have been replaced with inherited DoCopyProps(From); The problem is that procedure TFPCanvasHelper.DoCopyProps needs to be modified too, and it has no property declared to access variable FFlags, but has two protected routines:
procedure SetFlags (index:integer; AValue:boolean); virtual;
function GetFlags (index:integer) : boolean; virtual;
Private variable FFlags is word and these routines use booleans. Regarding DoCopyProps, I think a FPC developer should look at TFPCanvasHelper code because in addition to FFlags and FFPColor, it has other private variables that may need to be copied.
procedure TFPCanvasHelper.DoCopyProps (From:TFPCanvasHelper);
ignores everything except for FPColor.
procedure TFPCanvasHelper.DoCopyProps (From:TFPCanvasHelper);
begin
FPColor := from.FPColor;
end;