Facing issue with chinese characters

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Facing issue with chinese characters

Postby Satrajit » Wed Nov 27, 2019 3:34 am

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"));
Satrajit
Mentor
 
Posts: 87
Joined: Wed Jan 09, 2019 6:11 am

Re: Facing issue with chinese characters

Postby Satrajit » Wed Nov 27, 2019 5:56 am

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
Satrajit
Mentor
 
Posts: 87
Joined: Wed Jan 09, 2019 6:11 am

Re: Facing issue with chinese characters

Postby magreenblatt » Wed Nov 27, 2019 10:58 am

You can specify a charset as part of the data URL. See for example here.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Facing issue with chinese characters

Postby Satrajit » Thu Nov 28, 2019 4:10 am

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.
Satrajit
Mentor
 
Posts: 87
Joined: Wed Jan 09, 2019 6:11 am

Re: Facing issue with chinese characters

Postby magreenblatt » Thu Nov 28, 2019 10:15 am

You need to use utf8 or another encoding that works with byte streams.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Facing issue with chinese characters

Postby Satrajit » Mon Dec 02, 2019 5:48 am

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;
}
Satrajit
Mentor
 
Posts: 87
Joined: Wed Jan 09, 2019 6:11 am

Re: Facing issue with chinese characters

Postby Satrajit » Tue Dec 17, 2019 4:21 am

got it resolved with setting
charset=utf-8

I was wrongly doing it as charset="utf-8"
Satrajit
Mentor
 
Posts: 87
Joined: Wed Jan 09, 2019 6:11 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 17 guests