Wikia

Sawfish

Pango draw() ignores font

773pages on
this wiki
Talk0
Browse all patches

Author Edit

Yuuki Harano and Rodrigo Gallardo

Synopsis Edit

~/.sawfishrc:

(setq test-font1 (get-font-typed "pango" "Arial Italic 8"))
(setq test-font2 (get-font-typed "pango" "Arial Italic 20"))

(define (test-update w type)
  `(((background . "white")
     (foreground . "black")
     (text . ,window-name)
     (left-edge . 0)
     (right-edge . 0)
     (top-edge . -20)
     (height . 20)
     (font . ,(if (equal (window-class w) "XTerm") test-font2 test-font1))
     ))
  )

(add-frame-style 'test test-update)

~/.sawfish/custom is empty.

Then, text in title bar of xterm should be large font, and other title bar should be small font. But all is large.

pango_context is created and set font with fontdesc in pango_load(), and used in pango_draw() without font changes. So, only one font is used.

You should set font before using pango_context in pango_draw().


Patch Edit

diff --git a/src/fonts.c b/src/fonts.c
index d4f05d7..3fb7258 100644
--- a/src/fonts.c
+++ b/src/fonts.c
@@ -459,24 +459,29 @@ pango_load (Lisp_Font *f)
     pango_context_set_font_description (pango_context, fontdesc);
     font = pango_context_load_font (pango_context, fontdesc);

-    if (!font)
+    if (!font) {
+        pango_font_description_free(fontdesc);
        return FALSE;
+    }

     metrics = pango_font_get_metrics (font, language);

-    f->font = font;
     f->ascent = metrics->ascent / PANGO_SCALE;
     f->descent = metrics->descent / PANGO_SCALE;

     pango_font_metrics_unref (metrics);

+    f->font = fontdesc; // We save the font description, not the font itself!
+                        // That's because it seems we can't recover it perfectly
+                        // later, and the layout routines want a description
+
     return TRUE;
 }

 static void
 pango_finalize (Lisp_Font *f)
 {
-    g_object_unref (f->font);
+    pango_font_description_free (f->font);
 }

 static int
@@ -486,6 +491,7 @@ pango_measure (Lisp_Font *f, u_char *string, size_t length)
     PangoRectangle rect;

     layout = pango_layout_new (pango_context);
+    pango_layout_set_font_description(layout, f->font);
     pango_layout_set_text (layout, string, length);

     pango_layout_get_extents (layout, NULL, &rect);
@@ -541,6 +547,7 @@ pango_draw (Lisp_Font *f, u_char *string, size_t length,
     xft_color.color.alpha = fg->alpha;

     layout = pango_layout_new (pango_context);
+    pango_layout_set_font_description(layout, f->font);
     pango_layout_set_text (layout, string, length);
     iter = pango_layout_get_iter (layout);

Community's reasons for inclusion or rejection Edit

Patch submitters, please vote also! Yes, obviosuly your vote will be positive, but it's the place to give your explanation why this patch is good for all Sawfish users, and why it is correct - good reasons for inclusion.

When voting anonymously please write your name, so that it can be associated with your posts on the mailing list. If you are logged in you can sign yourself by typing four tilda characters: ~~~~.

  • Yes vote: yes. Tested it by mixing fonts via different themes and also the cycle window font faces and it works. Before SF was unable to show more than one pango font (but multiple xlfd was fine). This bug was mentioned in Merlin site time ago. GSR 20:01, 30 October 2007 (UTC)
  • Yes vote: yes. Fixes the testcase and apparently no regressions. - Aav 09:02, 16 January 2008 (UTC)
  • Wtf vote: pondering. I tested this patch and some problems with fixed fonts appeared, see this thread for details (screenshots: [1], [2] and the worst one: [3] - compare window title with the selected font). This patch ought to be corrected to not change the font if it's a fixed font - because apparantly it's the only case when the font gets broken. I hope that improved patch will be applied for next sawfish release. Janek Kozicki 22:26, 20 January 2008 (UTC)
  • Yes vote: yes. But this vote is for the new version. AFAICT the size problems were caused because the trip font_description -> font is not reverible, thus the font_description the first version of the patch was not necesarily the one the config was setting. RodrigoGallardo 01:08, 6 February 2008 (UTC)
  • Wtf vote: pondering. Am using this since a week. I didn't have the problem before but it hasn't caused any new ones for me. -- Peter.
  • Yes vote: yes. since without risk there can't be any progress, les't apply this patch ;-) Janek Kozicki 19:19, 18 February 2008 (UTC)

Around Wikia's network

Random Wiki