Преглед изворни кода

lcl+skia: fixed free fonts

mattias пре 1 година
родитељ
комит
936bd5d3d4

+ 16 - 0
src/base/fresnel.dom.pas

@@ -516,6 +516,7 @@ type
     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
     procedure SetParentComponent(Value: TComponent); override;
     procedure ChildDestroying(El: TFresnelElement); virtual;
+    procedure ViewportDisconnecting(aViewport: TFresnelViewport); virtual;
     procedure DoRender({%H-}aRenderer: IFresnelRenderer); virtual;
     { IFResnelRenderable }
     Procedure BeforeRender;
@@ -698,6 +699,7 @@ type
     procedure ApplyCSS; virtual;
     procedure ClearCSSValues; override;
     procedure DomChanged; override;
+    procedure Disconnecting; virtual;
     function AllocateFont(const Desc: TFresnelFontDesc): IFresnelFont; virtual;
     function GetCSSInitialAttribute(const AttrID: TCSSNumericalID): TCSSString; override;
     function GetElementAt(const x, y: TFresnelLength): TFresnelElement; virtual;
@@ -1366,6 +1368,11 @@ begin
     OnDomChanged(Self);
 end;
 
+procedure TFresnelViewport.Disconnecting;
+begin
+  ViewportDisconnecting(Self);
+end;
+
 function TFresnelViewport.AllocateFont(const Desc: TFresnelFontDesc
   ): IFresnelFont;
 begin
@@ -3887,6 +3894,15 @@ begin
     FParent.ChildDestroying(El);
 end;
 
+procedure TFresnelElement.ViewportDisconnecting(aViewport: TFresnelViewport);
+var
+  i: Integer;
+begin
+  for i:=0 to NodeCount-1 do
+    Nodes[i].ViewportDisconnecting(aViewport);
+  FFont:=nil;
+end;
+
 procedure TFresnelElement.DoRender(aRenderer: IFresnelRenderer);
 begin
   //

+ 10 - 3
src/base/fresnel.forms.pas

@@ -453,7 +453,11 @@ end;
 procedure TFresnelCustomForm.SetWSForm(const AValue: TFresnelWSForm);
 begin
   if FWSForm=AValue then exit;
-  FreeAndNil(FWSForm);
+  if FWSForm<>nil then
+  begin
+    Disconnecting;
+    FreeAndNil(FWSForm);
+  end;
   FWSForm:=AValue;
   if FWSForm<>nil then
     FreeNotification(FWSForm);
@@ -465,10 +469,13 @@ begin
   inherited Notification(AComponent, Operation);
   if Operation=opRemove then
   begin
-    if FWSForm=AComponent then
-      FWSForm:=nil;
     if fMouseDownElement=AComponent then
       fMouseDownElement:=nil;
+    if FWSForm=AComponent then
+    begin
+      Disconnecting;
+      FWSForm:=nil;
+    end;
   end;
 end;
 

+ 1 - 1
src/lcl/fresnel.lcl.pas

@@ -492,7 +492,7 @@ begin
   FLCLForm.OnPaint:=@LCLPaint;
 
   // resize lcl form
-  LCLForm.BoundsRect:=FresnelForm.FormBounds.GetRect;
+  FLCLForm.BoundsRect:=FresnelForm.FormBounds.GetRect;
 end;
 
 { TFresnelLCLWidgetSet }

+ 17 - 2
src/lcl/fresnellcl.lpk

@@ -6,6 +6,7 @@
     <CompilerOptions>
       <Version Value="11"/>
       <SearchPaths>
+        <OtherUnitFiles Value="../skia;../skia/skia4delphi"/>
         <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
       </SearchPaths>
       <Conditionals Value="// FresnelRenderer
@@ -15,7 +16,6 @@ end;
 
 if FresnelLCLRenderer=&apos;skia&apos; then begin
   CustomOptions += &apos; -dFresnelSkia&apos;;
-  UnitPath += &apos;;../skia;../skia/skia4delphi&apos;;
 end;
 
 // linker options
@@ -40,7 +40,7 @@ end;"/>
     <License Value="Same as LCL.
 Modified LGPL-2."/>
     <Version Minor="3"/>
-    <Files Count="5">
+    <Files Count="8">
       <Item1>
         <Filename Value="fresnel.lcl.pas"/>
         <UnitName Value="Fresnel.LCL"/>
@@ -61,6 +61,21 @@ Modified LGPL-2."/>
         <Filename Value="fresnel.lclevents.pas"/>
         <UnitName Value="fresnel.lclevents"/>
       </Item5>
+      <Item6>
+        <Filename Value="../skia/fresnel.skiarenderer.pas"/>
+        <AddToUsesPkgSection Value="False"/>
+        <UnitName Value="Fresnel.SkiaRenderer"/>
+      </Item6>
+      <Item7>
+        <Filename Value="../skia/skia4delphi/System.Skia.API.pas"/>
+        <AddToUsesPkgSection Value="False"/>
+        <UnitName Value="System.Skia.API"/>
+      </Item7>
+      <Item8>
+        <Filename Value="../skia/skia4delphi/System.Skia.pas"/>
+        <AddToUsesPkgSection Value="False"/>
+        <UnitName Value="System.Skia"/>
+      </Item8>
     </Files>
     <CompatibilityMode Value="True"/>
     <RequiredPkgs Count="2">

+ 4 - 1
src/skia/fresnel.skiarenderer.pas

@@ -224,7 +224,7 @@ procedure TFresnelSkiaFont.SetTypeFace(const AValue: TFresnelSkiaTypeFace);
 begin
   if FTypeFace=AValue then Exit;
   if FTypeFace<>nil then
-    FTypeFace.Release;
+    FTypeFace.Release; // this might free FTypeFace
   FTypeFace:=AValue;
   if FTypeFace<>nil then
     FTypeFace.AddRef;
@@ -313,6 +313,8 @@ begin
   begin
     aFont:=TFresnelSkiaFont(Node.Data);
     Node.Data:=nil;
+    if aFont.RefCount>1 then
+      raise Exception.Create('TFresnelSkiaFontEngine.Destroy RefCount='+IntToStr(aFont.RefCount)+' '+aFont.GetDescription);
     aFont._Release;
     Node:=Node.Successor;
   end;
@@ -367,6 +369,7 @@ begin
   if aTypeFace=nil then
   begin
     aTypeFace:=TFresnelSkiaTypeFace.Create;
+    aTypeFace.Engine:=Self;
     aTypeFace.CSSFamily:=Desc.Family;
     aTypeFace.CSSKerning:=Desc.Kerning;
     aTypeFace.CSSStyle:=Desc.Style;