Permalink
Browse files

Subtitles: Apply OSDCC708TextZoom to CEA-608 captions as well.

If appropriate care is taken, there is no reason not to apply the text
zoom setting to CEA-608 captions as well as CEA-708 and text captions.
This provides a consistent look across all the caption types.

If the zoom factor would cause the vertical layout to fall outside the
safe area, we try to shift and squeeze the lines back into the safe
area, while also ensuring they don't overlap.
  • Loading branch information...
1 parent 99512fb commit 5206271159967dceccfcef4bdfe08c53e1ee696e @stichnot stichnot committed Feb 29, 2012
Showing with 53 additions and 1 deletion.
  1. +52 −1 mythtv/libs/libmythtv/subtitlescreen.cpp
  2. +1 −0 mythtv/libs/libmythtv/subtitlescreen.h
@@ -643,6 +643,7 @@ void SubtitleScreen::DisplayCC608Subtitles(void)
FormattedTextSubtitle fsub(m_safeArea, m_useBackground, this);
fsub.InitFromCC608(textlist->buffers);
+ fsub.Layout608();
fsub.Layout();
m_refreshArea = fsub.Draw() || m_refreshArea;
textlist->lock.unlock();
@@ -858,7 +859,8 @@ void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers)
bool useBackground = m_useBackground && !teletextmode;
//int xscale = teletextmode ? 40 : 36;
int yscale = teletextmode ? 25 : 17;
- int pixelSize = m_safeArea.height() / (yscale * LINE_SPACING);
+ int pixelSize = m_safeArea.height() / (yscale * LINE_SPACING) *
+ (parent ? parent->m_textFontZoom : 100) / 100;
if (parent)
parent->SetFontSizes(pixelSize, pixelSize, pixelSize);
@@ -1132,6 +1134,55 @@ void FormattedTextSubtitle::WrapLongLines(void)
}
}
+// Adjusts the Y coordinates to avoid overlap, which could happen as a
+// result of a large text zoom factor. Then, if the total height
+// exceeds the safe area, compresses each piece of vertical blank
+// space proportionally to make it fit.
+void FormattedTextSubtitle::Layout608(void)
+{
+ int i;
+ int totalHeight = 0;
+ int totalSpace = 0;
+ int firstY = 0;
+ int prevY = 0;
+ QVector<int> heights(m_lines.size());
+ QVector<int> spaceBefore(m_lines.size());
+ // Calculate totalHeight and totalSpace
+ for (i = 0; i < m_lines.size(); i++)
+ {
+ m_lines[i].y_indent = max(m_lines[i].y_indent, prevY); // avoid overlap
+ int y = m_lines[i].y_indent;
+ if (i == 0)
+ firstY = prevY = y;
+ int height = m_lines[i].CalcSize().height();
+ heights[i] = height;
+ spaceBefore[i] = y - prevY;
+ totalSpace += (y - prevY);
+ prevY = y + height;
+ totalHeight += height;
+ }
+ int safeHeight = m_safeArea.height();
+ int overage = min(totalHeight - safeHeight, totalSpace);
+
+ // Recalculate Y coordinates, applying the shrink factor to space
+ // between each line.
+ if (overage > 0 && totalSpace > 0)
+ {
+ float shrink = (totalSpace - overage) / (float)totalSpace;
+ prevY = firstY;
+ for (i = 0; i < m_lines.size(); i++)
+ {
+ m_lines[i].y_indent = prevY + spaceBefore[i] * shrink;
+ prevY = m_lines[i].y_indent + heights[i];
+ }
+ }
+
+ // Shift Y coordinates back up into the safe area.
+ int shift = min(firstY, max(0, prevY - safeHeight));
+ for (i = 0; i < m_lines.size(); i++)
+ m_lines[i].y_indent -= shift;
+}
+
// Resolves any TBD x_indent and y_indent values in FormattedTextLine
// objects. Calculates m_bounds. Prunes most leading and all
// trailing whitespace from each line so that displaying with a black
@@ -192,6 +192,7 @@ class FormattedTextSubtitle
void InitFromSRT(QStringList &subs, int textFontZoom);
void WrapLongLines(void);
void Layout(void);
+ void Layout608(void);
bool Draw(QList<MythUIType*> *imageCache = 0,
uint64_t start = 0, uint64_t duration = 0) const;
QStringList ToSRT(void) const;

0 comments on commit 5206271

Please sign in to comment.