2 Commits
2 changed files with 9 additions and 3 deletions

No files matched your search

+2 -2
View File
@@ -84,7 +84,7 @@ namespace Vocaluxe.Base
if (_WidthTrimmed < 0f)
{
string text = Text.TrimEnd(null);
_WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font, -1, StringFormat.GenericTypographic).Width;
_WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font).Width;
}
return _WidthTrimmed;
}
@@ -94,7 +94,7 @@ namespace Vocaluxe.Base
public CTextElement(string text, Graphics g, Font font)
{
Text = text;
SizeF dimensions = g.MeasureString(text, font, -1, StringFormat.GenericTypographic);
SizeF dimensions = g.MeasureString(text, font);
Width = dimensions.Width;
Height = (dimensions.Height + font.Height) / 2;
_Graphics = g;
+7 -1
View File
@@ -51,7 +51,13 @@ namespace Vocaluxe.Base.Fonts
if (chr != ' ')
{
//Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped
_BoundingBox = g.MeasureString(chrString, fo, -1, StringFormat.GenericTypographic);
//See https://stackoverflow.com/questions/11708621/how-to-measure-width-of-a-string-precisely
StringFormat format = StringFormat.GenericTypographic;
RectangleF rect = new RectangleF(0, 0, 1000, 1000);
CharacterRange[] ranges = { new CharacterRange(0, chrString.Length) };
format.SetMeasurableCharacterRanges(ranges);
_BoundingBox = g.MeasureCharacterRanges(chrString, fo, rect, format)[0].GetBounds(g).Size;
// ReSharper disable CompareOfFloatsByEqualityOperator
if (_BoundingBox.Height == 0)
// ReSharper restore CompareOfFloatsByEqualityOperator