Exemplo n.º 1
0
        private void RefreshStyleList(AssDocument document)
        {
            _styles       = document.Styles.ToDictionary(s => s.Name);
            _defaultStyle = document.DefaultStyle;
            foreach (AssStyle style in document.Styles)
            {
                if (!_styleOptions.ContainsKey(style.Name))
                {
                    _styleOptions.Add(style.Name, new AssStyleOptions(style));
                }
            }

            int selectedIndex = _lstStyles.SelectedIndex;

            _lstStyles.DataSource = document.Styles.Select(s => _styleOptions[s.Name]).ToList();
            if (_lstStyles.Items.Count > selectedIndex)
            {
                _lstStyles.SelectedIndex = selectedIndex;
            }
            else if (_lstStyles.Items.Count > 0)
            {
                _lstStyles.SelectedIndex = 0;
            }
        }
Exemplo n.º 2
0
        public static string GenerateHtml(AssStyle style, AssStyleOptions options, float defaultFontSize)
        {
            StringBuilder html = new StringBuilder();

            html.Append($@"
                  <!DOCTYPE html>
                  <html>
                  <head>
                      <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />
                      <style>
                          html, body
                          {{
                              width: 100%;
                              height: 100%;
                              padding: 0;
                              margin: 0;
                              cursor: default;
                          }}
                          body
                          {{
                              display: table;
                              background-image: url({GetBackgroundImageUrl(options)});
                              background-position: {GetBackgroundImagePosition(options)};
                              background-repeat: {GetBackgroundImageRepeat(options)};
                              -ms-user-select: none;
                          }}
                          #wrapper
                          {{
                              display: table-cell;
                              height: 100%;
                              padding: 10px;
                              text-align: {GetTextAlign(style, options)};
                              vertical-align: {GetVerticalAlign(style, options)};
                          }}
            ");

            if (options != null)
            {
                GenerateBackgroundCss(html, "#background", style, defaultFontSize);
                GenerateForegroundCss(html, "#regular", style, style.PrimaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                if (options.IsKaraoke)
                {
                    GenerateForegroundCss(
                        html,
                        "#singing",
                        style,
                        !options.CurrentWordTextColor.IsEmpty ? options.CurrentWordTextColor : style.PrimaryColor,
                        !options.CurrentWordOutlineColor.IsEmpty ? options.CurrentWordOutlineColor : style.OutlineColor,
                        !options.CurrentWordShadowColor.IsEmpty ? options.CurrentWordShadowColor : style.ShadowColor,
                        options.ShadowTypes
                        );
                    GenerateForegroundCss(html, "#unsung", style, style.SecondaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                }
            }

            html.Append(@"
                      </style>
                  </head>
                  <body>
                      <div id=""wrapper"">
            ");

            if (options != null)
            {
                html.Append(@"<span id=""background"">");

                if (options.IsKaraoke)
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleKaraoke1}</span>");
                    html.Append($@"<span id=""singing"">{Resources.PreviewSampleKaraoke2}</span>");
                    html.Append($@"<span id=""unsung"">{Resources.PreviewSampleKaraoke3}</span>");
                }
                else
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleRegular}</span>");
                }

                html.Append(@"</span>");
            }

            html.Append(@"
                      </div>
                  </body>
                  </html>
            ");
            return(html.ToString());
        }
Exemplo n.º 3
0
        private static void GenerateForegroundCss(StringBuilder html, string selector, AssStyle style, Color foreColor, Color outlineColor, Color shadowColor, List <ShadowType> shadowTypes)
        {
            html.Append($@"
                {selector}
                {{
            ");

            if (style.Bold)
            {
                html.Append("font-weight: bold;");
            }

            if (style.Italic)
            {
                html.Append("font-style: italic;");
            }

            if (style.Underline)
            {
                html.Append("text-decoration: underline;");
            }

            if (IsSupportedFont(style.Font))
            {
                html.Append($"font-family: '{FixFontName(style.Font)}', 'Arial';");
            }
            else
            {
                html.Append("font-family: 'Roboto', 'Arial';");
            }

            html.Append($"color: {ToRgba(foreColor)};");

            List <string> shadows = new List <string>();

            if (style.HasOutline && !style.OutlineIsBox)
            {
                shadows.Add($"0 0 2px {ToHex(outlineColor)}, 0 0 2px {ToHex(outlineColor)}, 0 0 3px {ToHex(outlineColor)}, 0 0 4px {ToHex(outlineColor)}");
            }

            if (style.HasShadow)
            {
                if (shadowTypes.Contains(ShadowType.Glow) && !(style.HasOutline && !style.HasOutlineBox))
                {
                    shadows.Add($"0 0 2px {ToHex(shadowColor)}, 0 0 2px {ToHex(shadowColor)}, 0 0 3px {ToHex(shadowColor)}, 0 0 4px {ToHex(shadowColor)}");
                }

                if (shadowTypes.Contains(ShadowType.Bevel))
                {
                    shadows.Add($"2px 2px 0 {ToHex(shadowColor)}, -2px -2px 0 {ToHex(shadowColor)}");
                }

                if (shadowTypes.Contains(ShadowType.SoftShadow))
                {
                    shadows.Add($"2px 2px 3px {ToHex(shadowColor)}, 2px 2px 4px {ToHex(shadowColor)}, 2px 2px 5px {ToHex(shadowColor)}");
                }

                if (shadowTypes.Contains(ShadowType.HardShadow))
                {
                    shadows.Add($"1px 1px 0 {ToHex(shadowColor)}, 2px 2px 0 {ToHex(shadowColor)}, 3px 3px 0 {ToHex(shadowColor)}");
                }
            }

            if (shadows.Count > 0)
            {
                html.Append($"text-shadow: {string.Join(", ", shadows)};");
            }

            html.AppendLine(@"
                }
            ");
        }
Exemplo n.º 4
0
        private static void GenerateBackgroundCss(StringBuilder html, string selector, AssStyle style, float defaultFontSize)
        {
            html.Append($@"
                {selector}
                {{
                    padding: 3px 5px;
                    border-radius: 3px;
                    font-size: {Math.Max(32 * style.FontSize / defaultFontSize, 24)}px;
            ");

            if (style.HasOutline && style.OutlineIsBox)
            {
                html.Append($"background-color: {ToRgba(style.OutlineColor)};");
            }

            html.Append(@"
                }
            ");
        }
Exemplo n.º 5
0
        private static void GenerateForegroundCss(StringBuilder html, string selector, AssStyle style, Color foreColor, Color outlineColor, Color shadowColor, List <ShadowType> shadowTypes)
        {
            html.Append($@"
                {selector}
                {{
            ");

            if (style.Bold)
            {
                html.Append("font-weight: bold;");
            }

            if (style.Italic)
            {
                html.Append("font-style: italic;");
            }

            if (style.Underline)
            {
                html.Append("text-decoration: underline;");
            }

            html.Append($"font-family: {string.Join(", ", GetFontListContaining(style.Font).Select(f => "\"" + f + "\""))};");
            html.Append($"color: {ToRgba(foreColor)};");

            List <string> shadows = new List <string>();

            if (style.HasOutline && !style.OutlineIsBox)
            {
                shadows.Add($"0 0 2px {ToHex(outlineColor)}, 0 0 2px {ToHex(outlineColor)}, 0 0 3px {ToHex(outlineColor)}, 0 0 4px {ToHex(outlineColor)}");
            }

            if (style.HasShadow)
            {
                if (shadowTypes.Contains(ShadowType.Glow) && !(style.HasOutline && !style.HasOutlineBox))
                {
                    shadows.Add($"0 0 2px {ToHex(shadowColor)}, 0 0 2px {ToHex(shadowColor)}, 0 0 3px {ToHex(shadowColor)}, 0 0 4px {ToHex(shadowColor)}");
                }

                if (shadowTypes.Contains(ShadowType.Bevel))
                {
                    if (shadowColor.R == 0x22 && shadowColor.G == 0x22 && shadowColor.B == 0x22)
                    {
                        shadows.Add("-1px -1px 0 #222222, 1px 1px 0 #CCCCCC");
                    }
                    else
                    {
                        shadows.Add($"-1px -1px 0 {ToHex(shadowColor)}, 1px 1px 0 {ToHex(shadowColor)}");
                    }
                }

                if (shadowTypes.Contains(ShadowType.SoftShadow))
                {
                    shadows.Add($"2px 2px 3px {ToHex(shadowColor)}, 2px 2px 4px {ToHex(shadowColor)}, 2px 2px 5px {ToHex(shadowColor)}");
                }

                if (shadowTypes.Contains(ShadowType.HardShadow))
                {
                    shadows.Add($"1px 1px 0 {ToHex(shadowColor)}, 2px 2px 0 {ToHex(shadowColor)}, 3px 3px 0 {ToHex(shadowColor)}");
                }
            }

            if (shadows.Count > 0)
            {
                html.Append($"text-shadow: {string.Join(", ", shadows)};");
            }

            html.AppendLine(@"
                }
            ");
        }
Exemplo n.º 6
0
        private static void GenerateBackgroundCss(StringBuilder html, string selector, AssStyle style, AssStyle defaultStyle, float windowsScaleFactor)
        {
            html.Append($@"
                {selector}
                {{
                    padding: 1px 8px;
                    font-size: {(int)(Math.Max(32 * style.LineHeight / defaultStyle.LineHeight, 24) * windowsScaleFactor)}px;
            ");

            if (style.HasOutline && style.OutlineIsBox)
            {
                html.Append($"background-color: {ToRgba(style.OutlineColor)};");
            }

            html.Append(@"
                }
            ");
        }
Exemplo n.º 7
0
        private static void GenerateBackgroundCss(StringBuilder html, string selector, AssStyle style)
        {
            html.Append($@"
                {selector}
                {{
                    padding: 3px 5px;
                    border-radius: 3px;
                    font-size: 32px;
            ");

            if (style.HasOutline && style.OutlineIsBox)
            {
                html.Append($"background-color: {ToRgba(style.OutlineColor)};");
            }

            html.Append(@"
                }
            ");
        }
Exemplo n.º 8
0
        private void UpdateStylePreview()
        {
            AssStyle style = _styles?[SelectedStyleOptions.Name];

            _brwPreview.DocumentText = StylePreviewGenerator.GenerateHtml(style, SelectedStyleOptions);
        }
Exemplo n.º 9
0
        public static string GenerateHtml(AssStyle style, AssStyleOptions options)
        {
            StringBuilder html = new StringBuilder();

            html.Append($@"
                  <!DOCTYPE html>
                  <html>
                  <head>
                      <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />
                      <style>
                          html, body {{ width: 100%; height: 100%; padding: 0; margin: 0; }}
                          body {{ display: table; background-image: url(data:image/png;base64,{BackgroundImageData}); }}
                          #wrapper {{ display: table-cell; height: 100%; text-align: center; vertical-align: middle; }}
            ");

            if (options != null)
            {
                GenerateBackgroundCss(html, "#background", style);
                GenerateForegroundCss(html, "#regular", style, style.PrimaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                if (options.IsKaraoke)
                {
                    GenerateForegroundCss(
                        html,
                        "#singing",
                        style,
                        !options.CurrentWordTextColor.IsEmpty ? options.CurrentWordTextColor : style.PrimaryColor,
                        !options.CurrentWordOutlineColor.IsEmpty ? options.CurrentWordOutlineColor : style.OutlineColor,
                        !options.CurrentWordShadowColor.IsEmpty ? options.CurrentWordShadowColor : style.ShadowColor,
                        options.ShadowTypes
                        );
                    GenerateForegroundCss(html, "#unsung", style, style.SecondaryColor, style.OutlineColor, style.ShadowColor, options.ShadowTypes);
                }
            }

            html.Append(@"
                      </style>
                  </head>
                  <body>
                      <div id=""wrapper"">
            ");

            if (options != null)
            {
                html.Append(@"<span id=""background"">");

                if (options.IsKaraoke)
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleKaraoke1}</span>");
                    html.Append($@"<span id=""singing"">{Resources.PreviewSampleKaraoke2}</span>");
                    html.Append($@"<span id=""unsung"">{Resources.PreviewSampleKaraoke3}</span>");
                }
                else
                {
                    html.Append($@"<span id=""regular"">{Resources.PreviewSampleRegular}</span>");
                }

                html.Append(@"</span>");
            }

            html.Append(@"
                      </div>
                  </body>
                  </html>
            ");
            return(html.ToString());
        }