[MWF] Use full width for measuring text

Previously we applied the padding twice.
This commit is contained in:
Eberhard Beilharz committed 2014-10-16 14:08:53 +02:00
1 parent 45deb48384
commit 885b065e06
2 files changed
+19 -14

No files matched your search

@@ -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;
@@ -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;
}
}