summaryrefslogtreecommitdiffstats
path: root/libass/ass_render.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-26 20:49:18 +0100
committerwm4 <wm4@nowhere>2015-02-26 21:18:49 +0100
commit51a93b5571acf51d3c7fe841d3e1e34720524c23 (patch)
treec53e64261140c251f3b0077b278f66605d99b819 /libass/ass_render.c
parent230f855fd3a80a6acfefe753b778b422191be26f (diff)
downloadlibass-51a93b5571acf51d3c7fe841d3e1e34720524c23.tar.bz2
libass-51a93b5571acf51d3c7fe841d3e1e34720524c23.tar.xz
Allow more fine grained control over style overrides
Add tons of ASS_OVERRIDE_ flags, which control whether certain ASS_Style fields are copied when doing selective style overrides with ass_set_selective_style_override_enabled(). This comes with some cleanup. It should be fully backwards-compatible.
Diffstat (limited to 'libass/ass_render.c')
-rw-r--r--libass/ass_render.c97
1 files changed, 69 insertions, 28 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c
index 3e54710..b03fc30 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -139,6 +139,7 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library)
priv->text_info.lines = calloc(MAX_LINES_INITIAL, sizeof(LineInfo));
priv->settings.font_size_coeff = 1.;
+ priv->settings.selective_style_overrides = ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE;
priv->shaper = ass_shaper_new(0);
ass_shaper_info(library);
@@ -750,55 +751,95 @@ static ASS_Style *handle_selective_style_overrides(ASS_Renderer *render_priv,
ASS_Style *rstyle)
{
// The script style is the one the event was declared with.
- // The rstyle is either NULL, or the style used with a \r tag.
ASS_Style *script = render_priv->track->styles +
render_priv->state.event->Style;
+ // The user style was set with ass_set_selective_style_override().
+ ASS_Style *user = &render_priv->user_override_style;
ASS_Style *new = &render_priv->state.override_style_temp_storage;
int explicit = event_is_positioned(render_priv->state.event->Text);
int requested = render_priv->settings.selective_style_overrides;
double scale;
+ user->Name = "OverrideStyle"; // name insignificant
+
+ // Either the event's style, or the style forced with a \r tag.
if (!rstyle)
rstyle = script;
- render_priv->state.style = script;
- render_priv->state.overrides = ASS_OVERRIDE_BIT_FONT_SIZE; // odd default
-
- if (explicit && (requested & ASS_OVERRIDE_BIT_FONT_SIZE))
- render_priv->state.overrides &= ~(unsigned)ASS_OVERRIDE_BIT_FONT_SIZE;
-
- if (!explicit && (requested & ASS_OVERRIDE_BIT_STYLE))
- render_priv->state.overrides |= ASS_OVERRIDE_BIT_STYLE;
-
- if (!(render_priv->state.overrides & ASS_OVERRIDE_BIT_STYLE))
- return rstyle;
-
// Create a new style that contains a mix of the original style and
// user_style (the user's override style). Copy only fields from the
// script's style that are deemed necessary.
- *new = render_priv->user_override_style;
+ *new = *rstyle;
+
+ render_priv->state.apply_font_scale =
+ !explicit || !(requested & ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE);
- new->Bold = rstyle->Bold;
- new->StrikeOut = rstyle->StrikeOut;
- new->Underline = rstyle->Underline;
- new->Angle = rstyle->Angle;
+ // On positioned events, do not apply most overrides.
+ if (explicit)
+ requested = 0;
- new->MarginL = rstyle->MarginL;
- new->MarginR = rstyle->MarginR;
- new->MarginV = rstyle->MarginV;
- new->Alignment = rstyle->Alignment;
- new->Encoding = rstyle->Encoding;
+ if (requested & ASS_OVERRIDE_BIT_STYLE)
+ requested |= ASS_OVERRIDE_BIT_FONT_NAME |
+ ASS_OVERRIDE_BIT_FONT_SIZE_FIELDS |
+ ASS_OVERRIDE_BIT_COLORS |
+ ASS_OVERRIDE_BIT_BORDER |
+ ASS_OVERRIDE_BIT_ATTRIBUTES;
+
+ // Copies fields even not covered by any of the other bits.
+ if (requested & ASS_OVERRIDE_FULL_STYLE)
+ *new = *user;
// The user style is supposed to be independent of the script resolution.
// Treat the user style's values as if they were specified for a script with
// PlayResY=288, and rescale the values to the current script.
scale = render_priv->track->PlayResY / 288.0;
- new->FontSize *= scale;
- new->Spacing *= scale;
- new->Outline *= scale;
- new->Shadow *= scale;
+
+ if (requested & ASS_OVERRIDE_BIT_FONT_SIZE_FIELDS) {
+ new->FontSize = user->FontSize * scale;
+ new->Spacing = user->Spacing * scale;
+ new->ScaleX = user->ScaleX;
+ new->ScaleY = user->ScaleY;
+ }
+
+ if (requested & ASS_OVERRIDE_BIT_FONT_NAME) {
+ new->FontName = user->FontName;
+ new->treat_fontname_as_pattern = user->treat_fontname_as_pattern;
+ }
+
+ if (requested & ASS_OVERRIDE_BIT_COLORS) {
+ new->PrimaryColour = user->PrimaryColour;
+ new->SecondaryColour = user->SecondaryColour;
+ new->OutlineColour = user->OutlineColour;
+ new->BackColour = user->BackColour;
+ }
+
+ if (requested & ASS_OVERRIDE_BIT_ATTRIBUTES) {
+ new->Bold = user->Bold;
+ new->Italic = user->Italic;
+ new->Underline = user->Underline;
+ new->StrikeOut = user->StrikeOut;
+ }
+
+ if (requested & ASS_OVERRIDE_BIT_BORDER) {
+ new->BorderStyle = user->BorderStyle;
+ new->Outline = user->Outline * scale;
+ new->Shadow = user->Shadow * scale;
+ }
+
+ if (requested & ASS_OVERRIDE_BIT_ALIGNMENT)
+ new->Alignment = user->Alignment;
+
+ if (requested & ASS_OVERRIDE_BIT_MARGINS) {
+ new->MarginL = user->MarginL;
+ new->MarginR = user->MarginR;
+ new->MarginV = user->MarginV;
+ }
+
+ if (!new->FontName)
+ new->FontName = rstyle->FontName;
render_priv->state.style = new;
+ render_priv->state.overrides = requested;
return new;
}
@@ -823,7 +864,7 @@ static void init_font_scale(ASS_Renderer *render_priv)
if (!settings_priv->storage_height)
render_priv->blur_scale = render_priv->border_scale;
- if (render_priv->state.overrides & ASS_OVERRIDE_BIT_FONT_SIZE) {
+ if (render_priv->state.apply_font_scale) {
render_priv->font_scale *= settings_priv->font_size_coeff;
render_priv->border_scale *= settings_priv->font_size_coeff;
render_priv->blur_scale *= settings_priv->font_size_coeff;