Skip to content

Commit

Permalink
Subtitles: Allow the theme to customize caption/subtitle formatting.
Browse files Browse the repository at this point in the history
Subtitle format specification, e.g. the choice of font and background,
is moved into the theme's osd_subtitle.xml file, in the osd_subtitle
window.  Separate controls are given for text, teletext, CEA-608, and
the 8 CEA-708 fonts.

Subtitle types are named text, teletext, 608, 708_0, 708_1, ...,
708_7.  Each subtitle type has a fontdef component for the text and a
shape component for the background.  By default, the attributes of a
subtitle type come from either the provider (e.g. text color, italics)
or the system default (e.g. font family).  These attributes can be
overridden by the xml file.

The names of the fontdef and the background shape are both simply the
name of the subtitle type.  The fontdef and shape should ultimately
inherit from the special value "provider", otherwise all provider
values will be ignored.

The following example forces .srt subtitles to be rendered in
yellow text, FreeSans font, black shadow, with a translucent black
background.  The fontdef and shape names are "text" since the
subtitles come from a .srt file.  Note that in this example, color
formatting controls in the .srt file will be ignored due to the
explicit setting of yellow text.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE mythuitheme SYSTEM "http://www.mythtv.org/schema/mythuitheme.dtd">
<mythuitheme>
  <window name="osd_subtitle">
    <fontdef name="text" face="FreeSans" from="provider">
      <color>#FFFF00</color>
      <shadowoffset>2,2</shadowoffset>
      <shadowcolor>#000000</shadowcolor>
    </fontdef>
    <shape name="text" from="provider">
      <fill color="#000000" alpha="100" />
    </shape>
  </window>
</mythuitheme>

The settings CCBackground and DefaultSubtitleFont are no longer
necessary and have been removed.

Teletext does not yet use this mechanism, but some temporary code
allows the teletext font to be taken from osd_subtitle.xml rather than
the DefaultSubtitleFont setting.  Note that as before, the frontend
must be restarted for teletext font changes to take effect (this will
be fixed in the future).

All elements/attributes of fontdef and shape can be used.  Note
however that area and position are explicitly ignored, as these are
dictated by the subtitle layout.

The default values for the specific fonts are kept unchanged from the
original code (except that a proportional font is now used for text
subtitles).  Note that some of these fonts, particularly many of the
CEA-708 fonts, were somewhat arbitrarily chosen and aren't necessarily
present on the user's system, so we will need to settle on the precise
set of fonts and likely include them in the MythTV fonts directory.

These changes are implemented with almost no MythUI modifications (the
only such change is to make the new helper class a friend of
MythUIShape in order to get access to some protected members).  The
basic idea is to construct two different "provider" objects; then
parse osd_subtitle.xml twice with respect to each provider object; and
finally compare the resulting objects, attribute by attribute, to
discover which attributes are fixed by the theme and which the
provider may control.  This is done once to collect the set of
attributes, and the results are cached and used for drawing each
subtitle.
  • Loading branch information
stichnot committed May 2, 2012
1 parent 8a4adc5 commit f13eeb0
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 227 deletions.
5 changes: 2 additions & 3 deletions mythtv/libs/libmythtv/cc708window.h
Expand Up @@ -90,7 +90,7 @@ class CC708CharacterAttribute
QColor actual_fg_color;

CC708CharacterAttribute(bool isItalic, bool isBold, bool isUnderline,
QColor fgColor, bool hasBackground) :
QColor fgColor) :
pen_size(k708AttrSizeStandard),
offset(k708AttrOffsetNormal),
text_tag(0), // "dialog", ignored
Expand All @@ -102,8 +102,7 @@ class CC708CharacterAttribute
fg_color(k708AttrColorWhite), // will be overridden
fg_opacity(k708AttrOpacitySolid), // solid
bg_color(k708AttrColorBlack),
bg_opacity(hasBackground ? k708AttrOpacitySolid :
k708AttrOpacityTransparent),
bg_opacity(k708AttrOpacitySolid),
edge_color(k708AttrColorBlack),
override_fg_color(true),
actual_fg_color(fgColor)
Expand Down

0 comments on commit f13eeb0

Please sign in to comment.