Page 1 of 1

Facing issue with chinese characters

PostPosted: Wed Nov 27, 2019 3:34 am
by Satrajit
I have used a similar type like this.
But facing issue with chinese characters. Even wstring was of no use.

frame->LoadURL(test_runner::GetDataURI(ss.str(), "text/html"));

Re: Facing issue with chinese characters

PostPosted: Wed Nov 27, 2019 5:56 am
by Satrajit
Used the same code in test_runner.cc

std::string GetDataURI(const std::string& data, const std::string& mime_type) {
return "data:" + mime_type + ";base64," +
CefURIEncode(CefBase64Encode(data.data(), data.size()), false)
.ToString();
}

1. If I use data to be string then garbage characters are coming.
2. If data is wstring then
CefURIEncode(CefBase64Encode(data.ToWString().data(), data.size()), false) //is not working

Issue is
1. Can't use string which is not expected in utf-16
2. CefBase64Encode is not supporting wstring


Found same issue here, but couldn't get the solution.
Would be helpful if someone can post an example for the above for chinese like characters

Re: Facing issue with chinese characters

PostPosted: Wed Nov 27, 2019 10:58 am
by magreenblatt
You can specify a charset as part of the data URL. See for example here.

Re: Facing issue with chinese characters

PostPosted: Thu Nov 28, 2019 4:10 am
by Satrajit
CefString &data = The whole html that needs to be shown. in <html> tags and without the charsets.
Adding the charsets at later point of time in GetDataURI()

If worked using string then DBCS characters are not working else everything is working fine.

CefString SimpleHandler::GetDataURI(const CefString &data, const CefString &mime_type)
{
CefString temp = CefString("data:").ToString() + mime_type.ToString() +
CefString(";charset=").ToString() +
CefString("\"utf-16\"").ToString() +
CefString(";base64,").ToString() + CefURIEncode(CefBase64Encode(data.ToString().data(), data.size()), false).ToString();
return temp;
}

But if worked using wstring and adding charset=utf-16 then CefBase64Encode(data.ToWString().data(), data.size()) is causing the problem.
CefString SimpleHandler::GetDataURI(const CefString &data, const CefString &mime_type)
{
CefString temp = CefString("data:").ToWString() + mime_type.ToWString() +
CefString(";charset=").ToWString() +
CefString("\"utf-16\"").ToWString() +
CefString(";base64,").ToWString() + CefURIEncode(CefBase64Encode(data.ToWString().data(), data.size()), false).ToWString();
return temp;
}

Don't know where I am going wrong. Confused now.

Re: Facing issue with chinese characters

PostPosted: Thu Nov 28, 2019 10:15 am
by magreenblatt
You need to use utf8 or another encoding that works with byte streams.

Re: Facing issue with chinese characters

PostPosted: Mon Dec 02, 2019 5:48 am
by Satrajit
Used utf-8 and ucs2, but of no use.
Still facing the same issue.

Don't know whether there is a different way to add the charset.

CefString SimpleHandler::GetDataURI(const CefString &data, const CefString &mime_type)
{
CefString temp = CefString("data:").ToString() + mime_type.ToString() +
CefString(";charset=").ToString() +
CefString("\"utf-8\"").ToString() +
CefString(";base64,").ToString() + CefURIEncode(CefBase64Encode(data.ToString().data(), data.size()), false).ToString();
return temp;
}

Re: Facing issue with chinese characters

PostPosted: Tue Dec 17, 2019 4:21 am
by Satrajit
got it resolved with setting
charset=utf-8

I was wrongly doing it as charset="utf-8"