[MWF] Use full width for measuring text
authorEberhard Beilharz <eb1@sil.org>
Thu, 16 Oct 2014 12:08:53 +0000 (14:08 +0200)
committerEberhard Beilharz <eb1@sil.org>
Thu, 16 Oct 2014 12:08:53 +0000 (14:08 +0200)
Previously we applied the padding twice.

mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs

index 6f3be9db10be9310c4830d8d11564c5497078377..bda5da96f78d996a6c4122998e5c19a7568cdba0 100644 (file)
@@ -258,11 +258,19 @@ namespace System.Windows.Forms
                        StringFormat sf = FlagsToStringFormat (flags);
 
                                Size retval;
-                               
+
+                               int proposedWidth;
+                               if (proposedSize.Width == 0)
+                                       proposedWidth = Int32.MaxValue;
+                               else {
+                                       proposedWidth = proposedSize.Width;
+                                       if ((flags & TextFormatFlags.NoPadding) == 0)
+                                               proposedWidth -= 9;
+                               }
                                if (dc is Graphics)
-                                       retval = (dc as Graphics).MeasureString (text, font, proposedSize.Width == 0 ? Int32.MaxValue : proposedSize.Width, sf).ToSize ();
+                                       retval = (dc as Graphics).MeasureString (text, font, proposedWidth, sf).ToSize ();
                                else
-                                       retval = TextRenderer.MeasureString (text, font, proposedSize.Width == 0 ? Int32.MaxValue : proposedSize.Width, sf).ToSize ();
+                                       retval = TextRenderer.MeasureString (text, font, proposedWidth, sf).ToSize ();
 
                                if (retval.Width > 0 && (flags & TextFormatFlags.NoPadding) == 0)
                                        retval.Width += 9;
index a9ed1ebec31cff77c3038a0458d0e0ebc8ca1ade..78a5679ade619b77bbd055dcf0c112d230c2c38b 100644 (file)
@@ -369,21 +369,18 @@ namespace System.Windows.Forms
                        Image image = button.Image;
                        string text = button.Text;
                        Rectangle content_rect = button.PaddingClientRectangle;
-                       if (button.TextImageRelation != TextImageRelation.Overlay)
-                               content_rect.Inflate(-4, -4);
-                       Size text_size = TextRenderer.MeasureTextInternal (g, text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
+                       Size text_size = TextRenderer.MeasureTextInternal (g, text, button.Font, content_rect.Size, button.TextFormatFlags | TextFormatFlags.NoPadding, button.UseCompatibleTextRendering);
                        Size image_size = image == null ? Size.Empty : image.Size;
 
-                       textRectangle = Rectangle.Empty;
+                       textRectangle = Rectangle.Inflate (content_rect, -4, -4);
                        imageRectangle = Rectangle.Empty;
                        
                        switch (button.TextImageRelation) {
                                case TextImageRelation.Overlay:
                                        // Overlay is easy, text always goes here
-                                       textRectangle = Rectangle.Inflate (content_rect, -4, -4);
 
-                                       if (button.Pressed)
-                                               textRectangle.Offset (1, 1);
+                                               if (button.Pressed)
+                                                       textRectangle.Offset (1, 1);
                                                
                                        // Image is dependent on ImageAlign
                                        if (image == null)
@@ -440,16 +437,16 @@ namespace System.Windows.Forms
                                        imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
                                        break;
                                case TextImageRelation.ImageAboveText:
-                                       LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+                                       LayoutTextAboveOrBelowImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
                                        break;
                                case TextImageRelation.TextAboveImage:
-                                       LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+                                       LayoutTextAboveOrBelowImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
                                        break;
                                case TextImageRelation.ImageBeforeText:
-                                       LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+                                       LayoutTextBeforeOrAfterImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
                                        break;
                                case TextImageRelation.TextBeforeImage:
-                                       LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+                                       LayoutTextBeforeOrAfterImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
                                        break;
                        }
                }