From d94868f4660c092bc24ee4e1ceeccc1e7aa48dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 7 Sep 2017 16:56:31 +0200 Subject: [PATCH] Fixed drawing non-latin character not correctly, closes #310 --- Vocaluxe/Base/CCoverGenerator.cs | 4 ++-- Vocaluxe/Base/Fonts/CGlyph.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CCoverGenerator.cs b/Vocaluxe/Base/CCoverGenerator.cs index 1ff20fa9..39034d1b 100644 --- a/Vocaluxe/Base/CCoverGenerator.cs +++ b/Vocaluxe/Base/CCoverGenerator.cs @@ -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; diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index 6b949903..f9bc02ed 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -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