1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0031171: Draw - support Unicode input / output in console on Windows

System console is configured at DRAW start to use UTF-8 encoding, for cout and cin to deal correctly with Unicode symbols.
Use of std::wcout is avoided as it leads to corrupted output.

Command testgrid is improved to enforce UTF-8 encoding in child DRAW processes to preserve Unicode symbols in captured output.

Test bugs fclasses bug22125 is refactored:
- avoid dependency on external data file
- avoid producing snapshot
- check that Unicode name of the file created by OCCT procedure matches the name interpreted by Tcl functions
This commit is contained in:
abv
2019-11-16 08:59:38 +03:00
parent 9a90a4524e
commit 8f00325d73
6 changed files with 30 additions and 36 deletions

View File

@@ -185,8 +185,9 @@ LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
GetCaretPos (&pos);
SendMessageW (hWnd, EM_REPLACESEL, 0, (LPARAM )THE_PROMPT);
// Display the command in the console
std::wcout << aCmdBuffer << std::endl;
//TCollection_AsciiString aCmdUtf8 (aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1);
//std::wcout << aCmdBuffer << std::endl; // wcout does not work well with UTF-8
TCollection_AsciiString aCmdUtf8 (aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1);
std::cout << aCmdUtf8.ToCString() << std::endl;
//Draw_Interprete (aCmdUtf8.ToCString());
//if (toExit) { DestroyProc (hWnd); }
wcscpy_s (console_command, aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1);

View File

@@ -621,12 +621,7 @@ Standard_Boolean Draw_Interprete(const char* com)
if (*theCommands.Result())
{
#ifdef _WIN32
const TCollection_ExtendedString aResWide (theCommands.Result());
std::wcout << aResWide.ToWideString() << std::endl;
#else
std::cout << theCommands.Result() << std::endl;
#endif
}
if (Draw_Chrono && hadchrono) {

View File

@@ -371,15 +371,7 @@ void Draw_Interpretor::Reset()
Draw_Interpretor& Draw_Interpretor::Append(const Standard_CString s)
{
#ifdef TCL_USES_UTF8
// Convert string to UTF-8 format for Tcl
Tcl_DString TclString;
Tcl_ExternalToUtfDString ( NULL, s, -1, &TclString );
Tcl_AppendResult ( myInterp, Tcl_DStringValue ( &TclString ), (Standard_CString)0 );
Tcl_DStringFree ( &TclString );
#else
Tcl_AppendResult(myInterp,s,(Standard_CString)0);
#endif
return *this;
}
@@ -457,21 +449,7 @@ Draw_Interpretor& Draw_Interpretor::Append(const Standard_SStream& s)
void Draw_Interpretor::AppendElement(const Standard_CString s)
{
#ifdef TCL_USES_UTF8
// Convert string to UTF-8 format for Tcl
Tcl_DString TclString;
Tcl_ExternalToUtfDString ( NULL, s, -1, &TclString );
Tcl_AppendElement ( myInterp, Tcl_DStringValue ( &TclString ) );
Tcl_DStringFree ( &TclString );
#else
#ifdef IRIX
//AppendElement is declared as (Tcl_Interp *interp, char *string)
//on SGI 32
Tcl_AppendElement(myInterp,(char*) s);
#else
Tcl_AppendElement(myInterp, s);
#endif
#endif
}
//=======================================================================

View File

@@ -70,6 +70,11 @@ Standard_Integer Draw_Main (int /*argc*/, char* argv[], const FDraw_InitAppli fD
Draw_IsConsoleSubsystem = Standard_True;
theDraw_InitAppli = fDraw_InitAppli;
// Set console code page to UTF-8 so that input from cin and output to cout
// pass Unicode symbols as expected
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
// MKV 01.02.05
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
Tcl_FindExecutable(argv[0]);