ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  addText() does not correctly right-align multiline text in SVG files
Posted by David Wilson on Dec-07-2018 03:07
If you add right-aligned multi-line text to a ChartDirector chart, then generate an SVG file, the text does not always display as correctly right-aligned.

For example:

I create some multi-line text:

std::string text(
    "This is a big long text linen"
    "This is another big long text linen"
    "This is yet another big big long long text line"
);

I add it to the chart top-right aligned to a point (x, y) near the top right corner of the chart:

chart.addText(x, y, text, font, font_size, Chart::TextColor, Chart::TopRight);

Then I generate my SVG file:

chart.makeChart(Chart::SVG);

When viewing the resultant SVG file in various applications, the text lines are not correctly right-aligned.  In my tests, Firefox shows better alignment, while other applications can show very poor alignment (IE, Word, PowerPoint, Inkscape, &c).

I have determined that the problem is not with the rendering engines of the various applications, it is in the SVG file generated by ChartDirector.

The problem is that, even for text is supposed to be right-aligned, ChartDirector generates commands for left-aligned text:

<text id='b660' style="font-family:'Arial';font-size:8px;" x='764' y='32'>This is a big long text line</text>

where 764 is the left end of the text.

The right end of left-aligned text will be correct only if the application chooses the exact same font and renders the text with the exact anticipated length. Unfortunately, different applications seem to render the same text with the same font and font size with different lengths, so we see poor right alignment in some applications.

To fix this, addText() should store right-aligned text as right-aligned in the SVG file:

<text id='b660' style="font-family:'Arial';font-size:8px;" x='840' y='32' text-anchor='end'>This is a big long text line</text>

Here 840 is the right end of the text, and the 'text-anchor' flag aligns the text to the right end.  This change fixes right alignment of multi-line text in all applications I have tested.

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Peter Kwan on Dec-07-2018 16:48
Hi David,

The is the same issue as:

https://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1540997602#N1541448683

The root cause of this problem is because every SVG viewer can draw SVG text differently. Even for the same SVG viewer, it can draw text with different relative length when the scale changes. That is, even if two text are of the same length in one scale, they are not necessarily of the same length when drawn at 2x scale, and SVG (Scalable Vector Graphics), as its name implies, is designed to be drawn at various scales.

Because ChartDirector text layout can be relatively complex (remember the text can be arbitrarily complex CDML - see https://www.advsofteng.com/doc/cdcpp.htm#cdml.htm), ChartDirector internally does not use text-anchor, as it is not sufficient to support complex layout. ChartDirector just puts the text at the position computed by itself.

SVG 1.1 introduces the textLength attribute, which is specifically designed for this kind of issues. It allows the SVG viewer (such as the browser) to know the text length computed by the SVG producer (such as ChartDirector), so it can position the text as originally intended.

From your code, I assume you are using C++. As mentioned in the page above, we have created an update for Linux (x86_64) based on ChartDirector 6.3 that can generate text with the "textlength" attribute. If you are using other OS, please let me know operating system you are using and whether it is 32-bit or 64-bit, so I can provide the updated DLL or shared object to you.

Regards
Peter Kwan

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by David Wilson on Dec-07-2018 22:59
Thank you for your prompt reply, and your help with past issues.

Yes, I would certainly like to try out the "textlength" upgrade for 64-bit Windows.  Please email me as to where I can obtain the upgrade.

It would be helpful to address the right-alignment issue, since we are moving (with Microsoft) toward open graphics format (SVG, PNG), and this issue manifests in many of our target applications (IE, Edge, Chrome, Office 365, Inkscape).

Note that this is a minor criticism, we have generally found ChartDirector quite serviceable. In regard to SVG chart presentation issues, I have traced almost all of them to the renderer, this is the only one I was able to trace to ChartDirector.

Kudos.

Dave Wilson

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Peter Kwan on Dec-08-2018 19:04
Hi David,

I have just uploaded the updated chartdir60.dll (64-bit) to:

https://www.advsofteng.com/chartdir63p1_win64.zip

This updated chartdir60.dll will include the textLength attribute in SVG text, so the alignment should be very accurate.

Regards
Peter Kwan

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by David Wilson on Dec-13-2018 23:16
Thank you for the library, it fixed SVG right text alignment rendering issues in all of our Windows 7 and Windows 10 target applications, including:

Office 365 apps: Word, PowerPoint.
Browsers: Internet Explorer, Edge, Chrome, Firefox.
Image editors: Inkscape

- Dave

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by DanieldeParis on Dec-19-2018 15:28
Peter Kwan wrote:
I have just uploaded the updated chartdir60.dll (64-bit) to:
https://www.advsofteng.com/chartdir63p1_win64.zip
This updated chartdir60.dll will include the textLength attribute in SVG text, so the alignment should be very accurate.
Regards
Peter Kwan

Hi Peter,

Exactly the same kind of issues here with the SVG text output:-)  Labels do not adjust to the sizes of boxes when working with SVG. On any font.

We have disabled it and rely on transparent PNGs (clipboard) and the great vectorial pdf support (printout). Like Dave I'm quite happy with CD! But we'd be definitely glad to incorporate good-looking SVG support. As Dave, we are willing to suport SVG import within the MS-office tools, especially ppt.

Our app rely on the chartdir60.dll.  But currently still on the 32-bit edition. Could we get the patched 32-bit library?

Kind regards for the great work on vectgrial stuff. It is really a strong point for CD:-)

Daniel

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Peter Kwan on Dec-20-2018 00:37
Hi DanieldeParis,

We now have an updated DLL downloadable from the link below (includes both 32-bit and 64-bit versions). Apart from supporting the textLength in SVG for accurate text placement, it has a new text engine which will be used in newer versions of ChartDirector. With this new engine, the text will look slightly different.

https://www.advsofteng.com/chartdir631b1_win.zip

Regards
Peter Kwan

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Danieldeparis on Dec-20-2018 02:50
Peter Kwan wrote:

Hi DanieldeParis,

We now have an updated DLL downloadable from the link below (includes both 32-bit and 64-bit versions). Apart from supporting the textLength in SVG for accurate text placement, it has a new text engine which will be used in newer versions of ChartDirector. With this new engine, the text will look slightly different.

https://www.advsofteng.com/chartdir631b1_win.zip

Regards
Peter Kwan

Hi Peter,

This is all great news. It looks like there is an error in the http link. I look forward to downloading and testing the stuff!

Regards

Daniel

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Peter Kwan on Dec-20-2018 09:49
Hi Danieldeparis,

Sorry, it should be:

https://www.advsofteng.com/chartdir631b1.zip

Regards
Peter Kwan

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Danieldeparis on Dec-21-2018 17:48
Hi Peter,

Just ran a series of tests. Not the full set of the ones requires but definitely a range of significant ones. Vectors come as they need including in cases of arbitrary text positioning.

The new 6.3 version is REALLY great!

Seasons' greetings:-)

Daniel in Paris

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by David Wilson on Jan-16-2019 23:00
Peter:

My company has asked me to extend thanks to you for an excellent product, and for your prompt and helpful personal attention to our queries and issues.

Sincerely,

David W. Wilson
Senior Engineer
LTK Engineering Services

  Re: addText() does not correctly right-align multiline text in SVG files
Posted by Peter Kwan on Jan-17-2019 21:43
Hi David,

Thanks for your positive comment. It is really encouraging to us.

We must also thank you for helping to improve our product. Many of the improvements and features in ChartDirector originate from customer requirements and feedback. In your case, the precise SVG and PDF text positioning will become a permanent part of ChartDirector.

Regards
Peter Kwan