diff options
author | Eberhard Beilharz <eb1@sil.org> | 2014-10-16 16:08:53 +0400 |
---|---|---|
committer | Eberhard Beilharz <eb1@sil.org> | 2014-10-16 16:08:53 +0400 |
commit | 885b065e0633318eec99cb3c55c910c8946fb951 (patch) | |
tree | c67a28ee4a19aecd027c8151fbee737791ae77ea /mcs/class/Managed.Windows.Forms | |
parent | 45deb48384d293e137251815c94044ee428e161e (diff) |
[MWF] Use full width for measuring text
Previously we applied the padding twice.
Diffstat (limited to 'mcs/class/Managed.Windows.Forms')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs | 14 | ||||
-rw-r--r-- | mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs | 19 |
2 files changed, 19 insertions, 14 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs index 6f3be9db10b..bda5da96f78 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs @@ -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; diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs index a9ed1ebec31..78a5679ade6 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs @@ -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; } } |