Skip to content

Commit

Permalink
Support XFT and Bitmap fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
ideasman42 committed Aug 10, 2017
1 parent 32784ef commit 313f408
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 36 deletions.
5 changes: 5 additions & 0 deletions de/colour.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ typedef XftColor DEColour;
typedef unsigned long DEColour;
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_XFT
# define PIXEL(x) (x).pixel
#else /* HAVE_X11_XFT */
# define PIXEL(x) x
#endif /* HAVE_X11_XFT */

DECLSTRUCT(DEColourGroup){
GrStyleSpec spec;
Expand Down
8 changes: 0 additions & 8 deletions de/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@

#include <X11/extensions/shape.h>


#ifdef HAVE_X11_XFT
# define PIXEL(x) (x).pixel
#else /* HAVE_X11_XFT */
# define PIXEL(x) x
#endif /* HAVE_X11_XFT */


/*{{{ Colour group lookup */


Expand Down
94 changes: 68 additions & 26 deletions de/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#include "font.h"
#ifdef HAVE_X11_XFT
#include <fontconfig/fontconfig.h>
#else
#include "fontset.h"
#endif /* HAVE_X11_XFT */
#ifdef HAVE_X11_BMF
#include "fontset.h"
#endif /* HAVE_X11_BMF */
#include "brush.h"
#include "precompose.h"

Expand Down Expand Up @@ -110,13 +111,15 @@ const char *de_default_fontname()

DEFont *de_load_font(const char *fontname)
{
DEFont *fnt;
const char *default_fontname=de_default_fontname();
#ifdef HAVE_X11_XFT
XftFont *font;
XftFont *font=NULL;
#endif
DEFont *fnt;
#ifdef HAVE_X11_BMF
XFontSet fontset=NULL;
XFontStruct *fontstruct=NULL;
const char *default_fontname=de_default_fontname();
#endif

assert(fontname!=NULL);

Expand All @@ -133,7 +136,11 @@ DEFont *de_load_font(const char *fontname)
if(strncmp(fontname, "xft:", 4)==0){
font=XftFontOpenName(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname+4);
}else{
#ifdef HAVE_X11_BMF
goto bitmap_font;
#else
font=XftFontOpenXlfd(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname);
#endif
}

if(font==NULL){
Expand All @@ -149,7 +156,11 @@ DEFont *de_load_font(const char *fontname)
}else{
FcPatternPrint(font->pattern);
}
#else /* HAVE_X11_XFT */
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_BMF
bitmap_font:

if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){
LOG(DEBUG, FONT, "Loading fontset %s", fontname);
fontset=de_create_font_set(fontname);
Expand Down Expand Up @@ -177,16 +188,17 @@ DEFont *de_load_font(const char *fontname)
}
return NULL;
}
#endif

#endif /* HAVE_X11_XFT */
fnt=ALLOC(DEFont);

if(fnt==NULL)
return NULL;

#ifdef HAVE_X11_XFT
fnt->font=font;
#else
#endif
#ifdef HAVE_X11_BMF
fnt->fontset=fontset;
fnt->fontstruct=fontstruct;
#endif
Expand Down Expand Up @@ -289,7 +301,8 @@ void defont_get_font_extents(DEFont *font, GrFontExtents *fnte)
fnte->baseline=font->font->ascent;
return;
}
#else /* HAVE_X11_XFT */
#endif /* HAVE_X11_XFT */
#ifdef HAVE_X11_BMF
if(font->fontset!=NULL){
XFontSetExtents *ext=XExtentsOfFontSet(font->fontset);
if(ext==NULL)
Expand All @@ -305,8 +318,8 @@ void defont_get_font_extents(DEFont *font, GrFontExtents *fnte)
fnte->baseline=fnt->ascent;
return;
}
#endif /* HAVE_X11_XFT */
fail:
#endif /* HAVE_X11_BMF */
DE_RESET_FONT_EXTENTS(fnte);
}

Expand All @@ -330,10 +343,10 @@ uint defont_get_text_width(DEFont *font, const char *text, uint len)
else
XftTextExtents8(ioncore_g.dpy, font->font, (XftChar8*)text, len, &extents);
return extents.xOff;
}else{
return 0;
}
#else /* HAVE_X11_XFT */
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_BMF
if(font->fontset!=NULL){
XRectangle lext;
#ifdef CF_DE_USE_XUTF8
Expand All @@ -358,10 +371,11 @@ uint defont_get_text_width(DEFont *font, const char *text, uint len)
}else{
return XTextWidth(font->fontstruct, text, len);
}
}else{
}
#endif /* HAVE_X11_BMF */
else{
return 0;
}
#endif /* HAVE_X11_XFT */
}


Expand All @@ -372,10 +386,11 @@ uint defont_get_text_width(DEFont *font, const char *text, uint len)


#ifdef HAVE_X11_XFT
void debrush_do_draw_string_default(DEBrush *brush,
int x, int y, const char *str,
int len, bool needfill,
DEColourGroup *colours)
static void debrush_do_draw_string_default_xft(
DEBrush *brush,
int x, int y, const char *str,
int len, bool needfill,
DEColourGroup *colours)
{
Window win = brush->win;
GC gc=brush->d->normal_gc;
Expand Down Expand Up @@ -407,17 +422,21 @@ void debrush_do_draw_string_default(DEBrush *brush,
XftDrawString8(draw, &(colours->fg), font, x, y, (XftChar8*)str, len);
}
}
#else /* HAVE_X11_XFT */
void debrush_do_draw_string_default(DEBrush *brush, int x, int y,
const char *str, int len, bool needfill,
DEColourGroup *colours)
#endif /* HAVE_X11_XFT */

#ifdef HAVE_X11_BMF
void debrush_do_draw_string_default_bmf(
DEBrush *brush,
int x, int y, const char *str,
int len, bool needfill,
DEColourGroup *colours)
{
GC gc=brush->d->normal_gc;

if(brush->d->font==NULL)
return;

XSetForeground(ioncore_g.dpy, gc, colours->fg);
XSetForeground(ioncore_g.dpy, gc, PIXEL(colours->fg));

if(!needfill){
if(brush->d->font->fontset!=NULL){
Expand All @@ -442,7 +461,7 @@ void debrush_do_draw_string_default(DEBrush *brush, int x, int y,
}
}
}else{
XSetBackground(ioncore_g.dpy, gc, colours->bg);
XSetBackground(ioncore_g.dpy, gc, PIXEL(colours->bg));
if(brush->d->font->fontset!=NULL){
#ifdef CF_DE_USE_XUTF8
if(ioncore_g.enc_utf8)
Expand All @@ -466,8 +485,31 @@ void debrush_do_draw_string_default(DEBrush *brush, int x, int y,
}
}
}
#endif /* HAVE_X11_BMF */

void debrush_do_draw_string_default(
DEBrush *brush,
int x, int y, const char *str,
int len, bool needfill,
DEColourGroup *colours)
{
if (brush->d->font) {
#ifdef HAVE_X11_XFT
if (brush->d->font->font) {
debrush_do_draw_string_default_xft(brush, x, y, str, len, needfill, colours);
return;
}
#endif
#ifdef HAVE_X11_BMF
if (brush->d->font->fontset) {
debrush_do_draw_string_default_bmf(brush, x, y, str, len, needfill, colours);
return;
}
#endif
}

}

#endif /* HAVE_X11_XFT */

void debrush_do_draw_string(DEBrush *brush, int x, int y,
const char *str, int len, bool needfill,
Expand Down
2 changes: 2 additions & 0 deletions de/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ INTRSTRUCT(DEFont);
DECLSTRUCT(DEFont){
char *pattern;
int refcount;
#ifdef HAVE_X11_BMF
XFontSet fontset;
XFontStruct *fontstruct;
#endif /* HAVE_X11_BMF */
#ifdef HAVE_X11_XFT /* HAVE_X11_XFT */
XftFont *font;
#endif /* HAVE_X11_XFT */
Expand Down
4 changes: 2 additions & 2 deletions de/style.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void destyle_create_tab_gcs(DEStyle *style)
/*gcv.function=GXclear;*/
gcv.stipple=stipple_pixmap;
gcvmask=GCFillStyle|GCStipple/*|GCFunction*/;
#ifndef HAVE_X11_XFT
#ifdef HAVE_X11_BMF
if(style->font!=NULL && style->font->fontstruct!=NULL){
gcv.font=style->font->fontstruct->fid;
gcvmask|=GCFont;
}
#endif /* HAVE_X11_XFT */
#endif /* HAVE_X11_BMF */

style->stipple_gc=XCreateGC(dpy, root, gcvmask, &gcv);
XCopyGC(dpy, style->normal_gc,
Expand Down
3 changes: 3 additions & 0 deletions system-autodetect.mk
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ ifeq ($(USE_XFT),1)
X11_INCLUDES += `pkg-config xft --cflags`
X11_LIBS += `pkg-config xft --libs`
DEFINES += -DHAVE_X11_XFT
DEFINES += -DHAVE_X11_BMF
else
DEFINES += -DHAVE_X11_BMF
endif


Expand Down

0 comments on commit 313f408

Please sign in to comment.