示例#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());
        }
示例#2
0
        public void CommandSetPenLocation()
        {
            var command = new SetPenLocation(0, new byte[] { 2, 4 }, 0);
            var bytes   = command.GetBytes();

            Assert.AreEqual(bytes.Length, 3);
            Assert.AreEqual(bytes[0], SetPenLocation.Id);
            Assert.AreEqual(bytes[1], 2);
            Assert.AreEqual(bytes[2], 4);
        }
示例#3
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());
        }