Ticket #3851: osdtypes.diff

File osdtypes.diff, 1.3 KB (added by ido roseman <ido_roseman@…>, 17 years ago)

fix right-to-left text on OSD

  • libs/libmythtv/osdtypes.cpp

    old new  
    736736
    737737void OSDTypeText::SetText(const QString &text)
    738738{
    739     m_message = text;
     739//    m_message = text;
     740
     741    QChar::Direction text_dir;
     742    QStringList rtl_string_composer;
     743    bool handle_rtl(false);
     744    QChar prev_char;
     745
     746    //Handling Right-to-Left languages.
     747    //Left-to-Right languages are not affected.
     748    for (int i = (int)text.length() - 1; i >= 0; i--) {
     749        text_dir = text[i].direction();
     750        if (text_dir != QChar::DirR && text_dir != QChar::DirRLE && text_dir != QChar::DirRLO) {
     751                if (handle_rtl || rtl_string_composer.empty())
     752                        rtl_string_composer.append(QString());
     753
     754                if (text[i].isSpace() && !prev_char.isNull() && prev_char.isDigit() && handle_rtl)
     755                        rtl_string_composer.back().append(text[i]);
     756                else
     757                        rtl_string_composer.back().prepend(text[i]);
     758                prev_char = text[i];
     759
     760                if (handle_rtl)
     761                        handle_rtl = false;
     762        }
     763        else {
     764                if (!handle_rtl) {
     765                        rtl_string_composer.append(QString());
     766                        handle_rtl = true;
     767                        prev_char = QChar();
     768                }
     769                rtl_string_composer.back().append(text[i]);
     770        }
     771    }
     772    m_message = rtl_string_composer.join("");
     773
    740774    m_cursorpos = text.length();
    741775    m_scrollinit = false;
    742776}