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
38 /// Summary description for StringFormat.
40 public sealed class StringFormat
: MarshalByRefObject
, IDisposable
, ICloneable
42 private static StringFormat genericDefault
;
43 private IntPtr nativeStrFmt
= IntPtr
.Zero
;
44 private int language
= GDIPlus
.LANG_NEUTRAL
;
46 public StringFormat() : this (0, GDIPlus
.LANG_NEUTRAL
)
51 public StringFormat(StringFormatFlags options
, int lang
)
53 Status status
= GDIPlus
.GdipCreateStringFormat (options
, lang
, out nativeStrFmt
);
54 GDIPlus
.CheckStatus (status
);
56 LineAlignment
= StringAlignment
.Near
;
57 Alignment
= StringAlignment
.Near
;
61 internal StringFormat(IntPtr native
)
63 nativeStrFmt
= native
;
71 public void Dispose ()
74 System
.GC
.SuppressFinalize (this);
77 void Dispose (bool disposing
)
79 if (nativeStrFmt
!= IntPtr
.Zero
) {
80 Status status
= GDIPlus
.GdipDeleteStringFormat (nativeStrFmt
);
81 GDIPlus
.CheckStatus (status
);
83 nativeStrFmt
= IntPtr
.Zero
;
87 public StringFormat (StringFormat source
)
89 Status status
= GDIPlus
.GdipCloneStringFormat (source
.NativeObject
, out nativeStrFmt
);
90 GDIPlus
.CheckStatus (status
);
93 public StringFormat (StringFormatFlags flags
)
95 Status status
= GDIPlus
.GdipCreateStringFormat (flags
, GDIPlus
.LANG_NEUTRAL
, out nativeStrFmt
);
96 GDIPlus
.CheckStatus (status
);
99 public StringAlignment Alignment
{
101 StringAlignment align
;
102 Status status
= GDIPlus
.GdipGetStringFormatAlign (nativeStrFmt
, out align
);
103 GDIPlus
.CheckStatus (status
);
109 Status status
= GDIPlus
.GdipSetStringFormatAlign (nativeStrFmt
, value);
110 GDIPlus
.CheckStatus (status
);
114 public StringAlignment LineAlignment
{
116 StringAlignment align
;
117 Status status
= GDIPlus
.GdipGetStringFormatLineAlign (nativeStrFmt
, out align
);
118 GDIPlus
.CheckStatus (status
);
124 Status status
= GDIPlus
.GdipSetStringFormatLineAlign (nativeStrFmt
, value);
125 GDIPlus
.CheckStatus (status
);
129 public StringFormatFlags FormatFlags
{
131 StringFormatFlags flags
;
132 Status status
= GDIPlus
.GdipGetStringFormatFlags (nativeStrFmt
, out flags
);
133 GDIPlus
.CheckStatus (status
);
139 Status status
= GDIPlus
.GdipSetStringFormatFlags (nativeStrFmt
, value);
140 GDIPlus
.CheckStatus (status
);
144 public HotkeyPrefix HotkeyPrefix
{
146 HotkeyPrefix hotkeyPrefix
;
147 Status status
= GDIPlus
.GdipGetStringFormatHotkeyPrefix (nativeStrFmt
, out hotkeyPrefix
);
148 GDIPlus
.CheckStatus (status
);
154 Status status
= GDIPlus
.GdipSetStringFormatHotkeyPrefix (nativeStrFmt
, value);
155 GDIPlus
.CheckStatus (status
);
160 public StringTrimming Trimming
{
162 StringTrimming trimming
;
163 Status status
= GDIPlus
.GdipGetStringFormatTrimming (nativeStrFmt
, out trimming
);
164 GDIPlus
.CheckStatus (status
);
169 Status status
= GDIPlus
.GdipSetStringFormatTrimming (nativeStrFmt
, value);
170 GDIPlus
.CheckStatus (status
);
174 public static StringFormat GenericDefault
{
178 Status status
= GDIPlus
.GdipStringFormatGetGenericDefault (out ptr
);
179 GDIPlus
.CheckStatus (status
);
181 return new StringFormat (ptr
);
187 public int DigitSubstitutionLanguage
{
194 public static StringFormat GenericTypographic
{
199 Status status
= GDIPlus
.GdipStringFormatGetGenericTypographic (out ptr
);
200 GDIPlus
.CheckStatus (status
);
202 return new StringFormat (ptr
);
206 public StringDigitSubstitute DigitSubstitutionMethod
{
208 StringDigitSubstitute substitute
;
210 Status status
= GDIPlus
.GdipGetStringFormatDigitSubstitution(nativeStrFmt
, language
, out substitute
);
211 GDIPlus
.CheckStatus (status
);
218 public void SetMeasurableCharacterRanges (CharacterRange
[] range
)
220 Status status
= GDIPlus
.GdipSetStringFormatMeasurableCharacterRanges (nativeStrFmt
,
221 range
.Length
, range
);
223 GDIPlus
.CheckStatus (status
);
226 internal int GetMeasurableCharacterRangeCount ()
229 Status status
= GDIPlus
.GdipGetStringFormatMeasurableCharacterRangeCount (nativeStrFmt
, out cnt
);
231 GDIPlus
.CheckStatus (status
);
235 public object Clone()
239 Status status
= GDIPlus
.GdipCloneStringFormat (nativeStrFmt
, out native
);
240 GDIPlus
.CheckStatus (status
);
242 return new StringFormat (native
);
245 public override string ToString()
247 return "[StringFormat, FormatFlags=" + this.FormatFlags
.ToString() + "]";
250 internal IntPtr NativeObject
256 nativeStrFmt
= value;
260 public void SetTabStops(float firstTabOffset
, float[] tabStops
)
262 Status status
= GDIPlus
.GdipSetStringFormatTabStops(nativeStrFmt
, firstTabOffset
, tabStops
.Length
, tabStops
);
263 GDIPlus
.CheckStatus (status
);
266 public void SetDigitSubstitution(int language
, StringDigitSubstitute substitute
)
268 Status status
= GDIPlus
.GdipSetStringFormatDigitSubstitution(nativeStrFmt
, this.language
, substitute
);
269 GDIPlus
.CheckStatus (status
);
272 public float[] GetTabStops(out float firstTabOffset
)
277 Status status
= GDIPlus
.GdipGetStringFormatTabStopCount(nativeStrFmt
, out count
);
278 GDIPlus
.CheckStatus (status
);
280 float[] tabStops
= new float[count
];
283 status
= GDIPlus
.GdipGetStringFormatTabStops(nativeStrFmt
, count
, out firstTabOffset
, tabStops
);
284 GDIPlus
.CheckStatus (status
);