Ignore:
Timestamp:
Dec 22, 2016, 8:49:19 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgrasvgtype.pas

    r472 r494  
    2626      function GetIsStrokeNone: boolean;
    2727      function GetMatrix(AUnit: TCSSUnit): TAffineMatrix;
     28      function GetOpacity: single;
    2829      function GetOrthoAttributeOrStyleWithUnit(AName: string
    2930        ): TFloatWithCSSUnit;
    3031      function GetStroke: string;
    3132      function GetStrokeColor: TBGRAPixel;
     33      function GetStrokeLineCap: string;
     34      function GetStrokeLineJoin: string;
     35      function GetStrokeMiterLimit: single;
    3236      function GetStrokeOpacity: single;
    3337      function GetStrokeWidth: TFloatWithCSSUnit;
     
    5054      procedure SetHorizAttributeWithUnit(AName: string; AValue: TFloatWithCSSUnit);
    5155      procedure SetMatrix(AUnit: TCSSUnit; const AValue: TAffineMatrix);
     56      procedure SetOpacity(AValue: single);
    5257      procedure SetStroke(AValue: string);
    5358      procedure SetStrokeColor(AValue: TBGRAPixel);
     59      procedure SetStrokeLineCap(AValue: string);
     60      procedure SetStrokeLineJoin(AValue: string);
     61      procedure SetStrokeMiterLimit(AValue: single);
    5462      procedure SetStrokeOpacity(AValue: single);
    5563      procedure SetStrokeWidth(AValue: TFloatWithCSSUnit);
     
    6674      procedure InternalDraw({%H-}ACanvas2d: TBGRACanvas2D; {%H-}AUnit: TCSSUnit); virtual;
    6775      procedure LocateStyleDeclaration(AText: string; AProperty: string; out AStartPos,AColonPos,AValueLength: integer);
     76      procedure ApplyStrokeStyle(ACanvas2D: TBGRACanvas2D; AUnit: TCSSUnit);
    6877    public
    6978      constructor Create({%H-}ADocument: TXMLDocument; AElement: TDOMElement; AUnits: TCSSUnitConverter); virtual;
     
    93102      property strokeColor: TBGRAPixel read GetStrokeColor write SetStrokeColor;
    94103      property strokeOpacity: single read GetStrokeOpacity write SetStrokeOpacity;
     104      property strokeMiterLimit: single read GetStrokeMiterLimit write SetStrokeMiterLimit;
     105      property strokeLineJoin: string read GetStrokeLineJoin write SetStrokeLineJoin;
     106      property strokeLineCap: string read GetStrokeLineCap write SetStrokeLineCap;
    95107      property fill: string read GetFill write SetFill;
    96108      property fillColor: TBGRAPixel read GetFillColor write SetFillColor;
    97109      property fillOpacity: single read GetFillOpacity write SetFillOpacity;
     110      property opacity: single read GetOpacity write SetOpacity;
    98111  end;
    99112
     
    123136implementation
    124137
    125 uses Math;
    126 
    127138{ TSVGParser }
    128139
     
    264275begin
    265276  result := StrToBGRA(fill,BGRABlack);
    266   result.alpha := round(result.alpha*fillOpacity);
     277  result.alpha := round(result.alpha*fillOpacity*opacity);
    267278  if result.alpha = 0 then result := BGRAPixelTransparent;
    268279end;
     
    359370    begin
    360371      angle := parser.ParseFloat;
    361       result *= AffineMatrix(1,tan(angle*Pi/180),0,
    362                              0,        1,        0);
     372      result *= AffineMatrixSkewXDeg(angle);
    363373    end else
    364374    if compareText(kind,'skewy')=0 then
    365375    begin
    366376      angle := parser.ParseFloat;
    367       result *= AffineMatrix(1,         0        ,0,
    368                      tan(angle*Pi/180), 1,        0);
     377      result *= AffineMatrixSkewYDeg(angle);
    369378    end;
    370379    parser.SkipUpToSymbol(')');
     
    375384end;
    376385
     386function TSVGElement.GetOpacity: single;
     387var errPos: integer;
     388begin
     389  val(AttributeOrStyle['opacity'], result, errPos);
     390  if errPos <> 0 then result := 1 else
     391    if result < 0 then result := 0 else
     392      if result > 1 then result := 1;
     393end;
     394
    377395function TSVGElement.GetOrthoAttributeOrStyleWithUnit(AName: string
    378396  ): TFloatWithCSSUnit;
     
    390408begin
    391409  result := StrToBGRA(stroke);
    392   result.alpha := round(result.alpha*strokeOpacity);
     410  result.alpha := round(result.alpha*strokeOpacity*opacity);
    393411  if result.alpha = 0 then result := BGRAPixelTransparent;
     412end;
     413
     414function TSVGElement.GetStrokeLineCap: string;
     415begin
     416  result := AttributeOrStyle['stroke-linecap'];
     417  if result = '' then result := 'butt';
     418end;
     419
     420function TSVGElement.GetStrokeLineJoin: string;
     421begin
     422  result := AttributeOrStyle['stroke-linejoin'];
     423  if result = '' then result := 'miter';
     424end;
     425
     426function TSVGElement.GetStrokeMiterLimit: single;
     427var errPos: integer;
     428begin
     429  val(AttributeOrStyle['stroke-miterlimit'], result, errPos);
     430  if errPos <> 0 then result := 4 else
     431    if result < 1 then result := 1;
    394432end;
    395433
     
    405443function TSVGElement.GetStrokeWidth: TFloatWithCSSUnit;
    406444begin
    407   result := HorizAttributeOrStyleWithUnit['stroke-width'];
     445  result := OrthoAttributeOrStyleWithUnit['stroke-width'];
    408446end;
    409447
     
    525563end;
    526564
     565procedure TSVGElement.SetOpacity(AValue: single);
     566begin
     567  Attribute['opacity'] := Units.formatValue(AValue);
     568  RemoveStyle('opacity');
     569end;
     570
    527571procedure TSVGElement.SetStroke(AValue: string);
    528572begin
     
    536580  AValue.alpha:= 255;
    537581  stroke := BGRAToStr(AValue, CSSColors);
     582end;
     583
     584procedure TSVGElement.SetStrokeLineCap(AValue: string);
     585begin
     586  Attribute['stroke-linecap'] := AValue;
     587  RemoveStyle('stroke-linecap');
     588end;
     589
     590procedure TSVGElement.SetStrokeLineJoin(AValue: string);
     591begin
     592  Attribute['stroke-linejoin'] := AValue;
     593  RemoveStyle('stroke-linejoin');
     594end;
     595
     596procedure TSVGElement.SetStrokeMiterLimit(AValue: single);
     597begin
     598  if AValue < 1 then AValue := 1;
     599  Attribute['stroke-miterlimit'] := Units.formatValue(AValue);
     600  RemoveStyle('stroke-miterlimit');
    538601end;
    539602
     
    671734    if AText[i] = ';' then
    672735    begin
    673       curValueLength := i-curColon;
     736      curValueLength := i-(curColon+1);
    674737      if CheckShouldReturnResult then exit;
    675738      curStart := -1;
     
    680743  if curColon <> -1 then
    681744  begin
    682     curValueLength:= length(AText)-curColon;
     745    curValueLength:= length(AText)-(curColon+1)+1;
    683746    if CheckShouldReturnResult then exit;
    684747  end;
     748end;
     749
     750procedure TSVGElement.ApplyStrokeStyle(ACanvas2D: TBGRACanvas2D; AUnit: TCSSUnit);
     751begin
     752  ACanvas2d.strokeStyle(strokeColor);
     753  ACanvas2d.lineWidth := Units.ConvertWidth(strokeWidth,AUnit).value;
     754  ACanvas2d.lineCap := strokeLineCap;
     755  ACanvas2d.lineJoin := strokeLineJoin;
     756  ACanvas2d.miterLimit := strokeMiterLimit;
    685757end;
    686758
Note: See TracChangeset for help on using the changeset viewer.