소스 검색

fixed place absolute nodes

mattias 1 년 전
부모
커밋
59f79c81dc
7개의 변경된 파일66개의 추가작업 그리고 38개의 파일을 삭제
  1. 14 14
      demo/Slider/MainUnit.lfm
  2. 3 1
      demo/Slider/MainUnit.pas
  3. 1 1
      src/base/fresnel.classes.pas
  4. 9 5
      src/base/fresnel.dom.pas
  5. 13 10
      src/base/fresnel.layouter.pas
  6. 5 2
      src/base/fresnel.renderer.pas
  7. 21 5
      src/skia/fresnel.skiarenderer.pas

+ 14 - 14
demo/Slider/MainUnit.lfm

@@ -6,36 +6,36 @@ object FresnelSliderForm: TFresnelSliderForm
   FormHeight = 240
   OnCreate = FresnelSliderFormCreate
   object Div1: TDiv
-    object SliderDiv: TDiv
+    object CaptionDiv: TDiv
       CSSClasses.Strings = (
-        'Slider'
+        'SliderCaptionDiv'
       )
-      object SliderRangeDiv: TDiv
+      object CaptionLabel: TLabel
         CSSClasses.Strings = (
-          'SliderRange'
+          'SliderLabel'
         )
+        Caption = 'Caption'
       end
-      object SliderPointDiv: TDiv
+      object ValueLabel: TLabel
         CSSClasses.Strings = (
-          'SliderPoint'
+          'SliderValue'
         )
+        Caption = 'Value'
       end
     end
-    object CaptionDiv: TDiv
+    object SliderDiv: TDiv
       CSSClasses.Strings = (
-        'SliderCaptionDiv'
+        'Slider'
       )
-      object CaptionLabel: TLabel
+      object SliderRangeDiv: TDiv
         CSSClasses.Strings = (
-          'SliderLabel'
+          'SliderRange'
         )
-        Caption = 'Caption'
       end
-      object ValueLabel: TLabel
+      object SliderPointDiv: TDiv
         CSSClasses.Strings = (
-          'SliderValue'
+          'SliderPoint'
         )
-        Caption = 'Value'
       end
     end
   end

+ 3 - 1
demo/Slider/MainUnit.pas

@@ -52,8 +52,8 @@ begin
     +'  color: #f66020;'
     +'}'
     +'.Slider {'
-    +'  display: none;' // testing
     +'  margin: 15px 0 5px;'
+    +'  position: relative;'
     +'  border: 1px solid #5080e0;'
     +'  background-color: #b6d6f0;'
     +'  height: 9px;'
@@ -84,6 +84,8 @@ begin
     +'}'
     ;
   Div1.Style:='width: 150px';
+  SliderRangeDiv.Style:='width: 50%;';
+  SliderPointDiv.Style:='left: 50%;';
 end;
 
 end.

+ 1 - 1
src/base/fresnel.classes.pas

@@ -552,7 +552,7 @@ end;
 
 function TFresnelRect.ToString: string;
 begin
-  Result:=Format('Rect[(%gx%g),(%gx%g)',[Left,Top,Right,Bottom]);
+  Result:=Format('Rect[%g,%g,r=%g,b=%g]',[Left,Top,Right,Bottom]);
 end;
 
 function TFresnelRect.GetHeight: TFresnelLength;

+ 9 - 5
src/base/fresnel.dom.pas

@@ -2911,13 +2911,17 @@ begin
       end;
       inc(p);
     end;
-    if not (p^ in ['0'..'9']) then
-    begin
+    case p^ of
+    '.': ;
+    '0'..'9':
+      begin
+        inc(p);
+        while p^ in ['0'..'9'] do inc(p);
+      end;
+    else
       Invalid(20221016220901);
       exit;
     end;
-    inc(p);
-    while p^ in ['0'..'9'] do inc(p);
     if p^='.' then
     begin
       // float
@@ -4014,7 +4018,7 @@ begin
     fcaLeft,
     fcaTop,
     fcaRight,
-    fcaBottom,
+    fcaBottom: Result:=CheckCSSLength(Attr,s);
     fcaWidth,
     fcaHeight: Result:=CheckCSSLength(Attr,s,[flcNoNegative]);
     fcaBorder: Result:=CheckOrSetCSSBorder(s,true);

+ 13 - 10
src/base/fresnel.layouter.pas

@@ -306,7 +306,7 @@ begin
     ChildEl:=ChildNode.Element;
 
     ChildTop:=FLineBorderBoxTop-BFCNode.MarginTop;
-    //writeln('TFLBlockFormattingContext.PlaceLineNodes ',ChildEl.GetPath,' ',BFCNode.Left,' ',ChildTop,' BFCNode.Height=',BFCNode.ContentBoxHeight);
+    //writeln('TFLBlockFormattingContext.PlaceLineNodes ',i,' ',ChildEl.GetPath,' ',BFCNode.Left,' ',ChildTop,' BFCNode.Height=',BFCNode.ContentBoxHeight);
     ChildBottom:=FLineBorderBoxTop
                 +BFCNode.BorderTop+BFCNode.PaddingTop
                 +BFCNode.ContentBoxHeight
@@ -420,6 +420,7 @@ begin
   ChildBorderBoxHeight:=ChildEl.GetComputedCSSLength(fcaHeight,false,true);
   if not IsNan(ChildBorderBoxHeight) then
     ChildBorderBoxHeight:=ChildBorderBoxHeight+ChildPadBorderY;
+
   ChildPrefBorderBox.X:=-1;
 
   // either ChildLeft or ChildRight must be set
@@ -472,14 +473,14 @@ begin
   ChildEl.CSSComputedAttribute[fcaBottom]:=FloatToCSSStr(ChildBottom);
   ChildEl.CSSComputedAttribute[fcaWidth]:=FloatToCSSStr(ChildBorderBoxWidth-ChildPadBorderX);
   ChildEl.CSSComputedAttribute[fcaHeight]:=FloatToCSSStr(ChildBorderBoxHeight-ChildPadBorderY);
-  FLLog(etDebug,['TFLBlockFormattingContext.PlaceAbsoluteNode ',ChildEl.GetPath,
-    ' Left=',ChildEl.CSSComputedAttribute[fcaLeft],
-    ' Top=',ChildEl.CSSComputedAttribute[fcaTop],
-    ' Right=',ChildEl.CSSComputedAttribute[fcaRight],
-    ' Bottom=',ChildEl.CSSComputedAttribute[fcaBottom],
-    ' Width=',ChildEl.CSSComputedAttribute[fcaWidth],
-    ' Height=',ChildEl.CSSComputedAttribute[fcaHeight],
-    '']);
+  //writeln('TFLBlockFormattingContext.PlaceAbsoluteNode ',ChildEl.GetPath,
+  //  ' Left=',ChildEl.CSSComputedAttribute[fcaLeft],
+  //  ' Top=',ChildEl.CSSComputedAttribute[fcaTop],
+  //  ' Right=',ChildEl.CSSComputedAttribute[fcaRight],
+  //  ' Bottom=',ChildEl.CSSComputedAttribute[fcaBottom],
+  //  ' Width=',ChildEl.CSSComputedAttribute[fcaWidth],
+  //  ' Height=',ChildEl.CSSComputedAttribute[fcaHeight],
+  //  '');
 end;
 
 procedure TFLBlockFormattingContext.ClearLineNodes;
@@ -1203,11 +1204,13 @@ begin
     fcuPercent:
       begin
         aContainer:=GetBlockContainer(El);
+        //writeln('TViewportLayouter.GetPixPerUnit ',El.GetPath,' ',aContainer<>nil,' ',IsHorizontal);
         if aContainer<>nil then
         begin
           if IsHorizontal then
           begin
             Result:=aContainer.GetComputedCSSLength(fcaWidth,false);
+            //writeln('TViewportLayouter.GetPixPerUnit ',El.GetPath,' Container=',aContainer.GetPath,' ',IsHorizontal,' Con.Width=',Result);
             B:=aContainer.GetComputedCSSLength(fcaPaddingLeft,false);
             Result:=Result+B;
             B:=aContainer.GetComputedCSSLength(fcaPaddingRight,false);
@@ -1215,7 +1218,7 @@ begin
           end
           else begin
             Result:=aContainer.GetComputedCSSLength(fcaHeight,false);
-            exit(0);
+            //writeln('TViewportLayouter.GetPixPerUnit ',El.GetPath,' Container=',aContainer.GetPath,' ',IsHorizontal,' Con.Height=',Result);
             B:=aContainer.GetComputedCSSLength(fcaPaddingTop,false);
             Result:=Result+B;
             B:=aContainer.GetComputedCSSLength(fcaPaddingBottom,false);

+ 5 - 2
src/base/fresnel.renderer.pas

@@ -196,15 +196,18 @@ var
   OldOrigin: TFresnelPoint;
   LNode: TSimpleFresnelLayoutNode;
   i: Integer;
+  ChildEl: TFresnelElement;
 begin
   LNode:=TSimpleFresnelLayoutNode(El.LayoutNode);
 
   OldOrigin:=Origin;
   Origin:=OldOrigin+El.RenderedContentBox.TopLeft;
-  //writeln('TFresnelRenderer.DrawChildren ',El.Name,' Old=',OldOrigin.ToString,' Origin=',Origin.ToString);
+  //writeln('TFresnelRenderer.DrawChildren ',El.GetPath,' Old=',OldOrigin.ToString,' Origin=',Origin.ToString);
   for i:=0 to LNode.NodeCount-1 do
   begin
-    DrawElement(TSimpleFresnelLayoutNode(LNode.Nodes[i]).Element);
+    ChildEl:=TSimpleFresnelLayoutNode(LNode.Nodes[i]).Element;
+    //writeln('TFresnelRenderer.DrawChildren ',El.GetPath,' Child=',ChildEl.GetPath);
+    DrawElement(ChildEl);
   end;
   Origin:=OldOrigin;
 end;

+ 21 - 5
src/skia/fresnel.skiarenderer.pas

@@ -330,6 +330,7 @@ var
   SkWeight: integer;
   SkWidth: Integer;
   SkSlant: TSkFontSlant;
+  SkFamily, SkDefaultFamilyname: String;
 begin
   aFont:=FindFont(Desc);
   if aFont<>nil then
@@ -353,7 +354,13 @@ begin
     if SkWeight<>aFontStyle.Weight then
       aFontStyle:=TSkFontStyle.Create(SkWeight,SkWidth,SkSlant);
 
-    aTypeface.SKTypeFace := TSkTypeface.MakeFromName('Monospace', aFontStyle);
+    SkDefaultFamilyname:='sans-serif';
+    SkFamily:=aTypeFace.CSSFamily;
+    if SkFamily='' then
+      SkFamily:=SkDefaultFamilyname;
+    aTypeface.SKTypeFace := TSkTypeface.MakeFromName(SkFamily, aFontStyle);
+    if aTypeface.SKTypeFace=nil then
+      aTypeface.SKTypeFace := TSkTypeface.MakeFromName(SkDefaultFamilyname, aFontStyle);
   end;
 
   aFont:=TFresnelSkiaFont.Create;
@@ -435,6 +442,13 @@ var
   SkCorner: TSkRoundRectCorner;
   Side: TFresnelCSSSide;
 begin
+  if (Params.Box.Width<=MinStrokeWidth)
+      or (Params.Box.Height<=MinStrokeWidth) then
+  begin
+    //writeln('TFresnelSkiaRenderer.DrawElBorder ',El.GetPath,' Params.Box=',Params.Box.ToString);
+    exit;
+  end;
+
   for Side in TFresnelCSSSide do
     NormStroke(Params.Width[Side],true);
 
@@ -461,14 +475,16 @@ begin
 
   if HasBorder then begin
     // with border
-    r:=RectF(Params.Width[ffsLeft]/2-0.5,
-             Params.Width[ffsTop]/2-0.5,
-             Params.Box.Width-Params.Width[ffsRight]/2+0.5,
-             Params.Box.Height-Params.Width[ffsBottom]/2+0.5);
+    r:=RectF(Params.Width[ffsLeft]/2,
+             Params.Width[ffsTop]/2,
+             Params.Box.Width-Params.Width[ffsRight]/2,
+             Params.Box.Height-Params.Width[ffsBottom]/2);
   end else begin
     // no border
     r:=RectF(0,0,Params.Box.Width,Params.Box.Height);
   end;
+  r.Offset(Params.Box.Left+Origin.X,Params.Box.Top+Origin.Y);
+  //writeln('TFresnelSkiaRenderer.DrawElBorder ',El.GetPath,' Box=',Params.Box.ToString,' Origin=',Origin.ToString,' r=',r.Left,',',r.Top,',',r.Right,',',r.Bottom);
 
   // draw background
   if Params.BackgroundColorFP.Alpha>alphaTransparent then