Page 1 of 1

Bug in SVG generation

Posted: Mon May 14, 2007 6:48 am
by 9343832
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.

Posted: Wed May 16, 2007 8:43 am
by yeray
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;

Posted: Wed May 16, 2007 9:07 am
by 9343832
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.

Posted: Fri May 18, 2007 7:44 am
by yeray
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.

Posted: Wed May 23, 2007 11:48 am
by 9343832
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.

Posted: Thu May 24, 2007 12:00 pm
by narcis
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

Posted: Fri May 25, 2007 7:39 am
by 9343832
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?

Posted: Mon May 28, 2007 7:28 am
by narcis
Hi Tonik,

Thanks for the information. We will try to implement char support for 6 xml defined entities.