Exemplo n.º 1
0
        private static void FormatLine(StringBuilder sb, TextLineInfo lineInfo)
        {
            int index = 0;
            string text;

            string lineHeader = @"<tr><td class=""lineNumber"">{0}</td><td>";

            sb.Append(string.Format(lineHeader, lineInfo.LineNumber));

            foreach (var seg in lineInfo.Segments)
            {
                if (seg.StartIndex != index)
                {
                    text = lineInfo.TextLine.Substring(index, seg.StartIndex - index);
                    sb.Append(FormatSegemnt(text, null));
                }

                text = lineInfo.TextLine.Substring(seg.StartIndex, seg.Length);
                sb.Append(FormatSegemnt(text, seg.Foreground));

                index = seg.StartIndex + seg.Length;
            }

            if (lineInfo.TextLine.Length != index)
            {
                text = lineInfo.TextLine.Substring(index, lineInfo.TextLine.Length - index);
                sb.Append(FormatSegemnt(text, null));
            }

            string lineTail = @"</td></tr>";
            sb.AppendLine(lineTail);
        }
Exemplo n.º 2
0
        private static void GenerateHtml(StringBuilder sb, TextLineInfo[] infos)
        {
            string header = @"
            <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">
            <head>
            <style>
            <!--
            .lineNumber {
            font-size:10.0pt;
            font-family:""Consolas"",""sans-serif"";
            background-color: Beige;
            color: darkgray;
            width: 20pt;
            }
            .code {
            font-size:10.0pt;
            font-family:""Consolas"",""sans-serif"";
            background-color: #ffffff;
            }
            -->
            </style>
            </head>
            <body bgcolor=""white"" lang=""EN-US"" link=""blue"" vlink=""purple""  >
            <table class=""code"" style=""width:100%;cellpadding=""0""; cellspacing=""0"""">";

            sb.AppendLine(header);

            for (int i = 0; i < infos.Length; ++i)
            {
                FormatLine(sb, infos[i]);
            }

            string footer = @"
             </table>

            </body>
            </html>";
            sb.AppendLine(footer);
        }
Exemplo n.º 3
0
        public void UpdateLines(TextLineInfo[] lines)
        {
            this.rightScrollBar.Minimum = 0;
            this.rightScrollBar.Maximum = lines.Length;
            this.rightScrollBar.Value = 0;

            double totalHeight = lines.Length * GetLineHeight();
            SetThumbLength(this.rightScrollBar, totalHeight);

            this.bottomScrollBar.Minimum = 0;
            this.bottomScrollBar.Maximum = lines.Max(l => l.TextLine.Length);
            this.bottomScrollBar.Value = 0;

            double totalWidth = this.bottomScrollBar.Maximum * LineHeightText.WidthIncludingTrailingWhitespace / 120;
            SetThumbLength(this.bottomScrollBar, totalWidth);

            this.codeView.LineInfos = lines;
            this.lineBar.Width = GetLineBarWidth(lines.Length);

            ResetFirstLine();

            InvalidateVisual();
        }