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:


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:50
Due to a glitch in our system, this post is a duplication. The original post is at: