]> Dogcows Code - chaz/openbox/commitdiff
make the pango rendering code really complicated because that is the only way to...
authorMikael Magnusson <mikachu@comhem.se>
Sat, 16 Jul 2005 00:56:45 +0000 (00:56 +0000)
committerMikael Magnusson <mikachu@comhem.se>
Sat, 16 Jul 2005 00:56:45 +0000 (00:56 +0000)
render/font.c
render/font.h

index 0f2ce8fb9b2312cee8427621905162c5fedc3881..71302467ad7c25da44f379f46a8999a146c6345b 100644 (file)
@@ -128,7 +128,10 @@ static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
     }
 
     PangoFontset *pfs = pango_font_map_load_fontset(pfm, context, out->pango_font_description, NULL);
-    out->pango_font_metrics = pango_fontset_get_metrics(pfs);
+    PangoFontMetrics *metrics = pango_fontset_get_metrics(pfs);
+    out->pango_ascent = pango_font_metrics_get_ascent(metrics);
+    out->pango_descent = pango_font_metrics_get_descent(metrics);
+    pango_font_metrics_unref(metrics);
 #endif /* USE_PANGO */
 
     if (FcPatternGetBool(match, OB_SHADOW, 0, &out->shadow) != FcResultMatch)
@@ -188,7 +191,6 @@ void RrFontClose(RrFont *f)
         g_free(f);
     }
 #ifdef USE_PANGO
-    pango_font_metrics_unref(f->pango_font_metrics);
     pango_font_description_free(f->pango_font_description);
 #endif
 }
@@ -230,10 +232,9 @@ RrSize *RrFontMeasureString(const RrFont *f, const gchar *str)
 gint RrFontHeight(const RrFont *f)
 {
 #ifdef USE_PANGO
-    int ascent, descent;
-    ascent = pango_font_metrics_get_ascent(f->pango_font_metrics);
-    descent = pango_font_metrics_get_descent(f->pango_font_metrics);
-    return (ascent + descent) / PANGO_SCALE;
+    return (f->pango_ascent
+            + f->pango_descent
+           ) / PANGO_SCALE;
 #else
     return f->xftfont->ascent + f->xftfont->descent +
         (f->shadow ? f->offset : 0);
@@ -256,6 +257,7 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     gboolean shortened = FALSE;
 #else
     PangoLayout *pl;
+    PangoLayoutLine *pll;
     PangoRectangle rect;
 
     pl = pango_layout_new (context);
@@ -291,17 +293,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     }
     if (!l) return;
 
-    switch (t->justify) {
-    case RR_JUSTIFY_LEFT:
-        break;
-    case RR_JUSTIFY_RIGHT:
-        x += (w - mw);
-        break;
-    case RR_JUSTIFY_CENTER:
-        x += (w - mw) / 2;
-        break;
-    }
-
     l = strlen(text->str); /* number of bytes */
 
 #else
@@ -310,13 +301,29 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     pango_layout_set_single_paragraph_mode(pl, TRUE);
     pango_layout_set_width(pl, w * PANGO_SCALE);
     pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_MIDDLE);
-    pango_layout_set_alignment(pl, (PangoAlignment)(t->justify));
+    /* This doesn't work with layout_line() of course */
+/*    pango_layout_set_alignment(pl, (PangoAlignment)(t->justify)); */
     pango_layout_get_pixel_extents(pl, NULL, &rect);
+    mw = rect.width;
     y = area->y +
-        (area->height - rect.height) / 2;
+        area->height / 2 +
+        /* go to great lengths to center the text while keeping the baseline in
+         * the same place */
+        t->font->pango_descent / PANGO_SCALE;
 
 #endif /* USE_PANGO */
 
+    switch (t->justify) {
+    case RR_JUSTIFY_LEFT:
+        break;
+    case RR_JUSTIFY_RIGHT:
+        x += (w - mw);
+        break;
+    case RR_JUSTIFY_CENTER:
+        x += (w - mw) / 2;
+        break;
+    }
+
     if (t->font->shadow) {
         if (t->font->tint >= 0) {
             c.color.red = 0;
@@ -338,8 +345,10 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
                           t->font->xftfont->ascent + y + t->font->offset,
                           (FcChar8*)text->str, l);
 #else /* USE_PANGO */
-        pango_xft_render_layout(d, &c, pl, (x + t->font->offset) * PANGO_SCALE,
-                                (y + t->font->offset) * PANGO_SCALE);
+        /* see below... */
+        pango_xft_render_layout_line(d, &c, pll = pango_layout_get_line(pl, 0),
+                                     (x + t->font->offset) * PANGO_SCALE,
+                                     (y + t->font->offset) * PANGO_SCALE);
 #endif /* USE_PANGO */
     }
     c.color.red = t->color->r | t->color->r << 8;
@@ -353,7 +362,13 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
                       t->font->xftfont->ascent + y,
                       (FcChar8*)text->str, l);
 #else /* USE_PANGO */
-    pango_xft_render_layout(d, &c, pl, x * PANGO_SCALE, y * PANGO_SCALE);
+    /* This looks retarded, but layout_line() bases y on the baseline, while
+     * layout() bases y on the top of the ink layout shit ass fucking crap.
+     * We want the baseline to always be in the same place, thusly, we use
+     * layout_line()
+     * The actual line doesn't need to be freed */
+    pango_xft_render_layout_line(d, &c, pll = pango_layout_get_line(pl, 0),
+                                 x * PANGO_SCALE, y * PANGO_SCALE);
     g_object_unref(pl);
 #endif
 
index 8f0d4e6ffa176ae1e998b5fa78fd22169a541619..f299763946fa89ab7ff6cbc2d2666d1f03188b82 100644 (file)
 
 struct _RrFont {
     const RrInstance *inst;
-#ifdef USE_PANGO
-    PangoFontDescription *pango_font_description;
-    PangoFontMetrics *pango_font_metrics;
-#endif /* USE_PANGO */
     XftFont *xftfont;
     gint elipses_length;
     gint shadow;
     gchar tint;
     gint offset;
+#ifdef USE_PANGO
+    PangoFontDescription *pango_font_description;
+    gint pango_ascent;
+    gint pango_descent;
+#endif /* USE_PANGO */
 };
 
 RrFont *RrFontOpen(const RrInstance *inst, gchar *fontstring);
This page took 0.030782 seconds and 4 git commands to generate.