Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Async/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Rendering/VisualLineElementTextRunProperties.cs @ 13508

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

#2077: created branch and added first version

File size: 7.9 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.Globalization;
21using System.Windows;
22using System.Windows.Media;
23using System.Windows.Media.TextFormatting;
24using ICSharpCode.AvalonEdit.Utils;
25
26namespace ICSharpCode.AvalonEdit.Rendering
27{
28  /// <summary>
29  /// <see cref="TextRunProperties"/> implementation that allows changing the properties.
30  /// A <see cref="VisualLineElementTextRunProperties"/> instance usually is assigned to a single
31  /// <see cref="VisualLineElement"/>.
32  /// </summary>
33  public class VisualLineElementTextRunProperties : TextRunProperties, ICloneable
34  {
35    Brush backgroundBrush;
36    BaselineAlignment baselineAlignment;
37    CultureInfo cultureInfo;
38    double fontHintingEmSize;
39    double fontRenderingEmSize;
40    Brush foregroundBrush;
41    Typeface typeface;
42    TextDecorationCollection textDecorations;
43    TextEffectCollection textEffects;
44    TextRunTypographyProperties typographyProperties;
45    NumberSubstitution numberSubstitution;
46   
47    /// <summary>
48    /// Creates a new VisualLineElementTextRunProperties instance that copies its values
49    /// from the specified <paramref name="textRunProperties"/>.
50    /// For the <see cref="TextDecorations"/> and <see cref="TextEffects"/> collections, deep copies
51    /// are created if those collections are not frozen.
52    /// </summary>
53    public VisualLineElementTextRunProperties(TextRunProperties textRunProperties)
54    {
55      if (textRunProperties == null)
56        throw new ArgumentNullException("textRunProperties");
57      backgroundBrush = textRunProperties.BackgroundBrush;
58      baselineAlignment = textRunProperties.BaselineAlignment;
59      cultureInfo = textRunProperties.CultureInfo;
60      fontHintingEmSize = textRunProperties.FontHintingEmSize;
61      fontRenderingEmSize = textRunProperties.FontRenderingEmSize;
62      foregroundBrush = textRunProperties.ForegroundBrush;
63      typeface = textRunProperties.Typeface;
64      textDecorations = textRunProperties.TextDecorations;
65      if (textDecorations != null && !textDecorations.IsFrozen) {
66        textDecorations = textDecorations.Clone();
67      }
68      textEffects = textRunProperties.TextEffects;
69      if (textEffects != null && !textEffects.IsFrozen) {
70        textEffects = textEffects.Clone();
71      }
72      typographyProperties = textRunProperties.TypographyProperties;
73      numberSubstitution = textRunProperties.NumberSubstitution;
74    }
75   
76    /// <summary>
77    /// Creates a copy of this instance.
78    /// </summary>
79    public virtual VisualLineElementTextRunProperties Clone()
80    {
81      return new VisualLineElementTextRunProperties(this);
82    }
83   
84    object ICloneable.Clone()
85    {
86      return Clone();
87    }
88   
89    /// <inheritdoc/>
90    public override Brush BackgroundBrush {
91      get { return backgroundBrush; }
92    }
93   
94    /// <summary>
95    /// Sets the <see cref="BackgroundBrush"/>.
96    /// </summary>
97    public void SetBackgroundBrush(Brush value)
98    {
99      ExtensionMethods.CheckIsFrozen(value);
100      backgroundBrush = value;
101    }
102   
103    /// <inheritdoc/>
104    public override BaselineAlignment BaselineAlignment {
105      get { return baselineAlignment; }
106    }
107   
108    /// <summary>
109    /// Sets the <see cref="BaselineAlignment"/>.
110    /// </summary>
111    public void SetBaselineAlignment(BaselineAlignment value)
112    {
113      baselineAlignment = value;
114    }
115   
116    /// <inheritdoc/>
117    public override CultureInfo CultureInfo {
118      get { return cultureInfo; }
119    }
120   
121    /// <summary>
122    /// Sets the <see cref="CultureInfo"/>.
123    /// </summary>
124    public void SetCultureInfo(CultureInfo value)
125    {
126      if (value == null)
127        throw new ArgumentNullException("value");
128      cultureInfo = value;
129    }
130   
131    /// <inheritdoc/>
132    public override double FontHintingEmSize {
133      get { return fontHintingEmSize; }
134    }
135   
136    /// <summary>
137    /// Sets the <see cref="FontHintingEmSize"/>.
138    /// </summary>
139    public void SetFontHintingEmSize(double value)
140    {
141      fontHintingEmSize = value;
142    }
143   
144    /// <inheritdoc/>
145    public override double FontRenderingEmSize {
146      get { return fontRenderingEmSize; }
147    }
148   
149    /// <summary>
150    /// Sets the <see cref="FontRenderingEmSize"/>.
151    /// </summary>
152    public void SetFontRenderingEmSize(double value)
153    {
154      fontRenderingEmSize = value;
155    }
156   
157    /// <inheritdoc/>
158    public override Brush ForegroundBrush {
159      get { return foregroundBrush; }
160    }
161   
162    /// <summary>
163    /// Sets the <see cref="ForegroundBrush"/>.
164    /// </summary>
165    public void SetForegroundBrush(Brush value)
166    {
167      ExtensionMethods.CheckIsFrozen(value);
168      foregroundBrush = value;
169    }
170   
171    /// <inheritdoc/>
172    public override Typeface Typeface {
173      get { return typeface; }
174    }
175   
176    /// <summary>
177    /// Sets the <see cref="Typeface"/>.
178    /// </summary>
179    public void SetTypeface(Typeface value)
180    {
181      if (value == null)
182        throw new ArgumentNullException("value");
183      typeface = value;
184    }
185   
186    /// <summary>
187    /// Gets the text decorations. The value may be null, a frozen <see cref="TextDecorationCollection"/>
188    /// or an unfrozen <see cref="TextDecorationCollection"/>.
189    /// If the value is an unfrozen <see cref="TextDecorationCollection"/>, you may assume that the
190    /// collection instance is only used for this <see cref="TextRunProperties"/> instance and it is safe
191    /// to add <see cref="TextDecoration"/>s.
192    /// </summary>
193    public override TextDecorationCollection TextDecorations {
194      get { return textDecorations; }
195    }
196   
197    /// <summary>
198    /// Sets the <see cref="TextDecorations"/>.
199    /// </summary>
200    public void SetTextDecorations(TextDecorationCollection value)
201    {
202      ExtensionMethods.CheckIsFrozen(value);
203      textDecorations = value;
204    }
205   
206    /// <summary>
207    /// Gets the text effects. The value may be null, a frozen <see cref="TextEffectCollection"/>
208    /// or an unfrozen <see cref="TextEffectCollection"/>.
209    /// If the value is an unfrozen <see cref="TextEffectCollection"/>, you may assume that the
210    /// collection instance is only used for this <see cref="TextRunProperties"/> instance and it is safe
211    /// to add <see cref="TextEffect"/>s.
212    /// </summary>
213    public override TextEffectCollection TextEffects {
214      get { return textEffects; }
215    }
216   
217    /// <summary>
218    /// Sets the <see cref="TextEffects"/>.
219    /// </summary>
220    public void SetTextEffects(TextEffectCollection value)
221    {
222      ExtensionMethods.CheckIsFrozen(value);
223      textEffects = value;
224    }
225   
226    /// <summary>
227    /// Gets the typography properties for the text run.
228    /// </summary>
229    public override TextRunTypographyProperties TypographyProperties {
230      get { return typographyProperties; }
231    }
232   
233    /// <summary>
234    /// Sets the <see cref="TypographyProperties"/>.
235    /// </summary>
236    public void SetTypographyProperties(TextRunTypographyProperties value)
237    {
238      typographyProperties = value;
239    }
240   
241    /// <summary>
242    /// Gets the number substitution settings for the text run.
243    /// </summary>
244    public override NumberSubstitution NumberSubstitution {
245      get { return numberSubstitution; }
246    }
247   
248    /// <summary>
249    /// Sets the <see cref="NumberSubstitution"/>.
250    /// </summary>
251    public void SetNumberSubstitution(NumberSubstitution value)
252    {
253      numberSubstitution = value;
254    }
255  }
256}
Note: See TracBrowser for help on using the repository browser.