Enlightenment CVS committal
Author : kwo
Project : e16
Module : e
Dir : e16/e/src
Modified Files:
Makefile.am tclass.h text.c ttfont.c
Added Files:
text_pango.c text_xft.c
Log Message:
Split up font stuff, preparing for loadable font type handlers.
===================================================================
RCS file: /cvs/e/e16/e/src/Makefile.am,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -3 -r1.91 -r1.92
--- Makefile.am 23 Aug 2007 18:48:20 -0000 1.91
+++ Makefile.am 25 Aug 2007 05:38:53 -0000 1.92
@@ -96,12 +96,12 @@
systray.c \
tclass.c tclass.h \
text.c \
+ ttfont.c text_xft.c text_pango.c \
theme.c \
timers.c timers.h \
tooltips.c tooltips.h \
user.c user.h \
util.h \
- ttfont.c \
warp.c \
windowmatch.c windowmatch.h \
x.c xwin.h \
@@ -111,24 +111,29 @@
$(SRCS_ECOMPMGR) \
$(SRCS_SNPRINTF)
-
LDADD = \
$(LTLIBINTL) \
$(LTLIBICONV) \
$(ECORE_LIBS) \
- $(ESD_LIBS) \
- $(IMLIB2_LIBS) \
- $(GLX_LIBS) \
- $(PANGO_LIBS) \
- $(XFT_LIBS) \
- $(X_LIBS) \
- $(SM_LIBS) \
- $(XINERAMA_LIBS) \
- $(X_EXTRA_LIBS) \
- $(E_X_LIBS) \
+ $(ESD_LIBS) \
+ $(IMLIB2_LIBS) \
+ $(GLX_LIBS) \
+ $(PANGO_LIBS) \
+ $(XFT_LIBS) \
+ $(X_LIBS) \
+ $(SM_LIBS) \
+ $(XINERAMA_LIBS) \
+ $(X_EXTRA_LIBS) \
+ $(E_X_LIBS) \
-lX11 -lm
-INCLUDES = -I$(top_builddir) -I$(top_srcdir) $(ECORE_CFLAGS) $(ESD_CFLAGS)
$(IMLIB2_CFLAGS) $(PANGO_CFLAGS) $(XFT_CFLAGS) $(X_CFLAGS)
+INCLUDES = -I$(top_builddir) -I$(top_srcdir) \
+ $(ECORE_CFLAGS) \
+ $(ESD_CFLAGS) \
+ $(IMLIB2_CFLAGS) \
+ $(PANGO_CFLAGS) \
+ $(XFT_CFLAGS) \
+ $(X_CFLAGS)
install-data-local:
$(top_srcdir)/mkinstalldirs $(DESTDIR)$(ENLIGHTENMENT_ROOT)/themes
===================================================================
RCS file: /cvs/e/e16/e/src/tclass.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- tclass.h 7 Aug 2007 22:05:16 -0000 1.21
+++ tclass.h 25 Aug 2007 05:38:53 -0000 1.22
@@ -24,6 +24,7 @@
#ifndef _TCLASS_H
#define _TCLASS_H
+#include "eimage.h"
#include "etypes.h"
#include "xwin.h"
@@ -37,15 +38,19 @@
#define FONT_TO_LEFT 3
#define FONT_TYPE_UNKNOWN 0
-#define FONT_TYPE_IFT 1 /* Imlib2/FreeType */
-#define FONT_TYPE_XFT 2 /* Xft */
-#define FONT_TYPE_XFS 3 /* XFontSet */
#define FONT_TYPE_XFONT 0 /* XFontStruct */
+#define FONT_TYPE_XFS 2 /* XFontSet */
+#define FONT_TYPE_IFT 3 /* Imlib2/FreeType */
+#if USE_XFT
+#define FONT_TYPE_XFT 4 /* Xft */
+#endif
+#if USE_PANGO
#define FONT_TYPE_PANGO_XFT 5 /* Pango-Xft */
+#endif
typedef struct
{
- int (*Load) (TextState * ts, int fallback);
+ int (*Load) (TextState * ts, const char *name);
void (*Destroy) (TextState * ts);
void (*TextSize) (TextState * ts, const char *text, int len,
int *width, int *height, int *ascent);
@@ -115,5 +120,10 @@
int active, int sticky, int state,
const char *text, int x, int y, int w, int h,
int fsize, int justification);
+
+int _xft_FdcInit(TextState * ts, Win win, Drawable draw);
+void _xft_FdcFini(TextState * ts);
+void _xft_FdcSetDrawable(TextState * ts, unsigned long draw);
+void _xft_FdcSetColor(TextState * ts, XColor * xc);
#endif /* _TCLASS_H */
===================================================================
RCS file: /cvs/e/e16/e/src/text.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -3 -r1.90 -r1.91
--- text.c 7 Aug 2007 22:05:16 -0000 1.90
+++ text.c 25 Aug 2007 05:38:53 -0000 1.91
@@ -26,27 +26,6 @@
#include "tclass.h"
#include "xwin.h"
-#ifdef USE_PANGO
-#include <X11/Xft/Xft.h>
-#include <pango/pangoxft.h>
-/* If we have pango-xft we might as well also have xft */
-#undef USE_XFT
-#define USE_XFT 1
-#else
-#undef FONT_TYPE_PANGO_XFT
-#endif
-
-#ifdef USE_XFT
-#include <X11/extensions/Xrender.h>
-#include <X11/Xft/Xft.h>
-#else
-#undef FONT_TYPE_XFT
-#endif
-
-#if FONT_TYPE_IFT
-extern const FontOps FontOpsIft;
-#endif
-
static GC
_get_gc(Win win)
{
@@ -417,268 +396,6 @@
EwcClose();
}
-#if FONT_TYPE_XFT
-/*
- * Xft
- */
-extern const FontOps FontOpsXft;
-
-typedef struct
-{
- XftFont *font;
- Win win;
- Drawable draw;
- XftDraw *xftd;
- XftColor xftc;
-} FontCtxXft;
-
-static int
-_xft_Load(TextState * ts, int fallback __UNUSED__)
-{
- XftFont *font;
- FontCtxXft *fdc;
- const char *name;
-
- name = ts->fontname;
- if (!strncmp(name, "xft:", 4))
- name += 4;
- else if (strchr(name, '/'))
- return -1;
-
- if (name[0] == '-')
- font = XftFontOpenXlfd(disp, VRoot.scr, name);
- else
- font = XftFontOpenName(disp, VRoot.scr, name);
-
- if (!font)
- return -1;
-
-#if 0 /* Debug */
- {
- FT_Face ftf = XftLockFace(font);
-
- if (ftf == NULL)
- return -1;
- Eprintf("Font %s family_name=%s style_name=%s\n", name,
- ftf->family_name, ftf->style_name);
- XftUnlockFace(font);
- }
-#endif
-
- fdc = EMALLOC(FontCtxXft, 1);
- if (!fdc)
- return -1;
- fdc->font = font;
- ts->fdc = fdc;
- ts->need_utf8 = 1;
- ts->type = FONT_TYPE_XFT;
- ts->ops = &FontOpsXft;
- return 0;
-}
-
-static void
-_xft_Unload(TextState * ts)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
-
- XftFontClose(disp, fdc->font);
-}
-
-static void
-_xft_TextSize(TextState * ts, const char *text, int len,
- int *width, int *height, int *ascent)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
- XGlyphInfo gi;
-
- if (len == 0)
- len = strlen(text);
- XftTextExtentsUtf8(disp, fdc->font, (const XftChar8 *)text, len, &gi);
- *width = gi.xOff;
- *height = fdc->font->height;
- if (*height < fdc->font->ascent + fdc->font->descent)
- *height = fdc->font->ascent + fdc->font->descent;
- *ascent = fdc->font->ascent;
-#if 0
- Eprintf("asc/dsc/h=%d/%d/%d x,y=%2d,%d wxh=%dx%d ox,y=%3d,%d: (%d)%s\n",
- fdc->font->ascent, fdc->font->descent, fdc->font->height, gi.x, gi.y,
- gi.width, gi.height, gi.xOff, gi.yOff, len, text);
-#endif
-}
-
-static void
-_xft_TextDraw(TextState * ts, int x, int y, const char *text, int len)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
-
- XftDrawStringUtf8(fdc->xftd, &(fdc->xftc), fdc->font, x, y,
- (const XftChar8 *)text, len);
-}
-
-static int
-_xft_FdcInit(TextState * ts, Win win, Drawable draw)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
-
- fdc->win = win;
- fdc->draw = draw;
-
- fdc->xftd = XftDrawCreate(disp, draw, WinGetVisual(win), WinGetCmap(win));
- if (!fdc->xftd)
- return -1;
- return 0;
-}
-
-static void
-_xft_FdcFini(TextState * ts)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
-
- XftDrawDestroy(fdc->xftd);
-}
-
-static void
-_xft_FdcSetDrawable(TextState * ts, unsigned long draw)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
-
- if (fdc->draw == draw)
- return;
- fdc->draw = draw;
- XftDrawChange(fdc->xftd, draw);
-}
-
-static void
-_xft_FdcSetColor(TextState * ts, XColor * xc)
-{
- FontCtxXft *fdc = (FontCtxXft *) ts->fdc;
- XRenderColor xrc;
-
- xrc.red = xc->red * 256;
- xrc.green = xc->green * 256;
- xrc.blue = xc->blue * 256;
- xrc.alpha = 65535;
-
- XftColorAllocValue(disp, WinGetVisual(fdc->win), WinGetCmap(fdc->win),
- &xrc, &(fdc->xftc));
-}
-
-const FontOps FontOpsXft = {
- _xft_Load, _xft_Unload, _xft_TextSize, TextstateTextFit, _xft_TextDraw,
- _xft_FdcInit, _xft_FdcFini, _xft_FdcSetDrawable, _xft_FdcSetColor
-};
-#endif /* FONT_TYPE_XFT */
-
-#if FONT_TYPE_PANGO_XFT
-/*
- * Pango-Xft
- */
-extern const FontOps FontOpsPangoXft;
-
-static PangoContext *_pango_ctx = NULL;
-
-/* Beware! The layout of FontCtxPangoXft must match FontCtxXft
- * in order to reuse the _xft_Fdc... functions. */
-typedef struct
-{
- PangoFontDescription *font;
- Win win;
- Drawable draw;
- XftDraw *xftd;
- XftColor xftc;
-} FontCtxPangoXft;
-
-static int
-_pango_xft_Load(TextState * ts, int fallback __UNUSED__)
-{
- FontCtxPangoXft *fdc;
- PangoFontDescription *font;
- PangoFontMask flags;
- const char *name;
-
- name = ts->fontname;
- if (strncmp(name, "pango:", 6))
- return -1;
- name += 6;
-
- if (!_pango_ctx)
- _pango_ctx = pango_xft_get_context(disp, VRoot.scr);
- if (!_pango_ctx)
- return -1;
-
- font = pango_font_description_from_string(name);
- if (!font)
- return -1;
-
- flags = pango_font_description_get_set_fields(font);
- if ((flags & PANGO_FONT_MASK_FAMILY) == 0)
- pango_font_description_set_family(font, "sans");
- if ((flags & PANGO_FONT_MASK_SIZE) == 0)
- pango_font_description_set_size(font, 10 * PANGO_SCALE);
-
- fdc = EMALLOC(FontCtxPangoXft, 1);
- if (!fdc)
- return -1;
- fdc->font = font;
- ts->fdc = fdc;
- ts->need_utf8 = 1;
- ts->type = FONT_TYPE_PANGO_XFT;
- ts->ops = &FontOpsPangoXft;
- return 0;
-}
-
-static void
-_pango_xft_Unload(TextState * ts)
-{
- FontCtxPangoXft *fdc = (FontCtxPangoXft *) ts->fdc;
-
- pango_font_description_free(fdc->font);
-}
-
-static void
-_pango_xft_TextSize(TextState * ts, const char *text, int len __UNUSED__,
- int *width, int *height, int *ascent)
-{
- FontCtxPangoXft *fdc = (FontCtxPangoXft *) ts->fdc;
- PangoLayout *layout;
- PangoRectangle logical_rect;
-
- layout = pango_layout_new(_pango_ctx);
- pango_layout_set_text(layout, text, -1);
- pango_layout_set_font_description(layout, fdc->font);
- pango_layout_get_extents(layout, NULL, &logical_rect);
-
- *width = PANGO_PIXELS(logical_rect.x + logical_rect.width);
- *height = PANGO_PIXELS(logical_rect.height);
- *ascent = PANGO_PIXELS(-logical_rect.y);
-
- g_object_unref(layout);
-}
-
-static void
-_pango_xft_TextDraw(TextState * ts, int x, int y, const char *text,
- int len __UNUSED__)
-{
- FontCtxPangoXft *fdc = (FontCtxPangoXft *) ts->fdc;
- PangoLayout *layout;
-
- layout = pango_layout_new(_pango_ctx);
- pango_layout_set_text(layout, text, -1);
- pango_layout_set_font_description(layout, fdc->font);
-
- pango_xft_render_layout(fdc->xftd, &(fdc->xftc), layout,
- x * PANGO_SCALE, y * PANGO_SCALE);
-
- g_object_unref(layout);
-}
-
-const FontOps FontOpsPangoXft = {
- _pango_xft_Load, _pango_xft_Unload,
- _pango_xft_TextSize, TextstateTextFit, _pango_xft_TextDraw,
- _xft_FdcInit, _xft_FdcFini, _xft_FdcSetDrawable, _xft_FdcSetColor
-};
-#endif /* FONT_TYPE_PANGO_XFT */
-
#if FONT_TYPE_XFS
/*
* XFontSet - XCreateFontSet
@@ -695,37 +412,27 @@
} FontCtxXfs;
static int
-_xfs_Load(TextState * ts, int fallback)
+_xfs_Load(TextState * ts, const char *name)
{
XFontSet font;
FontCtxXfs *fdc;
int i, missing_cnt, font_cnt;
- char **missing_list, *def_str, **fn;
+ char **missing_list, *def_str, **fnlr;
XFontStruct **fs;
- font = XCreateFontSet(disp, ts->fontname, &missing_list,
- &missing_cnt, &def_str);
+ font = XCreateFontSet(disp, name, &missing_list, &missing_cnt, &def_str);
if (missing_cnt)
XFreeStringList(missing_list);
-
- if (!font && fallback)
- {
- font = XCreateFontSet(disp, "fixed", &missing_list,
- &missing_cnt, &def_str);
- if (missing_cnt)
- XFreeStringList(missing_list);
- }
-
if (!font)
return -1;
- if (EDebug(EDBUG_TYPE_FONTS))
+ if (EDebug(EDBUG_TYPE_FONTS) >= 2)
{
Eprintf("- XBaseFontNameListOfFontSet %s\n",
XBaseFontNameListOfFontSet(font));
- font_cnt = XFontsOfFontSet(font, &fs, &fn);
+ font_cnt = XFontsOfFontSet(font, &fs, &fnlr);
for (i = 0; i < font_cnt; i++)
- Eprintf("- XFontsOfFontSet %d: %s\n", i, fn[i]);
+ Eprintf("- XFontsOfFontSet %d: %s\n", i, fnlr[i]);
}
fdc = EMALLOC(FontCtxXfs, 1);
@@ -734,7 +441,7 @@
fdc->font = font;
ts->fdc = fdc;
fdc->ascent = 0;
- font_cnt = XFontsOfFontSet(font, &fs, &fn);
+ font_cnt = XFontsOfFontSet(font, &fs, &fnlr);
for (i = 0; i < font_cnt; i++)
fdc->ascent = MAX(fs[i]->ascent, fdc->ascent);
ts->type = FONT_TYPE_XFS;
@@ -822,24 +529,15 @@
} FontCtxXfont;
static int
-_xfont_Load(TextState * ts, int fallback __UNUSED__)
+_xfont_Load(TextState * ts, const char *name)
{
- XFontStruct *font = NULL;
+ XFontStruct *font;
FontCtxXfont *fdc;
- if (strchr(ts->fontname, ',') == NULL)
- font = XLoadQueryFont(disp, ts->fontname);
- if (font)
- goto done;
-
- /* This one really should succeed! */
- font = XLoadQueryFont(disp, "fixed");
- if (font)
- goto done;
-
- return -1; /* Failed */
+ font = XLoadQueryFont(disp, name);
+ if (!font)
+ return -1;
- done:
fdc = EMALLOC(FontCtxXfont, 1);
if (!fdc)
return -1;
@@ -952,9 +650,51 @@
ts->ops->TextDraw(ts, x, y, text, len);
}
+typedef struct
+{
+ const char *type;
+ const FontOps *ops;
+ char checked;
+} FontHandler;
+
+#define FONT(type, ops, opsm) { type, ops, 0 }
+
+#if FONT_TYPE_IFT
+extern const FontOps FontOps_ift;
+#endif
+#if FONT_TYPE_XFT
+extern const FontOps FontOps_xft;
+#endif
+#if FONT_TYPE_PANGO_XFT
+extern const FontOps FontOps_pango;
+#endif
+
+static FontHandler fhs[] = {
+#if FONT_TYPE_XFONT
+ FONT("xfont", &FontOpsXfont, &FontOpsXfont), /* XFontStruct -
XLoadQueryFont */
+#endif
+#if FONT_TYPE_XFS
+ FONT("xfs", &FontOpsXfs, &FontOpsXfs), /* XFontSet - XCreateFontSet */
+#endif
+#if FONT_TYPE_IFT
+ FONT("ift", &FontOps_ift, NULL), /* Imlib2/FreeType */
+#endif
+#if FONT_TYPE_XFT
+ FONT("xft", &FontOps_xft, NULL), /* Xft */
+#endif
+#if FONT_TYPE_PANGO_XFT
+ FONT("pango", &FontOps_pango, NULL), /* Pango-Xft */
+#endif
+ {NULL, NULL, 0},
+};
+
static void
TextStateLoadFont(TextState * ts)
{
+ const char *s, *type, *name;
+ char buf[1024];
+ FontHandler *fhp = fhs;
+
if (!ts->fontname)
return;
@@ -964,28 +704,48 @@
ts->need_utf8 = Mode.locale.utf8_int;
+ type = NULL;
+ name = ts->fontname;
#if FONT_TYPE_IFT
- if (!FontOpsIft.Load(ts, 0)) /* Imlib2/FreeType */
- goto done;
+ if (strchr(ts->fontname, '/'))
+ {
+ type = "ift";
+ goto check;
+ }
#endif
#if FONT_TYPE_XFS
- if (!FontOpsXfs.Load(ts, 0)) /* XFontSet - XCreateFontSet */
- goto done;
-#endif
-#if FONT_TYPE_PANGO_XFT
- if (!FontOpsPangoXft.Load(ts, 0)) /* Pango-Xft */
- goto done;
-#endif
-#if FONT_TYPE_XFT
- if (!FontOpsXft.Load(ts, 0)) /* Xft */
- goto done;
+ if (ts->fontname[0] == '-')
+ {
+ type = "xfs";
+ goto check;
+ }
#endif
+ s = strchr(ts->fontname, ':');
+ if (!s || s == ts->fontname)
+ goto fallback;
+ if (s - ts->fontname > 16)
+ goto fallback;
+ memcpy(buf, ts->fontname, s - ts->fontname);
+ buf[s - ts->fontname] = '\0';
+ type = buf;
+ name = s + 1;
+
+ check:
+ for (fhp = fhs; fhp->type; fhp++)
+ {
+ if (strcmp(fhp->type, type))
+ continue;
+ ts->ops = fhp->ops;
+ ts->ops->Load(ts, name);
+ goto done;
+ }
+ fallback:
#if FONT_TYPE_XFS
- if (!FontOpsXfs.Load(ts, 1)) /* XFontSet - XCreateFontSet */
+ if (!FontOpsXfs.Load(ts, "fixed")) /* XFontSet - XCreateFontSet */
goto done;
#endif
#if FONT_TYPE_XFONT
- if (!FontOpsXfont.Load(ts, 1)) /* XFontStruct - XLoadQueryFont */
+ if (!FontOpsXfont.Load(ts, "fixed")) /* XFontStruct - XLoadQueryFont
*/
goto done;
#endif
===================================================================
RCS file: /cvs/e/e16/e/src/ttfont.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -3 -r1.60 -r1.61
--- ttfont.c 17 Jan 2007 01:10:43 -0000 1.60
+++ ttfont.c 25 Aug 2007 05:38:53 -0000 1.61
@@ -22,11 +22,16 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "E.h"
-#include "eimage.h"
#include "tclass.h"
-#include <Imlib2.h>
#if FONT_TYPE_IFT
+#include "eimage.h"
+#include <Imlib2.h>
+
+/*
+ * Imlib2/FreeType
+ */
+extern const FontOps FontOps_ift;
typedef void EFont;
@@ -97,11 +102,6 @@
imlib_text_draw(x, y - imlib_get_font_ascent(), text);
}
-/*
- * Imlib2/FreeType
- */
-extern const FontOps FontOpsIft;
-
typedef struct
{
EFont *font;
@@ -110,7 +110,7 @@
} FontCtxIft;
static int
-_ift_Load(TextState * ts, int fallback __UNUSED__)
+_ift_Load(TextState * ts, const char *name __UNUSED__)
{
EFont *font;
FontCtxIft *fdc;
@@ -138,7 +138,7 @@
ts->fdc = fdc;
ts->need_utf8 = 1;
ts->type = FONT_TYPE_IFT;
- ts->ops = &FontOpsIft;
+ ts->ops = &FontOps_ift;
return 0;
}
@@ -191,7 +191,7 @@
EGetColor(xc, &(fdc->r), &(fdc->g), &(fdc->b));
}
-const FontOps FontOpsIft = {
+const FontOps FontOps_ift = {
_ift_Load, _ift_Unload, _ift_TextSize, TextstateTextFit, _ift_TextDraw,
_ift_FdcInit, NULL, _ift_FdcSetDrawable, _ift_FdcSetColor
};
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs