Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[CS3 - Mac] Error with cyrillic characters

Community Beginner ,
Dec 05, 2008 Dec 05, 2008
Hi

On Mac I am using: Xcode 3.1, InDesign CS3 and InDesign SDK 5.0.4

If I open an InDesign document on Mac and I write cyrillic characters, it appears on screen without problems but if I create a char variable with the same cyrillic characters and then I print it, the result is not correct.

Example:
char *myText = "My russian text:Русский компонент";
CAlert::WarningAlert(myText);

The result is:
"My russian text:ÉÅÅ∫∏π ∫æºøæΩµΩÇ"

Note: If I create a simple c++ program with this code it works!:
char *myText = "My russian text:Русский компонент";
std::cout << myText;

Any idea is welcome!
TOPICS
SDK
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 05, 2008 Dec 05, 2008
Use a WideString not a char* - cyrillic is not part of ASCII... You may be able to do something like WarningAlert(L"My russian...");

Ian
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 09, 2008 Dec 09, 2008
Thanks Ian

Yes, I know it works with WideString but I need to use char* because I call a function which returns this type of variable.

I need to convert my char* to a legible data (for example using std::cout, but in InDesign)

With this command (in a simple c++ program) I see the text perfectly
std::cout << myText;

I suppose than cout makes an internal transformation, I need some similar but into InDesign

Something like:
CAlert::WarningAlert(std::cout << myText);

Nolo
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 12, 2008 Dec 12, 2008
I found a SDK function "CharToTextChar" which converts a char to UTF16TextChar and then I create a PMString with this variable.

#include "CTUnicodeTranslator.h"

char *myText = "My russian text:Русский компонент";
int tamano = strlen(myText);
UTF16TextChar *toUTFString = new UTF16TextChar[tamano+1];

int32 numWChars = ::CTUnicodeTranslator::Instance()->CharToTextChar(myText, tamano, toUTFString, tamano);

PMString myString;
myString.InsertW(toUTFString, numWChars);


Unfortunately this doesn't works and I obtain the same result (strange characters) and there is not difference between both messages:

CAlert::WarningAlert(myText);
CAlert::WarningAlert(myString);

Nobody works on Mac with Cyrillic, Arabic or some simlimar language which is not included in ASCII code?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 12, 2008 Dec 12, 2008
Hi,<br /><br />This is really not easy from a char*...<br />You must first convert it in wchar_t*. There is a method called "mbstowcs()" but doesn't work :<br /><br />#include <string><br />char *myText = "My russian text:&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081; &#1082;&#1086;&#1084;&#1087;&#1086;&#1085;&#1077;&#1085;&#1090;";<br />size_t size = strlen(myText) + 1;<br />wchar_t myString[size];<br />mbstowcs(myString, myText, size);<br />WideString wideString(myString);<br />CAlert::WarningAlert(wideString);<br /><br />I guess you can't change your method for your char* ?<br />Cause a wchar_t* resolve all your problems :<br /><br />wchar_t *myText = L"My russian text:&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081; &#1082;&#1086;&#1084;&#1087;&#1086;&#1085;&#1077;&#1085;&#1090;";<br />WideString wideString(myText);<br />CAlert::WarningAlert(wideString);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 15, 2008 Dec 15, 2008
Thanks John

The problem is solved!! I have created a function whose entry is a char and the output is a PMString.

My char variable has UTF-8 encoding. This type of encoding is described in "http://en.wikipedia.org/wiki/UTF-8".

The key is to convert each char to integer, but some characters (for example cyrillic) are saved into 2 or 3 bytes. So it's neccesary to read these 2 or 3 bytes to generate their decimals.

For example:

char myText[] = "й"

myText has 2 bytes: 11010000 and 10111001, so that, reads these 2 bytes and transforms to decimal (1081). This number is assigned to PMString with the "AppendW" function.

This is the function (it works with 1, 2 or 3 bytes):

PMString Convert_UTF8_to_PMString (char * myText)
{
PMString myString;
int total;
char binary[4];
bool two_bytes = false;
bool third_byte = false;

for (int cont=0; cont < strlen(myText); cont++)
{
int i = CHAR_BIT;
while(i>4)
{
--i;
binary[7-ib]=(const char)(myText[cont]&(1 << i) ? '1' : '0');
}

int num = myText[cont];

if (strncmp(binary,"110",3)==0)
{
// 2 BYTES
two_bytes = true;
total = (num+64)*64;
}
else if (strncmp(binary,"1110",4)==0)
{
// 3 BYTES
two_bytes = false;
total = (num+32)*4096;
}
else if (strncmp(binary,"10",2)==0)
{
if (two_bytes)
{
myString.AppendW(total + num + 128);
}
else
{
if (third_byte)
{
third_byte = false;
myString.AppendW(total + num + 128);
}
else
{
total = total + ((num + 128)*64);
third_byte = true;
}
}
}
else
{
// 1 BYTE
two_bytes = false;
myString.AppendW(num);
}
}

return myString;
}

Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 23, 2014 Sep 23, 2014
LATEST

Hi,

       Can u help me to convert the special characters in to unicode hexadecimal value

Thanks in advance,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 23, 2008 Dec 23, 2008
More simple method to display cyrillic text:<br />InterfacePtr<ITextControlData> textData((ITextControlData*)(widgetParent->QueryParentFor(ITextControlData::kDefaultIID)));<br />if( textData == nil )<br /> break;<br /> <br />PMString panelName = "&#1055;&#1088;&#1080;&#1074;&#1077;&#1090; &#1086;&#1090; &#1070;&#1088;&#1082;&#1080; &#1055;&#1077;&#1090;&#1088;&#1086;&#1074;&#1072;!";<br />panelName.SetEncoding(PMString::kEncodingCyrillic);<br />textData->SetString( panelName );<br /><br />Works fine in Xcode&VS2005
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 23, 2008 Dec 23, 2008
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 23, 2008 Dec 23, 2008
Hi Yury

If you have only cyrillic characters, your solution is good. But with my function, you can use it with any language (english, russian, chinesse...) and you do not have to know beforehand the kind of language to read.

Example:

char *myText = "1 - one, 2 - два, 4 - τέσσερα";

PMString myString;
myString = Convert_UTF8_to_PMString(myText);

CAlert::WarningAlert(myString);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 23, 2008 Dec 23, 2008
Other language such as Russian, Chinese, Japanese can not be assigned to a 8 bit char as char* *myText=" "; One needs to use wide char or PMString to hold it, otherwise, it will lose information when it is operated for sure. Englisg is an exception. It can be represented by 8 bits char.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 16, 2009 Jan 16, 2009
Just for the record: PMString initialization is done in the codepage of the source-file, which is set in the development tool. Xcode: "Get Info" on the source file. DevStudio: "Advanced Save" options in the File menu

So to get the constant string correctly into the PMString, select a codepage matching the encoding you want to use... Or do the UTF8 trick... Or store the strings in a resource file and have InDesign do the correct encoding ...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines