Pārlūkot izejas kodu

TFresnelCSSAttribute: added fcaTextShadow

mattias 1 gadu atpakaļ
vecāks
revīzija
cc35fab74d
1 mainītis faili ar 120 papildinājumiem un 56 dzēšanām
  1. 120 56
      src/base/fresnel.dom.pas

+ 120 - 56
src/base/fresnel.dom.pas

@@ -97,6 +97,7 @@ type
     fcaFontStyle, // normal|italic|oblique
     fcaFontWeight, // normal|bold|bolder|lighter|number
     fcaFontVariant,
+    fcaTextShadow,
     fcaLineHeight,
     fcaMargin, // shorthand
     fcaMarginLeft,
@@ -181,6 +182,7 @@ const
     'font-style',
     'font-weight',
     'font-variant',
+    'text-shadow',
     'line-height',
     'margin',
     'margin-left',
@@ -324,7 +326,7 @@ type
   PFresnelFontDesc = ^TFresnelFontDesc;
 
   TFresnelLengthCheck = (
-    fclNoWarn,
+    flcNoWarn,
     flcNoNegative,
     flcNoPercentage,
     flcInteger
@@ -395,7 +397,7 @@ type
     function CheckCSSZIndex(const AValue: string): boolean; virtual;
     function CheckCSSDirection(const AValue: string): boolean; virtual;
     function CheckOrSetCSSBorder(const AValue: string; Check: boolean): boolean; virtual;
-    function CheckOrSetCSSBorderX(AttrWidth: TFresnelCSSAttribute; const AValue: string; Check: boolean): boolean; virtual;
+    function CheckOrSetCSSBorderX(Attr: TFresnelCSSAttribute; const AValue: string; Check: boolean): boolean; virtual;
     function CheckOrSetCSSBorderLeft(const AValue: string; Check: boolean): boolean; virtual;
     function CheckOrSetCSSBorderTop(const AValue: string; Check: boolean): boolean; virtual;
     function CheckOrSetCSSBorderRight(const AValue: string; Check: boolean): boolean; virtual;
@@ -422,6 +424,7 @@ type
     function CheckCSSFontStyle(const AValue: string): boolean; virtual;
     function CheckCSSFontWeight(const AValue: string): boolean; virtual;
     function CheckCSSFontVariant(const AValue: string): boolean; virtual;
+    function CheckCSSTextShadow(const AValue: string): boolean; virtual;
     function CheckOrSetCSSPadding(const AValue: string; Check: boolean): boolean; virtual;
     function CheckCSSVisibility(const AValue: string): boolean; virtual;
     function CheckOrSetCSSBackground(const AValue: string; Check: boolean): boolean; virtual;
@@ -1767,35 +1770,38 @@ end;
 
 function TFresnelElement.CheckOrSetCSSBorder(const AValue: string;
   Check: boolean): boolean;
+// width, style, color
 var
-  p: Integer;
+  p, i: Integer;
   aWidth, aStyle, aColor, s: String;
 begin
-  // width, style, color
+  Result:=false;
   p:=1;
-  s:=CSSReadNextValue(AValue,p);
-  if CheckCSSBorderXWidth(fcaBorderLeftWidth,s) then
-  begin
-    // first value is width
-    aWidth:=s;
-    s:=CSSReadNextValue(AValue,p);
-  end else
-    aWidth:='';
-  if CheckCSSBorderXStyle(fcaBorderLeftStyle,s) then
-  begin
-    // next value is style
-    aStyle:=s;
-    s:=CSSReadNextValue(AValue,p);
-  end else
-    aStyle:='';
-  if CheckCSSBorderXColor(fcaBorderLeftColor,s) then
+  aWidth:='';
+  aStyle:='';
+  aColor:='';
+  for i:=1 to 4 do
   begin
-    // next value is color
-    aColor:=s;
     s:=CSSReadNextValue(AValue,p);
+    if s='' then
+    begin
+      if i=1 then
+      begin
+        CSSInvalidValueWarning(20240527105003,fcaBorder,AValue);
+        exit;
+      end;
+      break;
+    end else if (aWidth='') and CheckCSSBorderXWidth(fcaBorderLeftWidth,s) then
+      aWidth:=s
+    else if (aStyle='') and CheckCSSBorderXStyle(fcaBorderLeftStyle,s) then
+      aStyle:=s
+    else if (aColor='') and CheckCSSBorderXColor(fcaBorderLeftColor,s) then
+      aColor:=s
+    else begin
+      CSSInvalidValueWarning(20240527103748,fcaBorder,s);
+      exit;
+    end;
   end;
-  if s>'' then
-    exit(false);
   if not Check then
   begin
     if aWidth>'' then
@@ -1822,41 +1828,46 @@ begin
   end;
 end;
 
-function TFresnelElement.CheckOrSetCSSBorderX(AttrWidth: TFresnelCSSAttribute;
+function TFresnelElement.CheckOrSetCSSBorderX(Attr: TFresnelCSSAttribute;
   const AValue: string; Check: boolean): boolean;
+// shorthand for width style color
+// any order
 var
-  p: Integer;
+  p, i: Integer;
   aWidth, aStyle, aColor, s: String;
-  AttrStyle, AttrColor: TFresnelCSSAttribute;
+  AttrWidth, AttrStyle, AttrColor: TFresnelCSSAttribute;
 begin
-  AttrStyle:=TFresnelCSSAttribute(ord(AttrWidth)+ord(fcaBorderLeftStyle)-ord(fcaBorderLeftWidth));
-  AttrColor:=TFresnelCSSAttribute(ord(AttrWidth)+ord(fcaBorderLeftColor)-ord(fcaBorderLeftWidth));
+  Result:=false;
+  AttrWidth:=TFresnelCSSAttribute(ord(Attr)+ord(fcaBorderLeftWidth)-ord(fcaBorderLeft));
+  AttrStyle:=TFresnelCSSAttribute(ord(Attr)+ord(fcaBorderLeftStyle)-ord(fcaBorderLeft));
+  AttrColor:=TFresnelCSSAttribute(ord(Attr)+ord(fcaBorderLeftColor)-ord(fcaBorderLeft));
 
-  // width, style, color
   p:=1;
-  s:=CSSReadNextValue(AValue,p);
-  if CheckCSSBorderXWidth(AttrWidth,s) then
-  begin
-    // first value is width
-    aWidth:=s;
-    s:=CSSReadNextValue(AValue,p);
-  end else
-    aWidth:='';
-  if CheckCSSBorderXStyle(AttrStyle,s) then
+  aWidth:='';
+  aStyle:='';
+  aColor:='';
+  for i:=1 to 4 do
   begin
-    // next value is style
-    aStyle:=s;
-    s:=CSSReadNextValue(AValue,p);
-  end else
-    aStyle:='';
-  if CheckCSSBorderXColor(AttrColor,s) then
-  begin
-    // next value is color
-    aColor:=s;
     s:=CSSReadNextValue(AValue,p);
+    if s='' then
+    begin
+      if i=1 then
+      begin
+        CSSInvalidValueWarning(20240527104624,Attr,AValue);
+        exit;
+      end;
+      break;
+    end else if (aWidth='') and CheckCSSBorderXWidth(AttrWidth,s) then
+      aWidth:=s
+    else if (aStyle='') and CheckCSSBorderXStyle(AttrStyle,s) then
+      aStyle:=s
+    else if (aColor='') and CheckCSSBorderXColor(AttrColor,s) then
+      aColor:=s
+    else begin
+      CSSInvalidValueWarning(20240527104909,Attr,s);
+      exit;
+    end;
   end;
-  if s>'' then
-    exit(false);
   if not Check then
   begin
     if aWidth>'' then
@@ -1866,30 +1877,31 @@ begin
     if aColor>'' then
       SetCSSElAttribute(AttrColor,aColor);
   end;
+  Result:=true;
 end;
 
 function TFresnelElement.CheckOrSetCSSBorderLeft(const AValue: string;
   Check: boolean): boolean;
 begin
-  Result:=CheckOrSetCSSBorderX(fcaBorderLeftWidth,AValue,Check);
+  Result:=CheckOrSetCSSBorderX(fcaBorderLeft,AValue,Check);
 end;
 
 function TFresnelElement.CheckOrSetCSSBorderTop(const AValue: string;
   Check: boolean): boolean;
 begin
-  Result:=CheckOrSetCSSBorderX(fcaBorderTopWidth,AValue,Check);
+  Result:=CheckOrSetCSSBorderX(fcaBorderTop,AValue,Check);
 end;
 
 function TFresnelElement.CheckOrSetCSSBorderRight(const AValue: string;
   Check: boolean): boolean;
 begin
-  Result:=CheckOrSetCSSBorderX(fcaBorderRightWidth,AValue,Check);
+  Result:=CheckOrSetCSSBorderX(fcaBorderRight,AValue,Check);
 end;
 
 function TFresnelElement.CheckOrSetCSSBorderBottom(const AValue: string;
   Check: boolean): boolean;
 begin
-  Result:=CheckOrSetCSSBorderX(fcaBorderBottomWidth,AValue,Check);
+  Result:=CheckOrSetCSSBorderX(fcaBorderBottom,AValue,Check);
 end;
 
 function TFresnelElement.CheckOrSetCSSBorderWidth(const AValue: string;
@@ -2061,6 +2073,7 @@ end;
 
 function TFresnelElement.CheckOrSetCSSBorderRadius(const AValue: string;
   Check: boolean): boolean;
+// shorthand for all four corners, order matters
 // 1..4 lengths, e.g. 10px 20px 30px 40px
 // Plus optional separated by / 1..4 lengths for vertical radius
 // e.g. 10px / 20px 30px
@@ -2182,6 +2195,8 @@ end;
 
 function TFresnelElement.CheckOrSetCSSMargin(const AValue: string;
   Check: boolean): boolean;
+// shorthand for top right bottom left
+// order matters
 var
   p: Integer;
   aTop, aRight, aBottom, aLeft: String;
@@ -2321,6 +2336,8 @@ end;
 
 function TFresnelElement.CheckOrSetCSSFont(const AValue: string; Check: boolean
   ): boolean;
+// shorthand for font-style font-variant font-weight font-size/line-height font-family
+// order does matter
 var
   p, Code, Weight: Integer;
   s, LineHeight: String;
@@ -2496,6 +2513,52 @@ begin
   end;
 end;
 
+function TFresnelElement.CheckCSSTextShadow(const AValue: string): boolean;
+// color offset-x offset-y blur-radius
+// color can be at a later position
+var
+  p, i: Integer;
+  s, aColor, aOffsetX, aOffsetY, aRadius: String;
+begin
+  Result:=false;
+  p:=1;
+  aColor:='';
+  aOffsetX:='';
+  aOffsetY:='';
+  aRadius:='';
+  for i:=1 to 4 do
+  begin
+    s:=CSSReadNextValue(AValue,p);
+    if s='' then
+    begin
+      if i=1 then
+      begin
+        CSSInvalidValueWarning(20240527105902,fcaTextShadow,AValue);
+        exit;
+      end;
+      break;
+    end else if CheckCSSLength(fcaTextShadow,s,[flcNoWarn,flcNoPercentage]) then
+    begin
+      if aOffsetX='' then
+        aOffsetX:=s
+      else if aOffsetY='' then
+        aOffsetY:=s
+      else if aRadius='' then
+        aRadius:=s
+      else begin
+        CSSInvalidValueWarning(20240527110536,fcaTextShadow,s);
+        exit;
+      end;
+    end else if (aColor='') and CheckCSSColor(s) then
+      aColor:=s
+    else begin
+      CSSInvalidValueWarning(20240527110309,fcaTextShadow,s);
+      exit;
+    end;
+  end;
+  Result:=true;
+end;
+
 function TFresnelElement.CheckOrSetCSSPadding(const AValue: string;
   Check: boolean): boolean;
 var
@@ -2773,7 +2836,7 @@ function TFresnelElement.CheckCSSLength(Attr: TFresnelCSSAttribute;
 
   procedure Invalid(const ID: int64);
   begin
-    if fclNoWarn in Checks then exit;
+    if flcNoWarn in Checks then exit;
     CSSInvalidValueWarning(ID,Attr,AValue);
   end;
 
@@ -2785,7 +2848,7 @@ begin
     Result:=true
   else if AValue='' then
   begin
-    if not (fclNoWarn in Checks) then
+    if not (flcNoWarn in Checks) then
       CSSWarning(20221016220554,'missing '+FresnelCSSAttributeNames[Attr]+' value')
   end else begin
     // <float><unit>
@@ -3657,6 +3720,7 @@ begin
     fcaFontStyle: Result:=CheckCSSFontStyle(s);
     fcaFontWeight: Result:=CheckCSSFontWeight(s);
     fcaFontVariant: Result:=CheckCSSFontVariant(s);
+    fcaTextShadow: Result:=CheckCSSTextShadow(s);
     fcaLineHeight: Result:=CheckCSSLineHeight(s);
     fcaMargin: Result:=CheckOrSetCSSMargin(s,true);
     fcaMarginLeft,