Recent

Author Topic: SVG example needed  (Read 4290 times)

mm7

  • Full Member
  • ***
  • Posts: 231
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
SVG example needed
« on: June 15, 2015, 10:11:00 pm »
There is lazarus.svg (lazarus/1.4RC2/images/icons/lazarus.svg),
I am trying to show it on canvas.
But it does not work. Picture is spiky.
May be I am doing something wrong?
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  BGRABitmap,BGRASVG,BGRAUnits;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    BgraBitmap: TBGRABitmap;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  BgraSvg: TBGRASVG;
begin
  BgraBitmap := TBGRABitmap.Create;
  BgraBitmap.SetSize(600,600);
  BgraBitmap.Bitmap.Canvas.FillRect(0,0,600,600);

  BgraSvg := TBGRASVG.Create(600,600,cuPixel);
  BgraSvg.LoadFromFile('lazarus.svg');
  BgraSvg.Draw(BgraBitmap.Canvas2D,0,0, cuPixel);
  BgraSvg.Destroy;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  BgraBitmap.Draw(Canvas,0,0,True);
end;

end.
Could someone give a correct example?

circular

  • Hero Member
  • *****
  • Posts: 4467
    • Personal webpage
Re: SVG example needed
« Reply #1 on: June 15, 2015, 10:35:48 pm »
Your code is ok.

You could simplify the code like this:
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var
  BgraSvg: TBGRASVG;
begin
  BgraBitmap := TBGRABitmap.Create;
  BgraBitmap.SetSize(600,600);
  BgraBitmap.Fill(BGRAWhite);

  BgraSvg := TBGRASVG.Create('lazarus.svg');
  BgraSvg.Draw(BgraBitmap.Canvas2D,0,0, cuPixel);
  BgraSvg.Destroy;
end;

The thing that happens here is that this file uses advanced features like matrix transformation and gradients, that are not supported yet.
Conscience is the debugger of the mind

mm7

  • Full Member
  • ***
  • Posts: 231
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: SVG example needed
« Reply #2 on: June 15, 2015, 11:12:35 pm »
thanks circular.
I tried this and that, including what you have proposed. no difference in result.

Any plans to support advanced features like matrix transformation and gradients?

Apart from lazarus.svg I tried examples from w3c.org, they also drawn differently/incorrectly.
For example this arc http://www.w3.org/TR/SVG2/images/paths/arcs01.svg

Or, this one lazarus/1.4RC2/components/aggpas/svg/tiger.svg is drown spiky. (but, yes, it has transform="tranlslate")
« Last Edit: June 15, 2015, 11:14:56 pm by mm7 »

circular

  • Hero Member
  • *****
  • Posts: 4467
    • Personal webpage
Re: SVG example needed
« Reply #3 on: June 15, 2015, 11:41:51 pm »
Indeed. Thanks for reporting those bugs.

It looks like there is some work to do.  :-[
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: SVG example needed
« Reply #4 on: June 16, 2015, 12:19:35 am »
I will try this seems the next awesome feature i will use  :)

 

TinyPortal © 2005-2018