Jelajahi Sumber

fresnel: parsing font-variant-* attributes

mattias 6 bulan lalu
induk
melakukan
c532e58656

File diff ditekan karena terlalu besar
+ 701 - 53
src/base/fresnel.dom.pas


+ 42 - 12
src/lcl/fresnel.lcl.pas

@@ -40,16 +40,21 @@ type
     Kerning: TFresnelCSSKerning;
     Size: TFresnelLength;
     Style: string;
-    Variant_: string;
     Weight: TFresnelLength;
     Width: TFresnelLength;
     LCLFont: TFont;
     destructor Destroy; override;
+    function GetAlternates: string;
+    function GetCaps: TFresnelCSSFontVarCaps;
+    function GetEastAsians: TFresnelCSSFontVarEastAsians;
+    function GetEmoji: TFresnelCSSFontVarEmoji;
     function GetFamily: string;
     function GetKerning: TFresnelCSSKerning;
+    function GetLigatures: TFresnelCSSFontVarLigaturesSet;
+    function GetNumerics: TFresnelCSSFontVarNumerics;
+    function GetPosition: TFresnelCSSFontVarPosition;
     function GetSize: TFresnelLength;
     function GetStyle: string;
-    function GetVariant: string;
     function GetWeight: TFresnelLength;
     function GetWidth: TFresnelLength;
     function TextSize(const aText: string): TFresnelPoint; virtual;
@@ -191,8 +196,6 @@ begin
   if Result<>0 then exit;
   Result:=CompareText(Font1.Style,Font2.Style);
   if Result<>0 then exit;
-  Result:=CompareText(Font1.Variant_,Font2.Variant_);
-  if Result<>0 then exit;
   Result:=CompareValue(Font1.Weight,Font2.Weight);
   if Result<>0 then exit;
   Result:=CompareValue(Font1.Width,Font2.Width);
@@ -215,8 +218,6 @@ begin
   if Result<>0 then exit;
   Result:=CompareValue(Desc^.Width,aFont.Width);
   if Result<>0 then exit;
-  Result:=CompareText(Desc^.Variant_,aFont.Variant_);
-  if Result<>0 then exit;
   Result:=CompareValue(ord(Desc^.Kerning),ord(aFont.Kerning));
 end;
 
@@ -784,7 +785,6 @@ begin
   aFont.Kerning:=Desc.Kerning;
   aFont.Size:=Desc.Size;
   aFont.Style:=Desc.Style;
-  aFont.Variant_:=Desc.Variant_;
   aFont.Weight:=Desc.Weight;
   aFont.Width:=Desc.Width;
   FFonts.Add(aFont);
@@ -868,6 +868,26 @@ begin
   inherited Destroy;
 end;
 
+function TFresnelLCLFont.GetAlternates: string;
+begin
+  Result:='normal';
+end;
+
+function TFresnelLCLFont.GetCaps: TFresnelCSSFontVarCaps;
+begin
+  Result:=ffvcNormal;
+end;
+
+function TFresnelLCLFont.GetEastAsians: TFresnelCSSFontVarEastAsians;
+begin
+  Result:=[ffveaNormal];
+end;
+
+function TFresnelLCLFont.GetEmoji: TFresnelCSSFontVarEmoji;
+begin
+  Result:=ffveNormal;
+end;
+
 function TFresnelLCLFont.GetFamily: string;
 begin
   Result:=Family;
@@ -878,6 +898,21 @@ begin
   Result:=Kerning;
 end;
 
+function TFresnelLCLFont.GetLigatures: TFresnelCSSFontVarLigaturesSet;
+begin
+  Result:=[ffvlNormal];
+end;
+
+function TFresnelLCLFont.GetNumerics: TFresnelCSSFontVarNumerics;
+begin
+  Result:=[ffvnNormal];
+end;
+
+function TFresnelLCLFont.GetPosition: TFresnelCSSFontVarPosition;
+begin
+  Result:=ffvpNormal;
+end;
+
 function TFresnelLCLFont.GetSize: TFresnelLength;
 begin
   Result:=Size;
@@ -888,11 +923,6 @@ begin
   Result:=Style;
 end;
 
-function TFresnelLCLFont.GetVariant: string;
-begin
-  Result:=Variant_;
-end;
-
 function TFresnelLCLFont.GetWeight: TFresnelLength;
 begin
   Result:=Weight;

+ 32 - 124
src/lcl/fresnel.lclcontrols.pas

@@ -10,6 +10,15 @@ uses
 
 type
 
+  { TFresnelLCLCtlViewport }
+
+  TFresnelLCLCtlViewport = class(TFresnelViewport)
+  protected
+    FIsDrawing: boolean;
+  public
+    function IsDrawing: boolean; override;
+  end;
+
   { TFresnelLCLControl }
 
   TFresnelLCLControl = class(TCustomControl)
@@ -19,7 +28,7 @@ type
     FLayouter: TViewportLayouter;
     FLayoutQueued: boolean;
     FRenderer: TFresnelLCLRenderer;
-    FViewport: TFresnelViewport;
+    FViewport: TFresnelLCLCtlViewport;
     FLCLEvents: TFresnelLCLEventControl;
     procedure OnDomChanged(Sender: TObject);
     procedure OnQueuedLayout({%H-}Data: PtrInt);
@@ -31,7 +40,7 @@ type
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
-    property Viewport: TFresnelViewport read FViewport;
+    property Viewport: TFresnelLCLCtlViewport read FViewport;
     property Layouter: TViewportLayouter read FLayouter;
     property FontEngine: TFresnelLCLFontEngine read FFontEngine;
     property Renderer: TFresnelLCLRenderer read FRenderer;
@@ -42,6 +51,13 @@ implementation
 
 uses Dialogs;
 
+{ TFresnelLCLCtlViewport }
+
+function TFresnelLCLCtlViewport.IsDrawing: boolean;
+begin
+  Result:=FIsDrawing;
+end;
+
 { TFresnelLCLControl }
 
 procedure TFresnelLCLControl.SetLayoutQueued(const AValue: boolean);
@@ -84,15 +100,26 @@ end;
 
 procedure TFresnelLCLControl.Paint;
 begin
-  inherited Paint;
+  if Viewport.FIsDrawing then
+    raise Exception.Create('20250303212620 already drawing');
+  Viewport.FIsDrawing:=true;
+  try
+    inherited Paint;
 
-  Renderer.Draw(Viewport);
+    if Viewport.DomModified then
+    begin
+      Viewport.ApplyCSS;
+    end;
+    Renderer.Draw(Viewport);
+  finally
+    Viewport.FIsDrawing:=false;
+  end;
 end;
 
 constructor TFresnelLCLControl.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
-  FViewport:=TFresnelViewport.Create(nil);
+  FViewport:=TFresnelLCLCtlViewport.Create(nil);
   FViewport.OnDomChanged:=@OnDomChanged;
   FFontEngine:=TFresnelLCLFontEngine.Create(nil);
   FViewport.FontEngine:=FontEngine;
@@ -117,124 +144,5 @@ begin
   inherited Destroy;
 end;
 
-{ TOldFresnelCustomForm }
-(*
-function TOldFresnelCustomForm.GetStylesheet: TStrings;
-begin
-  Result:=Viewport.Stylesheet;
-end;
-
-procedure TOldFresnelCustomForm.OnDomChanged(Sender: TObject);
-begin
-  LayoutQueued:=true;
-end;
-
-procedure TOldFresnelCustomForm.OnQueuedLayout(Data: PtrInt);
-begin
-  ViewPort.ApplyCSS;
-  //Layouter.WriteLayoutTree;
-  Layouter.Apply(ViewPort);
-  Invalidate;
-end;
-
-procedure TOldFresnelCustomForm.SetLayoutQueued(const AValue: boolean);
-begin
-  if FLayoutQueued=AValue then Exit;
-  if FClearing then exit;
-  if csDestroyingHandle in ControlState then exit;
-  if csDestroying in ComponentState then exit;
-  FLayoutQueued:=AValue;
-  if FLayoutQueued then
-    Application.QueueAsyncCall(@OnQueuedLayout,0);
-end;
-
-procedure TOldFresnelCustomForm.SetStylesheet(const AValue: TStrings);
-begin
-  Viewport.Stylesheet:=AValue;
-end;
-
-procedure TOldFresnelCustomForm.Notification(AComponent: TComponent;
-  Operation: TOperation);
-begin
-  inherited Notification(AComponent, Operation);
-  if Operation=opRemove then
-  begin
-    if AComponent=FViewport then
-      FViewport:=nil;
-    if AComponent=FFontEngine then
-      FFontEngine:=nil;
-    if AComponent=FLayouter then
-    begin
-      FLayouter:=nil;
-      if FViewport<>nil then
-        FViewport.Layouter:=nil;
-    end;
-    if AComponent=FRenderer then
-      FRenderer:=nil;
-  end;
-end;
-
-procedure TOldFresnelCustomForm.Paint;
-begin
-  inherited Paint;
-  Renderer.Draw(Viewport);
-end;
-
-function TOldFresnelCustomForm.GetViewport: TFresnelViewport;
-begin
-  Result:=FViewport;
-end;
-
-constructor TOldFresnelCustomForm.Create(AOwner: TComponent);
-begin
-  inherited Create(AOwner);
-  FViewport:=TFresnelViewport.Create(nil);
-  FViewport.Name:='Viewport';
-  FViewport.OnDomChanged:=@OnDomChanged;
-  FFontEngine:=TFresnelLCLFontEngine.Create(nil);
-  FViewport.FontEngine:=FontEngine;
-  FontEngine.Canvas:=Canvas;
-  FLayouter:=TSimpleFresnelLayouter.Create(nil);
-  Layouter.Viewport:=ViewPort;
-  FRenderer:=TFresnelLCLRenderer.Create(nil);
-  FRenderer.Canvas:=Canvas;
-end;
-
-destructor TOldFresnelCustomForm.Destroy;
-begin
-  FClearing:=true;
-  FreeAndNil(FRenderer);
-  FreeAndNil(FLayouter);
-  FreeAndNil(FViewport);
-  FreeAndNil(FFontEngine);
-  Application.RemoveAllHandlersOfObject(Self);
-  inherited Destroy;
-end;
-
-procedure TOldFresnelCustomForm.GetChildren(Proc: TGetChildProc; Root: TComponent);
-var
-  i: Integer;
-  OwnedComponent: TComponent;
-  ChildEl: TFresnelElement;
-begin
-  if Root=Self then
-  begin
-    // first all children of Viewport
-    for i:=0 to Viewport.NodeCount-1 do
-    begin
-      ChildEl:=Viewport.Nodes[i];
-      if ChildEl.Owner=Root then
-        Proc(ChildEl);
-    end;
-    // then all non visual components
-    for i := 0 to ComponentCount - 1 do
-    begin
-      OwnedComponent := Components[i];
-      if not OwnedComponent.HasParent then
-        Proc(OwnedComponent);
-    end;
-  end;
-end;
-   *)
 end.
 

+ 42 - 12
src/skia/fresnel.skiarenderer.pas

@@ -49,7 +49,6 @@ type
     CSSFamily: string;
     CSSKerning: TFresnelCSSKerning;
     CSSStyle: string;
-    CSSVariant_: string;
     CSSWeight: TFresnelLength;
     procedure AddRef;
     procedure Release;
@@ -69,11 +68,17 @@ type
     CSSSize: TFresnelLength;
     CSSWidth: TFresnelLength;
     destructor Destroy; override;
+    function GetAlternates: string;
+    function GetCaps: TFresnelCSSFontVarCaps;
+    function GetEastAsians: TFresnelCSSFontVarEastAsians;
+    function GetEmoji: TFresnelCSSFontVarEmoji;
     function GetFamily: string;
     function GetKerning: TFresnelCSSKerning;
+    function GetLigatures: TFresnelCSSFontVarLigaturesSet;
+    function GetNumerics: TFresnelCSSFontVarNumerics;
+    function GetPosition: TFresnelCSSFontVarPosition;
     function GetSize: TFresnelLength;
     function GetStyle: string;
-    function GetVariant: string;
     function GetWeight: TFresnelLength;
     function GetWidth: TFresnelLength;
     function TextSize(const aText: string): TFresnelPoint; virtual;
@@ -202,8 +207,6 @@ begin
   if Result<>0 then exit;
   Result:=CompareText(Face1.CSSStyle,Face2.CSSStyle);
   if Result<>0 then exit;
-  Result:=CompareText(Face1.CSSVariant_,Face2.CSSVariant_);
-  if Result<>0 then exit;
   Result:=CompareValue(Face1.CSSWeight,Face2.CSSWeight);
 end;
 
@@ -229,8 +232,6 @@ begin
   Result:=CompareText(Desc^.Style,Face.CSSStyle);
   if Result<>0 then exit;
   Result:=CompareValue(Desc^.Weight,Face.CSSWeight);
-  if Result<>0 then exit;
-  Result:=CompareText(Desc^.Variant_,Face.CSSVariant_);
 end;
 
 { TFresnelSkiaTypeFace }
@@ -267,6 +268,26 @@ begin
   inherited Destroy;
 end;
 
+function TFresnelSkiaFont.GetAlternates: string;
+begin
+  Result:='normal';
+end;
+
+function TFresnelSkiaFont.GetCaps: TFresnelCSSFontVarCaps;
+begin
+  Result:=ffvcNormal;
+end;
+
+function TFresnelSkiaFont.GetEastAsians: TFresnelCSSFontVarEastAsians;
+begin
+  Result:=[ffveaNormal];
+end;
+
+function TFresnelSkiaFont.GetEmoji: TFresnelCSSFontVarEmoji;
+begin
+  Result:=ffveNormal;
+end;
+
 function TFresnelSkiaFont.GetFamily: string;
 begin
   Result:=TypeFace.CSSFamily;
@@ -277,6 +298,21 @@ begin
   Result:=Typeface.CSSKerning;
 end;
 
+function TFresnelSkiaFont.GetLigatures: TFresnelCSSFontVarLigaturesSet;
+begin
+  Result:=[ffvlNormal];
+end;
+
+function TFresnelSkiaFont.GetNumerics: TFresnelCSSFontVarNumerics;
+begin
+  Result:=[ffvnNormal];
+end;
+
+function TFresnelSkiaFont.GetPosition: TFresnelCSSFontVarPosition;
+begin
+  Result:=ffvpNormal;
+end;
+
 function TFresnelSkiaFont.GetSize: TFresnelLength;
 begin
   Result:=CSSSize;
@@ -287,11 +323,6 @@ begin
   Result:=TypeFace.CSSStyle;
 end;
 
-function TFresnelSkiaFont.GetVariant: string;
-begin
-  Result:=TypeFace.CSSVariant_;
-end;
-
 function TFresnelSkiaFont.GetWeight: TFresnelLength;
 begin
   Result:=TypeFace.CSSWeight;
@@ -409,7 +440,6 @@ begin
     aTypeFace.CSSFamily:=Desc.Family;
     aTypeFace.CSSKerning:=Desc.Kerning;
     aTypeFace.CSSStyle:=Desc.Style;
-    aTypeFace.CSSVariant_:=Desc.Variant_;
     aTypeFace.CSSWeight:=Desc.Weight;
     FTypeFaces.Add(aTypeFace);
 

+ 42 - 12
src/wasm/fresnel.wasm.font.pp

@@ -36,14 +36,19 @@ Type
     Kerning: TFresnelCSSKerning;
     Size: double;
     Style: string;
-    Variant_: string;
     Weight: double;
     Width: double;
+    function GetAlternates: string;
+    function GetCaps: TFresnelCSSFontVarCaps;
+    function GetEastAsians: TFresnelCSSFontVarEastAsians;
+    function GetEmoji: TFresnelCSSFontVarEmoji;
     function GetFamily: string;
     function GetKerning: TFresnelCSSKerning;
+    function GetLigatures: TFresnelCSSFontVarLigaturesSet;
+    function GetNumerics: TFresnelCSSFontVarNumerics;
+    function GetPosition: TFresnelCSSFontVarPosition;
     function GetSize: TFresnelLength;
     function GetStyle: string;
-    function GetVariant: string;
     function GetWeight: TFresnelLength;
     function GetWidth: TFresnelLength;
     function TextSize(const aText: string): TFresnelPoint; virtual;
@@ -88,8 +93,6 @@ begin
   if Result<>0 then exit;
   Result:=CompareValue(Font1.Width,Font2.Width);
   if Result<>0 then exit;
-  Result:=CompareText(Font1.Variant_,Font2.Variant_);
-  if Result<>0 then exit;
   Result:=CompareValue(ord(Font1.Kerning),ord(Font2.Kerning));
 end;
 
@@ -112,8 +115,6 @@ begin
   if Result<>0 then exit;
   Result:=CompareValue(Desc^.Width,aFont.Width);
   if Result<>0 then exit;
-  Result:=CompareText(Desc^.Variant_,aFont.Variant_);
-  if Result<>0 then exit;
   Result:=CompareValue(ord(Desc^.Kerning),ord(aFont.Kerning));
 end;
 
@@ -126,11 +127,46 @@ begin
   Result:=Family;
 end;
 
+function TFresnelWasmFont.GetAlternates: string;
+begin
+  Result:='normal';
+end;
+
+function TFresnelWasmFont.GetCaps: TFresnelCSSFontVarCaps;
+begin
+  Result:=ffvcNormal;
+end;
+
+function TFresnelWasmFont.GetEastAsians: TFresnelCSSFontVarEastAsians;
+begin
+  Result:=[ffveaNormal];
+end;
+
+function TFresnelWasmFont.GetEmoji: TFresnelCSSFontVarEmoji;
+begin
+  Result:=ffveNormal;
+end;
+
 function TFresnelWasmFont.GetKerning: TFresnelCSSKerning;
 begin
   Result:=Kerning;
 end;
 
+function TFresnelWasmFont.GetLigatures: TFresnelCSSFontVarLigaturesSet;
+begin
+  Result:=[ffvlNormal];
+end;
+
+function TFresnelWasmFont.GetNumerics: TFresnelCSSFontVarNumerics;
+begin
+  Result:=[ffvnNormal];
+end;
+
+function TFresnelWasmFont.GetPosition: TFresnelCSSFontVarPosition;
+begin
+  Result:=ffvpNormal;
+end;
+
 function TFresnelWasmFont.GetSize: TFresnelLength;
 begin
   Result:=Size;
@@ -141,11 +177,6 @@ begin
   Result:=Style;
 end;
 
-function TFresnelWasmFont.GetVariant: string;
-begin
-  Result:=Variant_;
-end;
-
 function TFresnelWasmFont.GetWeight: TFresnelLength;
 begin
   Result:=Weight;
@@ -237,7 +268,6 @@ begin
   aFont.Kerning:=Desc.Kerning;
   aFont.Size:=Desc.Size;
   aFont.Style:=Desc.Style;
-  aFont.Variant_:=Desc.Variant_;
   aFont.Weight:=Desc.Weight;
   aFont.Width:=Desc.Width;
   FFonts.Add(aFont);

+ 1 - 0
tests/exploration/skia/.gitignore

@@ -1 +1,2 @@
 SkiaCmdLine1
+SkiaFont1

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini