Ticket #4501: osd_fcnfont.patch
| File osd_fcnfont.patch, 10.3 KB (added by Ron Frazier <ron@…>, 4 years ago) |
|---|
-
libs/libmythtv/osd.h
81 81 int length); 82 82 void SetChannumText(const QString &text, int length); 83 83 84 void SetFontFunction(const QString &container, const QString &funcgroup, 85 const QString &funcname); 86 84 87 // CC-608 and DVB text captions (not DVB/DVD subtitles). 85 88 void AddCCText(const QString &text, int x, int y, int color, 86 89 bool teletextmode = false); -
libs/libmythtv/osd.cpp
872 872 { 873 873 QRect area = QRect(0, 0, 0, 0); 874 874 QString font = "", altfont = ""; 875 QStringList fcnGroups; 876 QMap<QString, QString> fcnFontsNeeded; 875 877 QString statictext = ""; 876 878 QString defaulttext = ""; 877 879 bool multiline = false; … … 906 908 { 907 909 altfont = getFirstText(info); 908 910 } 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 } 909 942 else if (info.tagName() == "multiline") 910 943 { 911 944 if (getFirstText(info).lower() == "yes") … … 972 1005 text->SetAltFont(ttffont); 973 1006 } 974 1007 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 975 1019 if (statictext != "") 976 1020 text->SetText(statictext); 977 1021 if (defaulttext != "") … … 1736 1780 osdlock.unlock(); 1737 1781 } 1738 1782 1783 void 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 1739 1793 void OSD::SetUpOSDClosedHandler(TV *tv) 1740 1794 { 1741 1795 OSDSet *container = GetSet("status"); -
libs/libmythtv/osdtypes.h
103 103 void SetShowWith(const QString &re) { m_showwith = re; }; 104 104 bool SetSelected(int index); 105 105 void SetText(const InfoMap &infoMap); 106 void SetFontFunction(const QString &group, const QString &function); 106 107 107 108 signals: 108 109 void OSDClosed(int); … … 203 204 void SetAltFont(TTFFont *font); 204 205 void SetUseAlt(bool usealt) { m_usingalt = usealt; } 205 206 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 206 211 void SetText(const QString &text); 207 212 QString GetText(void) const; 208 213 … … 245 250 protected: 246 251 ~OSDTypeText(); 247 252 253 TTFFont* GetCurrentFont(); 248 254 void DrawString(OSDSurface *surface, QRect rect, const QString &text, 249 255 int fade, int maxfade, int xoff, int yoff, 250 256 bool double_size=false); … … 261 267 TTFFont *m_font; 262 268 TTFFont *m_altfont; 263 269 270 QStringList m_fcngroups; 271 QMap<QString, TTFFont*> m_fcnfonts; 272 QString m_fontfunction; 273 264 274 bool m_centered; 265 275 bool m_right; 266 276 -
libs/libmythtv/osdtypes.cpp
307 307 m_needsupdate = true; 308 308 } 309 309 310 void 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 310 322 void OSDSet::GetText(QMap<QString, QString> &infoMap) const 311 323 { 312 324 vector<OSDType*>::const_iterator it = allTypes->begin(); … … 755 767 m_altfont = font; 756 768 } 757 769 770 void 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 758 779 QString OSDTypeText::BasicConvertFromRtoL(const QString &text) 759 780 { 760 781 QStringList rtl_string_composer; … … 908 929 m_displaysize = m_screensize = bias(m_unbiasedsize, wmult, hmult); 909 930 } 910 931 932 TTFFont* 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 911 944 void OSDTypeText::Draw(OSDSurface *surface, int fade, int maxfade, int xoff, 912 945 int yoff) 913 946 { … … 929 962 if (m_scroller) 930 963 m_parent->SetDrawEveryFrame(true); 931 964 932 m_font->CalcWidth(m_message, &textlength);933 934 965 int maxlength = m_displaysize.width(); 935 966 936 967 if (m_multiline) 937 968 { 969 TTFFont *tmpfont = GetCurrentFont(); 970 tmpfont->CalcWidth(m_message, &textlength); 971 938 972 QString tmp_msg = QDeepCopy<QString>(m_message); 939 973 regexp_lock.lock(); 940 974 tmp_msg.replace(br, "\n"); … … 966 1000 if (!length && word == "\n") 967 1001 continue; 968 1002 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) || 971 1005 (word == "\n")) 972 1006 { 973 1007 QRect drawrect = m_displaysize; 974 drawrect.setTop((int)(m_displaysize.top() + m_font->Size() *1008 drawrect.setTop((int)(m_displaysize.top() + tmpfont->Size() * 975 1009 (lines) * m_linespacing)); 976 1010 DrawString(surface, drawrect, line, fade, maxfade, xoff, yoff); 977 1011 length = 0; … … 994 1028 else 995 1029 { 996 1030 line += " " + word; 997 length += textlength + m_font->SpaceWidth();1031 length += textlength + tmpfont->SpaceWidth(); 998 1032 } 999 1033 } 1000 1034 1001 1035 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) * 1003 1037 m_linespacing)); 1004 1038 DrawString(surface, drawrect, line, fade, maxfade, xoff, yoff); 1005 1039 } 1006 1040 else if (m_scroller) 1007 1041 { 1042 TTFFont *tmpfont = GetCurrentFont(); 1043 1008 1044 if (!m_scrollinit) 1009 1045 { 1010 1046 m_displaysize = m_screensize; 1011 1047 if (m_scrollx < 0) 1012 1048 { 1013 int numspaces = m_displaysize.width() / m_font->SpaceWidth();1049 int numspaces = m_displaysize.width() / tmpfont->SpaceWidth(); 1014 1050 for (int i = 0; i < numspaces; i++) 1015 1051 m_message.prepend(" "); 1016 1052 1017 1053 int messagewidth = 0; 1018 m_font->CalcWidth(m_message, &messagewidth);1054 tmpfont->CalcWidth(m_message, &messagewidth); 1019 1055 m_scrollstartx = 0; 1020 1056 m_scrollendx = 0 - (messagewidth); 1021 1057 m_scrollposx = m_scrollstartx; … … 1024 1060 else if (m_scrollx > 0) 1025 1061 { 1026 1062 int messagewidth = 0; 1027 m_font->CalcWidth(m_message, &messagewidth);1063 tmpfont->CalcWidth(m_message, &messagewidth); 1028 1064 m_scrollstartx = 0 - (messagewidth); 1029 1065 m_scrollendx = m_displaysize.width(); 1030 1066 m_scrollposx = m_scrollstartx; … … 1183 1219 { 1184 1220 QMutexLocker locker(&m_lock); 1185 1221 1222 TTFFont *font = GetCurrentFont(); 1223 if ((m_usingalt || m_selected) && m_altfont) 1224 font = m_altfont; 1225 1186 1226 if (m_centered || m_right) 1187 1227 { 1188 1228 int textlength = 0; 1189 m_font->CalcWidth(text, &textlength);1229 font->CalcWidth(text, &textlength); 1190 1230 1191 1231 int xoffset = rect.width() - textlength; 1192 1232 if (m_centered) … … 1204 1244 if (maxfade > 0 && fade >= 0) 1205 1245 alphamod = (int)((((float)(fade) / maxfade) * 256.0) + 0.5); 1206 1246 1207 TTFFont *font = m_font;1208 if ((m_usingalt || m_selected) && m_altfont)1209 font = m_altfont;1210 1247 1211 1248 font->DrawString(surface, rect.left(), rect.top(), text, 1212 1249 rect.right(), rect.bottom(), alphamod, doubl); … … 1216 1253 { 1217 1254 xoff = 0; 1218 1255 if (m_cursorpos > 0) 1219 m_font->CalcWidth(text.left(m_cursorpos), &xoff);1256 font->CalcWidth(text.left(m_cursorpos), &xoff); 1220 1257 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); 1222 1259 if (crect.right() < surface->width && crect.right() < rect.right()) 1223 1260 { 1224 1261 OSDTypeBox box("cursor", crect, 1.0f, 1.0f);
