Recent

Author Topic: Updating and redrawing SVG  (Read 486 times)

PawelO

  • New Member
  • *
  • Posts: 25
    • Polish railway traffic and interlocking simulator developed with Lazarus
Updating and redrawing SVG
« on: March 31, 2025, 07:01:16 pm »
Hello,
I'm trying to use BGRASVG to draw a picture that need to be updated (changing elements colors, text strings etc.), and I have two questions:

1. Is it possible to redraw only selected (i.e. changed) SVG elements? There is TSVGElement.Visible property, which disables element drawing (in TSVGElement.Draw), but setting it to False doesn't change its value (TSVGElement.SetVisible setter is doing something in SVG attributes, but .Visible remains on True). I can add and control another property there, but modifying existing BGRASVG code is something I would avoid.

2. What need to be done to update <text> element string (content)? After changing TSVGElement.DOMElement.TextContent it has new value, but when redrawing, it keeps beeing drawn with old value. I can reload SVG file after change, but this is rather not optimal solution.

Are there any other SVG libraries that maybe can handle this better/faster?

PawelO

  • New Member
  • *
  • Posts: 25
    • Polish railway traffic and interlocking simulator developed with Lazarus
Re: Updating and redrawing SVG
« Reply #1 on: April 28, 2025, 07:52:00 pm »
Ad. 2. Solved, it can be changed using TSVGText.SimpleText property.

Ad. 1. It looks like a bug in BGRASVGType unit to me.

Code: Pascal  [Select][+][-]
  1. procedure TSVGElement.SetVisible(AValue: boolean);
  2. begin
  3.   if AValue <> Visible then
  4.     Style['display'] := 'inline';
  5.   FDomElem.RemoveAttribute('display');
  6. end;

Style should be set to 'inline' or 'none' depending on AValue if I understand correctly, but AValue is not used at all. Possible fix:

Code: Pascal  [Select][+][-]
  1.     Style['display'] := BoolToStr(AValue, 'inline', 'none');

lainz

  • Hero Member
  • *****
  • Posts: 4705
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Updating and redrawing SVG
« Reply #2 on: April 28, 2025, 09:53:47 pm »
Please report in BGRABitmap repository at GitHub

PawelO

  • New Member
  • *
  • Posts: 25
    • Polish railway traffic and interlocking simulator developed with Lazarus
Re: Updating and redrawing SVG
« Reply #3 on: April 28, 2025, 11:00:19 pm »
Done.

 

TinyPortal © 2005-2018