From 6aac1f308676e904bc1dd964ee734f1bc7d1aeaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 1 May 2019 04:08:21 +0200 Subject: [PATCH] dont create dummy surface for measuring text --- Crow/src/GraphicObjects/Label.cs | 56 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 29 deletions(-) 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; + } } } -- 2.47.3