示例#1
0
        HexLinePartsCollection CreateLinePartsCollection(HexAndAdornmentCollection coll, HexBufferLine bufferLine)
        {
            var lineExtent = bufferLine.TextSpan;

            if (coll.Count == 0)
            {
                return(new HexLinePartsCollection(emptyLineParts, lineExtent, bufferLine.Text));
            }

            var list = new List <HexLinePart>();

            int column    = 0;
            int startOffs = lineExtent.Start;

            foreach (var seqElem in coll)
            {
                if (seqElem.ShouldRenderText)
                {
                    var cspans   = new List <HexClassificationSpan>();
                    var textSpan = bufferLine.TextSpan.Intersection(seqElem.Span) ?? new VST.Span(bufferLine.TextSpan.End, 0);
                    aggregateClassifier.GetClassificationSpans(cspans, new HexClassificationContext(bufferLine, textSpan));
                    int lastOffs = seqElem.Span.Start;
                    for (int i = 0; i < cspans.Count; i++)
                    {
                        var cspan     = cspans[i];
                        int otherSize = cspan.Span.Start - lastOffs;
                        if (otherSize != 0)
                        {
                            Debug.Assert(otherSize > 0);
                            list.Add(new HexLinePart(list.Count, column, new VST.Span(lastOffs - startOffs, otherSize), DefaultTextProperties));
                            column += otherSize;
                        }
                        Add(list, column, cspan, lineExtent);
                        column  += cspan.Span.Length;
                        lastOffs = cspan.Span.End;
                    }
                    int lastSize = seqElem.Span.End - lastOffs;
                    if (lastSize != 0)
                    {
                        list.Add(new HexLinePart(list.Count, column, new VST.Span(lastOffs - startOffs, lastSize), DefaultTextProperties));
                        column += lastSize;
                    }
                }
                else
                {
                    var adornmentElement = seqElem as HexAdornmentElement;
                    if (adornmentElement != null)
                    {
                        var span = seqElem.Span;
                        list.Add(new HexLinePart(list.Count, column, new VST.Span(span.Start - startOffs, span.Length), adornmentElement, DefaultTextProperties));
                        column += list[list.Count - 1].ColumnLength;
                    }
                }
            }
            Debug.Assert(list.Sum(a => a.ColumnLength) == column);

            return(new HexLinePartsCollection(list, lineExtent, bufferLine.Text));
        }
示例#2
0
		public void Add(HexBufferLineProvider 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;
				}
			}
		}
示例#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;
                    }
                }
            }
        }