Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 12-Feb-2011 11:36:08

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

[Solved][flash interface] string convert

my flash ui call pass a chinese words to scol,
then i use dailog box and debug console to display that words,
but the reasult is like this:
\198\223\292\198

how to convert it to factual string? is there any function I missed?

Last edited by kenshin1987 (13-Feb-2011 00:07:46)

Offline

#2 12-Feb-2011 18:51:17

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,081
Website

Re: [Solved][flash interface] string convert

wooh ...

i remember that scol could manage chinese language, but flash seem's to send unicode ?!

is other interface manage correctly chinese language ? (in dialog box title for example)

another cause could be a missed conversion in hikari flash call

Online

#3 12-Feb-2011 20:37:12

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

Re: [Solved][flash interface] string convert

arkeon wrote:

wooh ...

i remember that scol could manage chinese language, but flash seem's to send unicode ?!

is other interface manage correctly chinese language ? (in dialog box title for example)

another cause could be a missed conversion in hikari flash call

other interface like dialogbox can display chinese correctly,

somewhere in scol trun the chinese string to \xxx\xxx\xxx\xxx

fun cbGetMessage(flashctrl, constr, message, args)=
  _DMSevent this (getPluginInstanceEvent constr.FLINT_instance message) (listToString args) nil;
  0;;

after function listToString the value changed...

Last edited by kenshin1987 (12-Feb-2011 20:45:42)

Offline

#4 12-Feb-2011 21:47:17

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: [Solved][flash interface] string convert

Hello

kenshin1987 wrote:

after function listToString the value changed...

In this case, what is the code of this function ?

Offline

#5 12-Feb-2011 23:14:07

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

Re: [Solved][flash interface] string convert

fun listToString(l)=
  let nil -> ret in
  (
    let sizelist l -> size in
    let 0 -> i in
    while (i < size) do
    (
      let nth_list l i -> line in
      let strextr line -> lp in
        set ret = lcat ret (hd lp)::nil;
        
      set i = i + 1;
    );
    if ret == nil then nil else strbuild ret;
  );;

Offline

#6 12-Feb-2011 23:40:13

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: [Solved][flash interface] string convert

strbuild is a Scol function, in the standard library. But i see already some similars problems (with a french or english language). The reason was a bad formatted string at the entry.

Here, it may be the contain of the list ...
strbuild / strextr works the same way.
Are you tested "args" in cbGetMessage ?

However, Arkeon knows the os3d better than me, so wait his response.

Offline

#7 13-Feb-2011 00:13:55

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

Re: [Solved][flash interface] string convert

problem come from here,

the flash interface plugint when recieve the message form flash

fun cbGetMessage(flashctrl, constr, message, args)=
  _DMSevent this (getPluginInstanceEvent constr.FLINT_instance message) (listToString args) nil;
  0;;

it will call listToString function and this function will call strbuild.

strbuild will convert unicode word to \xxx\xxx\xxx\xxx format

so if I use strextr before show dialog,string display correct.

let hd hd (strextr message) -> message in

but this is only display the first word...

so we need use strcatn replace the listToString

Last edited by kenshin1987 (13-Feb-2011 00:28:38)

Offline

#8 13-Feb-2011 00:39:10

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: [Solved][flash interface] string convert

Ok !

Do you just need the first element  (hd strextr message) ? Not strextr message ?
strcatn take a [S r1] as argument, not [[S r1] r1]

Thanks to your work

Offline

#9 13-Feb-2011 03:07:52

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,081
Website

Re: [Solved][flash interface] string convert

oups i didn't see your responses ... i was working on 3D sounds (done) ...

the strbuild function made me crazy several times ...

i already rewrite the listToString function but in some cases the strbuild is needed

kenshin could you send me by mail your flash interface with an xos file using it ?

Online

#10 13-Feb-2011 06:19:02

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

Re: [Solved][flash interface] string convert

ok,no problem

Offline

#11 13-Feb-2011 15:00:46

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,081
Website

Re: [Solved][flash interface] string convert

could you try this instead ?

fun listToString(l)=
  let nil -> ret in
  (
    let sizelist l -> size in
    let 0 -> i in
    while (i < size) do
    (
      let nth_list l i -> line in
      let strextr line -> lp in
        set ret = lcat ret (strcatnSep (hd lp) " ")::nil;
        
      set i = i + 1;
    );
    if ret == nil then nil else strcatnSep ret "\n";
  );;

I changed my system language to japanese to test but text input don't seem's to work for me

Online

#12 14-Feb-2011 01:24:28

kenshin1987
Member
Registered: 10-Nov-2010
Posts: 100

Re: [Solved][flash interface] string convert

hi,arkeon
you use mbstowcs and wcstombs function to convert the string and wstring,not enough ,also should set setlocale(LC_ALL, "chs");.

but you can choose another way

like

std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen)

{
int nSize = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszSrc, nLen, 0, 0);
if(nSize <= 0) return NULL;

WCHAR *pwszDst = new WCHAR[nSize+1];
if( NULL == pwszDst) return NULL;

MultiByteToWideChar(CP_ACP, 0,(LPCSTR)pszSrc, nLen, pwszDst, nSize);
pwszDst[nSize] = 0;

if( pwszDst[0] == 0xFEFF) // skip Oxfeff
for(int i = 0; i < nSize; i ++)
pwszDst[i] = pwszDst[i+1];

wstring wcharString(pwszDst);
delete pwszDst;

return wcharString;
}

std::wstring s2ws(const string& s){ return Ansi2WChar(s.c_str(),s.size());}

 
std::string WChar2Ansi(LPCWSTR pwszSrc)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);

if (nLen<= 0) return std::string("");

char* pszDst = new char[nLen];
if (NULL == pszDst) return std::string("");

WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
pszDst[nLen -1] = 0;

std::string strTemp(pszDst);
delete [] pszDst;

return strTemp;
}

string ws2s(wstring& inputws){ return WChar2Ansi(inputws.c_str()); }

and about the flash keyborad input:

void FlashControl::handleKeyEvent(UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT aResult;
    if(msg == WM_CHAR)
    {
        if(wParam > 0x7F)
        {
            if(!__mbr_enable)
            {
                __mbr_enable = true;
                __mbr_save_w = wParam;
                __mbr_save_l = lParam;
            }
            else
            {
                __mbr_enable = false;

                windowlessObject->OnWindowMessage(msg, wParam, lParam, &aResult);
                windowlessObject->OnWindowMessage(msg, __mbr_save_w,__mbr_save_l, &aResult);    
            }
        }
        else
        {
            __mbr_enable = false;
            windowlessObject->OnWindowMessage(msg, wParam, lParam, &aResult);
        }
    }
    else
        windowlessObject->OnWindowMessage(msg, wParam, lParam, &aResult);
}

because the code

fact input  :中文测试 : d6 d0 ce c4 b2 e2 ca d4
displayed  :兄奈獠允 : d0 d6 c4 ce e2 b2 d4 ca

this is why everything happening.when windows decide to transfer a unicode character,it will send two WM_CHAR to the target window,first the lower two bytes,then the higher two bytes.maybe this is windows needed,but it seems the flash player doesn`t think so.so what we have to do is quite simple.we should reverse the two WM_CHAR messages before they were sent to flash player activex.we will need some hacking on our Hikari.in the FlashControl::handleKeyEvent,we join a procedure before calling windowlessObject->OnWindowMessage.we pick the WM_CHAR message,then check the wParam,if it`s not an ascii character,then we do something discussed above,else we just pass it.

Offline

#13 14-Feb-2011 09:30:54

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,081
Website

Re: [Solved][flash interface] string convert

thanks kenshin we will try this

Online

#14 14-Feb-2011 13:19:28

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: [Solved][flash interface] string convert

Yes ! We already talked about that on the old Scolring. It's an important work to do. At this time, no localization exists in Scol. It's a really problem if a language is not latin encoded, there may be undefined behaviors. There are a lot of things to do on the strings. I note that to do some tests with y lib "TEST".

If needed, my "bible" : http://www.linuxcertif.com/man/3/setlocale/ (fr, en, ...)
setlocale is C89 and Posix. It's standard and portable.
In these sources, there are some exmaples / uses : newtonsdk, ogre3d, ... See the redmine.
Good luck smile

Offline

#15 14-Feb-2011 22:47:51

Nodrev
Scol Language & OS3D developer
From: Nantes, France
Registered: 29-Dec-2009
Posts: 197

Re: [Solved][flash interface] string convert

Seems that you use the "old" FlashControl class.
We will have to test if it's ok with the new one (SFlashWidget)...

Nodrev

Offline

Board footer

Powered by FluxBB