commit 946b81acbe5d02fda902d86e7da5d860f71ad651
Author: Gregorio Gervasio, Jr <ggervasio@yahoo.com>
Date:   Sat Mar 3 15:12:53 2012 -0800

    Modified to scale CC608 region according to text zoom setting.

diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp
index c092e67..147adbd 100644
--- a/mythtv/libs/libmythtv/subtitlescreen.cpp
+++ b/mythtv/libs/libmythtv/subtitlescreen.cpp
@@ -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,7 @@ 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 +858,40 @@ 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;
+    int yoffset = 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;
+    }
+    LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("xmid = %1, fontwidth = %4").
+                                             arg(xmid).arg(fontwidth));
+
+    int rows, cols;
+    if (teletextmode)
+    {
+        // teletext expects a 24 row / 40 char grid
+        rows = 24+1;
+        cols = 40;
+    }
+    else
+    {
+        // CC has 15 rows, 32 columns
+        // - add one row top and bottom for margin
+        rows = 15+2;
+        cols = 32;
+    }
 
     for (; i != buffers.end(); ++i)
     {
@@ -873,21 +901,31 @@ 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 - cols/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 < rows/2)
+            // top half -- anchor up
+            y = yoffset + (orig_y * m_safeArea.height() * textFontZoom
+                           / (rows * 100));
+        else
+            // bottom half -- anchor down
+            y = yoffset + m_safeArea.height()
+                    - ((rows - orig_y) * m_safeArea.height() * textFontZoom
+                       / (rows * 100));
+
+        FormattedTextLine line(x, y, orig_x, orig_y);
         while (!text.isNull())
         {
             QString captionText =
diff --git a/mythtv/libs/libmythtv/subtitlescreen.h b/mythtv/libs/libmythtv/subtitlescreen.h
index 0ab77a3..44b3f6a 100644
--- a/mythtv/libs/libmythtv/subtitlescreen.h
+++ b/mythtv/libs/libmythtv/subtitlescreen.h
@@ -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,
