Example #1
0
        public void Generate(Project project, IXenonASTElement _Parent)
        {
            Slide slide = new Slide
            {
                Name      = "UNNAMED_titledliturgyverse",
                Number    = project.NewSlideNumber,
                Lines     = new List <SlideLine>(),
                Asset     = "",
                Format    = SlideFormat.LiturgyTitledVerse,
                MediaType = MediaType.Image
            };


            Dictionary <string, string> otherspeakers = new Dictionary <string, string>();
            var s = project.GetAttribute("otherspeakers");

            foreach (var item in s)
            {
                var match = Regex.Match(item, "(?<speaker>(.*)-(?<text>.*))").Groups;
                otherspeakers.Add(match["speaker"].Value, match["text"].Value);
            }


            LiturgyLayoutEngine layoutEngine = new LiturgyLayoutEngine();

            layoutEngine.BuildLines(Text, otherspeakers);
            layoutEngine.BuildTextLines(project.Layouts.TitleLiturgyVerseLayout.Textbox);

            slide.Data["lines"]       = layoutEngine.LiturgyTextLines;
            slide.Data["title"]       = Title;
            slide.Data["reference"]   = Reference;
            slide.Data["drawspeaker"] = DrawSpeaker;

            if (project.GetAttribute("alphatranscol").Count > 0)
            {
                slide.Colors.Add("keytrans", GraphicsHelper.ColorFromRGB(project.GetAttribute("alphatranscol").FirstOrDefault()));
            }


            project.Slides.Add(slide);
        }
        public void Generate(Project project, IXenonASTElement _Parent)
        {
            Dictionary <string, string> otherspeakers = new Dictionary <string, string>();
            // get otherspeakers from project

            var s = project.GetAttribute("otherspeakers");

            foreach (var item in s)
            {
                var match = Regex.Match(item, "(?<speaker>(.*))-(?<text>.*)").Groups;
                otherspeakers.Add(match["speaker"].Value, match["text"].Value);
            }



            LiturgyLayoutEngine layoutEngine = new LiturgyLayoutEngine();

            layoutEngine.BuildLines(Content.Select(p => p.TextContent).ToList(), otherspeakers, ForceSpeakerStartOnNewline);
            layoutEngine.BuildSlideLines(project.Layouts.LiturgyLayout.GetRenderInfo());
            layoutEngine.BuildTextLines(project.Layouts.LiturgyLayout.Text);


            // override colors if requried on slide

            bool overridespeakercolor    = false;
            bool overridetextcolor       = false;
            bool overridebackgroundcolor = false;

            System.Drawing.Color liturgyspeakercolor    = new System.Drawing.Color();
            System.Drawing.Color liturgytextcolor       = new System.Drawing.Color();
            System.Drawing.Color liturgybackgroundcolor = new System.Drawing.Color();
            System.Drawing.Color liturgytransppcolor    = System.Drawing.Color.Gray;

            if (project.GetAttribute("litspeakertextcol").Count > 0)
            {
                liturgyspeakercolor  = GraphicsHelper.ColorFromRGB(project.GetAttribute("litspeakertextcol").FirstOrDefault());
                overridespeakercolor = true;
            }
            if (project.GetAttribute("littextcol").Count > 0)
            {
                liturgytextcolor  = GraphicsHelper.ColorFromRGB(project.GetAttribute("littextcol").FirstOrDefault());
                overridetextcolor = true;
            }
            if (project.GetAttribute("litbackgroundcol").Count > 0)
            {
                liturgybackgroundcolor  = GraphicsHelper.ColorFromRGB(project.GetAttribute("litbackgroundcol").FirstOrDefault());
                overridebackgroundcolor = true;
            }
            if (project.GetAttribute("alphatranscol").Count > 0)
            {
                liturgytransppcolor = GraphicsHelper.ColorFromRGB(project.GetAttribute("alphatranscol").FirstOrDefault());
            }



            // turn lines into slides

            /*
             *  We start by computing the height of each line
             *  Add this to the running total height of the slide's lines + min interline spacing
             *  Once we can't fit any more declare a slide, figure out the slide
             *
             *  Also must follow the 3 golden rules of slide layout
             *
             *  1. If the starting speaker is [C] Congregation, no other speaker allowed on the slide (or if starting speaker is [R] respondant
             *  2. There may be no more than 2 speakers per slide
             *  3. If a logical-line requires wrapping the line must be the first line of the slide
             */

            Slide liturgyslide = new Slide
            {
                Asset     = string.Empty,
                Name      = "UNNAMED_liturgy",
                Number    = project.NewSlideNumber,
                Format    = SlideFormat.Liturgy,
                MediaType = MediaType.Image,
            };

            if (overridespeakercolor)
            {
                liturgyslide.Colors["alttext"] = liturgyspeakercolor;
            }
            if (overridetextcolor)
            {
                liturgyslide.Colors["text"] = liturgytextcolor;
            }
            if (overridebackgroundcolor)
            {
                liturgyslide.Colors["keybackground"] = liturgybackgroundcolor;
            }
            liturgyslide.Colors["keytrans"] = liturgytransppcolor;


            double lineheight = -project.Layouts.LiturgyLayout.InterLineSpacing;

            string lastspeaker  = "";
            int    speakers     = 0;
            string startspeaker = layoutEngine.LiturgyTextLines.FirstOrDefault().Speaker ?? "";

            foreach (var line in layoutEngine.LiturgyTextLines)
            {
                if (lastspeaker != line.Speaker)
                {
                    speakers++;
                }

                bool overheight             = lineheight + project.Layouts.LiturgyLayout.InterLineSpacing + line.Height > project.Layouts.LiturgyLayout.GetRenderInfo().TextBox.Height;
                bool overspeakerswitch      = speakers > 2;                                                                                 // Rule 2
                bool incorrrectspeakerorder = (startspeaker == "C" && line.Speaker != "C") || (startspeaker == "R" && line.Speaker != "R"); // Rule 1
                bool paragraphwrapissue     = speakers > 1 && line.MultilineParagraph;                                                      // Rule 3
                if (overheight || overspeakerswitch || incorrrectspeakerorder || paragraphwrapissue)
                {
                    // need to start a new slide for this one
                    project.Slides.Add(liturgyslide);
                    // create new slide
                    liturgyslide = new Slide
                    {
                        Asset     = string.Empty,
                        Name      = "UNNAMED_liturgy",
                        Number    = project.NewSlideNumber,
                        Format    = SlideFormat.Liturgy,
                        MediaType = MediaType.Image,
                    };
                    if (overridespeakercolor)
                    {
                        liturgyslide.Colors["alttext"] = liturgyspeakercolor;
                    }
                    if (overridetextcolor)
                    {
                        liturgyslide.Colors["text"] = liturgytextcolor;
                    }
                    if (overridebackgroundcolor)
                    {
                        liturgyslide.Colors["keybackground"] = liturgybackgroundcolor;
                    }
                    liturgyslide.Colors["keytrans"] = liturgytransppcolor;

                    lineheight   = 0;
                    startspeaker = line.Speaker;
                    lastspeaker  = line.Speaker;
                    speakers     = 1;
                }
                lastspeaker = line.Speaker;
                lineheight += project.Layouts.LiturgyLayout.InterLineSpacing + line.Height;
                liturgyslide.Lines.Add(
                    new SlideLine()
                {
                    Content =
                    {
                        new SlideLineContent()
                            {
                            Data = line.Speaker, Attributes ={ ["width"]                                       = line.Width, ["height"] = line.Height }
                            },
                        new SlideLineContent()
                            {
                            Data       = string.Join("", line.Words.Select(w => w.Value)).Trim(),
                            Attributes =
                            {
                            ["textline"] = line,
                            ["width"]    = line.Width,
                            ["height"]   = line.Height
                            }
                            }
                    }
                }
                    );
            }
            // add slide to project
            project.Slides.Add(liturgyslide);
        }