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

Message ListMessage List     Post MessagePost Message

  How to write vertical Japanese text in label?
Posted by Yejin Lee on Jun-21-2017 18:58
Attachments:
Hi,
i made a chart and set label(in Japanese) vertically and the result is like the picture i attached.

Vertical Japanese text is supposed to be shown like the table on the bottom side of attached pic(chartdir_pic.png).
Please compare each x-axis label & column on the table(Those are same word but shown differently!).


It doesn't simply solved by changing the angel of the character because Japanese character has Halfwidth and Fullwidth Forms.
Especially, Japanese text with Halfwidth form should be like the character on the attached PDF file(halfwidth_vertical_text.pdf) if I use it vertically.

We can use both forms together like the words shown on the attached pic. or someone can mix both forms in one word.
Each letter should be operated properly when we typed it in vertical.




In conclusion, What I want to ask is,
: Can you support vertical Japanese text in Halfwidth and Fullwidth Forms?


My code is
[
lableangle = 0;
pLabel->setFontAngle(labelangle, axisInfo->m_labelAngleVertical);
]


If you can, How can i modify my code?
halfwidth_vertical_text.pdf
halfwidth_vertical_text.pdf

177.02 Kb
    
chartdir_pic.png

  Re: How to write vertical Japanese text in label?
Posted by Peter Kwan on Jun-22-2017 05:31
Hi Yejin,

Sorry for this issue. ChartDirector does not have built-in support to distinguish "full width" and "half width" Japanese characters and layout them differently. I have just written a simple utility "ToVerticalArray" that will insert some CDML tags in the text to layout them like in your last message. With the "ToVerticalArray", instead of using:

c->xAxis()->setLabels(StringArray(myLabels, count));

please use:

c->xAxis()->setLabels(ToVerticalArray(StringArray(myLabels, count)));

The code for "ToVerticalArray" is as follows. Please include them in your own code so that you can use "ToVerticalArray".



#include <vector>
#include <string>

// Converts a text string to vertical
class ToVertical
{
public :
    ToVertical(const char *str) {
        UTF8toWCHAR w(str);
        const wchar_t *wstr = (const wchar_t *)w;
        std::wstring ret;
        bool fullWidth = true;
        while (*wstr) {
            if (fullWidth != isFullWidth(*wstr))
                ret += !(fullWidth = isFullWidth(*wstr)) ? L"<*block,angle=270*>" : L"<*/*>n";
            ret += *wstr;
            if ((*++wstr) && fullWidth) ret += 'n';
        }
        buffer = WCHARtoUTF8(ret.c_str());
    }
    operator const char *() {
        return buffer.c_str();
    }
private :
    std::string buffer;
    bool isFullWidth(wchar_t c) {
        int i = ((int)(c)) & 0xffff;
        return ((i >= 3000) && (i <= 0x9fff)) || ((i >= 0xff01) && (i <= 0xff5e));
    }
};

// Converts a StringArray to vertical by inserting newlines
class ToVerticalArray
{
public :
    ToVerticalArray(StringArray labels) {
        buffer.resize(labels.len);
        for (int i = 0; i < labels.len; ++i)
            verticalLabels.push_back((buffer[i] = ToVertical(labels[i])).c_str());
    }
    operator StringArray() {
        return StringArray(&(verticalLabels[0]), verticalLabels.size());
    }
private :
    std::vector<std::string> buffer;
    std::vector<const char *> verticalLabels;
};


Hope this can help.

Regards
Peter Kwan