// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.IO; using System.Windows; using System.Windows.Media; using ICSharpCode.AvalonEdit.Highlighting; namespace ICSharpCode.AvalonEdit.Utils { // TODO: This class (and derived classes) is currently unused; decide whether to keep it. // (until this is decided, keep the class internal) /// /// A text writer that supports creating spans of highlighted text. /// abstract class RichTextWriter : TextWriter { /// /// Gets called by the RichTextWriter base class when a BeginSpan() method /// that is not overwritten gets called. /// protected abstract void BeginUnhandledSpan(); /// /// Writes the RichText instance. /// public void Write(RichText richText) { Write(richText, 0, richText.Length); } /// /// Writes the RichText instance. /// public virtual void Write(RichText richText, int offset, int length) { foreach (var section in richText.GetHighlightedSections(offset, length)) { BeginSpan(section.Color); Write(richText.Text.Substring(section.Offset, section.Length)); EndSpan(); } } /// /// Begin a colored span. /// public virtual void BeginSpan(Color foregroundColor) { BeginUnhandledSpan(); } /// /// Begin a span with modified font weight. /// public virtual void BeginSpan(FontWeight fontWeight) { BeginUnhandledSpan(); } /// /// Begin a span with modified font style. /// public virtual void BeginSpan(FontStyle fontStyle) { BeginUnhandledSpan(); } /// /// Begin a span with modified font family. /// public virtual void BeginSpan(FontFamily fontFamily) { BeginUnhandledSpan(); } /// /// Begin a highlighted span. /// public virtual void BeginSpan(Highlighting.HighlightingColor highlightingColor) { BeginUnhandledSpan(); } /// /// Begin a span that links to the specified URI. /// public virtual void BeginHyperlinkSpan(Uri uri) { BeginUnhandledSpan(); } /// /// Marks the end of the current span. /// public abstract void EndSpan(); /// /// Increases the indentation level. /// public abstract void Indent(); /// /// Decreases the indentation level. /// public abstract void Unindent(); } }