Esempio n. 1
0
        public static string[] GenerateLinesFromText(string input, int counter)
        {
            //TODO: improve italic support
            var text = Utilities.RemoveSsaTags(input);

            text = HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagFont, HtmlUtil.TagBold);
            var results = new List <string>();
            var bytes   = new List <byte>();
            var italic  = text.StartsWith("<i>");

            text = HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagItalic);
            var lines    = text.SplitToLines();
            var commands = new List <ICea708Command>
            {
                new DefineWindow(lines.Count),
                new SetWindowAttributes(SetWindowAttributes.JustifyCenter),
                new SetPenAttributes(italic),
                new SetPenColor(),
            };

            foreach (var command in commands)
            {
                bytes.AddRange(command.GetBytes());
            }
            commands.Clear();

            foreach (var line in lines)
            {
                var c1 = new SetPenLocation();
                if (c1.GetBytes().Length + bytes.Count > 32)
                {
                    counter = FlushCommands(counter, bytes, results);
                }
                bytes.AddRange(c1.GetBytes());

                var c2 = new SetText(line);
                if (c2.GetBytes().Length + bytes.Count > 32)
                {
                    counter = FlushCommands(counter, bytes, results);
                }
                bytes.AddRange(c2.GetBytes());
            }

            FlushCommands(counter, bytes, results);
            return(results.ToArray());
        }
Esempio n. 2
0
        public static string[] GenerateLinesFromText(string text, int counter)
        {
            //TODO: chunk in max 32 bytes chunks (do not split commands)
            var results  = new List <string>();
            var bytes    = new List <byte>();
            var lines    = text.SplitToLines();
            var commands = new List <ICommand>
            {
                new DefineWindow(lines.Count),
                new SetWindowAttributes(SetWindowAttributes.JustifyCenter),
                new SetPenAttributes(false),
                new SetPenColor(),
            };

            foreach (var command in commands)
            {
                bytes.AddRange(command.GetBytes());
            }
            commands.Clear();

            foreach (var line in lines)
            {
                var c1 = new SetPenLocation();
                if (c1.GetBytes().Length + bytes.Count > 32)
                {
                    counter = FlushCommands(counter, bytes, results);
                }
                bytes.AddRange(c1.GetBytes());

                var c2 = new SetText(line);
                if (c2.GetBytes().Length + bytes.Count > 32)
                {
                    counter = FlushCommands(counter, bytes, results);
                }
                bytes.AddRange(c2.GetBytes());
            }

            FlushCommands(counter, bytes, results);
            return(results.ToArray());
        }
Esempio n. 3
0
        public void CommandTextCommand()
        {
            var command = new SetText(0, "Hallo!");
            var bytes   = command.GetBytes();

            Assert.AreEqual(bytes.Length, 6);
            Assert.AreEqual(bytes[0], 72);
            Assert.AreEqual(bytes[1], 97);
            Assert.AreEqual(bytes[2], 108);
            Assert.AreEqual(bytes[3], 108);
            Assert.AreEqual(bytes[4], 111);
            Assert.AreEqual(bytes[5], 33);
        }