fixes Graphics.MeasureCharacterRanges and StringFormat.MeasurableCharacterRanges
authorJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Wed, 21 Jul 2004 13:06:29 +0000 (13:06 -0000)
committerJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Wed, 21 Jul 2004 13:06:29 +0000 (13:06 -0000)
svn path=/trunk/mcs/; revision=31328

mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Graphics.cs
mcs/class/System.Drawing/System.Drawing/StringFormat.cs
mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs

index e64df934bc64265b615815c4e8092ba9704cd83b..f0813f1119ab2452b84b6d7248dc8734c2c93d3f 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 59845bacb28483a78b3d3a90365347a828487485..f5a31f380fb53b3c11da8bc1d1ecd0e7513e054e 100755 (executable)
@@ -1425,20 +1425,26 @@ namespace System.Drawing
                        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;                                                 
                }
 
                
index 68e49b9d94edf672d4f8a27fe82b20b74128e6f2..dacb1b9dab83df5010486b911ce82ca49517cf08 100644 (file)
@@ -42,8 +42,7 @@ namespace System.Drawing
                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)
                {                                          
                        
@@ -232,17 +231,28 @@ namespace System.Drawing
 
 
                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)
index a629970cb43a54cadc0d1e0f463888fb5b682989..efceb7e4be8ecf065e7aea36fbc24bdf1163a97e 100644 (file)
@@ -850,8 +850,20 @@ namespace System.Drawing
                [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);