From 6c7b59ed442941ed380f257539146e1c84017dac Mon Sep 17 00:00:00 2001 From: Flamefire Date: Wed, 10 Sep 2014 17:50:30 +0200 Subject: [PATCH] Adapt to changed usage of CFonts --- Vocaluxe/Base/CNoCoverGenerator.cs | 16 +++++----- Vocaluxe/Base/Fonts/CFonts.cs | 48 ++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Vocaluxe/Base/CNoCoverGenerator.cs b/Vocaluxe/Base/CNoCoverGenerator.cs index 36e49858..22faf258 100644 --- a/Vocaluxe/Base/CNoCoverGenerator.cs +++ b/Vocaluxe/Base/CNoCoverGenerator.cs @@ -138,7 +138,7 @@ namespace Vocaluxe.Base Text = text; SizeF dimensions = g.MeasureString(text, font, -1, StringFormat.GenericTypographic); Width = dimensions.Width; - Height = (dimensions.Height + CFonts.Height) / 2; + Height = (dimensions.Height + font.Height) / 2; _Graphics = g; _Font = font; } @@ -180,24 +180,22 @@ namespace Vocaluxe.Base if (text != "") { IEnumerable textParts = _SplitText(text); - CFonts.SetFont(_Font); - CFonts.Style = _Style; - CFonts.Height = bmp.Height - _TextMarginTop - _TextMarginBottom; - Font fo = CFonts.GetFont(); + CFont font = new CFont(_Font, _Style, bmp.Height - _TextMarginTop - _TextMarginBottom); + Font fo = CFonts.GetSystemFont(font); List elements = textParts.Select(line => new CTextElement(line, g, fo)).ToList(); float factor = _DistributeText(elements, bmp.Width, bmp.Height); foreach (CTextElement element in elements) element.AdjustSize(factor); - CFonts.Height *= factor / (1f + CFonts.Outline); //Adjust for outline size - fo = CFonts.GetFont(); + font.Height *= factor / (1f + CFonts.GetOutlineSize(font)); //Adjust for outline size + fo = CFonts.GetSystemFont(font); float maxHeight = elements.Select(el => el.Height).Max(); int lineCount = elements.Last().Line + 1; //Have to use size in em not pixels! float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); - float outlineSize = CFonts.Outline * CFonts.Height; - SColorF outlineColorF = CFonts.OutlineColor; + float outlineSize = CFonts.GetOutlineSize(font) * font.Height; + SColorF outlineColorF = CFonts.GetOutlineColor(font); outlineColorF.A = outlineColorF.A * _TextColor.A; using (var path = new GraphicsPath()) diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index e7ac6bdb..3888214f 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -180,22 +180,24 @@ namespace Vocaluxe.Base.Fonts return new RectangleF(text.X, text.Y, GetTextWidth(text.TranslatedText, text.Font), GetTextHeight(text.TranslatedText, text.Font)); } + public static Font GetSystemFont(CFont font) + { + return _GetFontStyle(font).GetSystemFont(font.Height); + } + + public static float GetOutlineSize(CFont font) + { + return _FontFamilies[_GetFontIndex(font.Name)].Outline; + } + + public static SColorF GetOutlineColor(CFont font) + { + return _FontFamilies[_GetFontIndex(font.Name)].OutlineColor; + } + private static CFontStyle _GetFontStyle(CFont font) { - int index = _GetPartyFontIndex(font.Name, PartyModeID); - if (index < 0) - index = _GetThemeFontIndex(font.Name, CConfig.Theme); - if (index < 0) - index = _GetFontIndex(font.Name); - if (index < 0) - { - if (!_LoggedMissingFonts.Contains(font.Name)) - { - _LoggedMissingFonts.Add(font.Name); - CLog.LogError("Font \"" + font.Name + "\" not found!"); - } - index = 0; - } + int index = _GetFontIndex(font.Name); switch (font.Style) { @@ -225,13 +227,29 @@ namespace Vocaluxe.Base.Fonts private static int _GetFontIndex(string fontName) { + int index = _GetPartyFontIndex(fontName, PartyModeID); + if (index < 0) + index = _GetThemeFontIndex(fontName, CConfig.Theme); + if (index >= 0) + return index; for (int i = 0; i < _FontFamilies.Count; i++) { if (_FontFamilies[i].Name == fontName) return i; } + if (index < 0) + { + if (!_LoggedMissingFonts.Contains(fontName)) + { + _LoggedMissingFonts.Add(fontName); + CLog.LogError("Font \"" + fontName + "\" not found!"); + } + if (_FontFamilies.Count == 0) + CLog.LogError("No fonts found!", true, true); + index = 0; + } - return -1; + return index; } private static int _GetThemeFontIndex(string fontName, string themeName)