Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Utils/RichTextWriter.cs @ 15377

Last change on this file since 15377 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 3.6 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.IO;
21using System.Windows;
22using System.Windows.Media;
23using ICSharpCode.AvalonEdit.Highlighting;
24
25namespace ICSharpCode.AvalonEdit.Utils
26{
27  // TODO: This class (and derived classes) is currently unused; decide whether to keep it.
28  // (until this is decided, keep the class internal)
29 
30  /// <summary>
31  /// A text writer that supports creating spans of highlighted text.
32  /// </summary>
33  abstract class RichTextWriter : TextWriter
34  {
35    /// <summary>
36    /// Gets called by the RichTextWriter base class when a BeginSpan() method
37    /// that is not overwritten gets called.
38    /// </summary>
39    protected abstract void BeginUnhandledSpan();
40   
41    /// <summary>
42    /// Writes the RichText instance.
43    /// </summary>
44    public void Write(RichText richText)
45    {
46      Write(richText, 0, richText.Length);
47    }
48   
49    /// <summary>
50    /// Writes the RichText instance.
51    /// </summary>
52    public virtual void Write(RichText richText, int offset, int length)
53    {
54      foreach (var section in richText.GetHighlightedSections(offset, length)) {
55        BeginSpan(section.Color);
56        Write(richText.Text.Substring(section.Offset, section.Length));
57        EndSpan();
58      }
59    }
60   
61    /// <summary>
62    /// Begin a colored span.
63    /// </summary>
64    public virtual void BeginSpan(Color foregroundColor)
65    {
66      BeginUnhandledSpan();
67    }
68   
69    /// <summary>
70    /// Begin a span with modified font weight.
71    /// </summary>
72    public virtual void BeginSpan(FontWeight fontWeight)
73    {
74      BeginUnhandledSpan();
75    }
76   
77    /// <summary>
78    /// Begin a span with modified font style.
79    /// </summary>
80    public virtual void BeginSpan(FontStyle fontStyle)
81    {
82      BeginUnhandledSpan();
83    }
84   
85    /// <summary>
86    /// Begin a span with modified font family.
87    /// </summary>
88    public virtual void BeginSpan(FontFamily fontFamily)
89    {
90      BeginUnhandledSpan();
91    }
92   
93    /// <summary>
94    /// Begin a highlighted span.
95    /// </summary>
96    public virtual void BeginSpan(Highlighting.HighlightingColor highlightingColor)
97    {
98      BeginUnhandledSpan();
99    }
100   
101    /// <summary>
102    /// Begin a span that links to the specified URI.
103    /// </summary>
104    public virtual void BeginHyperlinkSpan(Uri uri)
105    {
106      BeginUnhandledSpan();
107    }
108   
109    /// <summary>
110    /// Marks the end of the current span.
111    /// </summary>
112    public abstract void EndSpan();
113   
114    /// <summary>
115    /// Increases the indentation level.
116    /// </summary>
117    public abstract void Indent();
118   
119    /// <summary>
120    /// Decreases the indentation level.
121    /// </summary>
122    public abstract void Unindent();
123  }
124}
Note: See TracBrowser for help on using the repository browser.