2 // System.Drawing.StringFormat.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Miguel de Icaza (miguel@ximian.com)
7 // Jordi Mas i Hernandez (jordi@ximian.com)
9 // Copyright (C) 2002 Ximian, Inc (http://www.ximian.com)
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Drawing.Text;
35 namespace System.Drawing {
37 /// Summary description for StringFormat.
39 public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable {
42 private CharacterRange [] _charRanges;
43 private StringAlignment _alignment;
44 private StringAlignment _lineAlignment;
45 private HotkeyPrefix _hotkeyPrefix;
46 private StringFormatFlags _flags;
47 private StringDigitSubstitute _digitSubstituteMethod;
48 private int _digitSubstituteLanguage;
49 private StringTrimming _trimming;
51 private float _firstTabOffset;
52 private float [] _tabStops;
56 public StringFormat() : this(0, 0) {
59 public StringFormat(StringFormatFlags options) : this(options,0) {
62 public StringFormat(StringFormatFlags options, int lang) {
63 _alignment = StringAlignment.Near;
64 _digitSubstituteLanguage = lang;
65 _digitSubstituteMethod = StringDigitSubstitute.User;
67 _hotkeyPrefix = HotkeyPrefix.None;
68 _lineAlignment = StringAlignment.Near;
69 _trimming = StringTrimming.Character;
72 public StringFormat (StringFormat source) {
74 throw new ArgumentNullException("format");
76 _alignment = source.LineAlignment;
77 _digitSubstituteLanguage = source.DigitSubstitutionLanguage;
78 _digitSubstituteMethod = source.DigitSubstitutionMethod;
79 _flags = source.FormatFlags;
80 _hotkeyPrefix = source.HotkeyPrefix;
81 _lineAlignment = source.LineAlignment;
82 _trimming = source.Trimming;
90 public void Dispose() {
95 #region Public properties
97 public StringAlignment Alignment {
107 public StringAlignment LineAlignment {
109 return _lineAlignment;
112 _lineAlignment = value;
117 public StringFormatFlags FormatFlags {
128 public HotkeyPrefix HotkeyPrefix {
130 return _hotkeyPrefix;
134 _hotkeyPrefix = value;
139 public StringTrimming Trimming {
149 public int DigitSubstitutionLanguage {
151 return _digitSubstituteLanguage;
155 public StringDigitSubstitute DigitSubstitutionMethod {
157 return _digitSubstituteMethod;
164 #region static properties
166 public static StringFormat GenericDefault {
168 StringFormat genericDefault = new StringFormat();
169 return genericDefault;
173 public static StringFormat GenericTypographic {
175 StringFormat genericTypographic = new StringFormat(
176 StringFormatFlags.FitBlackBox |
177 StringFormatFlags.LineLimit |
178 StringFormatFlags.NoClip,
180 genericTypographic.Trimming = StringTrimming.None;
181 return genericTypographic;
187 #region internal accessors
188 internal bool NoWrap {
\r
190 return (FormatFlags & StringFormatFlags.NoWrap) != 0;
\r
194 internal bool IsVertical {
\r
196 return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;
\r
200 internal bool MeasureTrailingSpaces {
\r
202 return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;
\r
206 internal bool LineLimit {
\r
208 return (FormatFlags & StringFormatFlags.LineLimit) != 0;
\r
212 internal bool NoClip {
\r
214 return (FormatFlags & StringFormatFlags.NoClip) != 0;
\r
218 internal bool IsRightToLeft {
\r
220 return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;
\r
224 internal CharacterRange [] CharRanges {
231 #region public methods
233 public void SetMeasurableCharacterRanges (CharacterRange [] range) {
234 _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
237 public object Clone() {
238 StringFormat copy = (StringFormat)MemberwiseClone();
239 if (_charRanges != null)
240 copy._charRanges = (CharacterRange [])_charRanges.Clone();
241 if (_tabStops != null)
242 copy._tabStops = (float[])_tabStops.Clone();
246 public override string ToString() {
247 return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
250 public void SetTabStops(float firstTabOffset, float[] tabStops) {
251 // _firstTabOffset = firstTabOffset;
252 // _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
253 throw new NotSupportedException();
256 public void SetDigitSubstitution(int language, StringDigitSubstitute substitute) {
257 // _digitSubstituteMethod = substitute;
258 // _digitSubstituteLanguage = language;
259 throw new NotSupportedException();
263 public float[] GetTabStops(out float firstTabOffset) {
264 firstTabOffset = _firstTabOffset;
265 return _tabStops != null ? (float[])_tabStops.Clone() : null;