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;
54 private bool _genericTypeographic = false;
58 public StringFormat() : this(0, 0) {
61 public StringFormat(StringFormatFlags options) : this(options,0) {
64 public StringFormat(StringFormatFlags options, int lang) {
65 _alignment = StringAlignment.Near;
66 _digitSubstituteLanguage = lang;
67 _digitSubstituteMethod = StringDigitSubstitute.User;
69 _hotkeyPrefix = HotkeyPrefix.None;
70 _lineAlignment = StringAlignment.Near;
71 _trimming = StringTrimming.Character;
74 public StringFormat (StringFormat source) {
76 throw new ArgumentNullException("format");
78 _alignment = source.LineAlignment;
79 _digitSubstituteLanguage = source.DigitSubstitutionLanguage;
80 _digitSubstituteMethod = source.DigitSubstitutionMethod;
81 _flags = source.FormatFlags;
82 _hotkeyPrefix = source.HotkeyPrefix;
83 _lineAlignment = source.LineAlignment;
84 _trimming = source.Trimming;
92 public void Dispose() {
97 #region Public properties
99 public StringAlignment Alignment {
109 public StringAlignment LineAlignment {
111 return _lineAlignment;
114 _lineAlignment = value;
119 public StringFormatFlags FormatFlags {
130 public HotkeyPrefix HotkeyPrefix {
132 return _hotkeyPrefix;
136 _hotkeyPrefix = value;
141 public StringTrimming Trimming {
151 public int DigitSubstitutionLanguage {
153 return _digitSubstituteLanguage;
157 public StringDigitSubstitute DigitSubstitutionMethod {
159 return _digitSubstituteMethod;
166 #region static properties
168 public static StringFormat GenericDefault {
170 StringFormat genericDefault = new StringFormat();
171 return genericDefault;
175 public static StringFormat GenericTypographic {
177 StringFormat genericTypographic = new StringFormat(
178 StringFormatFlags.FitBlackBox |
179 StringFormatFlags.LineLimit |
180 StringFormatFlags.NoClip,
182 genericTypographic.Trimming = StringTrimming.None;
183 genericTypographic._genericTypeographic = true;
184 return genericTypographic;
190 #region internal accessors
191 internal bool NoWrap {
193 return (FormatFlags & StringFormatFlags.NoWrap) != 0;
197 internal bool IsVertical {
199 return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;
203 internal bool MeasureTrailingSpaces {
205 return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;
209 internal bool LineLimit {
211 return (FormatFlags & StringFormatFlags.LineLimit) != 0;
215 internal bool NoClip {
217 return (FormatFlags & StringFormatFlags.NoClip) != 0;
221 internal bool IsRightToLeft {
223 return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;
227 internal CharacterRange [] CharRanges {
233 internal bool IsGenericTypographic
236 return _genericTypeographic;
241 #region public methods
243 public void SetMeasurableCharacterRanges (CharacterRange [] range) {
244 _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
247 public object Clone() {
248 StringFormat copy = (StringFormat)MemberwiseClone();
249 if (_charRanges != null)
250 copy._charRanges = (CharacterRange [])_charRanges.Clone();
251 if (_tabStops != null)
252 copy._tabStops = (float[])_tabStops.Clone();
256 public override string ToString() {
257 return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
260 public void SetTabStops(float firstTabOffset, float[] tabStops) {
261 // _firstTabOffset = firstTabOffset;
262 // _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
263 throw new NotImplementedException();
266 public void SetDigitSubstitution(int language, StringDigitSubstitute substitute) {
267 // _digitSubstituteMethod = substitute;
268 // _digitSubstituteLanguage = language;
269 throw new NotImplementedException();
273 public float[] GetTabStops(out float firstTabOffset) {
274 firstTabOffset = _firstTabOffset;
275 return _tabStops != null ? (float[])_tabStops.Clone() : null;