[openbox] openbox pangofication (was: LIGHT arabic patch)
Mohammed Sameer
uniball at gmx.net
Sat Oct 23 23:43:48 EDT 2004
On Sat, Oct 23, 2004 at 08:04:56PM +0200, Mikael Magnusson wrote:
> On Sat, 23 Oct 2004, Mohammed Sameer wrote:
>
> >On Mon, Oct 18, 2004 at 04:12:17AM +0200, Mikael Magnusson wrote:
> >>As you may or may not know, I didn't write most of openbox, but i picked
> >>up maintainership after ben decided to do "other things", so I'm not very
> >>acquainted with the font functions myself, I've mostly looked at the logic
> >>parts so far. I'll try to help if I can. If you use IRC, it's #openbox on
> >>irc.oftc.net for faster replies most of the time.
> >
> >Sorry for being late.
> >
> >Well, I didn't even know that you are the current maintainer, But now I
> >do! :-)
> >
> >Here's an alpha patch, The only problem is that I didn't know how to
> >convert xftfont to pangofont, I'm still trying to find a way. That's why
> >the strings are being drawn but incomplete!
> >
> >I think I'll have to change the _RrFont struct and/or all/most of the
> >font handling API, But as I'm sure you'll hate me if I do. I've tested
> >the patch for a few minutes and it was fine.
> >
> >I'll continue working on it, But I'm just busy with my papers these days.
>
> Okay, tried it out a bit. It draws all strings completely as far as I can
> see, but it messes up shadows a bit (not important though). It seems to
> draw at least japanese fonts right mixed with normal text too, but it
> currently ignores the font set in the theme? I guess we want to somehow
> give a list of fonts to try at some point since one font only has one
> language usually, but that comes later :).
>
sorry, I didn't notice the shadow thing, I've fixed this in the attached patch.
And yes, It was ignoring the fonts, Now it's not.
> Keep up the good work, I'm very grateful, and fiddle with the structs all
> you want, I have no idea how they work anyway ;). As long as it's
> backwards config compatible I think we shouldn't have any problems since
> nothing outside Openbox uses that...
>
Thanks,
I'll try commenting the code parts I understand, I can say that I think I understand now the fonts handling, Maybe it's my imagination.
I wasn't able to get rid from xft as I'm still having problems getting pango to play with xft.
I'm just posting the patch here maybe someone can give me a hand as I'm not yet familiar with the pango API.
Maybe what I'm doing is not the Best thing or the right way ;-)
--
----------------
-- Katoob Main Developer, Arabbix Maintainer.
Linux registered user #224950
Proud Egyptian GNU/Linux User Group <www.eglug.org> Admin.
Life powered by Debian, Homepage: www.foolab.org
--
Don't send me any attachment in Micro$oft (.DOC, .PPT) format please
Read http://www.fsf.org/philosophy/no-word-attachments.html
Preferable attachments: .PDF, .HTML, .TXT
Thanx for adding this text to Your signature
-------------- next part --------------
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/configure.ac openbox-3.2/configure.ac
--- openbox-3.2.orig/configure.ac 2004-04-17 13:44:21.000000000 +0200
+++ openbox-3.2/configure.ac 2004-10-23 05:26:02.000000000 +0200
@@ -73,6 +73,10 @@
PKG_CHECK_MODULES([GLIB], [glib-2.0])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
+
+PKG_CHECK_MODULES([PANGO], [pango pangoxft])
+AC_SUBST(PANGO_CFLAGS)
+AC_SUBST(PANGO_LIBS)
PKG_CHECK_MODULES(XFT, [xft])
AC_SUBST(XFT_CFLAGS)
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/Makefile.am openbox-3.2/Makefile.am
--- openbox-3.2.orig/Makefile.am 2003-10-27 22:14:30.000000000 +0200
+++ openbox-3.2/Makefile.am 2004-10-23 05:29:39.000000000 +0200
@@ -42,6 +42,7 @@
render/libobrender.la \
$(XFT_LIBS) \
$(GLIB_LIBS) \
+ $(PANGO_LIBS) \
$(XML_LIBS) \
$(X_LIBS)
render_rendertest_SOURCES = render/test.c
@@ -51,6 +52,7 @@
$(XFT_CFLAGS) \
$(GLIB_CFLAGS) \
$(XML_CFLAGS) \
+ $(PANGO_CFLAGS) \
-DG_LOG_DOMAIN=\"ObRender\" \
-DDEFAULT_THEME=\"$(theme)\"
render_libobrender_la_LDFLAGS = \
@@ -113,6 +115,7 @@
$(VIDMODE_LIBS) \
$(XSHAPE_LIBS) \
$(GLIB_LIBS) \
+ $(PANGO_LIBS) \
$(X_LIBS) \
$(LIBSN_LIBS) \
$(XML_LIBS) \
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/render/font.c openbox-3.2/render/font.c
--- openbox-3.2.orig/render/font.c 2004-04-01 23:50:11.000000000 +0200
+++ openbox-3.2/render/font.c 2004-10-24 05:30:06.000000000 +0200
@@ -46,30 +46,39 @@
static void font_startup(void)
{
+
if (!XftInit(0)) {
g_warning(_("Couldn't initialize Xft."));
exit(EXIT_FAILURE);
}
+
+ g_type_init();
+ /* Here we are teaching xft about the shadow, shadowoffset & shadowtint */
FcNameRegisterObjectTypes(objs, (sizeof(objs) / sizeof(objs[0])));
}
static void measure_font(RrFont *f)
{
+/* xOff, yOff is the normal spacing to the next glyph. */
XGlyphInfo info;
/* measure an elipses */
- XftTextExtentsUtf8(RrDisplay(f->inst), f->xftfont,
- (FcChar8*)ELIPSES, strlen(ELIPSES), &info);
- f->elipses_length = (signed) info.xOff;
+ XftTextExtentsUtf8(RrDisplay(f->inst), f->xftfont,
+ (FcChar8*)ELIPSES, strlen(ELIPSES), &info);
+ f->elipses_length = (signed) info.xOff;
}
static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
{
+ /* This function is called for each font in the theme file. */
+ /* It returns a pointer to a RrFont struct after filling it. */
RrFont *out;
FcPattern *pat, *match;
XftFont *font;
FcResult res;
gint tint;
+ gchar *tmp_string = NULL;
+ gint tmp_int;
if (!(pat = XftNameParse(fontstring)))
return NULL;
@@ -81,6 +90,36 @@
out = g_new(RrFont, 1);
out->inst = inst;
+ /* printf("\n\n%s\n\n",fontstring);
+ FcPatternPrint(match); */
+
+ out->pango_font_description = pango_font_description_new();
+
+ if (FcPatternGetString(match, "family", 0, &tmp_string) != FcResultTypeMismatch)
+ {
+ pango_font_description_set_family(out->pango_font_description, tmp_string);
+ tmp_string = NULL;
+ }
+ if (FcPatternGetString(match, "style", 0, &tmp_string) != FcResultTypeMismatch)
+ {
+ /* Bold ? */
+ if (!strcasecmp("bold", tmp_string))
+ {
+ pango_font_description_set_weight(out->pango_font_description, PANGO_WEIGHT_BOLD);
+ }
+ /* Italic ? */
+ else if (!strcasecmp("italic", tmp_string))
+ {
+ pango_font_description_set_style(out->pango_font_description, PANGO_STYLE_ITALIC);
+ }
+ tmp_string = NULL;
+ }
+
+ if (FcPatternGetInteger(match, "pixelsize", 0, &tmp_int) != FcResultTypeMismatch)
+ {
+ /* TODO: is PANGO_SCALE correct ?? */
+ pango_font_description_set_size(out->pango_font_description, tmp_int*PANGO_SCALE);
+ }
if (FcPatternGetBool(match, OB_SHADOW, 0, &out->shadow) != FcResultMatch)
out->shadow = FALSE;
@@ -103,9 +142,9 @@
} else
out->xftfont = font;
- measure_font(out);
-
- return out;
+ /* FcPatternDestroy(match); */
+ measure_font(out);
+ return out;
}
RrFont *RrFontOpen(const RrInstance *inst, gchar *fontstring)
@@ -140,6 +179,20 @@
static void font_measure_full(const RrFont *f, const gchar *str,
gint *x, gint *y)
{
+ PangoContext *context;
+ PangoLayout *pl;
+ PangoRectangle rect;
+ /* TODO: Destroy all this. */
+ context = pango_xft_get_context (RrDisplay(f->inst), RrScreen(f->inst));
+ pl = pango_layout_new (context);
+ pango_layout_set_text(pl, str, -1);
+ pango_layout_set_font_description(pl, f->pango_font_description);
+ pango_layout_set_single_paragraph_mode(pl, TRUE);
+ pango_layout_get_pixel_extents(pl, NULL, &rect);
+ *x = rect.width + (f->shadow ? ABS(f->offset) : 0);
+ *y = rect.height + (f->shadow ? ABS(f->offset) : 0);
+
+ /*
XGlyphInfo info;
XftTextExtentsUtf8(RrDisplay(f->inst), f->xftfont,
@@ -147,6 +200,8 @@
*x = (signed) info.xOff + (f->shadow ? ABS(f->offset) : 0);
*y = info.height + (f->shadow ? ABS(f->offset) : 0);
+ */
+
}
gint RrFontMeasureString(const RrFont *f, const gchar *str)
@@ -158,8 +213,21 @@
gint RrFontHeight(const RrFont *f)
{
- return f->xftfont->ascent + f->xftfont->descent +
+ /*
+ PangoContext *context = pango_context_new ();
+
+ PangoFontMetrics *metrics = pango_context_get_metrics(context, f->pango_font, NULL);
+
+ gint result = pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent(metrics) +
(f->shadow ? f->offset : 0);
+
+ pango_font_metrics_unref(metrics);
+ TODO: How to Destroy the PangoContext ?
+ return result;
+*/
+ return f->xftfont->ascent + f->xftfont->descent +
+ (f->shadow ? f->offset : 0);
}
gint RrFontMaxCharWidth(const RrFont *f)
@@ -176,6 +244,15 @@
size_t l;
gboolean shortened = FALSE;
+ PangoLayout *pl;
+ PangoLayoutLine *pll;
+ PangoContext *context;
+ GSList *p;
+
+ /* TODO: How to Destroy the PangoContext ? */
+ context = pango_xft_get_context (RrDisplay(t->font->inst), RrScreen(t->font->inst));
+ pl = pango_layout_new (context);
+
/* center vertically */
y = area->y +
(area->height - RrFontHeight(t->font)) / 2;
@@ -216,7 +293,13 @@
l = strlen(text->str); /* number of bytes */
+ pango_layout_set_text(pl, text->str, l);
+ pango_layout_set_font_description(pl, t->font->pango_font_description);
+ pango_layout_set_single_paragraph_mode(pl, TRUE);
+ pll = pango_layout_get_line(pl, 0);
+
if (t->font->shadow) {
+ int x2 = x;
if (t->font->tint >= 0) {
c.color.red = 0;
c.color.green = 0;
@@ -231,20 +314,51 @@
c.color.alpha = 0xffff * -t->font->tint / 100;
c.pixel = WhitePixel(RrDisplay(t->font->inst),
RrScreen(t->font->inst));
- }
- XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
- t->font->xftfont->ascent + y + t->font->offset,
- (FcChar8*)text->str, l);
- }
+ }
+
+ for (p = pll->runs; p != NULL; p = p->next)
+ {
+ PangoLayoutRun *run = p->data;
+ PangoFont *font = run->item->analysis.font;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoRectangle rect;
+
+ pango_glyph_string_extents (glyphs, font, NULL, &rect);
+ pango_xft_render (d, &c, font, glyphs, x2 + t->font->offset, t->font->xftfont->ascent + y + t->font->offset);
+ x2 += rect.width / PANGO_SCALE;
+ }
+
+ /* XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
+ t->font->xftfont->ascent + y + t->font->offset,
+ (FcChar8*)text->str, l);
+ */
+
+ }
c.color.red = t->color->r | t->color->r << 8;
c.color.green = t->color->g | t->color->g << 8;
c.color.blue = t->color->b | t->color->b << 8;
c.color.alpha = 0xff | 0xff << 8; /* fully opaque text */
c.pixel = t->color->pixel;
- XftDrawStringUtf8(d, &c, t->font->xftfont, x,
- t->font->xftfont->ascent + y,
- (FcChar8*)text->str, l);
+ for (p = pll->runs; p != NULL; p = p->next)
+ {
+ PangoLayoutRun *run = p->data;
+ PangoFont *font = run->item->analysis.font;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoRectangle rect;
+
+ pango_glyph_string_extents (glyphs, font, NULL, &rect);
+ pango_xft_render (d, &c, font, glyphs, x, t->font->xftfont->ascent + y);
+ x += rect.width / PANGO_SCALE;
+ }
+
+ /* XftDrawStringUtf8(d, &c, t->font->xftfont, x,
+ t->font->xftfont->ascent + y,
+ (FcChar8*)text->str, l);
+ */
+
+ // pango_layout_line_unref(pll);
+ g_object_unref(pl);
g_string_free(text, TRUE);
return;
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/render/font.h openbox-3.2/render/font.h
--- openbox-3.2.orig/render/font.h 2003-10-15 05:59:35.000000000 +0200
+++ openbox-3.2/render/font.h 2004-10-24 05:32:01.000000000 +0200
@@ -21,9 +21,11 @@
#define __font_h
#include "render.h"
#include "geom.h"
+#include <pango/pango.h>
struct _RrFont {
const RrInstance *inst;
+ PangoFontDescription *pango_font_description;
XftFont *xftfont;
gint elipses_length;
gint shadow;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://icculus.org/pipermail/openbox/attachments/20041024/35350c31/attachment.pgp>
More information about the openbox
mailing list