Changeset 494 for GraphicTest/Packages/bgrabitmap/bgrasvgtype.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrasvgtype.pas
r472 r494 26 26 function GetIsStrokeNone: boolean; 27 27 function GetMatrix(AUnit: TCSSUnit): TAffineMatrix; 28 function GetOpacity: single; 28 29 function GetOrthoAttributeOrStyleWithUnit(AName: string 29 30 ): TFloatWithCSSUnit; 30 31 function GetStroke: string; 31 32 function GetStrokeColor: TBGRAPixel; 33 function GetStrokeLineCap: string; 34 function GetStrokeLineJoin: string; 35 function GetStrokeMiterLimit: single; 32 36 function GetStrokeOpacity: single; 33 37 function GetStrokeWidth: TFloatWithCSSUnit; … … 50 54 procedure SetHorizAttributeWithUnit(AName: string; AValue: TFloatWithCSSUnit); 51 55 procedure SetMatrix(AUnit: TCSSUnit; const AValue: TAffineMatrix); 56 procedure SetOpacity(AValue: single); 52 57 procedure SetStroke(AValue: string); 53 58 procedure SetStrokeColor(AValue: TBGRAPixel); 59 procedure SetStrokeLineCap(AValue: string); 60 procedure SetStrokeLineJoin(AValue: string); 61 procedure SetStrokeMiterLimit(AValue: single); 54 62 procedure SetStrokeOpacity(AValue: single); 55 63 procedure SetStrokeWidth(AValue: TFloatWithCSSUnit); … … 66 74 procedure InternalDraw({%H-}ACanvas2d: TBGRACanvas2D; {%H-}AUnit: TCSSUnit); virtual; 67 75 procedure LocateStyleDeclaration(AText: string; AProperty: string; out AStartPos,AColonPos,AValueLength: integer); 76 procedure ApplyStrokeStyle(ACanvas2D: TBGRACanvas2D; AUnit: TCSSUnit); 68 77 public 69 78 constructor Create({%H-}ADocument: TXMLDocument; AElement: TDOMElement; AUnits: TCSSUnitConverter); virtual; … … 93 102 property strokeColor: TBGRAPixel read GetStrokeColor write SetStrokeColor; 94 103 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; 95 107 property fill: string read GetFill write SetFill; 96 108 property fillColor: TBGRAPixel read GetFillColor write SetFillColor; 97 109 property fillOpacity: single read GetFillOpacity write SetFillOpacity; 110 property opacity: single read GetOpacity write SetOpacity; 98 111 end; 99 112 … … 123 136 implementation 124 137 125 uses Math;126 127 138 { TSVGParser } 128 139 … … 264 275 begin 265 276 result := StrToBGRA(fill,BGRABlack); 266 result.alpha := round(result.alpha*fillOpacity );277 result.alpha := round(result.alpha*fillOpacity*opacity); 267 278 if result.alpha = 0 then result := BGRAPixelTransparent; 268 279 end; … … 359 370 begin 360 371 angle := parser.ParseFloat; 361 result *= AffineMatrix(1,tan(angle*Pi/180),0, 362 0, 1, 0); 372 result *= AffineMatrixSkewXDeg(angle); 363 373 end else 364 374 if compareText(kind,'skewy')=0 then 365 375 begin 366 376 angle := parser.ParseFloat; 367 result *= AffineMatrix(1, 0 ,0, 368 tan(angle*Pi/180), 1, 0); 377 result *= AffineMatrixSkewYDeg(angle); 369 378 end; 370 379 parser.SkipUpToSymbol(')'); … … 375 384 end; 376 385 386 function TSVGElement.GetOpacity: single; 387 var errPos: integer; 388 begin 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; 393 end; 394 377 395 function TSVGElement.GetOrthoAttributeOrStyleWithUnit(AName: string 378 396 ): TFloatWithCSSUnit; … … 390 408 begin 391 409 result := StrToBGRA(stroke); 392 result.alpha := round(result.alpha*strokeOpacity );410 result.alpha := round(result.alpha*strokeOpacity*opacity); 393 411 if result.alpha = 0 then result := BGRAPixelTransparent; 412 end; 413 414 function TSVGElement.GetStrokeLineCap: string; 415 begin 416 result := AttributeOrStyle['stroke-linecap']; 417 if result = '' then result := 'butt'; 418 end; 419 420 function TSVGElement.GetStrokeLineJoin: string; 421 begin 422 result := AttributeOrStyle['stroke-linejoin']; 423 if result = '' then result := 'miter'; 424 end; 425 426 function TSVGElement.GetStrokeMiterLimit: single; 427 var errPos: integer; 428 begin 429 val(AttributeOrStyle['stroke-miterlimit'], result, errPos); 430 if errPos <> 0 then result := 4 else 431 if result < 1 then result := 1; 394 432 end; 395 433 … … 405 443 function TSVGElement.GetStrokeWidth: TFloatWithCSSUnit; 406 444 begin 407 result := HorizAttributeOrStyleWithUnit['stroke-width'];445 result := OrthoAttributeOrStyleWithUnit['stroke-width']; 408 446 end; 409 447 … … 525 563 end; 526 564 565 procedure TSVGElement.SetOpacity(AValue: single); 566 begin 567 Attribute['opacity'] := Units.formatValue(AValue); 568 RemoveStyle('opacity'); 569 end; 570 527 571 procedure TSVGElement.SetStroke(AValue: string); 528 572 begin … … 536 580 AValue.alpha:= 255; 537 581 stroke := BGRAToStr(AValue, CSSColors); 582 end; 583 584 procedure TSVGElement.SetStrokeLineCap(AValue: string); 585 begin 586 Attribute['stroke-linecap'] := AValue; 587 RemoveStyle('stroke-linecap'); 588 end; 589 590 procedure TSVGElement.SetStrokeLineJoin(AValue: string); 591 begin 592 Attribute['stroke-linejoin'] := AValue; 593 RemoveStyle('stroke-linejoin'); 594 end; 595 596 procedure TSVGElement.SetStrokeMiterLimit(AValue: single); 597 begin 598 if AValue < 1 then AValue := 1; 599 Attribute['stroke-miterlimit'] := Units.formatValue(AValue); 600 RemoveStyle('stroke-miterlimit'); 538 601 end; 539 602 … … 671 734 if AText[i] = ';' then 672 735 begin 673 curValueLength := i- curColon;736 curValueLength := i-(curColon+1); 674 737 if CheckShouldReturnResult then exit; 675 738 curStart := -1; … … 680 743 if curColon <> -1 then 681 744 begin 682 curValueLength:= length(AText)- curColon;745 curValueLength:= length(AText)-(curColon+1)+1; 683 746 if CheckShouldReturnResult then exit; 684 747 end; 748 end; 749 750 procedure TSVGElement.ApplyStrokeStyle(ACanvas2D: TBGRACanvas2D; AUnit: TCSSUnit); 751 begin 752 ACanvas2d.strokeStyle(strokeColor); 753 ACanvas2d.lineWidth := Units.ConvertWidth(strokeWidth,AUnit).value; 754 ACanvas2d.lineCap := strokeLineCap; 755 ACanvas2d.lineJoin := strokeLineJoin; 756 ACanvas2d.miterLimit := strokeMiterLimit; 685 757 end; 686 758
Note:
See TracChangeset
for help on using the changeset viewer.