Ticket #4501: osd_fcnfont.patch

File osd_fcnfont.patch, 10.3 KB (added by Ron Frazier <ron@…>, 4 years ago)

fcnfont support for OSD textarea objects

  • libs/libmythtv/osd.h

     
    8181                     int length); 
    8282    void SetChannumText(const QString &text, int length); 
    8383 
     84    void SetFontFunction(const QString &container, const QString &funcgroup, 
     85                         const QString &funcname); 
     86 
    8487    // CC-608 and DVB text captions (not DVB/DVD subtitles). 
    8588    void AddCCText(const QString &text, int x, int y, int color,  
    8689                   bool teletextmode = false); 
  • libs/libmythtv/osd.cpp

     
    872872{ 
    873873    QRect area = QRect(0, 0, 0, 0); 
    874874    QString font = "", altfont = ""; 
     875    QStringList fcnGroups; 
     876    QMap<QString, QString> fcnFontsNeeded; 
    875877    QString statictext = ""; 
    876878    QString defaulttext = ""; 
    877879    bool multiline = false; 
     
    906908            { 
    907909                altfont = getFirstText(info); 
    908910            } 
     911            else if (info.tagName() == "fcnfont") 
     912            { 
     913                QString fontname = ""; 
     914                QString fontgrp = ""; 
     915                QString fontfcn = ""; 
     916 
     917                fontname = info.attribute("name", ""); 
     918                fontgrp = info.attribute("group", ""); 
     919                fontfcn = info.attribute("function", ""); 
     920 
     921                if (fontname.isNull() || fontname.isEmpty()) 
     922                { 
     923                    cerr << "FcnFont needs a name\n"; 
     924                    return; 
     925                } 
     926 
     927                if (fontgrp.isNull() || fontgrp.isEmpty()) 
     928                { 
     929                    cerr << "FcnFont needs a group\n"; 
     930                    return; 
     931                } 
     932 
     933                if (fontfcn.isNull() || fontfcn.isEmpty()) 
     934                { 
     935                    cerr << "FcnFont needs a function\n"; 
     936                    return; 
     937                } 
     938                if (fcnGroups.findIndex(fontgrp) == -1) 
     939                    fcnGroups.push_back(fontgrp); 
     940                fcnFontsNeeded[fontgrp + "+" + fontfcn] = fontname; 
     941            } 
    909942            else if (info.tagName() == "multiline") 
    910943            { 
    911944                if (getFirstText(info).lower() == "yes") 
     
    9721005            text->SetAltFont(ttffont); 
    9731006    } 
    9741007 
     1008    QMap<QString, TTFFont*> fcnFonts; 
     1009    QMap<QString,QString>::Iterator it; 
     1010    for (it = fcnFontsNeeded.begin(); it != fcnFontsNeeded.end(); ++it) 
     1011    { 
     1012        TTFFont *tmpfont = GetFont(it.data()); 
     1013        if (tmpfont) 
     1014            fcnFonts[it.key()] = tmpfont; 
     1015    } 
     1016    if (fcnFonts.size() > 0) 
     1017        text->InitFontFunctions(fcnGroups, fcnFonts); 
     1018 
    9751019    if (statictext != "") 
    9761020        text->SetText(statictext); 
    9771021    if (defaulttext != "") 
     
    17361780    osdlock.unlock(); 
    17371781} 
    17381782 
     1783void OSD::SetFontFunction(const QString &container, const QString &funcgroup, 
     1784                     const QString &funcname) 
     1785{ 
     1786    osdlock.lock(); 
     1787    OSDSet *osdset = GetSet(container); 
     1788    if (osdset) 
     1789        osdset->SetFontFunction(funcgroup, funcname); 
     1790    osdlock.unlock(); 
     1791} 
     1792 
    17391793void OSD::SetUpOSDClosedHandler(TV *tv) 
    17401794{ 
    17411795    OSDSet *container = GetSet("status"); 
  • libs/libmythtv/osdtypes.h

     
    103103    void SetShowWith(const QString &re) { m_showwith = re; }; 
    104104    bool SetSelected(int index); 
    105105    void SetText(const InfoMap &infoMap); 
     106    void SetFontFunction(const QString &group, const QString &function); 
    106107     
    107108  signals: 
    108109    void OSDClosed(int); 
     
    203204    void SetAltFont(TTFFont *font); 
    204205    void SetUseAlt(bool usealt) { m_usingalt = usealt; } 
    205206 
     207    void InitFontFunctions(QStringList groups, QMap<QString, TTFFont*> fonts) { 
     208                          m_fcngroups = groups; m_fcnfonts = fonts; } 
     209    void SetFontFunction(const QString &group, const QString &function); 
     210 
    206211    void SetText(const QString &text); 
    207212    QString GetText(void) const; 
    208213 
     
    245250  protected: 
    246251    ~OSDTypeText(); 
    247252 
     253    TTFFont* GetCurrentFont(); 
    248254    void DrawString(OSDSurface *surface, QRect rect, const QString &text, 
    249255                    int fade, int maxfade, int xoff, int yoff, 
    250256                    bool double_size=false); 
     
    261267    TTFFont *m_font; 
    262268    TTFFont *m_altfont; 
    263269 
     270    QStringList             m_fcngroups; 
     271    QMap<QString, TTFFont*> m_fcnfonts; 
     272    QString                 m_fontfunction; 
     273 
    264274    bool m_centered; 
    265275    bool m_right; 
    266276 
  • libs/libmythtv/osdtypes.cpp

     
    307307    m_needsupdate = true; 
    308308} 
    309309 
     310void OSDSet::SetFontFunction(const QString &group, const QString &function) 
     311{ 
     312    vector<OSDType *>::iterator it = allTypes->begin(); 
     313    for (; it != allTypes->end(); it++) 
     314    { 
     315        OSDTypeText *item = dynamic_cast<OSDTypeText*>(*it); 
     316        if (item) 
     317            item->SetFontFunction(group, function); 
     318    } 
     319    m_needsupdate = true; 
     320} 
     321 
    310322void OSDSet::GetText(QMap<QString, QString> &infoMap) const 
    311323{ 
    312324    vector<OSDType*>::const_iterator it = allTypes->begin(); 
     
    755767    m_altfont = font; 
    756768} 
    757769 
     770void OSDTypeText::SetFontFunction(const QString &group, const QString &function) 
     771{ 
     772    if (m_fcngroups.findIndex(group) == -1) 
     773        return; 
     774 
     775    QString key = group + "+" + function; 
     776    m_fontfunction = (m_fcnfonts.contains(key)) ? key : ""; 
     777} 
     778 
    758779QString OSDTypeText::BasicConvertFromRtoL(const QString &text) 
    759780{ 
    760781    QStringList rtl_string_composer; 
     
    908929    m_displaysize = m_screensize = bias(m_unbiasedsize, wmult, hmult); 
    909930} 
    910931 
     932TTFFont* OSDTypeText::GetCurrentFont() 
     933{ 
     934    if (m_fontfunction != "") 
     935    { 
     936        TTFFont *tmpfont = m_fcnfonts[m_fontfunction]; 
     937        if (tmpfont) 
     938            return tmpfont; 
     939    }; 
     940 
     941    return m_font; 
     942} 
     943 
    911944void OSDTypeText::Draw(OSDSurface *surface, int fade, int maxfade, int xoff,  
    912945                       int yoff) 
    913946{ 
     
    929962    if (m_scroller) 
    930963        m_parent->SetDrawEveryFrame(true); 
    931964 
    932     m_font->CalcWidth(m_message, &textlength); 
    933  
    934965    int maxlength = m_displaysize.width(); 
    935966 
    936967    if (m_multiline) 
    937968    { 
     969        TTFFont *tmpfont = GetCurrentFont(); 
     970        tmpfont->CalcWidth(m_message, &textlength); 
     971     
    938972        QString tmp_msg = QDeepCopy<QString>(m_message); 
    939973        regexp_lock.lock(); 
    940974        tmp_msg.replace(br, "\n"); 
     
    9661000            if (!length && word == "\n") 
    9671001                continue; 
    9681002 
    969             m_font->CalcWidth(word, &textlength); 
    970             if ((textlength + m_font->SpaceWidth() + length > maxlength) || 
     1003            tmpfont->CalcWidth(word, &textlength); 
     1004            if ((textlength + tmpfont->SpaceWidth() + length > maxlength) || 
    9711005                (word == "\n")) 
    9721006            { 
    9731007                QRect drawrect = m_displaysize; 
    974                 drawrect.setTop((int)(m_displaysize.top() + m_font->Size() *  
     1008                drawrect.setTop((int)(m_displaysize.top() + tmpfont->Size() *  
    9751009                                      (lines) * m_linespacing)); 
    9761010                DrawString(surface, drawrect, line, fade, maxfade, xoff, yoff); 
    9771011                length = 0; 
     
    9941028            else 
    9951029            { 
    9961030                line += " " + word; 
    997                 length += textlength + m_font->SpaceWidth(); 
     1031                length += textlength + tmpfont->SpaceWidth(); 
    9981032            } 
    9991033        } 
    10001034 
    10011035        QRect drawrect = m_displaysize; 
    1002         drawrect.setTop((int)(m_displaysize.top() + m_font->Size() * (lines) * 
     1036        drawrect.setTop((int)(m_displaysize.top() + tmpfont->Size() * (lines) * 
    10031037                              m_linespacing)); 
    10041038        DrawString(surface, drawrect, line, fade, maxfade, xoff, yoff); 
    10051039    }            
    10061040    else if (m_scroller) 
    10071041    { 
     1042        TTFFont *tmpfont = GetCurrentFont(); 
     1043 
    10081044        if (!m_scrollinit) 
    10091045        { 
    10101046            m_displaysize = m_screensize; 
    10111047            if (m_scrollx < 0) 
    10121048            { 
    1013                 int numspaces = m_displaysize.width() / m_font->SpaceWidth(); 
     1049                int numspaces = m_displaysize.width() / tmpfont->SpaceWidth(); 
    10141050                for (int i = 0; i < numspaces; i++) 
    10151051                    m_message.prepend(" "); 
    10161052 
    10171053                int messagewidth = 0; 
    1018                 m_font->CalcWidth(m_message, &messagewidth); 
     1054                tmpfont->CalcWidth(m_message, &messagewidth); 
    10191055                m_scrollstartx = 0; 
    10201056                m_scrollendx = 0 - (messagewidth); 
    10211057                m_scrollposx = m_scrollstartx; 
     
    10241060            else if (m_scrollx > 0) 
    10251061            { 
    10261062                int messagewidth = 0; 
    1027                 m_font->CalcWidth(m_message, &messagewidth); 
     1063                tmpfont->CalcWidth(m_message, &messagewidth); 
    10281064                m_scrollstartx = 0 - (messagewidth); 
    10291065                m_scrollendx = m_displaysize.width(); 
    10301066                m_scrollposx = m_scrollstartx; 
     
    11831219{ 
    11841220    QMutexLocker locker(&m_lock); 
    11851221 
     1222    TTFFont *font = GetCurrentFont(); 
     1223    if ((m_usingalt || m_selected) && m_altfont) 
     1224        font = m_altfont; 
     1225 
    11861226    if (m_centered || m_right) 
    11871227    { 
    11881228        int textlength = 0; 
    1189         m_font->CalcWidth(text, &textlength); 
     1229        font->CalcWidth(text, &textlength); 
    11901230 
    11911231        int xoffset = rect.width() - textlength; 
    11921232        if (m_centered) 
     
    12041244    if (maxfade > 0 && fade >= 0) 
    12051245        alphamod = (int)((((float)(fade) / maxfade) * 256.0) + 0.5); 
    12061246 
    1207     TTFFont *font = m_font; 
    1208     if ((m_usingalt || m_selected) && m_altfont) 
    1209         font = m_altfont; 
    12101247 
    12111248    font->DrawString(surface, rect.left(), rect.top(), text, 
    12121249                     rect.right(), rect.bottom(), alphamod, doubl); 
     
    12161253    { 
    12171254        xoff = 0; 
    12181255        if (m_cursorpos > 0) 
    1219             m_font->CalcWidth(text.left(m_cursorpos), &xoff); 
     1256            font->CalcWidth(text.left(m_cursorpos), &xoff); 
    12201257 
    1221         QRect crect(rect.left(), rect.top(), 2, (m_font->Size() * 3) / 2); 
     1258        QRect crect(rect.left(), rect.top(), 2, (font->Size() * 3) / 2); 
    12221259        if (crect.right() < surface->width && crect.right() < rect.right()) 
    12231260        { 
    12241261            OSDTypeBox box("cursor", crect, 1.0f, 1.0f);