Bug in SVG generation

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ToniK
Newbie
Newbie
Posts: 13
Joined: Mon Oct 17, 2005 4:00 am

Bug in SVG generation

Post by ToniK » Mon May 14, 2007 6:48 am

TeeChart 7.11 SVG generation doesn't handle special XML characters in labels correctly. These characters are &, <, >, " and '. These characters has special meaning in XML and break the validity of outputted XML as they are not properly encoded.

Entity codings should be used to replace these special characters.

There also appears to be inconsistency in background gradient handling - the direction is turned to opposite in SVG view.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Wed May 16, 2007 8:43 am

Hi ToniK,

Yes, those are two bugs in our wish-list. I cannot think in a workaround for the gradient bug, but for special characters you can check the text before it's written to svg stream and replace literal chars like <, > %, &,... with their ascii char code.
You can use a method like the following:

Code: Select all

Function TForm1.VerifySpecial(S:String):String;
const NOTAllowedSVGChars=['!'..'/',':'..'@','['..'`','{'..'~'];
var t : Integer;
begin
  result:='';

  for t:=1 to Length(S) do
    if {$IFDEF CLR}AnsiChar{$ENDIF}(S[t]) in NOTAllowedSVGChars then
      result:=result+'&#'+IntToStr(Ord(S[t]))+';'
    else
      result:=result+S[t]
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ToniK
Newbie
Newbie
Posts: 13
Joined: Mon Oct 17, 2005 4:00 am

Post by ToniK » Wed May 16, 2007 9:07 am

Yes, those are two bugs in our wish-list.
Is there any timeframe for a proper fix to the 7.x version?

These and number of other issues in the SVG generation make it all but useless.

The workaround is good as such, but does not work well enough as most of the characters in question should be encoded with appropriate character entities and not as codes.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Fri May 18, 2007 7:44 am

Hi ToniK,

I'm afraid I can't tell you when it will be fixed for now. Please be aware at this forum for new releases announcements and what's being implemented/fixed on each release.

Also note that since I'm working with v8 beta, I'm not sure if you need to include the same characters than me in your NOTAllowedSVGChars list to be encoded, and thats why I've included "all the strange characters" in the sample. I suggest you to modify it as you need.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ToniK
Newbie
Newbie
Posts: 13
Joined: Mon Oct 17, 2005 4:00 am

Post by ToniK » Wed May 23, 2007 11:48 am

We fixed the XML generation by editing TeeChart source code in TeeSVGCanvas unit. We changed VerifySpecial function to take care of those XML special characters. Below is our implementation:

Code: Select all

  for t := 1 to Length(S) do
    if {$IFDEF CLR}AnsiChar{$ENDIF}(S[t]) in AllowedSVGChars then
       result := result + S[t]
    else
      case {$IFDEF CLR}AnsiChar{$ENDIF}(S[t]) of
        '&' : result := result + '&';
        '<' : result := result + '<';
        '>' : result := result + '>';
        '"' : result := result + '"';
        '''' : result := result + '&apos;';
      else
        result := result + '&#' + IntToStr(Ord(S[t])) + ';';
      end;
and AllowedSVGChars definition was slightly changed too:

Code: Select all

  AllowedSVGChars = ['!'..'z'] - ['&', '<', '>', '"', ''''];
Gradient problem we fixed by changing gradient tag generation in GradientTrasform-function to following:

Code: Select all

    Case Direction of
       gdTopBottom  : result:=' x1="0%" y1="100%" x2="0%" y2="0%" ';
       gdBottomTop  : result:=' x1="0%" y1="0%" x2="0%" y2="100%" ';
       gdLeftRight  : result:=' x1="0%" y1="0%" x2="100%" y2="0%" ';
       gdRightLeft  : result:=' x1="100%" y1="0%" x2="0%" y2="0%" ';
    end;
Code above probably don't take account all possible gradient directions but is sufficient for our needs.

Please, could you review these modifications? It would be great if you could include these in coming(?) TeeChart 7 releases. We also have couple of other issues with TeeChart but I'll report them in some other thread.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu May 24, 2007 12:00 pm

Hi Tonik,

Thank you very much for your suggestions. They seem fine to us (although &#60 is still interpreted as &amp) and we will try to include them TeeChart v8, which is the version we are currently working in.

Ideally, the following map could be used (for all non digit or letter chars):
http://tlt.its.psu.edu/suggestions/inte ... ehtml.html
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

ToniK
Newbie
Newbie
Posts: 13
Joined: Mon Oct 17, 2005 4:00 am

Post by ToniK » Fri May 25, 2007 7:39 am

Ideally, the following map could be used (for all non digit or letter chars):
http://tlt.its.psu.edu/suggestions/inte ... ehtml.html
Actually, you cannot use those entity names in XML (like SVG but not HTML) since they are not defined by default. Only mentioned five are built-in XML. See Wikipedia article about HTML and XML entity names:
http://en.wikipedia.org/wiki/List_of_XM ... references

We also noticed that labels are always horizontal in SVG. Rotation angle is discarded completely in SVG generation. Generally rotated labels are mislocated in TChart, if angle is not multiple of 45 degrees. Are you planning any fixes to these problems in TeeChart 8?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon May 28, 2007 7:28 am

Hi Tonik,

Thanks for the information. We will try to implement char support for 6 xml defined entities.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply