]> O.S.I.I.S - jp/crow.git/commitdiff
dont create dummy surface for measuring text
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 1 May 2019 02:08:21 +0000 (04:08 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 1 May 2019 02:08:21 +0000 (04:08 +0200)
Crow/src/GraphicObjects/Label.cs

index 9b49731bcadcc65a53aefd1a4441d20b5759b6cd..0cd3868856ec96b8e8e951485c14a36d608f52b4 100644 (file)
@@ -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;
+                                       }                                       
                                }
 
                        }