private void AppendLineTags(AssLine line, AssStyle style, AssLineContentBuilder lineContent) { if (line.AnchorPoint != style.AnchorPoint) { lineContent.AppendTag("an", GetAlignment(line.AnchorPoint)); } if (line.Position != null) { lineContent.AppendTag("pos", line.Position.Value.X, line.Position.Value.Y); } if (line.VerticalTextType != VerticalTextType.None) { lineContent.AppendTag("ytvert", AssVerticalTypeTagHandler.GetVerticalTextTypeId(line.VerticalTextType)); } }
private void AppendLineTags(AssLine line, AssStyle style, AssLineContentBuilder lineContent) { if (line.AnchorPoint != style.AnchorPoint) { lineContent.AppendTag("an", GetAlignment(line.AnchorPoint)); } if (line.Position != null) { lineContent.AppendTag("pos", line.Position.Value.X, line.Position.Value.Y); } if (line.VerticalTextType != VerticalTextType.None) { lineContent.AppendTag("ytvert", AssVerticalTypeTagHandler.GetVerticalTextTypeId(line.HorizontalTextDirection, line.VerticalTextType)); } else if (line.HorizontalTextDirection != HorizontalTextDirection.LeftToRight) { lineContent.AppendTag("ytdir", AssHorizontalTextDirectionTag.GetHorizontalTextDirectionId(line.HorizontalTextDirection)); } }
private void AppendSectionTags(AssSection section, AssSection prevSection, AssLineContentBuilder lineContent) { if (section.Font != prevSection.Font) { lineContent.AppendTag("fn", section.Font); } float prevLineHeight = ScaleToLineHeight(prevSection.Font, prevSection.Scale); float lineHeight = ScaleToLineHeight(section.Font, section.Scale); if (lineHeight != prevLineHeight) { lineContent.AppendTag("fs", lineHeight); } if (section.Bold != prevSection.Bold) { lineContent.AppendTag("b", section.Bold); } if (section.Italic != prevSection.Italic) { lineContent.AppendTag("i", section.Italic); } if (section.Underline != prevSection.Underline) { lineContent.AppendTag("u", section.Underline); } AppendColorTags("c", "1a", prevSection.ForeColor, section.ForeColor, lineContent); AppendColorTags("2c", "2a", prevSection.SecondaryColor, section.SecondaryColor, lineContent); if (section.BackColor.A > 0) { AppendColorTags("3c", "3a", prevSection.BackColor, section.BackColor, lineContent); if (prevSection.ShadowColors.Count == 1 && section.ShadowColors.Count == 1) { AppendColorTags("4c", "4a", prevSection.ShadowColors.Values.First(), section.ShadowColors.Values.First(), lineContent); } } else if (prevSection.ShadowColors.Count == 1 && section.ShadowColors.Count == 1) { if (section.ShadowColors.Keys.First() == ShadowType.Glow) { AppendColorTags("3c", "3a", prevSection.ShadowColors.Values.First(), section.ShadowColors.Values.First(), lineContent); } else { AppendColorTags("4c", "4a", prevSection.ShadowColors.Values.First(), section.ShadowColors.Values.First(), lineContent); } } if (section.Offset != prevSection.Offset) { lineContent.AppendTag( section.Offset switch { OffsetType.Subscript => "ytsub", OffsetType.Superscript => "ytsup", OffsetType.Regular => "ytsur", }
protected virtual void WriteLine(AssLine line, StreamWriter writer) { if (line.Sections.Count == 0) { return; } AssStyle style = GetStyleMatchingStructure((AssSection)line.Sections[0]); WriteLineMetadata(line, style, writer); AssSection prevSection = new AssSection(); AssStyle prevStyle = style; ApplyStyle(prevSection, prevStyle); AssLineContentBuilder lineContent = new AssLineContentBuilder(); AppendLineTags(line, style, lineContent); RubyPart currentRubyPosition = RubyPart.None; for (int i = 0; i < line.Sections.Count; i++) { AssSection section = (AssSection)line.Sections[i]; style = GetStyleMatchingStructure(section); if (style != prevStyle || (currentRubyPosition != RubyPart.None && section.RubyPart == RubyPart.None)) { lineContent.AppendTag("r", style); currentRubyPosition = RubyPart.None; prevSection = (AssSection)prevSection.Clone(); ApplyStyle(prevSection, style); } AppendSectionTags(section, prevSection, lineContent); if (section.RubyPart == RubyPart.Text) { RubyPart rubyPart; if (i + 4 > line.Sections.Count || ((rubyPart = line.Sections[i + 2].RubyPart) != RubyPart.RubyAbove && rubyPart != RubyPart.RubyBelow)) { throw new InvalidDataException("Invalid ruby sequence"); } if (rubyPart != currentRubyPosition) { lineContent.AppendTag("ytruby", rubyPart == RubyPart.RubyAbove ? 8 : 2); currentRubyPosition = rubyPart; } lineContent.AppendText($"[{section.Text}/{line.Sections[i + 2].Text}]"); i += 3; } else { lineContent.AppendText(section.Text); } prevSection = section; prevStyle = style; } writer.WriteLine(lineContent); }