コード例 #1
0
ファイル: YttDocument.cs プロジェクト: Queki/YTSubConverter
        /// <summary>
        /// The mobile apps have an unchangeable black background, meaning dark text is unreadable there.
        /// As a workaround, we overlap the dark subtitle with an invisible bright one: this way, we
        /// get the custom background and dark text on PC, and a black background and bright text
        /// on Android (because the Android app doesn't support transparency).
        /// Sadly, this trick doesn't work for iOS: that one supports (only) text transparency,
        /// meaning our bright yet invisible subtitle doesn't show up there.
        /// </summary>
        private int ExpandLineForDarkText(int lineIdx)
        {
            Line line = Lines[lineIdx];

            if (!line.Sections.Any(s => s.ForeColor.A > 0 && ColorUtil.IsDark(s.ForeColor)))
            {
                return(1);
            }

            Line brightLine = (Line)line.Clone();

            foreach (Section section in brightLine.Sections)
            {
                if (section.ForeColor.A > 0 && ColorUtil.IsDark(section.ForeColor))
                {
                    section.ForeColor = ColorUtil.Brighten(section.ForeColor);
                }

                section.ForeColor = ColorUtil.ChangeColorAlpha(section.ForeColor, 0);
                section.BackColor = ColorUtil.ChangeColorAlpha(section.BackColor, 0);
                section.ShadowColors.Clear();
            }

            Lines.Insert(lineIdx + 1, brightLine);
            return(2);
        }