Page MenuHomePhabricator

Unicode character display
Closed, ResolvedPublic

Description

ExtApp display uncorrectly when plugin.xml includes some non-ASCII
characters, such as Chinese character. Because it is coded in UTF-8
mode, like
simpleexample plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin>

<extension point="org.opencherry.ui.views">
  <view id="org.mitk.views.simpleexample"
        name="SimpleExample" -> changed this line to some Chinese characters
        class="::QmitkSimpleExampleView" />
</extension>

</plugin>

Then mitk should read the name in UTF-8 mode.

I added several lines to display UTF-8 characters correctly in
mitk\openCherry\Bundles\org.opencherry.ui.qt\src\internal\cherryQtShowViewAction.cpp, between

this->setParent(static_cast<QWidget*>(window->GetShell()->GetControl()));

and

this->setText(QString(desc->GetLabel().c_str()));
this->setToolTip(QString(desc->GetLabel().c_str()));

// the following is added to display correctly UTF-8 caracters

QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);

//
Do not know whether the code fashion change affect following exectuion,
like I/O.

If I only change following two lines to

this->setText(QString::fromUtf8(desc->GetLabel().c_str()));
this->setToolTip(QString::fromUtf8(desc->GetLabel().c_str()));

the menu characters is right, the control panel tilte is weird.

Event Timeline

I like the idea of supporting utf-8. Fucang, can you give us some information, what we have to do to be compatible? Or do you even plan to provide a patch for utf-8 support?

You said that some elements still look strange. Perhaps you can add a screenshot here (search this page for "add an attachment")?

This is the right display of some non-ASCII characters when loading form plugin.xml

CoreApp_right_Characters_display.png (800×1 px, 169 KB)

This is a wrong display of non-ASCII characters when loading form plugin.xml

CoreApp_wrong_Characters_display.png (800×1 px, 170 KB)

The Unicode description described is a dirty hack. I just noticed that the change can be set in one place, which is the begin part of CoreApp or ExtApp main function.

The plugin.xml part includs Chinese extension name.

mitk/CoreUI/Bundles/org.mitk.gui.qt.application/plugin.xml

.....
<extension point="org.opencherry.ui.editors">

  <editor
    id="org.mitk.editors.stdmultiwidget"
    name="标准视图"
    class="QmitkStdMultiWidgetEditor">
  </editor>
</extension>

mitk/openCherry/Bundles/org.opencherry.ui.qt/plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<?openCherry version="0.1"?>
<plugin>

<extension point="org.opencherry.ui.views"> 
   <category 
      id="org.opencherry.views.general" 
      name="General"/> 
   <view 
      id="org.opencherry.views.logview" 
      name="日志查看器" 
      category="org.opencherry.views.general" 
      class="cherry::LogView" />
</extension>

....

mitk/Applications/CoreApp/CoreApp.cpp

#include <org.opencherry.osgi/src/application/cherryStarter.h>
#include <Poco/Util/MapConfiguration.h>

// QTextCodec is needed for UTF-8 characters display
#include <QTextCodec>

int main(int argc, char** argv)
{

// These paths replace the .ini file and are tailored for installation
// packages created with CPack. If a .ini file is presented, it will
// overwrite the settings in MapConfiguration

// Text code should be set to UTF-8 for right display of UTF-8 characters in plugin.xml, if commented out the weird display will occur.

QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
 
Poco::Path basePath(argv[0]);
basePath.setFileName("");

Poco::Path openCherryPath(basePath);
openCherryPath.pushDirectory("openCherry");

Poco::Path corePath(basePath);
corePath.pushDirectory("CoreBundles");

std::string pluginDirs = openCherryPath.toString() + ";" + corePath.toString();

Poco::Util::MapConfiguration* coreConfig(new Poco::Util::MapConfiguration());
coreConfig->setString(cherry::Platform::ARG_PLUGIN_DIRS, pluginDirs);
return cherry::Starter::Run(argc, argv, coreConfig);

}

Conrespondingly, the CMakeLists.txt should add "INCLUDE(${QT_USE_FILE})" and
TARGET_LINK_LIBRARIES should add "${QT_LIBRARIES}"

In this way it works very well for ASCII and non-ASCII characters.

Thanks a lot for this report. I will have a look at unicode support and probably integrate your changes into the org.opencherry.ui.qt bundle such that every application benefits automatically from it.

[SVN revision 21481]
FIX (#2302): set encoding for c-strings used with QString and QObject::tr() calls to UTF-8