From: Jean-Philippe Bruyère Date: Wed, 1 May 2019 02:08:21 +0000 (+0200) Subject: dont create dummy surface for measuring text X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6aac1f308676e904bc1dd964ee734f1bc7d1aeaa;p=jp%2Fcrow.git dont create dummy surface for measuring text --- diff --git a/Crow/src/GraphicObjects/Label.cs b/Crow/src/GraphicObjects/Label.cs index 9b49731b..0cd38688 100644 --- a/Crow/src/GraphicObjects/Label.cs +++ b/Crow/src/GraphicObjects/Label.cs @@ -447,35 +447,33 @@ namespace Crow if (lines == null) lines = getLines; if (!textMeasureIsUpToDate) { - using (Surface img = new Surface (IFace.dev, 10, 10)) { - using (Context gr = new Context (img)) { - //Cairo.FontFace cf = gr.GetContextFontFace (); - - gr.FontFace = Font.Name; - gr.FontSize = (uint)Font.Size; - //gr.FontOptions = Interface.FontRenderingOptions; - //gr.Antialias = Interface.Antialias; - - fe = gr.FontExtents; - te = new TextExtents (); - - cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2; - - try { - for (int i = 0; i < lines.Count; i++) { - string l = lines[i].Replace ("\t", new String (' ', Interface.TabSize)); - - TextExtents tmp = gr.TextExtents (l); - - if (tmp.XAdvance > te.XAdvance) - te = tmp; - } - cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2; - textMeasureIsUpToDate = true; - } catch { - return -1; - } - } + using (Context gr = new Context (IFace.surf)) { + //Cairo.FontFace cf = gr.GetContextFontFace (); + + gr.FontFace = Font.Name; + gr.FontSize = (uint)Font.Size; + //gr.FontOptions = Interface.FontRenderingOptions; + //gr.Antialias = Interface.Antialias; + + fe = gr.FontExtents; + te = new TextExtents (); + + cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2; + + try { + for (int i = 0; i < lines.Count; i++) { + string l = lines[i].Replace ("\t", new String (' ', Interface.TabSize)); + + TextExtents tmp = gr.TextExtents (l); + + if (tmp.XAdvance > te.XAdvance) + te = tmp; + } + cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2; + textMeasureIsUpToDate = true; + } catch { + return -1; + } } }