瀏覽代碼

diff identity

Johann 6 年之前
父節點
當前提交
85fdf69583

+ 1 - 1
lazpaint/image/uimage.pas

@@ -97,7 +97,7 @@ type
     procedure OriginalChange({%H-}ASender: TObject;
       AOriginal: TBGRALayerCustomOriginal; var ADiff: TBGRAOriginalDiff);
     procedure OriginalEditingChange({%H-}ASender: TObject;
-      AOriginal: TBGRALayerCustomOriginal);
+      {%H-}AOriginal: TBGRALayerCustomOriginal);
     procedure SetBlendOperation(AIndex: integer; AValue: TBlendOperation);
     procedure SetCurrentFilenameUTF8(AValue: string);
     procedure LayeredBitmapReplaced;

+ 6 - 0
lazpaint/image/uimagediff.pas

@@ -375,6 +375,7 @@ type
     function GetImageDifferenceKind: TImageDifferenceKind; override;
     function GetChangingBounds: TRect; override;
     function GetChangingBoundsDefined: boolean; override;
+    function GetIsIdentity: boolean; override;
   public
     constructor Create({%H-}ADestination: TState; AOriginalGuid: TGuid; ADiff: TBGRAOriginalDiff; ABounds: TRect);
     destructor Destroy; override;
@@ -626,6 +627,11 @@ begin
   Result:= true;
 end;
 
+function TVectorOriginalEmbeddedDifference.GetIsIdentity: boolean;
+begin
+  Result:= FDiff.IsIdentity;
+end;
+
 constructor TVectorOriginalEmbeddedDifference.Create(ADestination: TState;
   AOriginalGuid: TGuid; ADiff: TBGRAOriginalDiff; ABounds: TRect);
 begin

+ 46 - 0
lazpaintcontrols/lcvectororiginal.pas

@@ -44,6 +44,7 @@ type
     procedure Unapply(AEndShape: TVectorShape); virtual; abstract;
     function CanAppend(ADiff: TVectorShapeDiff): boolean; virtual;
     procedure Append(ADiff: TVectorShapeDiff); virtual; abstract;
+    function IsIdentity: boolean; virtual; abstract;
   end;
   TVectorShapeDiffList = specialize TFPGList<TVectorShapeDiff>;
   TVectorShapeDiffAny = class of TVectorShapeDiff;
@@ -63,6 +64,7 @@ type
     procedure Unapply(AEndShape: TVectorShape); override;
     function CanAppend(ADiff: TVectorShapeDiff): boolean; override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TVectorShapeEmbeddedFillDiff }
@@ -80,6 +82,7 @@ type
     procedure Unapply(AEndShape: TVectorShape); override;
     function CanAppend(ADiff: TVectorShapeDiff): boolean; override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TVectorShapeCommonDiff }
@@ -100,6 +103,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TVectorShapeCommonFillDiff }
@@ -119,6 +123,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TVectorShape }
@@ -257,6 +262,7 @@ type
     procedure Unapply(AOriginal: TBGRALayerCustomOriginal); override;
     function CanAppend(ADiff: TBGRAOriginalDiff): boolean; override;
     procedure Append(ADiff: TBGRAOriginalDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TVectorOriginalShapeRangeDiff }
@@ -274,6 +280,7 @@ type
     procedure Unapply(AOriginal: TBGRALayerCustomOriginal); override;
     function CanAppend({%H-}ADiff: TBGRAOriginalDiff): boolean; override;
     procedure Append({%H-}ADiff: TBGRAOriginalDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   TVectorOriginalEditor = class;
@@ -510,6 +517,13 @@ begin
   end else FreeAndNil(FEndOutlineFill);
 end;
 
+function TVectorShapeCommonFillDiff.IsIdentity: boolean;
+begin
+  result := FStartPenFill.Equals(FEndPenFill) and
+    FStartBackFill.Equals(FEndBackFill) and
+    FStartOutlineFill.Equals(FEndOutlineFill);
+end;
+
 { TVectorOriginalShapeRangeDiff }
 
 constructor TVectorOriginalShapeRangeDiff.Create(ARangeStart: integer;
@@ -590,6 +604,11 @@ begin
   raise exception.Create('Merge not allowed');
 end;
 
+function TVectorOriginalShapeRangeDiff.IsIdentity: boolean;
+begin
+  result := false;
+end;
+
 { TVectorOriginalShapeDiff }
 
 constructor TVectorOriginalShapeDiff.Create(AShapeIndex: integer;
@@ -630,6 +649,11 @@ begin
     raise exception.Create('Merge not allowed');
 end;
 
+function TVectorOriginalShapeDiff.IsIdentity: boolean;
+begin
+  result := FShapeDiff.IsIdentity;
+end;
+
 { TVectorShapeCommonDiff }
 
 constructor TVectorShapeCommonDiff.Create(AStartShape: TVectorShape);
@@ -691,6 +715,14 @@ begin
   FEndJoinStyle:= next.FEndJoinStyle;
 end;
 
+function TVectorShapeCommonDiff.IsIdentity: boolean;
+begin
+  result := (FStartPenWidth = FEndPenWidth) and
+    PenStyleEqual(FStartPenStyle, FEndPenStyle) and
+    (FStartOutlineWidth = FEndOutlineWidth) and
+    (FStartJoinStyle = FEndJoinStyle);
+end;
+
 { TVectorShapeEmbeddedFillDiff }
 
 constructor TVectorShapeEmbeddedFillDiff.Create(AField: TVectorShapeField;
@@ -750,6 +782,11 @@ begin
   FFillDiff.Append(next.FFillDiff);
 end;
 
+function TVectorShapeEmbeddedFillDiff.IsIdentity: boolean;
+begin
+  result := FFillDiff.IsIdentity;
+end;
+
 { TVectorShapeComposedDiff }
 
 constructor TVectorShapeComposedDiff.Create(ADiffs: TVectorShapeDiffList);
@@ -847,6 +884,15 @@ begin
   end;
 end;
 
+function TVectorShapeComposedDiff.IsIdentity: boolean;
+var
+  i: Integer;
+begin
+  for i := 0 to high(FDiffs) do
+    if not FDiffs[i].IsIdentity then exit(false);
+  result := true;
+end;
+
 { TVectorOriginalEditor }
 
 constructor TVectorOriginalEditor.Create(AOriginal: TVectorOriginal);

+ 22 - 0
lazpaintcontrols/lcvectorpolyshapes.pas

@@ -47,6 +47,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TCustomPolypointShape }
@@ -370,6 +371,27 @@ begin
   FEndArrowSize := next.FEndArrowSize;
 end;
 
+function TCustomPolypointShapeDiff.IsIdentity: boolean;
+var
+  i: Integer;
+begin
+  result := (length(FStartPoints) = length(FEndPoints)) and
+    (FStartClosed = FEndClosed) and
+    (FStartArrowStartKind = FEndArrowStartKind) and
+    (FStartArrowEndKind = FEndArrowEndKind) and
+    (FStartArrowSize = FEndArrowSize);
+  if result then
+  begin
+    for i := 0 to high(FStartPoints) do
+      if (FStartPoints[i].coord<>FEndPoints[i].coord) or
+         (FStartPoints[i].data<>FEndPoints[i].data) then
+      begin
+        result := false;
+        break;
+      end;
+  end;
+end;
+
 { TCustomPolypointShape }
 
 function TCustomPolypointShape.GetClosed: boolean;

+ 18 - 0
lazpaintcontrols/lcvectorrectshapes.pas

@@ -25,6 +25,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TCustomRectShape }
@@ -136,6 +137,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TPhongShape }
@@ -240,6 +242,14 @@ begin
   FEndBorderSizePercent := next.FEndBorderSizePercent;
 end;
 
+function TPhongShapeDiff.IsIdentity: boolean;
+begin
+  result := (FStartShapeKind = FEndShapeKind) and
+    (FStartLightPosition = FEndLightPosition) and
+    (FStartShapeAltitudePercent = FEndShapeAltitudePercent) and
+    (FStartBorderSizePercent = FEndBorderSizePercent);
+end;
+
 { TCustomRectShapeDiff }
 
 constructor TCustomRectShapeDiff.Create(AStartShape: TVectorShape);
@@ -301,6 +311,14 @@ begin
   FEndFixedRatio := next.FEndFixedRatio;
 end;
 
+function TCustomRectShapeDiff.IsIdentity: boolean;
+begin
+  result := (FStartOrigin = FEndOrigin) and
+  (FStartXAxis = FEndXAxis) and
+  (FStartYAxis = FEndYAxis) and
+  (FStartFixedRatio = FEndFixedRatio);
+end;
+
 { TCustomRectShape }
 
 procedure TCustomRectShape.SetOrigin(AValue: TPointF);

+ 38 - 0
lazpaintcontrols/lcvectortextshapes.pas

@@ -32,6 +32,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TTextShapePhongDiff }
@@ -50,6 +51,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TTextShapeTextDiff }
@@ -70,6 +72,7 @@ type
     procedure Apply(AStartShape: TVectorShape); override;
     procedure Unapply(AEndShape: TVectorShape); override;
     procedure Append(ADiff: TVectorShapeDiff); override;
+    function IsIdentity: boolean; override;
   end;
 
   { TTextShape }
@@ -321,6 +324,26 @@ begin
     FParaAlignAfter[i] := next.FParaAlignAfter[i];
 end;
 
+function TTextShapeTextDiff.IsIdentity: boolean;
+var
+  i: Integer;
+begin
+  result := (FTextBefore = FTextAfter) and
+    (FSelStartBefore = FSelStartAfter) and
+    (FSelEndBefore = FSelEndAfter) and
+    (FVertAlignBefore = FVertAlignAfter) and
+    (length(FParaAlignBefore) = length(FParaAlignAfter));
+  if result then
+  begin
+    for i := 0 to high(FParaAlignBefore) do
+      if FParaAlignBefore[i] <> FParaAlignAfter[i] then
+      begin
+        result := false;
+        break;
+      end;
+  end;
+end;
+
 { TTextShapePhongDiff }
 
 constructor TTextShapePhongDiff.Create(AStartShape: TVectorShape);
@@ -377,6 +400,13 @@ begin
   FLightPositionAfter:= next.FLightPositionAfter;
 end;
 
+function TTextShapePhongDiff.IsIdentity: boolean;
+begin
+  result := (FAltitudePercentBefore = FAltitudePercentAfter) and
+    (FPenPhongBefore = FPenPhongAfter) and
+    (FLightPositionBefore = FLightPositionAfter);
+end;
+
 { TTextShapeFontDiff }
 
 constructor TTextShapeFontDiff.Create(AStartShape: TVectorShape);
@@ -440,6 +470,14 @@ begin
   FFontStyleAfter := next.FFontStyleAfter;
 end;
 
+function TTextShapeFontDiff.IsIdentity: boolean;
+begin
+  result := (FFontBidiModeBefore = FFontBidiModeAfter) and
+    (FFontEmHeightBefore = FFontEmHeightAfter) and
+    (FFontNameBefore = FFontNameAfter) and
+    (FFontStyleBefore = FFontStyleAfter);
+end;
+
 { TTextShape }
 
 procedure TTextShape.SetText(AValue: string);