Пример #1
0
        void InitializeBrushes(out Brush brush, out Brush overwriteBrush, VSTC.IClassificationType classificationType)
        {
            var props = classificationFormatMap.GetTextProperties(classificationType);

            if (!props.BackgroundBrushEmpty)
            {
                brush = props.BackgroundBrush;
            }
            else
            {
                Debug.Assert(!classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty);
                brush = classificationFormatMap.DefaultTextProperties.ForegroundBrush;
                if (classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
                {
                    brush = Brushes.Black;
                }
            }
            if (brush.CanFreeze)
            {
                brush.Freeze();
            }

            overwriteBrush         = brush.Clone();
            overwriteBrush.Opacity = 0.5;
            if (overwriteBrush.CanFreeze)
            {
                overwriteBrush.Freeze();
            }
        }
Пример #2
0
        void Add(List <HexLinePart> list, int column, HexClassificationSpan cspan, VST.Span lineExtent)
        {
            if (cspan.Span.Length == 0)
            {
                return;
            }
            int startOffs = lineExtent.Start;
            var props     = classificationFormatMap.GetTextProperties(cspan.ClassificationType);

            if (list.Count > 0)
            {
                var last = list[list.Count - 1];
                if (last.AdornmentElement == null && last.TextRunProperties == props && last.Span.End == cspan.Span.Start)
                {
                    list[list.Count - 1] = new HexLinePart(list.Count - 1, last.Column, VST.Span.FromBounds(last.Span.Start - startOffs, cspan.Span.End - startOffs), last.TextRunProperties);
                    return;
                }
            }
            list.Add(new HexLinePart(list.Count, column, new VST.Span(cspan.Span.Start - startOffs, cspan.Span.Length), props));
        }
Пример #3
0
        public void Add(HexBufferLineFormatter bufferLines, HexClassifier classifier, NormalizedHexBufferSpanCollection spans, CancellationToken cancellationToken)
        {
            if (bufferLines == null)
            {
                throw new ArgumentNullException(nameof(bufferLines));
            }
            if (classifier == null)
            {
                throw new ArgumentNullException(nameof(classifier));
            }
            if (spans == null)
            {
                throw new ArgumentNullException(nameof(spans));
            }
            if (spans.Count != 0 && spans[0].Buffer != bufferLines.Buffer)
            {
                throw new ArgumentException();
            }

            var classificationSpans = new List <HexClassificationSpan>();

            foreach (var span in spans)
            {
                if (spansCount > 0)
                {
                    htmlWriter.WriteRaw(delimiter);
                }
                spansCount++;

                var pos = span.Start;
                for (;;)
                {
                    classificationSpans.Clear();
                    var line    = bufferLines.GetLineFromPosition(pos);
                    var text    = line.GetText(span);
                    var context = new HexClassificationContext(line, line.TextSpan);
                    classifier.GetClassificationSpans(classificationSpans, context, cancellationToken);

                    int textPos = 0;
                    foreach (var tagSpan in classificationSpans)
                    {
                        if (textPos < tagSpan.Span.Start)
                        {
                            WriteCss(classificationFormatMap.DefaultTextProperties);
                            htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, tagSpan.Span.Start - textPos);
                        }
                        WriteCss(classificationFormatMap.GetTextProperties(tagSpan.ClassificationType));
                        htmlWriter.WriteSpan(cssWriter.ToString(), text, tagSpan.Span.Start, tagSpan.Span.Length);
                        textPos = tagSpan.Span.End;
                    }
                    if (textPos < text.Length)
                    {
                        WriteCss(classificationFormatMap.DefaultTextProperties);
                        htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, text.Length - textPos);
                    }
                    htmlWriter.WriteRaw("<br/>");

                    pos = line.BufferEnd;
                    if (pos >= span.End)
                    {
                        break;
                    }
                }
            }
        }