Permalink
Browse files

Subtitles: Improve layout of zoomed CEA-608 captions.

Thanks to Gregorio for the patch that improves the CEA-608 layout, in
particular when the zoom factor is less than 100%, by horizontally
centering the caption region and vertically snapping lines to the top
or bottom of the safe area.  One key difference from the original
patch is that horizontal centering is disabled when then zoom factor
is 100% or more.  While horizontal centering might be more visually
appropriate, I'm not comfortable that it becomes markedly different
from the "equivalent" CEA-708 layout.

Refs #10402.

Signed-off-by: Jim Stichnoth <jstichnoth@mythtv.org>
  • Loading branch information...
1 parent f51f5ea commit eac7f477dc5a5844c44f39e1b1d4daacf09cea0b @ggervasio ggervasio committed with stichnot Mar 11, 2012
Showing with 44 additions and 20 deletions.
  1. +43 −19 mythtv/libs/libmythtv/subtitlescreen.cpp
  2. +1 −1 mythtv/libs/libmythtv/subtitlescreen.h
@@ -643,7 +643,7 @@ void SubtitleScreen::DisplayCC608Subtitles(void)
}
FormattedTextSubtitle fsub(m_safeArea, m_useBackground, this);
- fsub.InitFromCC608(textlist->buffers);
+ fsub.InitFromCC608(textlist->buffers, m_textFontZoom);
fsub.Layout608();
fsub.Layout();
m_refreshArea = fsub.Draw() || m_refreshArea;
@@ -845,7 +845,8 @@ static QString srtColorString(QColor color)
.arg(color.blue(), 2, 16, QLatin1Char('0'));
}
-void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers)
+void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers,
+ int textFontZoom)
{
static const QColor clr[8] =
{
@@ -858,12 +859,26 @@ void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers)
vector<CC608Text*>::iterator i = buffers.begin();
bool teletextmode = (*i)->teletextmode;
bool useBackground = m_useBackground && !teletextmode;
- //int xscale = teletextmode ? 40 : 36;
+
+ int xscale = teletextmode ? 40 : 36;
int yscale = teletextmode ? 25 : 17;
- int pixelSize = m_safeArea.height() / (yscale * LINE_SPACING) *
- (parent ? parent->m_textFontZoom : 100) / 100;
+ int pixelSize = m_safeArea.height() * textFontZoom
+ / (yscale * LINE_SPACING * 100);
+ int fontwidth = 0;
+ int xmid = 0;
if (parent)
+ {
parent->SetFontSizes(pixelSize, pixelSize, pixelSize);
+ CC708CharacterAttribute def_attr(false, false, false, clr[0],
+ useBackground);
+ QFont *font = parent->Get708Font(def_attr)->GetFace();
+ QFontMetrics fm(*font);
+ fontwidth = fm.averageCharWidth();
+ xmid = m_safeArea.width() / 2;
+ // Disable centering for zoom factor >= 100%
+ if (textFontZoom >= 100)
+ xscale = m_safeArea.width() / fontwidth;
+ }
for (; i != buffers.end(); ++i)
{
@@ -873,21 +888,30 @@ void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers)
const bool isBold = false;
QString text(cc->text);
- int orig_x = teletextmode ? cc->y : (cc->x + 3);
+ int orig_x = teletextmode ? cc->y : cc->x;
+ // position as if we use a fixed size font
+ // - font size already has zoom factor applied
+
+ int x;
+ if (xmid)
+ // center horizontally
+ x = xmid + (orig_x - xscale / 2) * fontwidth;
+ else
+ // fallback
+ x = (orig_x + 3) * m_safeArea.width() / xscale;
+
int orig_y = teletextmode ? cc->x : cc->y;
- int y = (int)(((float)orig_y / (float)yscale) *
- (float)m_safeArea.height());
- FormattedTextLine line(0, y, orig_x, orig_y);
- // Indented lines are handled as initial strings of space
- // characters, to improve vertical alignment. Monospace fonts
- // are assumed.
- if (orig_x > 0)
- {
- CC708CharacterAttribute attr(false, false, false,
- Qt::white, useBackground);
- FormattedTextChunk chunk(QString(orig_x, ' '), attr, parent);
- line.chunks += chunk;
- }
+ int y;
+ if (orig_y < yscale / 2)
+ // top half -- anchor up
+ y = (orig_y * m_safeArea.height() * textFontZoom / (yscale * 100));
+ else
+ // bottom half -- anchor down
+ y = m_safeArea.height() -
+ ((yscale - orig_y - 0.5) * m_safeArea.height() * textFontZoom /
+ (yscale * 100));
+
+ FormattedTextLine line(x, y, orig_x, orig_y);
while (!text.isNull())
{
QString captionText =
@@ -184,7 +184,7 @@ class FormattedTextSubtitle
m_xAnchor = 0;
m_yAnchor = 0;
}
- void InitFromCC608(vector<CC608Text*> &buffers);
+ void InitFromCC608(vector<CC608Text*> &buffers, int textFontZoom = 100);
void InitFromCC708(const CC708Window &win, int num,
const vector<CC708String*> &list,
float aspect = 1.77777f,

0 comments on commit eac7f47

Please sign in to comment.