+2004-07-21 Jordi Mas i Hernandez <jordi@ximian.com>
+
+ * Graphics.cs: fixes MeasureCharacterRanges function. It was completely wrong.
+ * StringFormat.cs: MeasurableCharacterRanges should be passed to GDI+
+ * gdipFunctions.cs: new GDI function calls
+
2004-07-16 Ravindra <rkumar@novell.com>
* gdipFunctions.cs: Added P/Invokes for GraphicsPathIterator.
return IsVisible (new Rectangle (x, y, width, height));
}
- [MonoTODO]
+
public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
- {
- Region [] result=new Region[stringFormat.GetCharRanges.Length];
- string textFragment;
- SizeF fragmentSize;
+ {
+ Status status;
+ int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
+ IntPtr[] native_regions = new IntPtr [regcount];
+ Region[] regions = new Region [regcount];
- for (int i=0; i<stringFormat.GetCharRanges.Length; i++) {
- textFragment=text.Substring(stringFormat.GetCharRanges[i].First, stringFormat.GetCharRanges[i].Length);
- fragmentSize=MeasureString(textFragment, font, new SizeF(layoutRect.Width, layoutRect.Height), stringFormat);
- result[i]=new Region(new RectangleF(layoutRect.X, layoutRect.Y, layoutRect.X+fragmentSize.Width, layoutRect.Y+fragmentSize.Height));
- }
-
- return(result);
+ for (int i = 0; i < regcount; i++) {
+ regions[i] = new Region ();
+ native_regions[i] = regions[i].NativeObject;
+ }
+
+ status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
+ font.NativeObject, ref layoutRect, stringFormat.NativeObject,
+ regcount, out native_regions[0]);
+
+ GDIPlus.CheckStatus (status);
+
+ return regions;
}
private static StringFormat genericDefault;
private IntPtr nativeStrFmt = IntPtr.Zero;
private int language = GDIPlus.LANG_NEUTRAL;
- internal CharacterRange [] CharRanges;
-
+
public StringFormat() : this (0, GDIPlus.LANG_NEUTRAL)
{
public void SetMeasurableCharacterRanges (CharacterRange [] range)
- {
- CharRanges=(CharacterRange [])range.Clone();
+ {
+ lock (this)
+ {
+ Status status = GDIPlus.GdipSetStringFormatMeasurableCharacterRanges (nativeStrFmt,
+ range.Length, range);
+
+ GDIPlus.CheckStatus (status);
+ }
}
-
- internal CharacterRange [] GetCharRanges
+
+ internal int GetMeasurableCharacterRangeCount ()
{
- get {
- return(CharRanges);
+ lock (this)
+ {
+ int cnt;
+ Status status = GDIPlus.GdipGetStringFormatMeasurableCharacterRangeCount (nativeStrFmt, out cnt);
+
+ GDIPlus.CheckStatus (status);
+ return cnt;
}
- }
-
+ }
+
public object Clone()
{
lock (this)
[DllImport("gdiplus.dll", CharSet=CharSet.Unicode)]
internal static extern Status GdipMeasureString(IntPtr graphics, string str, int length, IntPtr font,
ref RectangleF layoutRect, IntPtr stringFormat, out RectangleF boundingBox, out int codepointsFitted,
- out int linesFilled);
+ out int linesFilled);
+
+ [DllImport("gdiplus.dll", CharSet=CharSet.Unicode)]
+ internal static extern Status GdipMeasureCharacterRanges (IntPtr graphics, string str, int length, IntPtr font,
+ ref RectangleF layoutRect, IntPtr stringFormat, int regcount, out IntPtr regions);
+
+ [DllImport("gdiplus.dll")]
+ internal static extern Status GdipSetStringFormatMeasurableCharacterRanges (IntPtr native,
+ int cnt, CharacterRange [] range);
+ [DllImport("gdiplus.dll")]
+ internal static extern Status GdipGetStringFormatMeasurableCharacterRangeCount (IntPtr native,
+ out int cnt);
+
// Bitmap functions
[DllImport("gdiplus.dll")]
internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);