This should fix #76928. This fix incorporates ideas from a patch
[mono.git] / mcs / class / System.Drawing / System.Drawing / StringFormat.jvm.cs
1 //
2 // System.Drawing.StringFormat.cs
3 //
4 // Authors:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Miguel de Icaza (miguel@ximian.com)
7 //   Jordi Mas i Hernandez (jordi@ximian.com)
8 //
9 // Copyright (C) 2002 Ximian, Inc (http://www.ximian.com)
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32 using System;
33 using System.Drawing.Text;
34
35 namespace System.Drawing {
36         /// <summary>
37         /// Summary description for StringFormat.
38         /// </summary>
39         public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable {
40                 
41                 
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;
50                 
51                 private float _firstTabOffset;
52                 private float [] _tabStops;
53                 
54                 #region Constructors
55
56                 public StringFormat() : this(0, 0) {                                       
57                 }
58                 
59                 public StringFormat(StringFormatFlags options) : this(options,0) {
60                 }
61                 
62                 public StringFormat(StringFormatFlags options, int lang) {
63                         _alignment = StringAlignment.Near;
64                         _digitSubstituteLanguage = lang;
65                         _digitSubstituteMethod = StringDigitSubstitute.User;
66                         _flags = options;
67                         _hotkeyPrefix = HotkeyPrefix.None;
68                         _lineAlignment = StringAlignment.Near;
69                         _trimming = StringTrimming.Character;
70                 }
71                 
72                 public StringFormat (StringFormat source) {
73                         if (source == null)
74                                 throw new ArgumentNullException("format");
75
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;
83                 }
84
85
86                 #endregion
87
88                 #region IDisposable
89
90                 public void Dispose() { 
91                 }
92
93                 #endregion
94
95                 #region Public properties
96
97                 public StringAlignment Alignment {
98                         get {
99                                 return _alignment;
100                         }
101
102                         set {
103                                 _alignment = value;
104                         }
105                 }
106
107                 public StringAlignment LineAlignment {
108                         get {
109                                 return _lineAlignment;
110                         }
111                         set {
112                                 _lineAlignment = value;
113                         }
114                 }
115
116                 [MonoTODO]
117                 public StringFormatFlags FormatFlags {
118                         get {                           
119                                 return _flags;
120                         }
121
122                         set {
123                                 _flags = value;
124                         }
125                 }
126
127                 [MonoTODO]
128                 public HotkeyPrefix HotkeyPrefix {
129                         get {                           
130                                 return _hotkeyPrefix;
131                         }
132
133                         set {
134                                 _hotkeyPrefix = value;
135                         }
136                 }
137
138                 [MonoTODO]
139                 public StringTrimming Trimming {
140                         get {
141                                 return _trimming;
142                         }
143
144                         set {
145                                 _trimming = value;
146                         }
147                 }
148
149                 public int DigitSubstitutionLanguage {
150                         get {
151                                 return _digitSubstituteLanguage;
152                         }
153                 }
154
155                 public StringDigitSubstitute DigitSubstitutionMethod {
156                         get {
157                                 return _digitSubstituteMethod;     
158                         }
159                 }
160
161
162                 #endregion
163
164                 #region static properties
165
166                 public static StringFormat GenericDefault {
167                         get {
168                                 StringFormat genericDefault = new StringFormat();
169                                 return genericDefault;
170                         }
171                 }
172                 
173                 public static StringFormat GenericTypographic {
174                         get {
175                                 StringFormat genericTypographic = new StringFormat(
176                                         StringFormatFlags.FitBlackBox |
177                                         StringFormatFlags.LineLimit |
178                                         StringFormatFlags.NoClip, 
179                                         0 );
180                                 genericTypographic.Trimming = StringTrimming.None;
181                                 return genericTypographic;
182                         }
183                 }
184
185                 #endregion
186
187                 #region internal accessors
188                 internal bool NoWrap {\r
189                         get {\r
190                                 return (FormatFlags & StringFormatFlags.NoWrap) != 0;\r
191                         }\r
192                 }\r
193 \r
194                 internal bool IsVertical {\r
195                         get {\r
196                                 return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;\r
197                         }\r
198                 }\r
199 \r
200                 internal bool MeasureTrailingSpaces {\r
201                         get {\r
202                                 return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;\r
203                         }\r
204                 }\r
205 \r
206                 internal bool LineLimit {\r
207                         get {\r
208                                 return (FormatFlags & StringFormatFlags.LineLimit) != 0;\r
209                         }\r
210                 }\r
211 \r
212                 internal bool NoClip {\r
213                         get {\r
214                                 return (FormatFlags & StringFormatFlags.NoClip) != 0;\r
215                         }\r
216                 }
217
218                 internal bool IsRightToLeft {\r
219                         get {\r
220                                 return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;\r
221                         }\r
222                 }
223                 
224                 internal CharacterRange [] CharRanges {
225                         get {
226                                 return _charRanges;
227                         }
228                 }
229                 #endregion
230
231                 #region public methods
232
233                 public void SetMeasurableCharacterRanges (CharacterRange [] range) {
234                         _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
235                 }
236         
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();
243                         return copy;
244                 }
245
246                 public override string ToString() {
247                         return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
248                 }
249                 
250                 public void SetTabStops(float firstTabOffset, float[] tabStops) {
251 //                      _firstTabOffset = firstTabOffset;
252 //                      _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
253                         throw new NotSupportedException();
254                 }
255
256                 public void SetDigitSubstitution(int language,  StringDigitSubstitute substitute) {
257 //                      _digitSubstituteMethod = substitute;
258 //                      _digitSubstituteLanguage = language;
259                         throw new NotSupportedException();
260                 }
261
262                 [MonoTODO]
263                 public float[] GetTabStops(out float firstTabOffset) {
264                         firstTabOffset = _firstTabOffset;
265                         return _tabStops != null ? (float[])_tabStops.Clone() : null;
266                 }
267
268                 #endregion
269         }
270 }