Skip to content

Commit e9a846f

Browse files
committed
Fix a number of bugs related to font stretching. In no particular order - Don't overwrite the global stretch value which is meant to deal with non-square pixel displays; Make the stretch adjustments for the XV osd earlier so that text isn't truncated at the wrong point; Allow the <stretch> element to work in the OSD. Don't leak an instance of MythFontProperties in MythUIGuideGrid.
git-svn-id: http://svn.mythtv.org/svn/trunk@26739 7dbf422c-18fa-0310-86e9-fd20926502f2
1 parent 71a564f commit e9a846f

File tree

11 files changed

+81
-32
lines changed

11 files changed

+81
-32
lines changed

mythtv/libs/libmythtv/osd.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ void OSD::OverrideUIScale(void)
200200
if (uirect == m_Rect)
201201
return;
202202

203+
m_savedFontStretch = GetMythUI()->GetFontStretch();
204+
GetMythUI()->SetFontStretch(m_fontStretch);
205+
203206
int width, height;
204207
MythUIHelper::getMythUI()->GetScreenSettings(width, m_SavedWMult,
205208
height, m_SavedHMult);
@@ -220,6 +223,7 @@ void OSD::RevertUIScale(void)
220223
{
221224
if (m_UIScaleOverride)
222225
{
226+
GetMythUI()->SetFontStretch(m_savedFontStretch);
223227
GetMythMainWindow()->SetScalingFactors(m_SavedWMult, m_SavedHMult);
224228
GetMythMainWindow()->SetUIScreenRect(m_SavedUIRect);
225229
}

mythtv/libs/libmythtv/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class OSD
203203
float m_SavedHMult;
204204
QRect m_SavedUIRect;
205205
int m_fontStretch;
206+
int m_savedFontStretch;
206207

207208
enum OSDFunctionalType m_FunctionalType;
208209
QString m_FunctionalWindow;

mythtv/libs/libmythtv/videooutbase.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,6 @@ bool VideoOutput::DisplayOSD(VideoFrame *frame, OSD *osd)
13231323
return false;
13241324
}
13251325

1326-
osd_painter->SetFontStretch(osd->GetFontStretch());
13271326
QRegion dirty = QRegion();
13281327
QRegion visible = osd->Draw(osd_painter, osd_image, osd_size, dirty,
13291328
frame->codec == FMT_YV12 ? ALIGN_X_MMX : 0,

mythtv/libs/libmythui/mythfontproperties.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
MythFontProperties::MythFontProperties() :
2222
m_brush(QColor(Qt::white)), m_hasShadow(false), m_shadowAlpha(255),
23-
m_hasOutline(false), m_outlineAlpha(255), m_bFreeze(false)
23+
m_hasOutline(false), m_outlineAlpha(255), m_bFreeze(false), m_stretch(100)
2424
{
2525
CalcHash();
2626
}
@@ -129,11 +129,21 @@ void MythFontProperties::Rescale(void)
129129
Rescale(rect.height());
130130
}
131131

132+
void MythFontProperties::AdjustStretch(int stretch)
133+
{
134+
int newStretch = (int)(((float)m_stretch * ((float)stretch / 100.0f)) + 0.5f);
135+
136+
if (newStretch <= 0)
137+
newStretch = 1;
138+
139+
m_face.setStretch(newStretch);
140+
}
141+
132142
void MythFontProperties::SetPixelSize(float size)
133143
{
134144
QSize baseSize = GetMythUI()->GetBaseSize();
135145
m_relativeSize = size / (float)(baseSize.height());
136-
m_face.setPixelSize(GetMythMainWindow()->NormY((int)(size + 0.5)));
146+
m_face.setPixelSize(GetMythMainWindow()->NormY((int)(size + 0.5f)));
137147
}
138148

139149
void MythFontProperties::SetPointSize(uint points)
@@ -359,33 +369,35 @@ MythFontProperties *MythFontProperties::ParseFromXml(
359369

360370
if (stretch == "ultracondensed" ||
361371
stretch == "1")
362-
newFont->m_face.setStretch(QFont::UltraCondensed);
372+
newFont->m_stretch = QFont::UltraCondensed;
363373
else if (stretch == "extracondensed" ||
364374
stretch == "2")
365-
newFont->m_face.setStretch(QFont::ExtraCondensed);
375+
newFont->m_stretch = QFont::ExtraCondensed;
366376
else if (stretch == "condensed" ||
367377
stretch == "3")
368-
newFont->m_face.setStretch(QFont::Condensed);
378+
newFont->m_stretch = QFont::Condensed;
369379
else if (stretch == "semicondensed" ||
370380
stretch == "4")
371-
newFont->m_face.setStretch(QFont::SemiCondensed);
381+
newFont->m_stretch = QFont::SemiCondensed;
372382
else if (stretch == "unstretched" ||
373383
stretch == "5")
374-
newFont->m_face.setStretch(QFont::Unstretched);
384+
newFont->m_stretch = QFont::Unstretched;
375385
else if (stretch == "semiexpanded" ||
376386
stretch == "6")
377-
newFont->m_face.setStretch(QFont::SemiExpanded);
387+
newFont->m_stretch = QFont::SemiExpanded;
378388
else if (stretch == "expanded" ||
379389
stretch == "7")
380-
newFont->m_face.setStretch(QFont::Expanded);
390+
newFont->m_stretch = QFont::Expanded;
381391
else if (stretch == "extraexpanded" ||
382392
stretch == "8")
383-
newFont->m_face.setStretch(QFont::ExtraExpanded);
393+
newFont->m_stretch = QFont::ExtraExpanded;
384394
else if (stretch == "ultraexpanded" ||
385395
stretch == "9")
386-
newFont->m_face.setStretch(QFont::UltraExpanded);
396+
newFont->m_stretch = QFont::UltraExpanded;
387397
else
388-
newFont->m_face.setStretch(QFont::Unstretched);
398+
newFont->m_stretch = QFont::Unstretched;
399+
400+
newFont->m_face.setStretch(newFont->m_stretch);
389401
}
390402
else
391403
{

mythtv/libs/libmythui/mythfontproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class MPUBLIC MythFontProperties: public XMLParseBase
4747
void SetPointSize(uint size);
4848
void Rescale(void);
4949
void Rescale(int height);
50+
void AdjustStretch(int stretch);
5051

5152
private:
5253
void Freeze(void); // no hash updates
@@ -75,6 +76,8 @@ class MPUBLIC MythFontProperties: public XMLParseBase
7576

7677
bool m_bFreeze;
7778

79+
int m_stretch;
80+
7881
friend class FontMap;
7982
};
8083

mythtv/libs/libmythui/mythpainter_yuva.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void MythYUVAPainter::DrawRect(const QRect &area, bool drawFill,
5353
lineWidth, yuv_line_color);
5454
}
5555

56-
void MythYUVAPainter::DrawRoundRect(const QRect &area, int radius,
57-
bool drawFill, const QColor &fillColor,
56+
void MythYUVAPainter::DrawRoundRect(const QRect &area, int radius,
57+
bool drawFill, const QColor &fillColor,
5858
bool drawLine, int lineWidth,
5959
const QColor &lineColor)
6060
{
@@ -70,7 +70,7 @@ void MythYUVAPainter::DrawRoundRect(const QRect &area, int radius,
7070

7171
MythFontProperties* MythYUVAPainter::GetConvertedFont(const MythFontProperties &font)
7272
{
73-
QString original = QString::number(m_fontStretch) + font.GetHash();
73+
QString original = font.GetHash();
7474

7575
if (m_convertedFonts.contains(original))
7676
{
@@ -104,10 +104,6 @@ MythFontProperties* MythYUVAPainter::GetConvertedFont(const MythFontProperties &
104104
new_font->SetOutline(true, yuv_color, size, alpha);
105105
}
106106

107-
int stretch = font.face().stretch();
108-
stretch = (int)(((float)stretch * ((float)m_fontStretch / 100.0f)) + 0.5f);
109-
new_font->GetFace()->setStretch(stretch);
110-
111107
m_convertedFonts.insert(original, new_font);
112108
m_expireList.push_back(original);
113109

mythtv/libs/libmythui/mythpainter_yuva.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MythFontProperties;
1010
class MPUBLIC MythYUVAPainter : public MythQImagePainter
1111
{
1212
public:
13-
MythYUVAPainter() : MythQImagePainter(), m_fontStretch(100) { }
13+
MythYUVAPainter() : MythQImagePainter() { }
1414
~MythYUVAPainter();
1515

1616
QString GetName(void) { return QString("YUVA"); }
@@ -19,12 +19,11 @@ class MPUBLIC MythYUVAPainter : public MythQImagePainter
1919
void DrawText(const QRect &dest, const QString &msg, int flags,
2020
const MythFontProperties &font, int alpha,
2121
const QRect &boundRect);
22-
void DrawRect(const QRect &area, bool drawFill, const QColor &fillColor,
22+
void DrawRect(const QRect &area, bool drawFill, const QColor &fillColor,
2323
bool drawLine, int lineWidth, const QColor &lineColor);
24-
void DrawRoundRect(const QRect &area, int radius,
25-
bool drawFill, const QColor &fillColor,
24+
void DrawRoundRect(const QRect &area, int radius,
25+
bool drawFill, const QColor &fillColor,
2626
bool drawLine, int lineWidth, const QColor &lineColor);
27-
void SetFontStretch(int font_stretch) { m_fontStretch = font_stretch; }
2827

2928
protected:
3029
MythFontProperties* GetConvertedFont(const MythFontProperties &font);

mythtv/libs/libmythui/mythuiguidegrid.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ MythUIGuideGrid::~MythUIGuideGrid()
8181

8282
delete [] allData;
8383

84+
delete m_font;
85+
m_font = NULL;
86+
8487
for (uint x = 0; x < RECSTATUSSIZE; x++)
8588
{
8689
if (m_recImages[x])
@@ -185,7 +188,14 @@ bool MythUIGuideGrid::ParseElement(
185188
font = GetGlobalFontMap()->GetFont(fontname);
186189

187190
if (font)
188-
m_font = font;
191+
{
192+
MythFontProperties fontcopy = *font;
193+
int screenHeight = GetMythMainWindow()->GetUIScreenRect().height();
194+
fontcopy.Rescale(screenHeight);
195+
int fontStretch = GetMythUI()->GetFontStretch();
196+
fontcopy.AdjustStretch(fontStretch);
197+
*m_font = fontcopy;
198+
}
189199
else
190200
VERBOSE(VB_IMPORTANT, LOC_ERR + "Unknown font: " + fontname);
191201
}
@@ -250,7 +260,7 @@ void MythUIGuideGrid::CopyFrom(MythUIType *base)
250260
m_textOffset = gg->m_textOffset;
251261
m_justification = gg->m_justification;
252262
m_multilineText = gg->m_multilineText;
253-
m_font = gg->m_font;
263+
*m_font = *gg->m_font;
254264
m_solidColor = gg->m_solidColor;
255265

256266
m_selType = gg->m_selType;

mythtv/libs/libmythui/mythuihelper.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class MythUIHelperPrivate
137137
MythUIMenuCallbacks callbacks;
138138

139139
MythUIHelper *parent;
140+
141+
int m_fontStretch;
140142
};
141143

142144
int MythUIHelperPrivate::x_override = -1;
@@ -154,7 +156,8 @@ MythUIHelperPrivate::MythUIHelperPrivate(MythUIHelper *p)
154156
m_cacheSizeLock(new QMutex(QMutex::Recursive)),
155157
m_screenxbase(0), m_screenybase(0), m_screenwidth(0), m_screenheight(0),
156158
screensaver(NULL), screensaverEnabled(false), display_res(NULL),
157-
screenSetup(false), m_imageThreadPool(new QThreadPool()), parent(p)
159+
screenSetup(false), m_imageThreadPool(new QThreadPool()), parent(p),
160+
m_fontStretch(100)
158161
{
159162
}
160163

@@ -334,12 +337,16 @@ void MythUIHelperPrivate::StoreGUIsettings()
334337
m_wmult = m_screenwidth / (float)m_baseWidth;
335338
m_hmult = m_screenheight / (float)m_baseHeight;
336339

340+
// Default font, _ALL_ fonts inherit from this!
341+
// e.g All fonts will be 19 pixels unless a new size is explicitly defined.
337342
QFont font = QFont("Arial");
338343
if (!font.exactMatch())
339344
font = QFont();
340345
font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
341-
font.setPointSize((int)floor(14 * m_hmult));
342-
font.setStretch((int)(100 / GetPixelAspectRatio()));
346+
font.setPixelSize((int)((19.0f * m_hmult) + 0.5f));
347+
int stretch = (int)(100 / GetPixelAspectRatio());
348+
font.setStretch(stretch); // QT
349+
m_fontStretch = stretch; // MythUI
343350

344351
QApplication::setFont(font);
345352
}
@@ -1667,3 +1674,13 @@ QSize MythUIHelper::GetBaseSize(void) const
16671674
{
16681675
return QSize(d->m_baseWidth, d->m_baseHeight);
16691676
}
1677+
1678+
void MythUIHelper::SetFontStretch(int stretch)
1679+
{
1680+
d->m_fontStretch = stretch;
1681+
}
1682+
1683+
int MythUIHelper::GetFontStretch(void) const
1684+
{
1685+
return d->m_fontStretch;
1686+
}

mythtv/libs/libmythui/mythuihelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class MPUBLIC MythUIHelper
130130
double GetPixelAspectRatio(void) const;
131131
QSize GetBaseSize(void) const;
132132

133+
void SetFontStretch(int stretch);
134+
int GetFontStretch(void) const;
135+
133136
protected:
134137
MythUIHelper();
135138
~MythUIHelper();

0 commit comments

Comments
 (0)