Skip to content

Commit

Permalink
Backport r27367 from trunk to release-0-24-fixes
Browse files Browse the repository at this point in the history
Improved teletext display.

    * fix some font stretch adjustments for double height text by basing
it on the actual stretch value.
    * be a little more agressive in determining the font height.
    * ignore the UI determined font stretch value and select the largest
possible value that will fill the width available for each character.

Collectively these ensure the font used is as large and as visible as
possible, especially on widescreen displays with VDPAU/OpenGL/Direct3D
and widescreen video sources (XVideo).

Use of a fixed space font is still highly recommended.

Refs #9271


git-svn-id: http://svn.mythtv.org/svn/branches/release-0-24-fixes@27418 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
Mark Kendall committed Dec 2, 2010
1 parent bb53a24 commit 17fbcbb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
85 changes: 52 additions & 33 deletions mythtv/libs/libmythtv/teletextscreen.cpp
Expand Up @@ -43,14 +43,15 @@ TeletextScreen::TeletextScreen(MythPlayer *player, const char * name,
int fontStretch) : int fontStretch) :
MythScreenType((MythScreenType*)NULL, name), MythScreenType((MythScreenType*)NULL, name),
m_player(player), m_safeArea(QRect()), m_player(player), m_safeArea(QRect()),
m_colSize(10), m_rowSize(10), m_colWidth(10), m_rowHeight(10),
m_fetchpage(0), m_fetchsubpage(0), m_fetchpage(0), m_fetchsubpage(0),
m_bgColor(QColor(kColorBlack)), m_bgColor(QColor(kColorBlack)),
m_curpage(0x100), m_cursubpage(-1), m_curpage(0x100), m_cursubpage(-1),
m_curpage_showheader(true), m_curpage_issubtitle(false), m_curpage_showheader(true), m_curpage_issubtitle(false),
m_transparent(false), m_revealHidden(false), m_transparent(false), m_revealHidden(false),
m_displaying(false), m_header_changed(false), m_displaying(false), m_header_changed(false),
m_page_changed(false), m_fontStretch(fontStretch) m_page_changed(false), m_fontStretch(fontStretch),
m_fontHeight(10)
{ {
memset(m_pageinput, 0, sizeof(m_pageinput)); memset(m_pageinput, 0, sizeof(m_pageinput));
memset(m_header, 0, sizeof(m_header)); memset(m_header, 0, sizeof(m_header));
Expand Down Expand Up @@ -86,10 +87,10 @@ void TeletextScreen::CleanUp(void)
QImage* TeletextScreen::GetRowImage(int row, QRect &rect) QImage* TeletextScreen::GetRowImage(int row, QRect &rect)
{ {
int y = row & ~1; int y = row & ~1;
rect.translate(0, -(y * m_rowSize)); rect.translate(0, -(y * m_rowHeight));
if (!m_rowImages.contains(y)) if (!m_rowImages.contains(y))
{ {
QImage* img = new QImage(m_safeArea.width(), m_rowSize * 2, QImage* img = new QImage(m_safeArea.width(), m_rowHeight * 2,
QImage::Format_ARGB32); QImage::Format_ARGB32);
if (img) if (img)
{ {
Expand Down Expand Up @@ -126,8 +127,8 @@ void TeletextScreen::OptimiseDisplayedArea(void)
if (uiimage) if (uiimage)
{ {
uiimage->SetImage(image); uiimage->SetImage(image);
uiimage->SetArea(MythRect(0, row * m_rowSize, uiimage->SetArea(MythRect(0, row * m_rowHeight,
m_safeArea.width(), m_rowSize * 2)); m_safeArea.width(), m_rowHeight * 2));
} }
} }


Expand Down Expand Up @@ -159,19 +160,41 @@ void TeletextScreen::OptimiseDisplayedArea(void)


void TeletextScreen::Pulse(void) void TeletextScreen::Pulse(void)
{ {
if (!InitialiseFont(m_fontStretch) || !m_displaying) if (!InitialiseFont() || !m_displaying)
return; return;


if (m_player && m_player->getVideoOutput()) if (m_player && m_player->getVideoOutput())
{ {
static const float kTextPadding = 0.96f;
QRect oldsafe = m_safeArea; QRect oldsafe = m_safeArea;
m_safeArea = m_player->getVideoOutput()->GetSafeRect(); m_safeArea = m_player->getVideoOutput()->GetSafeRect();
m_colWidth = (int)((float)m_safeArea.width() / (float)kTeletextColumns);
m_rowHeight = (int)((float)m_safeArea.height() / (float)kTeletextRows);

if (oldsafe != m_safeArea) if (oldsafe != m_safeArea)
{
m_page_changed = true; m_page_changed = true;
m_colSize = (int)((float)m_safeArea.width() / (float)kTeletextColumns);
m_rowSize = (int)((float)m_safeArea.height() / (float)kTeletextRows); int max_width = (int)((float)m_colWidth * kTextPadding);
gTTFont->GetFace()->setPixelSize(m_safeArea.height() / m_fontHeight = (int)((float)m_rowHeight * kTextPadding);
(kTeletextRows * 1.2)); if (max_width > (m_colWidth - 2))
max_width = m_colWidth -2;
if (m_fontHeight > (m_rowHeight - 2))
m_fontHeight = m_rowHeight - 2;
gTTFont->GetFace()->setPixelSize(m_fontHeight);

m_fontStretch = 200;
bool ok = false;
while (!ok && m_fontStretch > 50)
{
gTTFont->GetFace()->setStretch(m_fontStretch);
QFontMetrics font(*(gTTFont->GetFace()));
if (font.averageCharWidth() <= max_width || m_fontStretch < 50)
ok = true;
else
m_fontStretch -= 10;
}
}
} }
else else
{ {
Expand Down Expand Up @@ -918,18 +941,15 @@ void TeletextScreen::DrawCharacter(int x, int y, QChar ch, int doubleheight)
return; return;


int row = y; int row = y;
x *= m_colSize; x *= m_colWidth;
y *= m_rowSize; y *= m_rowHeight;
int height = m_rowSize * (doubleheight ? 2 : 1); int height = m_rowHeight * (doubleheight ? 2 : 1);
QRect rect(x, y, m_colSize, height); QRect rect(x, y, m_colWidth, height);


int fontheight = 10;
if (doubleheight) if (doubleheight)
{ {
fontheight = m_safeArea.height() / (kTeletextRows * 1.2); gTTFont->GetFace()->setPixelSize(m_fontHeight * 2);
int doubleheight = fontheight * 2; gTTFont->GetFace()->setStretch(m_fontStretch / 2);
gTTFont->GetFace()->setPixelSize(doubleheight);
gTTFont->GetFace()->setStretch(50);
} }


QImage* image = GetRowImage(row, rect); QImage* image = GetRowImage(row, rect);
Expand All @@ -945,8 +965,8 @@ void TeletextScreen::DrawCharacter(int x, int y, QChar ch, int doubleheight)
if (row & 1) if (row & 1)
{ {
row++; row++;
rect = QRect(x, y + m_rowSize, m_colSize, height); rect = QRect(x, y + m_rowHeight, m_colWidth, height);
rect.translate(0, -m_rowSize); rect.translate(0, -m_rowHeight);
image = GetRowImage(row, rect); image = GetRowImage(row, rect);
if (image) if (image)
{ {
Expand All @@ -960,17 +980,17 @@ void TeletextScreen::DrawCharacter(int x, int y, QChar ch, int doubleheight)


if (doubleheight) if (doubleheight)
{ {
gTTFont->GetFace()->setPixelSize(fontheight); gTTFont->GetFace()->setPixelSize(m_fontHeight);
gTTFont->GetFace()->setStretch(100); gTTFont->GetFace()->setStretch(m_fontStretch);
} }
} }


void TeletextScreen::DrawBackground(int x, int y) void TeletextScreen::DrawBackground(int x, int y)
{ {
int row = y; int row = y;
x *= m_colSize; x *= m_colWidth;
y *= m_rowSize; y *= m_rowHeight;
DrawRect(row, QRect(x, y, m_colSize, m_rowSize)); DrawRect(row, QRect(x, y, m_colWidth, m_rowHeight));
} }


void TeletextScreen::DrawRect(int row, QRect rect) void TeletextScreen::DrawRect(int row, QRect rect)
Expand All @@ -990,11 +1010,11 @@ void TeletextScreen::DrawRect(int row, QRect rect)
void TeletextScreen::DrawMosaic(int x, int y, int code, int doubleheight) void TeletextScreen::DrawMosaic(int x, int y, int code, int doubleheight)
{ {
int row = y; int row = y;
x *= m_colSize; x *= m_colWidth;
y *= m_rowSize; y *= m_rowHeight;


int dx = (int)round(m_colSize / 2) + 1; int dx = (int)round(m_colWidth / 2) + 1;
int dy = (int)round(m_rowSize / 3) + 1; int dy = (int)round(m_rowHeight / 3) + 1;
dy = (doubleheight) ? (2 * dy) : dy; dy = (doubleheight) ? (2 * dy) : dy;


if (code & 0x10) if (code & 0x10)
Expand Down Expand Up @@ -1246,7 +1266,7 @@ const TeletextSubPage *TeletextScreen::FindSubPageInternal(
return res; return res;
} }


bool TeletextScreen::InitialiseFont(int fontStretch) bool TeletextScreen::InitialiseFont()
{ {
static bool initialised = false; static bool initialised = false;
QString font = gCoreContext->GetSetting("OSDSubFont", "FreeSans"); QString font = gCoreContext->GetSetting("OSDSubFont", "FreeSans");
Expand All @@ -1262,7 +1282,6 @@ bool TeletextScreen::InitialiseFont(int fontStretch)
{ {
QFont newfont(font); QFont newfont(font);
font.detach(); font.detach();
newfont.setStretch(fontStretch);
mythfont->SetFace(newfont); mythfont->SetFace(newfont);
gTTFont = mythfont; gTTFont = mythfont;
} }
Expand Down
7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/teletextscreen.h
Expand Up @@ -92,7 +92,7 @@ class TeletextMagazine


class TeletextScreen: public MythScreenType, public TeletextViewer class TeletextScreen: public MythScreenType, public TeletextViewer
{ {
static bool InitialiseFont(int fontStretch = QFont::Unstretched); static bool InitialiseFont(void);


public: public:
TeletextScreen(MythPlayer *player, const char * name, int fontStretch); TeletextScreen(MythPlayer *player, const char * name, int fontStretch);
Expand Down Expand Up @@ -146,8 +146,8 @@ class TeletextScreen: public MythScreenType, public TeletextViewer


MythPlayer *m_player; MythPlayer *m_player;
QRect m_safeArea; QRect m_safeArea;
int m_colSize; int m_colWidth;
int m_rowSize; int m_rowHeight;


QMutex m_lock; QMutex m_lock;


Expand All @@ -172,6 +172,7 @@ class TeletextScreen: public MythScreenType, public TeletextViewer
unsigned char m_bitswap[256]; unsigned char m_bitswap[256];
QHash<int, QImage*> m_rowImages; QHash<int, QImage*> m_rowImages;
int m_fontStretch; int m_fontStretch;
int m_fontHeight;


public: public:
static const QColor kColorBlack; static const QColor kColorBlack;
Expand Down

0 comments on commit 17fbcbb

Please sign in to comment.