| Attached Files | 0001-Graphics-Use-modern-X-fonts-instead-of-X-core-fonts.patch [^] (9,122 bytes) 2009-11-12 18:01 [Show Content] [Hide Content]From 1c7d069afa53752b63c347ac590eb0930fb9d867 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones@redhat.com>
Date: Thu, 12 Nov 2009 16:54:10 +0000
Subject: [PATCH] Graphics: Use modern X fonts instead of X core fonts.
---
configure | 23 +++++++++++++---
otherlibs/graph/Makefile | 6 ++--
otherlibs/graph/events.c | 2 -
otherlibs/graph/libgraph.h | 4 ++-
otherlibs/graph/open.c | 4 +-
otherlibs/graph/text.c | 65 +++++++++++++++++++++++++++++++++----------
6 files changed, 77 insertions(+), 27 deletions(-)
diff --git a/configure b/configure
index cefeda3..a9d1681 100755
--- a/configure
+++ b/configure
@@ -1334,14 +1334,27 @@ do
fi
done
+# Xft library.
+xft_cflags="not found"
+xft_libs="not found"
-if test "$x11_include" = "not found" || test "$x11_link" = "not found"
+if pkg-config --cflags xft > /dev/null 2>/dev/null; then
+ xft_cflags=`pkg-config --cflags xft`
+fi
+
+if pkg-config --libs xft > /dev/null 2>/dev/null; then
+ xft_libs=`pkg-config --libs xft`
+fi
+
+if test "$x11_include" = "not found" || test "$x11_link" = "not found" || test "$xft_cflags" = "not found" || test "$xft_libs" = "not found"
then
- echo "X11 not found, the \"graph\" library will not be supported."
+ echo "X11 and Xft not found, the \"graph\" library will not be supported."
x11_include=""
else
echo "Location of X11 include files: $x11_include/X11"
echo "Options for linking with X11: $x11_link"
+ echo "CFLAGS for Xft programs: $xft_cflags"
+ echo "LIBS for Xft programs:: $xft_libs"
otherlibraries="$otherlibraries graph"
if test "$x11_include" = "/usr/include"; then
x11_include=""
@@ -1351,6 +1364,8 @@ else
fi
echo "X11_INCLUDES=$x11_include" >> Makefile
echo "X11_LINK=$x11_link" >> Makefile
+echo "XFT_CFLAGS=$xft_cflags" >> Makefile
+echo "XFT_LIBS=$xft_libs" >> Makefile
# See if we can compile the dbm library
@@ -1663,8 +1678,8 @@ echo " target architecture ...... $bng_arch (asm level $bng_asm_level)"
if test "$x11_include" != "not found" && test "$x11_lib" != "not found"; then
echo "Configuration for the \"graph\" library:"
-echo " options for compiling .... $x11_include"
-echo " options for linking ...... $x11_link"
+echo " options for compiling .... $xft_cflags $x11_include"
+echo " options for linking ...... $xft_libs"
fi
if test $has_tk = true; then
diff --git a/otherlibs/graph/Makefile b/otherlibs/graph/Makefile
index 2be9844..1319b63 100644
--- a/otherlibs/graph/Makefile
+++ b/otherlibs/graph/Makefile
@@ -20,10 +20,10 @@ COBJS=open.o draw.o fill.o color.o text.o \
image.o make_img.o dump_img.o point_col.o sound.o events.o \
subwindow.o
CAMLOBJS=graphics.cmo graphicsX11.cmo
-LINKOPTS=-cclib "\"$(X11_LINK)\""
-LDOPTS=-ldopt "$(X11_LINK)"
+LINKOPTS=-cclib "\"$(XFT_LIBS)\""
+LDOPTS=-ldopt "$(XFT_LIBS)"
-EXTRACFLAGS=$(X11_INCLUDES)
+EXTRACFLAGS=$(XFT_CFLAGS) $(X11_INCLUDES)
include ../Makefile
diff --git a/otherlibs/graph/events.c b/otherlibs/graph/events.c
index 069fa48..6a2fb10 100644
--- a/otherlibs/graph/events.c
+++ b/otherlibs/graph/events.c
@@ -88,8 +88,6 @@ void caml_gr_handle_event(XEvent * event)
XFillRectangle(caml_gr_display, newbstore.win, newbstore.gc,
0, 0, newbstore.w, newbstore.h);
XSetForeground(caml_gr_display, newbstore.gc, caml_gr_color);
- if (caml_gr_font != NULL)
- XSetFont(caml_gr_display, newbstore.gc, caml_gr_font->fid);
/* Copy the old backing store into the new one */
XCopyArea(caml_gr_display, caml_gr_bstore.win, newbstore.win, newbstore.gc,
diff --git a/otherlibs/graph/libgraph.h b/otherlibs/graph/libgraph.h
index 322a036..8a7b658 100644
--- a/otherlibs/graph/libgraph.h
+++ b/otherlibs/graph/libgraph.h
@@ -16,6 +16,8 @@
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <X11/Xft/Xft.h>
+#include <X11/extensions/Xrender.h>
#include <mlvalues.h>
struct canvas {
@@ -36,7 +38,7 @@ extern Bool caml_gr_display_modeflag; /* Display-mode flag */
extern Bool caml_gr_remember_modeflag; /* Remember-mode flag */
extern int caml_gr_x, caml_gr_y; /* Coordinates of the current point */
extern int caml_gr_color; /* Current *CAML* drawing color (can be -1) */
-extern XFontStruct * caml_gr_font; /* Current font */
+extern XftFont * caml_gr_font; /* Current font */
extern long caml_gr_selected_events; /* Events we are interested in */
extern Bool caml_gr_ignore_sigio; /* Whether to consume events on sigio */
diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c
index 82a4c0f..16cd457 100644
--- a/otherlibs/graph/open.c
+++ b/otherlibs/graph/open.c
@@ -38,7 +38,7 @@ Bool caml_gr_display_modeflag;
Bool caml_gr_remember_modeflag;
int caml_gr_x, caml_gr_y;
int caml_gr_color;
-extern XFontStruct * caml_gr_font;
+extern XftFont * caml_gr_font;
long caml_gr_selected_events;
Bool caml_gr_ignore_sigio = False;
static Bool caml_gr_initialized = False;
@@ -213,7 +213,7 @@ value caml_gr_close_graph(void)
setitimer(ITIMER_REAL, &it, NULL);
#endif
caml_gr_initialized = False;
- if (caml_gr_font != NULL) { XFreeFont(caml_gr_display, caml_gr_font); caml_gr_font = NULL; }
+ if (caml_gr_font != NULL) { XftFontClose (caml_gr_display, caml_gr_font); caml_gr_font = NULL; }
XFreeGC(caml_gr_display, caml_gr_window.gc);
XDestroyWindow(caml_gr_display, caml_gr_window.win);
XFreeGC(caml_gr_display, caml_gr_bstore.gc);
diff --git a/otherlibs/graph/text.c b/otherlibs/graph/text.c
index f4d980a..5a0e200 100644
--- a/otherlibs/graph/text.c
+++ b/otherlibs/graph/text.c
@@ -16,16 +16,22 @@
#include "libgraph.h"
#include <alloc.h>
-XFontStruct * caml_gr_font = NULL;
+XftFont * caml_gr_font = NULL;
static void caml_gr_get_font(char *fontname)
{
- XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname);
+ XftFont * font;
+
+ /* Is it a X Logical Font Description? LFDs start with a '-'
+ * character. If not, use nicer FontConfig names like "Courier-12".
+ */
+ if (fontname[0] == '-')
+ font = XftFontOpenXlfd (caml_gr_display, caml_gr_screen, fontname);
+ else
+ font = XftFontOpenName (caml_gr_display, caml_gr_screen, fontname);
if (font == NULL) caml_gr_fail("cannot find font %s", fontname);
- if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font);
+ if (caml_gr_font != NULL) XftFontClose (caml_gr_display, caml_gr_font);
caml_gr_font = font;
- XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid);
- XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid);
}
value caml_gr_set_font(value fontname)
@@ -42,16 +48,41 @@ value caml_gr_set_text_size (value sz)
static void caml_gr_draw_text(char *txt, int len)
{
+ int rgb;
+ XftColor xftcol;
+ XftDraw *d;
+ Visual *visual = DefaultVisual (caml_gr_display,caml_gr_screen);
+ XGlyphInfo info;
+
+ rgb = caml_gr_rgb_pixel (caml_gr_color);
+ xftcol.pixel = rgb;
+ /* The range of these fields is 0..0xffff */
+ xftcol.color.red = rgb >> 8;
+ xftcol.color.green = (rgb & 0xff00);
+ xftcol.color.blue = (rgb & 0xff) << 8;
+ xftcol.color.alpha = 0xffff;
+
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
- if (caml_gr_remember_modeflag)
- XDrawString(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
- caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
+ if (caml_gr_remember_modeflag) {
+ d = XftDrawCreate (caml_gr_display, caml_gr_bstore.win,
+ visual, caml_gr_colormap);
+ XftDrawString8 (d, &xftcol, caml_gr_font,
+ caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1,
+ (const FcChar8 *) txt, len);
+ }
+
if (caml_gr_display_modeflag) {
- XDrawString(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
- caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
+ d = XftDrawCreate (caml_gr_display, caml_gr_window.win,
+ visual, caml_gr_colormap);
+ XftDrawString8 (d, &xftcol, caml_gr_font,
+ caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1,
+ (const FcChar8 *) txt, len);
XFlush(caml_gr_display);
}
- caml_gr_x += XTextWidth(caml_gr_font, txt, len);
+
+ XftTextExtents8 (caml_gr_display, caml_gr_font,
+ (const FcChar8 *) txt, len, &info);
+ caml_gr_x += info.width;
}
value caml_gr_draw_char(value chr)
@@ -72,13 +103,17 @@ value caml_gr_draw_string(value str)
value caml_gr_text_size(value str)
{
- int width;
+ XGlyphInfo info;
value res;
+
caml_gr_check_open();
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
- width = XTextWidth(caml_gr_font, String_val(str), string_length(str));
+
+ XftTextExtents8 (caml_gr_display, caml_gr_font,
+ (const FcChar8 *) (String_val (str)), string_length (str),
+ &info);
res = alloc_small(2, 0);
- Field(res, 0) = Val_int(width);
- Field(res, 1) = Val_int(caml_gr_font->ascent + caml_gr_font->descent);
+ Field(res, 0) = Val_int(info.width);
+ Field(res, 1) = Val_int(info.height);
return res;
}
--
1.6.5.2
0001-Graphics-Use-modern-X-fonts-instead-of-X-core-fonts-2.patch [^] (9,164 bytes) 2009-11-12 18:33 [Show Content] [Hide Content]From 454d46e2297de0f905053ec21261927086019d7f Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones@redhat.com>
Date: Thu, 12 Nov 2009 16:54:10 +0000
Subject: [PATCH] Graphics: Use modern X fonts instead of X core fonts.
---
configure | 23 ++++++++++++--
otherlibs/graph/Makefile | 6 ++--
otherlibs/graph/events.c | 2 -
otherlibs/graph/libgraph.h | 4 ++-
otherlibs/graph/open.c | 4 +-
otherlibs/graph/text.c | 68 ++++++++++++++++++++++++++++++++++---------
6 files changed, 80 insertions(+), 27 deletions(-)
diff --git a/configure b/configure
index cefeda3..a9d1681 100755
--- a/configure
+++ b/configure
@@ -1334,14 +1334,27 @@ do
fi
done
+# Xft library.
+xft_cflags="not found"
+xft_libs="not found"
-if test "$x11_include" = "not found" || test "$x11_link" = "not found"
+if pkg-config --cflags xft > /dev/null 2>/dev/null; then
+ xft_cflags=`pkg-config --cflags xft`
+fi
+
+if pkg-config --libs xft > /dev/null 2>/dev/null; then
+ xft_libs=`pkg-config --libs xft`
+fi
+
+if test "$x11_include" = "not found" || test "$x11_link" = "not found" || test "$xft_cflags" = "not found" || test "$xft_libs" = "not found"
then
- echo "X11 not found, the \"graph\" library will not be supported."
+ echo "X11 and Xft not found, the \"graph\" library will not be supported."
x11_include=""
else
echo "Location of X11 include files: $x11_include/X11"
echo "Options for linking with X11: $x11_link"
+ echo "CFLAGS for Xft programs: $xft_cflags"
+ echo "LIBS for Xft programs:: $xft_libs"
otherlibraries="$otherlibraries graph"
if test "$x11_include" = "/usr/include"; then
x11_include=""
@@ -1351,6 +1364,8 @@ else
fi
echo "X11_INCLUDES=$x11_include" >> Makefile
echo "X11_LINK=$x11_link" >> Makefile
+echo "XFT_CFLAGS=$xft_cflags" >> Makefile
+echo "XFT_LIBS=$xft_libs" >> Makefile
# See if we can compile the dbm library
@@ -1663,8 +1678,8 @@ echo " target architecture ...... $bng_arch (asm level $bng_asm_level)"
if test "$x11_include" != "not found" && test "$x11_lib" != "not found"; then
echo "Configuration for the \"graph\" library:"
-echo " options for compiling .... $x11_include"
-echo " options for linking ...... $x11_link"
+echo " options for compiling .... $xft_cflags $x11_include"
+echo " options for linking ...... $xft_libs"
fi
if test $has_tk = true; then
diff --git a/otherlibs/graph/Makefile b/otherlibs/graph/Makefile
index 2be9844..1319b63 100644
--- a/otherlibs/graph/Makefile
+++ b/otherlibs/graph/Makefile
@@ -20,10 +20,10 @@ COBJS=open.o draw.o fill.o color.o text.o \
image.o make_img.o dump_img.o point_col.o sound.o events.o \
subwindow.o
CAMLOBJS=graphics.cmo graphicsX11.cmo
-LINKOPTS=-cclib "\"$(X11_LINK)\""
-LDOPTS=-ldopt "$(X11_LINK)"
+LINKOPTS=-cclib "\"$(XFT_LIBS)\""
+LDOPTS=-ldopt "$(XFT_LIBS)"
-EXTRACFLAGS=$(X11_INCLUDES)
+EXTRACFLAGS=$(XFT_CFLAGS) $(X11_INCLUDES)
include ../Makefile
diff --git a/otherlibs/graph/events.c b/otherlibs/graph/events.c
index 069fa48..6a2fb10 100644
--- a/otherlibs/graph/events.c
+++ b/otherlibs/graph/events.c
@@ -88,8 +88,6 @@ void caml_gr_handle_event(XEvent * event)
XFillRectangle(caml_gr_display, newbstore.win, newbstore.gc,
0, 0, newbstore.w, newbstore.h);
XSetForeground(caml_gr_display, newbstore.gc, caml_gr_color);
- if (caml_gr_font != NULL)
- XSetFont(caml_gr_display, newbstore.gc, caml_gr_font->fid);
/* Copy the old backing store into the new one */
XCopyArea(caml_gr_display, caml_gr_bstore.win, newbstore.win, newbstore.gc,
diff --git a/otherlibs/graph/libgraph.h b/otherlibs/graph/libgraph.h
index 322a036..8a7b658 100644
--- a/otherlibs/graph/libgraph.h
+++ b/otherlibs/graph/libgraph.h
@@ -16,6 +16,8 @@
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <X11/Xft/Xft.h>
+#include <X11/extensions/Xrender.h>
#include <mlvalues.h>
struct canvas {
@@ -36,7 +38,7 @@ extern Bool caml_gr_display_modeflag; /* Display-mode flag */
extern Bool caml_gr_remember_modeflag; /* Remember-mode flag */
extern int caml_gr_x, caml_gr_y; /* Coordinates of the current point */
extern int caml_gr_color; /* Current *CAML* drawing color (can be -1) */
-extern XFontStruct * caml_gr_font; /* Current font */
+extern XftFont * caml_gr_font; /* Current font */
extern long caml_gr_selected_events; /* Events we are interested in */
extern Bool caml_gr_ignore_sigio; /* Whether to consume events on sigio */
diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c
index 82a4c0f..16cd457 100644
--- a/otherlibs/graph/open.c
+++ b/otherlibs/graph/open.c
@@ -38,7 +38,7 @@ Bool caml_gr_display_modeflag;
Bool caml_gr_remember_modeflag;
int caml_gr_x, caml_gr_y;
int caml_gr_color;
-extern XFontStruct * caml_gr_font;
+extern XftFont * caml_gr_font;
long caml_gr_selected_events;
Bool caml_gr_ignore_sigio = False;
static Bool caml_gr_initialized = False;
@@ -213,7 +213,7 @@ value caml_gr_close_graph(void)
setitimer(ITIMER_REAL, &it, NULL);
#endif
caml_gr_initialized = False;
- if (caml_gr_font != NULL) { XFreeFont(caml_gr_display, caml_gr_font); caml_gr_font = NULL; }
+ if (caml_gr_font != NULL) { XftFontClose (caml_gr_display, caml_gr_font); caml_gr_font = NULL; }
XFreeGC(caml_gr_display, caml_gr_window.gc);
XDestroyWindow(caml_gr_display, caml_gr_window.win);
XFreeGC(caml_gr_display, caml_gr_bstore.gc);
diff --git a/otherlibs/graph/text.c b/otherlibs/graph/text.c
index f4d980a..07e05ea 100644
--- a/otherlibs/graph/text.c
+++ b/otherlibs/graph/text.c
@@ -16,16 +16,22 @@
#include "libgraph.h"
#include <alloc.h>
-XFontStruct * caml_gr_font = NULL;
+XftFont * caml_gr_font = NULL;
static void caml_gr_get_font(char *fontname)
{
- XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname);
+ XftFont * font;
+
+ /* Is it a X Logical Font Description? LFDs start with a '-'
+ * character. If not, use nicer FontConfig names like "Courier-12".
+ */
+ if (fontname[0] == '-')
+ font = XftFontOpenXlfd (caml_gr_display, caml_gr_screen, fontname);
+ else
+ font = XftFontOpenName (caml_gr_display, caml_gr_screen, fontname);
if (font == NULL) caml_gr_fail("cannot find font %s", fontname);
- if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font);
+ if (caml_gr_font != NULL) XftFontClose (caml_gr_display, caml_gr_font);
caml_gr_font = font;
- XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid);
- XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid);
}
value caml_gr_set_font(value fontname)
@@ -42,16 +48,44 @@ value caml_gr_set_text_size (value sz)
static void caml_gr_draw_text(char *txt, int len)
{
+ int rgb;
+ XftColor xftcol;
+ XftDraw *d = NULL;
+ Visual *visual = DefaultVisual (caml_gr_display,caml_gr_screen);
+ XGlyphInfo info;
+
+ rgb = caml_gr_rgb_pixel (caml_gr_color);
+ xftcol.pixel = rgb;
+ /* The range of these fields is 0..0xffff */
+ xftcol.color.red = rgb >> 8;
+ xftcol.color.green = (rgb & 0xff00);
+ xftcol.color.blue = (rgb & 0xff) << 8;
+ xftcol.color.alpha = 0xffff;
+
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
- if (caml_gr_remember_modeflag)
- XDrawString(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
- caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
+ if (caml_gr_remember_modeflag) {
+ d = XftDrawCreate (caml_gr_display, caml_gr_bstore.win,
+ visual, caml_gr_colormap);
+ XftDrawString8 (d, &xftcol, caml_gr_font,
+ caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1,
+ (const FcChar8 *) txt, len);
+ }
+
if (caml_gr_display_modeflag) {
- XDrawString(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
- caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
+ d = XftDrawCreate (caml_gr_display, caml_gr_window.win,
+ visual, caml_gr_colormap);
+ XftDrawString8 (d, &xftcol, caml_gr_font,
+ caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1,
+ (const FcChar8 *) txt, len);
XFlush(caml_gr_display);
}
- caml_gr_x += XTextWidth(caml_gr_font, txt, len);
+
+ if (d)
+ XftDrawDestroy (d);
+
+ XftTextExtents8 (caml_gr_display, caml_gr_font,
+ (const FcChar8 *) txt, len, &info);
+ caml_gr_x += info.width;
}
value caml_gr_draw_char(value chr)
@@ -72,13 +106,17 @@ value caml_gr_draw_string(value str)
value caml_gr_text_size(value str)
{
- int width;
+ XGlyphInfo info;
value res;
+
caml_gr_check_open();
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
- width = XTextWidth(caml_gr_font, String_val(str), string_length(str));
+
+ XftTextExtents8 (caml_gr_display, caml_gr_font,
+ (const FcChar8 *) (String_val (str)), string_length (str),
+ &info);
res = alloc_small(2, 0);
- Field(res, 0) = Val_int(width);
- Field(res, 1) = Val_int(caml_gr_font->ascent + caml_gr_font->descent);
+ Field(res, 0) = Val_int(info.width);
+ Field(res, 1) = Val_int(info.height);
return res;
}
--
1.6.5.2
|