Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-121395

Different space widths for different languages, even with the same font being used.

    XMLWordPrintable

Details

    Description

      It happens when render Sanskirt letters (probably also some other letters that I haven't tested) using certain fonts. Those certain fonts include, but probably not limited to, MS Gothic, Times New Roman, Consolas. When those fonts are used, space width for Sanskirt is different from most of other letters.

      Meanwhile, some other fonts, e.g. Arial, MS UI Gothic, Noto Sans, do not have such problem.

      A reproducer (I tested both QTextEdit and QPlainTextEdit and both show the issue):

      #include <QApplication>
      #include <QMainWindow>
      #include <QPlainTextEdit>
      #include <QVBoxLayout>
      
      //#define PLAINTEXT
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      
      	QMainWindow* mainWin = new QMainWindow();
      
      #ifdef PLAINTEXT
          QPlainTextEdit* textEdit = new QPlainTextEdit(mainWin);
          textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
      #else
          QTextEdit* textEdit = new QTextEdit(mainWin);
      #endif
          QFont font(QString::fromLocal8Bit("MS Gothic"), 10);
      	textEdit->setFont(font);
      
      	QStringList strs {
                      u8"                 안녕하세요:ハングル",
      		u8"                 नमस्ते:サンスクリット",
      		u8"                 Olá:ポルトガル",
      		u8"                 你好:中国",
      		u8"                 こんにちは:日本",
      		u8"                 Grüß Gott:ドイツ",
      		u8"                 Buenos días.:スペイン",
      		u8"                 สวัสดี:タイ",
      		u8"                 Здравствуйте:ロシア",
      		u8"                 Xin chào:ベトナム"
      	};
      
      	for (const QString& str : strs) {
      #ifdef PLAINTEXT
              textEdit->appendPlainText(str);
      #else
              textEdit->append(str);
      #endif
      		textEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
      	}
      
      	QVBoxLayout* layout = new QVBoxLayout;
      	layout->addWidget(textEdit, 1);
      	mainWin->setLayout(layout);
      
      	textEdit->resize(1200, 800);
      	mainWin->resize(1250, 850);
      	mainWin->show();
      
          qDebug() << textEdit->font();
      
      	return app.exec();
      }
      

      The result of MS Gothic (Sanskrit letter has narrower space):

      The result of Times New Roman (Sanskrit letter has wider space):

      The result of Arial (all letters have the same space width and are aligned as expected):

      Is it the problem of font files themselves or how Qt handles those fonts?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            luqiaochen Luqiao Chen
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes