Ticket #10402: cc608_zoom.patch

File cc608_zoom.patch, 5.0 KB (added by ggervasio@…, 12 years ago)
  • mythtv/libs/libmythtv/subtitlescreen.cpp

    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 b void SubtitleScreen::DisplayCC608Subtitles(void) 
    643643    }
    644644
    645645    FormattedTextSubtitle fsub(m_safeArea, m_useBackground, this);
    646     fsub.InitFromCC608(textlist->buffers);
     646    fsub.InitFromCC608(textlist->buffers, m_textFontZoom);
    647647    fsub.Layout608();
    648648    fsub.Layout();
    649649    m_refreshArea = fsub.Draw() || m_refreshArea;
    static QString srtColorString(QColor color) 
    845845        .arg(color.blue(),  2, 16, QLatin1Char('0'));
    846846}
    847847
    848 void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers)
     848void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers, int textFontZoom)
    849849{
    850850    static const QColor clr[8] =
    851851    {
    void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers) 
    858858    vector<CC608Text*>::iterator i = buffers.begin();
    859859    bool teletextmode = (*i)->teletextmode;
    860860    bool useBackground = m_useBackground && !teletextmode;
    861     //int xscale = teletextmode ? 40 : 36;
     861
     862    int xscale = teletextmode ? 40 : 36;
    862863    int yscale = teletextmode ? 25 : 17;
    863     int pixelSize = m_safeArea.height() / (yscale * LINE_SPACING) *
    864         (parent ? parent->m_textFontZoom : 100) / 100;
     864    int pixelSize = m_safeArea.height() * textFontZoom
     865                    / (yscale * LINE_SPACING * 100);
     866    int fontwidth = 0;
     867    int xmid = 0;
     868    int yoffset = 0;
    865869    if (parent)
     870    {
    866871        parent->SetFontSizes(pixelSize, pixelSize, pixelSize);
     872        CC708CharacterAttribute def_attr(false, false, false, clr[0], useBackground);
     873        QFont *font = parent->Get708Font(def_attr)->GetFace();
     874        QFontMetrics fm(*font);
     875        fontwidth = fm.averageCharWidth();
     876        xmid = m_safeArea.width()/2;
     877    }
     878    LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("xmid = %1, fontwidth = %4").
     879                                             arg(xmid).arg(fontwidth));
     880
     881    int rows, cols;
     882    if (teletextmode)
     883    {
     884        // teletext expects a 24 row / 40 char grid
     885        rows = 24+1;
     886        cols = 40;
     887    }
     888    else
     889    {
     890        // CC has 15 rows, 32 columns
     891        // - add one row top and bottom for margin
     892        rows = 15+2;
     893        cols = 32;
     894    }
    867895
    868896    for (; i != buffers.end(); ++i)
    869897    {
    void FormattedTextSubtitle::InitFromCC608(vector<CC608Text*> &buffers) 
    873901        const bool isBold = false;
    874902        QString text(cc->text);
    875903
    876         int orig_x = teletextmode ? cc->y : (cc->x + 3);
     904        int orig_x = teletextmode ? cc->y : cc->x;
     905        // position as if we use a fixed size font
     906        // - font size already has zoom factor applied
     907
     908        int x;
     909        if (xmid)
     910            // center horizontally
     911            x = xmid + (orig_x - cols/2) * fontwidth;
     912        else
     913            // fallback
     914            x = (orig_x + 3) * m_safeArea.width() / xscale;
     915
    877916        int orig_y = teletextmode ? cc->x : cc->y;
    878         int y = (int)(((float)orig_y / (float)yscale) *
    879                       (float)m_safeArea.height());
    880         FormattedTextLine line(0, y, orig_x, orig_y);
    881         // Indented lines are handled as initial strings of space
    882         // characters, to improve vertical alignment.  Monospace fonts
    883         // are assumed.
    884         if (orig_x > 0)
    885         {
    886             CC708CharacterAttribute attr(false, false, false,
    887                                          Qt::white, useBackground);
    888             FormattedTextChunk chunk(QString(orig_x, ' '), attr, parent);
    889             line.chunks += chunk;
    890         }
     917        int y;
     918        if (orig_y < rows/2)
     919            // top half -- anchor up
     920            y = yoffset + (orig_y * m_safeArea.height() * textFontZoom
     921                           / (rows * 100));
     922        else
     923            // bottom half -- anchor down
     924            y = yoffset + m_safeArea.height()
     925                    - ((rows - orig_y) * m_safeArea.height() * textFontZoom
     926                       / (rows * 100));
     927
     928        FormattedTextLine line(x, y, orig_x, orig_y);
    891929        while (!text.isNull())
    892930        {
    893931            QString captionText =
  • mythtv/libs/libmythtv/subtitlescreen.h

    diff --git a/mythtv/libs/libmythtv/subtitlescreen.h b/mythtv/libs/libmythtv/subtitlescreen.h
    index 0ab77a3..44b3f6a 100644
    a b class FormattedTextSubtitle 
    184184        m_xAnchor = 0;
    185185        m_yAnchor = 0;
    186186    }
    187     void InitFromCC608(vector<CC608Text*> &buffers);
     187    void InitFromCC608(vector<CC608Text*> &buffers, int textFontZoom = 100);
    188188    void InitFromCC708(const CC708Window &win, int num,
    189189                       const vector<CC708String*> &list,
    190190                       float aspect = 1.77777f,