protected virtual void Assign(Section section)
 {
     Text      = section.Text;
     Font      = section.Font;
     Scale     = section.Scale;
     Offset    = section.Offset;
     Bold      = section.Bold;
     Italic    = section.Italic;
     Underline = section.Underline;
     ForeColor = section.ForeColor;
     BackColor = section.BackColor;
     ShadowColors.Clear();
     ShadowColors.AddRange(section.ShadowColors);
     RubyPart = section.RubyPart;
 }
Exemple #2
0
        private static int GetRubyPartId(RubyPart part)
        {
            switch (part)
            {
            case RubyPart.None:
                return(0);

            case RubyPart.Text:
                return(1);

            case RubyPart.Parenthesis:
                return(2);

            case RubyPart.RubyAbove:
                return(4);

            case RubyPart.RubyBelow:
                return(5);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private static void InsertRubySection(AssLine line, Section format, string text, RubyPart rubyPart, int sectionIndex, ref int numSubSections)
        {
            AssSection section = (AssSection)format.Clone();

            section.Text     = text;
            section.RubyPart = rubyPart;
            section.Duration = TimeSpan.Zero;
            line.Sections.Insert(sectionIndex + numSubSections, section);
            numSubSections++;
        }
Exemple #4
0
        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);
        }